import type { PaymentMethodCreateParams } from '@stripe/stripe-react-native' ; import React , { useState } from 'react' ; import { Alert , StyleSheet , TextInput } from 'react-native' ; import { useConfirmPayment } from '@stripe/stripe-react-native' ; import Button from '../components/Button' ; import PaymentScreen from '../components/PaymentScreen' ; import { API_URL } from '../Config' ; import { colors } from '../colors' ; export default function EPSPaymentScreen ( ) { const [ email , setEmail ] = useState ( '' ) ; const { confirmPayment , loading } = useConfirmPayment ( ) ; const fetchPaymentIntentClientSecret = async ( ) => { const response = await fetch ( `${ API_URL }/create-payment-intent` , { method : 'POST' , headers : { 'Content-Type' : 'application/json' , } , body : JSON . stringify ( { email , currency : 'eur' , items : [ { id : 'id' } ] , payment_method_types : [ 'eps' ] , } ) , } ) ; const { clientSecret , error } = await response . json ( ) ; return { clientSecret , error } ; } ; const handlePayPress = async ( ) => { const { clientSecret , error : clientSecretError } = await fetchPaymentIntentClientSecret ( ) ; if ( clientSecretError ) { Alert . alert ( `Error` , clientSecretError ) ; return ; } const billingDetails = { name : 'John Doe' , } ; const { error , paymentIntent } = await confirmPayment ( clientSecret , { type : 'Eps' , billingDetails , } ) ; if ( error ) { Alert . alert ( `Error code: ${ error . code }` , error . message ) ; console . log ( 'Payment confirmation error' , error . message ) ; } else if ( paymentIntent ) { Alert . alert ( 'Success' , `The payment was confirmed successfully! currency: ${ paymentIntent . currency }` ) ; } } ; return ( < PaymentScreen > < TextInput autoCapitalize = "none" placeholder = "E-mail" keyboardType = "email-address" onChange = { ( value ) => setEmail ( value . nativeEvent . text ) } style = { styles . input } / > < Button variant = "primary" onPress = { handlePayPress } title = "Pay" loading = { loading } / > < /PaymentScreen>); } const styles = StyleSheet . create ( { cardField : { width : '100%' , height : 50 , marginVertical : 30 , } , row : { flexDirection : 'row' , alignItems : 'center' , marginBottom : 20 , } , text : { marginLeft : 12 , } , input : { height : 44 , borderBottomColor : colors . slate , borderBottomWidth : 1.5 , marginBottom : 20 , } , } ) ;