From 8a72e5c1c262eab00e6921cd792ceba875dd47c2 Mon Sep 17 00:00:00 2001 From: Oussama Date: Tue, 11 Apr 2023 10:16:24 +0100 Subject: [PATCH 1/3] chore: bacs ios implementation + working example --- example/ios/Podfile.lock | 2 +- example/server/index.ts | 1 + example/src/App.tsx | 6 + .../src/screens/BacsDebitPaymentScreen.tsx | 135 ++++++++++++++++++ example/src/screens/HomeScreen.tsx | 8 ++ .../src/screens/PaymentsUICompleteScreen.tsx | 4 + ios/PaymentMethodFactory.swift | 29 ++++ src/types/PaymentIntent.ts | 12 +- src/types/PaymentMethod.ts | 15 +- 9 files changed, 208 insertions(+), 4 deletions(-) create mode 100644 example/src/screens/BacsDebitPaymentScreen.tsx diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 4e59344d2a..92feb06ef6 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -650,4 +650,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: d98ea981c14c48ddbbd4f2d6bcf130927b15a93f -COCOAPODS: 1.11.3 +COCOAPODS: 1.12.0 diff --git a/example/server/index.ts b/example/server/index.ts index 952aec557c..df8ea32c92 100644 --- a/example/server/index.ts +++ b/example/server/index.ts @@ -71,6 +71,7 @@ function getKeys(payment_method?: string) { secret_key = process.env.STRIPE_SECRET_KEY_WECHAT; break; case 'paypal': + case 'bacs_debit': publishable_key = process.env.STRIPE_PUBLISHABLE_KEY_UK; secret_key = process.env.STRIPE_SECRET_KEY_UK; break; diff --git a/example/src/App.tsx b/example/src/App.tsx index 4835c70271..85353fbc64 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -41,6 +41,7 @@ import PayPalScreen from './screens/PayPalScreen'; import AffirmScreen from './screens/AffirmScreen'; import CollectBankAccountScreen from './screens/CollectBankAccountScreen'; import CashAppScreen from './screens/CashAppScreen'; +import BacsDebitPaymentScreen from './screens/BacsDebitPaymentScreen'; const Stack = createNativeStackNavigator(); @@ -83,6 +84,7 @@ export type RootStackParamList = { CashAppScreen: undefined; AffirmScreen: undefined; CollectBankAccountScreen: undefined; + BacsDebitPaymentScreen: undefined; }; declare global { @@ -200,6 +202,10 @@ export default function App() { name="SepaPaymentScreen" component={SepaPaymentScreen} /> + { + const response = await fetch(`${API_URL}/create-payment-intent`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + email, + currency: 'gbp', + items: ['id-1'], + payment_method_types: ['bacs_debit'], + }), + }); + 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: BillingDetails = { + name: 'John Doe', + email: email, + address: { + country: 'UK', + line1: 'test', + city: 'test', + }, + }; + setCanPay(false); + const { error, paymentIntent } = await confirmPayment(clientSecret, { + paymentMethodType: 'BacsDebit', + paymentMethodData: { billingDetails, sortCode, accountNumber }, + }); + + if (error) { + Alert.alert(`Error code: ${error.code}`, error.message); + } else if (paymentIntent) { + if (paymentIntent.status === PaymentIntent.Status.Processing) { + Alert.alert( + 'Processing', + `The debit has been successfully submitted and is now processing.` + ); + } else if (paymentIntent.status === PaymentIntent.Status.Succeeded) { + Alert.alert( + 'Success', + `The payment was confirmed successfully! currency: ${paymentIntent.currency}` + ); + } else { + Alert.alert('Payment status:', paymentIntent.status); + } + } + setCanPay(true); + }; + + return ( + + setEmail(value.nativeEvent.text)} + style={styles.input} + /> + setSortCode(value.nativeEvent.text.toLowerCase())} + style={styles.input} + /> + + + setAccountNumber(value.nativeEvent.text.toLowerCase()) + } + style={styles.input} + /> +