@stripe/stripe-react-native 0.42.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/pre-commit +0 -3
- package/CHANGELOG.md +26 -0
- package/android/.gradle/8.11.1/checksums/checksums.lock +0 -0
- package/android/.gradle/8.11.1/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/8.11.1/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/8.11.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/8.11.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
- package/android/.project +0 -11
- package/android/.settings/org.eclipse.buildship.core.prefs +3 -3
- package/android/build.gradle +8 -1
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/android/gradle.properties +4 -1
- package/android/gradlew +249 -0
- package/android/gradlew.bat +92 -0
- package/android/spotless.gradle +19 -0
- package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormView.kt +30 -34
- package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormViewManager.kt +20 -10
- package/android/src/main/java/com/reactnativestripesdk/CardChangedEvent.kt +12 -13
- package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +242 -105
- package/android/src/main/java/com/reactnativestripesdk/CardFieldViewManager.kt +58 -20
- package/android/src/main/java/com/reactnativestripesdk/CardFocusEvent.kt +8 -11
- package/android/src/main/java/com/reactnativestripesdk/CardFormCompleteEvent.kt +10 -12
- package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +135 -87
- package/android/src/main/java/com/reactnativestripesdk/CardFormViewManager.kt +57 -22
- package/android/src/main/java/com/reactnativestripesdk/CollectBankAccountLauncherFragment.kt +33 -24
- package/android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetFragment.kt +107 -85
- package/android/src/main/java/com/reactnativestripesdk/FormCompleteEvent.kt +9 -11
- package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonManager.kt +16 -9
- package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonView.kt +36 -28
- package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherFragment.kt +67 -43
- package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherFragment.kt +21 -16
- package/android/src/main/java/com/reactnativestripesdk/GooglePayRequestHelper.kt +101 -56
- package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherFragment.kt +244 -166
- package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +137 -156
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +181 -57
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +422 -258
- package/android/src/main/java/com/reactnativestripesdk/StripeContainerManager.kt +11 -4
- package/android/src/main/java/com/reactnativestripesdk/StripeContainerView.kt +5 -1
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +656 -299
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +12 -14
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherFragment.kt +42 -37
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetEvent.kt +12 -11
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +29 -29
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetViewManager.kt +50 -18
- package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetFragment.kt +227 -147
- package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerAdapter.kt +15 -18
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonManager.kt +33 -15
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt +63 -37
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletCompleteEvent.kt +9 -13
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/EphemeralKeyProvider.kt +15 -17
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/PushProvisioningProxy.kt +76 -60
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/TapAndPayProxy.kt +71 -47
- package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +117 -51
- package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +4 -3
- package/android/src/main/java/com/reactnativestripesdk/utils/KeepJsAwakeTask.kt +39 -0
- package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +295 -258
- package/android/src/main/java/com/reactnativestripesdk/utils/PostalCodeUtilities.kt +2 -11
- package/ios/CustomerSheet/CustomerSheetUtils.swift +13 -7
- package/ios/FinancialConnections.swift +6 -2
- package/ios/StripeSdk+CustomerSheet.swift +3 -1
- package/ios/StripeSdk+PaymentSheet.swift +86 -21
- package/ios/StripeSdk.m +2 -0
- package/ios/StripeSdk.swift +72 -11
- package/lib/commonjs/NativeStripeSdk.js +1 -1
- package/lib/commonjs/NativeStripeSdk.js.map +1 -1
- package/lib/commonjs/components/AddToWalletButton.js +1 -1
- package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
- package/lib/commonjs/components/AddressSheet.js +1 -1
- package/lib/commonjs/components/AddressSheet.js.map +1 -1
- package/lib/commonjs/components/ApplePayButtonNative.js +1 -1
- package/lib/commonjs/components/ApplePayButtonNative.js.map +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
- package/lib/commonjs/components/CardField.js +1 -1
- package/lib/commonjs/components/CardField.js.map +1 -1
- package/lib/commonjs/components/CardForm.js +1 -1
- package/lib/commonjs/components/CardForm.js.map +1 -1
- package/lib/commonjs/components/CustomerSheet.js +1 -1
- package/lib/commonjs/components/CustomerSheet.js.map +1 -1
- package/lib/commonjs/components/GooglePayButtonNative.js +1 -1
- package/lib/commonjs/components/GooglePayButtonNative.js.map +1 -1
- package/lib/commonjs/components/PlatformPayButton.js +1 -1
- package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
- package/lib/commonjs/components/StripeContainer.js +1 -1
- package/lib/commonjs/components/StripeContainer.js.map +1 -1
- package/lib/commonjs/components/StripeProvider.js +1 -1
- package/lib/commonjs/components/StripeProvider.js.map +1 -1
- package/lib/commonjs/functions.js +1 -1
- package/lib/commonjs/functions.js.map +1 -1
- package/lib/commonjs/helpers.js +1 -1
- package/lib/commonjs/helpers.js.map +1 -1
- package/lib/commonjs/hooks/useConfirmPayment.js.map +1 -1
- package/lib/commonjs/hooks/useConfirmSetupIntent.js.map +1 -1
- package/lib/commonjs/hooks/useFinancialConnectionsSheet.js.map +1 -1
- package/lib/commonjs/hooks/usePaymentSheet.js.map +1 -1
- package/lib/commonjs/hooks/usePlatformPay.js.map +1 -1
- package/lib/commonjs/hooks/useStripe.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/plugin/withStripe.js +1 -1
- package/lib/commonjs/plugin/withStripe.js.map +1 -1
- package/lib/commonjs/types/ApplePay.js.map +1 -1
- package/lib/commonjs/types/Common.js +1 -1
- package/lib/commonjs/types/Common.js.map +1 -1
- package/lib/commonjs/types/CustomerSheet.js.map +1 -1
- package/lib/commonjs/types/Errors.js +1 -1
- package/lib/commonjs/types/Errors.js.map +1 -1
- package/lib/commonjs/types/FinancialConnections.js +1 -1
- package/lib/commonjs/types/FinancialConnections.js.map +1 -1
- package/lib/commonjs/types/NextAction.js.map +1 -1
- package/lib/commonjs/types/PaymentIntent.js +1 -1
- package/lib/commonjs/types/PaymentIntent.js.map +1 -1
- package/lib/commonjs/types/PaymentMethod.js.map +1 -1
- package/lib/commonjs/types/PaymentSheet.js +1 -1
- package/lib/commonjs/types/PaymentSheet.js.map +1 -1
- package/lib/commonjs/types/PlatformPay.js +1 -1
- package/lib/commonjs/types/PlatformPay.js.map +1 -1
- package/lib/commonjs/types/PushProvisioning.js +1 -1
- package/lib/commonjs/types/PushProvisioning.js.map +1 -1
- package/lib/commonjs/types/SetupIntent.js +1 -1
- package/lib/commonjs/types/SetupIntent.js.map +1 -1
- package/lib/commonjs/types/ThreeDSecure.js +1 -1
- package/lib/commonjs/types/ThreeDSecure.js.map +1 -1
- package/lib/commonjs/types/Token.js.map +1 -1
- package/lib/commonjs/types/components/ApplePayButtonComponent.js.map +1 -1
- package/lib/commonjs/types/components/AuBECSDebitFormComponent.js.map +1 -1
- package/lib/commonjs/types/components/CardFieldInput.js +1 -1
- package/lib/commonjs/types/components/CardFieldInput.js.map +1 -1
- package/lib/commonjs/types/components/CardFormView.js.map +1 -1
- package/lib/commonjs/types/components/GooglePayButtonComponent.js.map +1 -1
- package/lib/commonjs/types/index.js +1 -1
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/module/NativeStripeSdk.js +1 -1
- package/lib/module/NativeStripeSdk.js.map +1 -1
- package/lib/module/components/AddToWalletButton.js +1 -1
- package/lib/module/components/AddToWalletButton.js.map +1 -1
- package/lib/module/components/AddressSheet.js +1 -1
- package/lib/module/components/AddressSheet.js.map +1 -1
- package/lib/module/components/ApplePayButtonNative.js +1 -1
- package/lib/module/components/ApplePayButtonNative.js.map +1 -1
- package/lib/module/components/AuBECSDebitForm.js +1 -1
- package/lib/module/components/AuBECSDebitForm.js.map +1 -1
- package/lib/module/components/CardField.js +1 -1
- package/lib/module/components/CardField.js.map +1 -1
- package/lib/module/components/CardForm.js +1 -1
- package/lib/module/components/CardForm.js.map +1 -1
- package/lib/module/components/CustomerSheet.js +1 -1
- package/lib/module/components/CustomerSheet.js.map +1 -1
- package/lib/module/components/GooglePayButtonNative.js +1 -1
- package/lib/module/components/GooglePayButtonNative.js.map +1 -1
- package/lib/module/components/PlatformPayButton.js +1 -1
- package/lib/module/components/PlatformPayButton.js.map +1 -1
- package/lib/module/components/StripeContainer.js +1 -1
- package/lib/module/components/StripeContainer.js.map +1 -1
- package/lib/module/components/StripeProvider.js +1 -1
- package/lib/module/components/StripeProvider.js.map +1 -1
- package/lib/module/functions.js +1 -1
- package/lib/module/functions.js.map +1 -1
- package/lib/module/helpers.js +1 -1
- package/lib/module/helpers.js.map +1 -1
- package/lib/module/hooks/useConfirmPayment.js.map +1 -1
- package/lib/module/hooks/useConfirmSetupIntent.js.map +1 -1
- package/lib/module/hooks/useFinancialConnectionsSheet.js.map +1 -1
- package/lib/module/hooks/usePaymentSheet.js.map +1 -1
- package/lib/module/hooks/usePlatformPay.js.map +1 -1
- package/lib/module/hooks/useStripe.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/module/plugin/withStripe.js +1 -1
- package/lib/module/plugin/withStripe.js.map +1 -1
- package/lib/module/types/ApplePay.js.map +1 -1
- package/lib/module/types/Common.js +1 -1
- package/lib/module/types/Common.js.map +1 -1
- package/lib/module/types/CustomerSheet.js.map +1 -1
- package/lib/module/types/Errors.js +1 -1
- package/lib/module/types/Errors.js.map +1 -1
- package/lib/module/types/FinancialConnections.js +1 -1
- package/lib/module/types/FinancialConnections.js.map +1 -1
- package/lib/module/types/NextAction.js.map +1 -1
- package/lib/module/types/PaymentIntent.js +1 -1
- package/lib/module/types/PaymentIntent.js.map +1 -1
- package/lib/module/types/PaymentMethod.js.map +1 -1
- package/lib/module/types/PaymentSheet.js +1 -1
- package/lib/module/types/PaymentSheet.js.map +1 -1
- package/lib/module/types/PlatformPay.js +1 -1
- package/lib/module/types/PlatformPay.js.map +1 -1
- package/lib/module/types/PushProvisioning.js +1 -1
- package/lib/module/types/PushProvisioning.js.map +1 -1
- package/lib/module/types/SetupIntent.js +1 -1
- package/lib/module/types/SetupIntent.js.map +1 -1
- package/lib/module/types/ThreeDSecure.js +1 -1
- package/lib/module/types/ThreeDSecure.js.map +1 -1
- package/lib/module/types/Token.js.map +1 -1
- package/lib/module/types/components/ApplePayButtonComponent.js.map +1 -1
- package/lib/module/types/components/AuBECSDebitFormComponent.js.map +1 -1
- package/lib/module/types/components/CardFieldInput.js +1 -1
- package/lib/module/types/components/CardFieldInput.js.map +1 -1
- package/lib/module/types/components/CardFormView.js.map +1 -1
- package/lib/module/types/components/GooglePayButtonComponent.js.map +1 -1
- package/lib/module/types/index.js +1 -1
- package/lib/module/types/index.js.map +1 -1
- package/lib/typescript/src/NativeStripeSdk.d.ts +4 -3
- package/lib/typescript/src/NativeStripeSdk.d.ts.map +1 -0
- package/lib/typescript/src/components/AddToWalletButton.d.ts +3 -1
- package/lib/typescript/src/components/AddToWalletButton.d.ts.map +1 -0
- package/lib/typescript/src/components/AddressSheet.d.ts +4 -2
- package/lib/typescript/src/components/AddressSheet.d.ts.map +1 -0
- package/lib/typescript/src/components/ApplePayButtonNative.d.ts +1 -0
- package/lib/typescript/src/components/ApplePayButtonNative.d.ts.map +1 -0
- package/lib/typescript/src/components/AuBECSDebitForm.d.ts +3 -1
- package/lib/typescript/src/components/AuBECSDebitForm.d.ts.map +1 -0
- package/lib/typescript/src/components/CardField.d.ts +1 -0
- package/lib/typescript/src/components/CardField.d.ts.map +1 -0
- package/lib/typescript/src/components/CardForm.d.ts +1 -0
- package/lib/typescript/src/components/CardForm.d.ts.map +1 -0
- package/lib/typescript/src/components/CustomerSheet.d.ts +2 -1
- package/lib/typescript/src/components/CustomerSheet.d.ts.map +1 -0
- package/lib/typescript/src/components/GooglePayButtonNative.d.ts +1 -0
- package/lib/typescript/src/components/GooglePayButtonNative.d.ts.map +1 -0
- package/lib/typescript/src/components/PlatformPayButton.d.ts +3 -1
- package/lib/typescript/src/components/PlatformPayButton.d.ts.map +1 -0
- package/lib/typescript/src/components/StripeContainer.d.ts +2 -1
- package/lib/typescript/src/components/StripeContainer.d.ts.map +1 -0
- package/lib/typescript/src/components/StripeProvider.d.ts +3 -2
- package/lib/typescript/src/components/StripeProvider.d.ts.map +1 -0
- package/lib/typescript/src/functions.d.ts +6 -5
- package/lib/typescript/src/functions.d.ts.map +1 -0
- package/lib/typescript/src/helpers.d.ts +1 -0
- package/lib/typescript/src/helpers.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useConfirmPayment.d.ts +2 -1
- package/lib/typescript/src/hooks/useConfirmPayment.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useConfirmSetupIntent.d.ts +1 -0
- package/lib/typescript/src/hooks/useConfirmSetupIntent.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useFinancialConnectionsSheet.d.ts +3 -2
- package/lib/typescript/src/hooks/useFinancialConnectionsSheet.d.ts.map +1 -0
- package/lib/typescript/src/hooks/usePaymentSheet.d.ts +2 -1
- package/lib/typescript/src/hooks/usePaymentSheet.d.ts.map +1 -0
- package/lib/typescript/src/hooks/usePlatformPay.d.ts +4 -3
- package/lib/typescript/src/hooks/usePlatformPay.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useStripe.d.ts +11 -8
- package/lib/typescript/src/hooks/useStripe.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/plugin/withStripe.d.ts +2 -1
- package/lib/typescript/src/plugin/withStripe.d.ts.map +1 -0
- package/lib/typescript/src/types/ApplePay.d.ts +6 -5
- package/lib/typescript/src/types/ApplePay.d.ts.map +1 -0
- package/lib/typescript/src/types/Common.d.ts +4 -1
- package/lib/typescript/src/types/Common.d.ts.map +1 -0
- package/lib/typescript/src/types/CustomerSheet.d.ts +16 -4
- package/lib/typescript/src/types/CustomerSheet.d.ts.map +1 -0
- package/lib/typescript/src/types/Errors.d.ts +2 -1
- package/lib/typescript/src/types/Errors.d.ts.map +1 -0
- package/lib/typescript/src/types/FinancialConnections.d.ts +21 -17
- package/lib/typescript/src/types/FinancialConnections.d.ts.map +1 -0
- package/lib/typescript/src/types/NextAction.d.ts +9 -8
- package/lib/typescript/src/types/NextAction.d.ts.map +1 -0
- package/lib/typescript/src/types/PaymentIntent.d.ts +16 -15
- package/lib/typescript/src/types/PaymentIntent.d.ts.map +1 -0
- package/lib/typescript/src/types/PaymentMethod.d.ts +21 -16
- package/lib/typescript/src/types/PaymentMethod.d.ts.map +1 -0
- package/lib/typescript/src/types/PaymentSheet.d.ts +91 -22
- package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -0
- package/lib/typescript/src/types/PlatformPay.d.ts +22 -21
- package/lib/typescript/src/types/PlatformPay.d.ts.map +1 -0
- package/lib/typescript/src/types/PushProvisioning.d.ts +5 -4
- package/lib/typescript/src/types/PushProvisioning.d.ts.map +1 -0
- package/lib/typescript/src/types/SetupIntent.d.ts +4 -3
- package/lib/typescript/src/types/SetupIntent.d.ts.map +1 -0
- package/lib/typescript/src/types/ThreeDSecure.d.ts +1 -0
- package/lib/typescript/src/types/ThreeDSecure.d.ts.map +1 -0
- package/lib/typescript/src/types/Token.d.ts +10 -9
- package/lib/typescript/src/types/Token.d.ts.map +1 -0
- package/lib/typescript/src/types/components/ApplePayButtonComponent.d.ts +3 -2
- package/lib/typescript/src/types/components/ApplePayButtonComponent.d.ts.map +1 -0
- package/lib/typescript/src/types/components/AuBECSDebitFormComponent.d.ts +1 -0
- package/lib/typescript/src/types/components/AuBECSDebitFormComponent.d.ts.map +1 -0
- package/lib/typescript/src/types/components/CardFieldInput.d.ts +8 -5
- package/lib/typescript/src/types/components/CardFieldInput.d.ts.map +1 -0
- package/lib/typescript/src/types/components/CardFormView.d.ts +9 -6
- package/lib/typescript/src/types/components/CardFormView.d.ts.map +1 -0
- package/lib/typescript/src/types/components/GooglePayButtonComponent.d.ts +1 -0
- package/lib/typescript/src/types/components/GooglePayButtonComponent.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +24 -23
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/package.json +32 -40
- package/src/NativeStripeSdk.tsx +4 -2
- package/src/components/CardField.tsx +1 -1
- package/src/components/CardForm.tsx +12 -9
- package/src/components/CustomerSheet.tsx +4 -6
- package/src/components/StripeProvider.tsx +17 -0
- package/src/functions.ts +13 -14
- package/src/helpers.ts +2 -1
- package/src/types/Common.ts +3 -0
- package/src/types/CustomerSheet.ts +11 -0
- package/src/types/FinancialConnections.ts +3 -0
- package/src/types/PaymentMethod.ts +5 -1
- package/src/types/PaymentSheet.ts +85 -4
- package/src/types/components/CardFieldInput.ts +8 -4
- package/src/types/components/CardFormView.ts +8 -4
- package/stripe-react-native.podspec +2 -1
- package/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.9/gc.properties +0 -0
- /package/android/.gradle/{8.9 → 8.11.1}/fileChanges/last-build.bin +0 -0
- /package/android/.gradle/{8.9/dependencies-accessors → 8.11.1}/gc.properties +0 -0
package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetFragment.kt
CHANGED
|
@@ -12,9 +12,19 @@ import android.view.View
|
|
|
12
12
|
import android.view.ViewGroup
|
|
13
13
|
import android.widget.FrameLayout
|
|
14
14
|
import androidx.fragment.app.Fragment
|
|
15
|
-
import com.facebook.react.bridge
|
|
15
|
+
import com.facebook.react.bridge.Arguments
|
|
16
|
+
import com.facebook.react.bridge.Promise
|
|
17
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
18
|
+
import com.facebook.react.bridge.WritableMap
|
|
19
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
16
20
|
import com.reactnativestripesdk.customersheet.ReactNativeCustomerAdapter
|
|
17
|
-
import com.reactnativestripesdk.utils
|
|
21
|
+
import com.reactnativestripesdk.utils.CreateTokenErrorType
|
|
22
|
+
import com.reactnativestripesdk.utils.ErrorType
|
|
23
|
+
import com.reactnativestripesdk.utils.KeepJsAwakeTask
|
|
24
|
+
import com.reactnativestripesdk.utils.PaymentSheetAppearanceException
|
|
25
|
+
import com.reactnativestripesdk.utils.createError
|
|
26
|
+
import com.reactnativestripesdk.utils.mapFromPaymentMethod
|
|
27
|
+
import com.reactnativestripesdk.utils.mapToPreferredNetworks
|
|
18
28
|
import com.stripe.android.ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi
|
|
19
29
|
import com.stripe.android.customersheet.CustomerAdapter
|
|
20
30
|
import com.stripe.android.customersheet.CustomerEphemeralKey
|
|
@@ -22,12 +32,11 @@ import com.stripe.android.customersheet.CustomerSheet
|
|
|
22
32
|
import com.stripe.android.customersheet.CustomerSheetResult
|
|
23
33
|
import com.stripe.android.customersheet.PaymentOptionSelection
|
|
24
34
|
import com.stripe.android.model.PaymentMethod
|
|
25
|
-
import com.stripe.android.paymentsheet
|
|
35
|
+
import com.stripe.android.paymentsheet.PaymentSheet
|
|
26
36
|
import kotlinx.coroutines.CoroutineScope
|
|
27
37
|
import kotlinx.coroutines.Dispatchers
|
|
28
38
|
import kotlinx.coroutines.launch
|
|
29
39
|
|
|
30
|
-
|
|
31
40
|
@OptIn(ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class)
|
|
32
41
|
class CustomerSheetFragment : Fragment() {
|
|
33
42
|
private var customerSheet: CustomerSheet? = null
|
|
@@ -35,28 +44,38 @@ class CustomerSheetFragment : Fragment() {
|
|
|
35
44
|
internal var context: ReactApplicationContext? = null
|
|
36
45
|
internal var initPromise: Promise? = null
|
|
37
46
|
private var presentPromise: Promise? = null
|
|
47
|
+
private var keepJsAwake: KeepJsAwakeTask? = null
|
|
38
48
|
|
|
39
49
|
override fun onCreateView(
|
|
40
50
|
inflater: LayoutInflater,
|
|
41
51
|
container: ViewGroup?,
|
|
42
|
-
savedInstanceState: Bundle
|
|
43
|
-
): View {
|
|
44
|
-
return FrameLayout(requireActivity()).also {
|
|
45
|
-
it.visibility = View.GONE
|
|
46
|
-
}
|
|
47
|
-
}
|
|
52
|
+
savedInstanceState: Bundle?,
|
|
53
|
+
): View = FrameLayout(requireActivity()).also { it.visibility = View.GONE }
|
|
48
54
|
|
|
49
|
-
override fun onViewCreated(
|
|
55
|
+
override fun onViewCreated(
|
|
56
|
+
view: View,
|
|
57
|
+
savedInstanceState: Bundle?,
|
|
58
|
+
) {
|
|
50
59
|
super.onViewCreated(view, savedInstanceState)
|
|
51
60
|
|
|
52
|
-
val context =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
val context =
|
|
62
|
+
context
|
|
63
|
+
?: run {
|
|
64
|
+
Log.e(
|
|
65
|
+
"StripeReactNative",
|
|
66
|
+
"No context found during CustomerSheet.initialize. Please file an issue: https://github.com/stripe/stripe-react-native/issues",
|
|
67
|
+
)
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
val initPromise =
|
|
71
|
+
initPromise
|
|
72
|
+
?: run {
|
|
73
|
+
Log.e(
|
|
74
|
+
"StripeReactNative",
|
|
75
|
+
"No promise found for CustomerSheet.initialize. Please file an issue: https://github.com/stripe/stripe-react-native/issues",
|
|
76
|
+
)
|
|
77
|
+
return
|
|
78
|
+
}
|
|
60
79
|
|
|
61
80
|
val headerTextForSelectionScreen = arguments?.getString("headerTextForSelectionScreen")
|
|
62
81
|
val merchantDisplayName = arguments?.getString("merchantDisplayName")
|
|
@@ -67,52 +86,69 @@ class CustomerSheetFragment : Fragment() {
|
|
|
67
86
|
val customerId = arguments?.getString("customerId")
|
|
68
87
|
val customerEphemeralKeySecret = arguments?.getString("customerEphemeralKeySecret")
|
|
69
88
|
val customerAdapterOverrideParams = arguments?.getBundle("customerAdapter")
|
|
70
|
-
val allowsRemovalOfLastSavedPaymentMethod =
|
|
89
|
+
val allowsRemovalOfLastSavedPaymentMethod =
|
|
90
|
+
arguments?.getBoolean("allowsRemovalOfLastSavedPaymentMethod", true) ?: true
|
|
71
91
|
val paymentMethodOrder = arguments?.getStringArrayList("paymentMethodOrder")
|
|
72
92
|
if (customerId == null) {
|
|
73
|
-
initPromise.resolve(
|
|
93
|
+
initPromise.resolve(
|
|
94
|
+
createError(ErrorType.Failed.toString(), "You must provide a value for `customerId`"),
|
|
95
|
+
)
|
|
74
96
|
return
|
|
75
97
|
}
|
|
76
98
|
if (customerEphemeralKeySecret == null) {
|
|
77
|
-
initPromise.resolve(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
} catch (error: PaymentSheetAppearanceException) {
|
|
84
|
-
initPromise.resolve(createError(ErrorType.Failed.toString(), error))
|
|
99
|
+
initPromise.resolve(
|
|
100
|
+
createError(
|
|
101
|
+
ErrorType.Failed.toString(),
|
|
102
|
+
"You must provide a value for `customerEphemeralKeySecret`",
|
|
103
|
+
),
|
|
104
|
+
)
|
|
85
105
|
return
|
|
86
106
|
}
|
|
87
107
|
|
|
88
|
-
val
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
108
|
+
val appearance =
|
|
109
|
+
try {
|
|
110
|
+
buildPaymentSheetAppearance(arguments?.getBundle("appearance"), context)
|
|
111
|
+
} catch (error: PaymentSheetAppearanceException) {
|
|
112
|
+
initPromise.resolve(createError(ErrorType.Failed.toString(), error))
|
|
113
|
+
return
|
|
114
|
+
}
|
|
94
115
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
116
|
+
val configuration =
|
|
117
|
+
CustomerSheet.Configuration
|
|
118
|
+
.builder(merchantDisplayName ?: "")
|
|
119
|
+
.appearance(appearance)
|
|
120
|
+
.googlePayEnabled(googlePayEnabled)
|
|
121
|
+
.headerTextForSelectionScreen(headerTextForSelectionScreen)
|
|
122
|
+
.preferredNetworks(
|
|
123
|
+
mapToPreferredNetworks(arguments?.getIntegerArrayList("preferredNetworks")),
|
|
124
|
+
).allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod)
|
|
125
|
+
.cardBrandAcceptance(mapToCardBrandAcceptance(arguments))
|
|
126
|
+
|
|
127
|
+
paymentMethodOrder?.let { configuration.paymentMethodOrder(it) }
|
|
98
128
|
billingDetailsBundle?.let {
|
|
99
129
|
configuration.defaultBillingDetails(createDefaultBillingDetails(billingDetailsBundle))
|
|
100
130
|
}
|
|
101
131
|
billingConfigParams?.let {
|
|
102
|
-
configuration.billingDetailsCollectionConfiguration(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
val customerAdapter = createCustomerAdapter(
|
|
106
|
-
context, customerId, customerEphemeralKeySecret, setupIntentClientSecret, customerAdapterOverrideParams
|
|
107
|
-
).also {
|
|
108
|
-
this.customerAdapter = it
|
|
132
|
+
configuration.billingDetailsCollectionConfiguration(
|
|
133
|
+
createBillingDetailsCollectionConfiguration(billingConfigParams),
|
|
134
|
+
)
|
|
109
135
|
}
|
|
110
136
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
137
|
+
val customerAdapter =
|
|
138
|
+
createCustomerAdapter(
|
|
139
|
+
context,
|
|
140
|
+
customerId,
|
|
141
|
+
customerEphemeralKeySecret,
|
|
142
|
+
setupIntentClientSecret,
|
|
143
|
+
customerAdapterOverrideParams,
|
|
144
|
+
).also { this.customerAdapter = it }
|
|
145
|
+
|
|
146
|
+
customerSheet =
|
|
147
|
+
CustomerSheet.create(
|
|
148
|
+
fragment = this,
|
|
149
|
+
customerAdapter = customerAdapter,
|
|
150
|
+
callback = ::handleResult,
|
|
151
|
+
)
|
|
116
152
|
|
|
117
153
|
customerSheet?.configure(configuration.build())
|
|
118
154
|
|
|
@@ -120,85 +156,98 @@ class CustomerSheetFragment : Fragment() {
|
|
|
120
156
|
}
|
|
121
157
|
|
|
122
158
|
private fun handleResult(result: CustomerSheetResult) {
|
|
123
|
-
val presentPromise = presentPromise ?: run {
|
|
124
|
-
Log.e("StripeReactNative", "No promise found for CustomerSheet.present")
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
|
|
128
159
|
var promiseResult = Arguments.createMap()
|
|
129
160
|
when (result) {
|
|
130
161
|
is CustomerSheetResult.Failed -> {
|
|
131
|
-
|
|
162
|
+
resolvePresentPromise(createError(ErrorType.Failed.toString(), result.exception))
|
|
132
163
|
}
|
|
133
164
|
is CustomerSheetResult.Selected -> {
|
|
134
165
|
promiseResult = createPaymentOptionResult(result.selection)
|
|
135
166
|
}
|
|
136
167
|
is CustomerSheetResult.Canceled -> {
|
|
137
168
|
promiseResult = createPaymentOptionResult(result.selection)
|
|
138
|
-
promiseResult.putMap(
|
|
169
|
+
promiseResult.putMap(
|
|
170
|
+
"error",
|
|
171
|
+
Arguments.createMap().also { it.putString("code", ErrorType.Canceled.toString()) },
|
|
172
|
+
)
|
|
139
173
|
}
|
|
140
174
|
}
|
|
141
|
-
|
|
175
|
+
resolvePresentPromise(promiseResult)
|
|
142
176
|
}
|
|
143
177
|
|
|
144
|
-
fun present(
|
|
178
|
+
fun present(
|
|
179
|
+
timeout: Long?,
|
|
180
|
+
promise: Promise,
|
|
181
|
+
) {
|
|
182
|
+
keepJsAwake = context?.let { KeepJsAwakeTask(it).apply { start() } }
|
|
145
183
|
presentPromise = promise
|
|
146
184
|
if (timeout != null) {
|
|
147
|
-
presentWithTimeout(timeout
|
|
148
|
-
}
|
|
149
|
-
customerSheet?.present() ?: run {
|
|
150
|
-
promise.resolve(createMissingInitError())
|
|
185
|
+
presentWithTimeout(timeout)
|
|
151
186
|
}
|
|
187
|
+
customerSheet?.present() ?: run { resolvePresentPromise(createMissingInitError()) }
|
|
152
188
|
}
|
|
153
189
|
|
|
154
|
-
private fun presentWithTimeout(timeout: Long
|
|
190
|
+
private fun presentWithTimeout(timeout: Long) {
|
|
155
191
|
var customerSheetActivity: Activity? = null
|
|
156
192
|
var activities: MutableList<Activity> = mutableListOf()
|
|
157
|
-
val activityLifecycleCallbacks =
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
193
|
+
val activityLifecycleCallbacks =
|
|
194
|
+
object : Application.ActivityLifecycleCallbacks {
|
|
195
|
+
override fun onActivityCreated(
|
|
196
|
+
activity: Activity,
|
|
197
|
+
savedInstanceState: Bundle?,
|
|
198
|
+
) {
|
|
199
|
+
customerSheetActivity = activity
|
|
200
|
+
activities.add(activity)
|
|
201
|
+
}
|
|
164
202
|
|
|
165
|
-
|
|
203
|
+
override fun onActivityStarted(activity: Activity) {}
|
|
166
204
|
|
|
167
|
-
|
|
205
|
+
override fun onActivityResumed(activity: Activity) {}
|
|
168
206
|
|
|
169
|
-
|
|
207
|
+
override fun onActivityPaused(activity: Activity) {}
|
|
170
208
|
|
|
171
|
-
|
|
209
|
+
override fun onActivityStopped(activity: Activity) {}
|
|
172
210
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
}
|
|
211
|
+
override fun onActivitySaveInstanceState(
|
|
212
|
+
activity: Activity,
|
|
213
|
+
outState: Bundle,
|
|
214
|
+
) {}
|
|
179
215
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
216
|
+
override fun onActivityDestroyed(activity: Activity) {
|
|
217
|
+
customerSheetActivity = null
|
|
218
|
+
activities = mutableListOf()
|
|
219
|
+
context?.currentActivity?.application?.unregisterActivityLifecycleCallbacks(this)
|
|
184
220
|
}
|
|
185
|
-
}
|
|
221
|
+
}
|
|
186
222
|
|
|
223
|
+
Handler(Looper.getMainLooper())
|
|
224
|
+
.postDelayed(
|
|
225
|
+
{
|
|
226
|
+
// customerSheetActivity?.finish()
|
|
227
|
+
for (a in activities) {
|
|
228
|
+
a.finish()
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
timeout,
|
|
232
|
+
)
|
|
187
233
|
|
|
188
|
-
context
|
|
234
|
+
context
|
|
235
|
+
?.currentActivity
|
|
236
|
+
?.application
|
|
237
|
+
?.registerActivityLifecycleCallbacks(activityLifecycleCallbacks)
|
|
189
238
|
|
|
190
|
-
customerSheet?.present() ?: run {
|
|
191
|
-
promise.resolve(createMissingInitError())
|
|
192
|
-
}
|
|
239
|
+
customerSheet?.present() ?: run { resolvePresentPromise(createMissingInitError()) }
|
|
193
240
|
}
|
|
194
241
|
|
|
195
242
|
internal fun retrievePaymentOptionSelection(promise: Promise) {
|
|
196
243
|
CoroutineScope(Dispatchers.IO).launch {
|
|
197
244
|
runCatching {
|
|
198
|
-
val result =
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
245
|
+
val result =
|
|
246
|
+
customerSheet?.retrievePaymentOptionSelection()
|
|
247
|
+
?: run {
|
|
248
|
+
promise.resolve(createMissingInitError())
|
|
249
|
+
return@launch
|
|
250
|
+
}
|
|
202
251
|
var promiseResult = Arguments.createMap()
|
|
203
252
|
when (result) {
|
|
204
253
|
is CustomerSheetResult.Failed -> {
|
|
@@ -209,7 +258,12 @@ class CustomerSheetFragment : Fragment() {
|
|
|
209
258
|
}
|
|
210
259
|
is CustomerSheetResult.Canceled -> {
|
|
211
260
|
promiseResult = createPaymentOptionResult(result.selection)
|
|
212
|
-
promiseResult.putMap(
|
|
261
|
+
promiseResult.putMap(
|
|
262
|
+
"error",
|
|
263
|
+
Arguments.createMap().also {
|
|
264
|
+
it.putString("code", ErrorType.Canceled.toString())
|
|
265
|
+
},
|
|
266
|
+
)
|
|
213
267
|
}
|
|
214
268
|
}
|
|
215
269
|
promise.resolve(promiseResult)
|
|
@@ -219,38 +273,51 @@ class CustomerSheetFragment : Fragment() {
|
|
|
219
273
|
}
|
|
220
274
|
}
|
|
221
275
|
|
|
276
|
+
private fun resolvePresentPromise(value: Any?) {
|
|
277
|
+
val presentPromise =
|
|
278
|
+
presentPromise
|
|
279
|
+
?: run {
|
|
280
|
+
Log.e("StripeReactNative", "No promise found for CustomerSheet.present")
|
|
281
|
+
return
|
|
282
|
+
}
|
|
283
|
+
keepJsAwake?.stop()
|
|
284
|
+
keepJsAwake = null
|
|
285
|
+
presentPromise.resolve(value)
|
|
286
|
+
}
|
|
287
|
+
|
|
222
288
|
companion object {
|
|
223
289
|
internal const val TAG = "customer_sheet_launch_fragment"
|
|
224
290
|
|
|
225
|
-
internal fun createMissingInitError(): WritableMap
|
|
226
|
-
|
|
227
|
-
}
|
|
291
|
+
internal fun createMissingInitError(): WritableMap =
|
|
292
|
+
createError(ErrorType.Failed.toString(), "No customer sheet has been initialized yet.")
|
|
228
293
|
|
|
229
294
|
internal fun createDefaultBillingDetails(bundle: Bundle): PaymentSheet.BillingDetails {
|
|
230
295
|
val addressBundle = bundle.getBundle("address")
|
|
231
|
-
val address =
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
296
|
+
val address =
|
|
297
|
+
PaymentSheet.Address(
|
|
298
|
+
addressBundle?.getString("city"),
|
|
299
|
+
addressBundle?.getString("country"),
|
|
300
|
+
addressBundle?.getString("line1"),
|
|
301
|
+
addressBundle?.getString("line2"),
|
|
302
|
+
addressBundle?.getString("postalCode"),
|
|
303
|
+
addressBundle?.getString("state"),
|
|
304
|
+
)
|
|
238
305
|
return PaymentSheet.BillingDetails(
|
|
239
306
|
address,
|
|
240
307
|
bundle.getString("email"),
|
|
241
308
|
bundle.getString("name"),
|
|
242
|
-
bundle.getString("phone")
|
|
309
|
+
bundle.getString("phone"),
|
|
310
|
+
)
|
|
243
311
|
}
|
|
244
312
|
|
|
245
|
-
internal fun createBillingDetailsCollectionConfiguration(bundle: Bundle): PaymentSheet.BillingDetailsCollectionConfiguration
|
|
246
|
-
|
|
313
|
+
internal fun createBillingDetailsCollectionConfiguration(bundle: Bundle): PaymentSheet.BillingDetailsCollectionConfiguration =
|
|
314
|
+
PaymentSheet.BillingDetailsCollectionConfiguration(
|
|
247
315
|
name = mapToCollectionMode(bundle.getString("name")),
|
|
248
316
|
phone = mapToCollectionMode(bundle.getString("phone")),
|
|
249
317
|
email = mapToCollectionMode(bundle.getString("email")),
|
|
250
318
|
address = mapToAddressCollectionMode(bundle.getString("address")),
|
|
251
|
-
attachDefaultsToPaymentMethod = bundle.getBoolean("attachDefaultsToPaymentMethod")
|
|
319
|
+
attachDefaultsToPaymentMethod = bundle.getBoolean("attachDefaultsToPaymentMethod"),
|
|
252
320
|
)
|
|
253
|
-
}
|
|
254
321
|
|
|
255
322
|
internal fun createCustomerAdapter(
|
|
256
323
|
context: ReactApplicationContext,
|
|
@@ -264,36 +331,44 @@ class CustomerSheetFragment : Fragment() {
|
|
|
264
331
|
CustomerEphemeralKey.create(
|
|
265
332
|
customerId = customerId,
|
|
266
333
|
ephemeralKey = customerEphemeralKeySecret,
|
|
267
|
-
)
|
|
268
|
-
)
|
|
269
|
-
}
|
|
270
|
-
val customerAdapter = if (setupIntentClientSecret != null) {
|
|
271
|
-
CustomerAdapter.create(
|
|
272
|
-
context,
|
|
273
|
-
customerEphemeralKeyProvider = ephemeralKeyProvider,
|
|
274
|
-
setupIntentClientSecretProvider = {
|
|
275
|
-
CustomerAdapter.Result.success(
|
|
276
|
-
setupIntentClientSecret,
|
|
277
|
-
)
|
|
278
|
-
}
|
|
279
|
-
)
|
|
280
|
-
} else {
|
|
281
|
-
CustomerAdapter.create(
|
|
282
|
-
context,
|
|
283
|
-
customerEphemeralKeyProvider = ephemeralKeyProvider,
|
|
284
|
-
setupIntentClientSecretProvider = null
|
|
334
|
+
),
|
|
285
335
|
)
|
|
286
336
|
}
|
|
337
|
+
val customerAdapter =
|
|
338
|
+
if (setupIntentClientSecret != null) {
|
|
339
|
+
CustomerAdapter.create(
|
|
340
|
+
context,
|
|
341
|
+
customerEphemeralKeyProvider = ephemeralKeyProvider,
|
|
342
|
+
setupIntentClientSecretProvider = {
|
|
343
|
+
CustomerAdapter.Result.success(
|
|
344
|
+
setupIntentClientSecret,
|
|
345
|
+
)
|
|
346
|
+
},
|
|
347
|
+
)
|
|
348
|
+
} else {
|
|
349
|
+
CustomerAdapter.create(
|
|
350
|
+
context,
|
|
351
|
+
customerEphemeralKeyProvider = ephemeralKeyProvider,
|
|
352
|
+
setupIntentClientSecretProvider = null,
|
|
353
|
+
)
|
|
354
|
+
}
|
|
287
355
|
|
|
288
356
|
return ReactNativeCustomerAdapter(
|
|
289
357
|
context = context,
|
|
290
358
|
adapter = customerAdapter,
|
|
291
|
-
overridesFetchPaymentMethods =
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
359
|
+
overridesFetchPaymentMethods =
|
|
360
|
+
customerAdapterOverrideParams?.getBoolean("fetchPaymentMethods") ?: false,
|
|
361
|
+
overridesAttachPaymentMethod =
|
|
362
|
+
customerAdapterOverrideParams?.getBoolean("attachPaymentMethod") ?: false,
|
|
363
|
+
overridesDetachPaymentMethod =
|
|
364
|
+
customerAdapterOverrideParams?.getBoolean("detachPaymentMethod") ?: false,
|
|
365
|
+
overridesSetSelectedPaymentOption =
|
|
366
|
+
customerAdapterOverrideParams?.getBoolean("setSelectedPaymentOption") ?: false,
|
|
367
|
+
overridesFetchSelectedPaymentOption =
|
|
368
|
+
customerAdapterOverrideParams?.getBoolean("fetchSelectedPaymentOption") ?: false,
|
|
369
|
+
overridesSetupIntentClientSecretForCustomerAttach =
|
|
370
|
+
customerAdapterOverrideParams?.getBoolean("setupIntentClientSecretForCustomerAttach")
|
|
371
|
+
?: false,
|
|
297
372
|
)
|
|
298
373
|
}
|
|
299
374
|
|
|
@@ -302,16 +377,16 @@ class CustomerSheetFragment : Fragment() {
|
|
|
302
377
|
|
|
303
378
|
when (selection) {
|
|
304
379
|
is PaymentOptionSelection.GooglePay -> {
|
|
305
|
-
paymentOptionResult =
|
|
306
|
-
selection.paymentOption.label,
|
|
307
|
-
selection.paymentOption.icon(),
|
|
308
|
-
null)
|
|
380
|
+
paymentOptionResult =
|
|
381
|
+
buildResult(selection.paymentOption.label, selection.paymentOption.icon(), null)
|
|
309
382
|
}
|
|
310
383
|
is PaymentOptionSelection.PaymentMethod -> {
|
|
311
|
-
paymentOptionResult =
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
384
|
+
paymentOptionResult =
|
|
385
|
+
buildResult(
|
|
386
|
+
selection.paymentOption.label,
|
|
387
|
+
selection.paymentOption.icon(),
|
|
388
|
+
selection.paymentMethod,
|
|
389
|
+
)
|
|
315
390
|
}
|
|
316
391
|
null -> {}
|
|
317
392
|
}
|
|
@@ -319,12 +394,17 @@ class CustomerSheetFragment : Fragment() {
|
|
|
319
394
|
return paymentOptionResult
|
|
320
395
|
}
|
|
321
396
|
|
|
322
|
-
private fun buildResult(
|
|
397
|
+
private fun buildResult(
|
|
398
|
+
label: String,
|
|
399
|
+
drawable: Drawable,
|
|
400
|
+
paymentMethod: PaymentMethod?,
|
|
401
|
+
): WritableMap {
|
|
323
402
|
val result = Arguments.createMap()
|
|
324
|
-
val paymentOption =
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
403
|
+
val paymentOption =
|
|
404
|
+
Arguments.createMap().also {
|
|
405
|
+
it.putString("label", label)
|
|
406
|
+
it.putString("image", getBase64FromBitmap(getBitmapFromDrawable(drawable)))
|
|
407
|
+
}
|
|
328
408
|
result.putMap("paymentOption", paymentOption)
|
|
329
409
|
if (paymentMethod != null) {
|
|
330
410
|
result.putMap("paymentMethod", mapFromPaymentMethod(paymentMethod))
|
package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerAdapter.kt
CHANGED
|
@@ -3,14 +3,13 @@ package com.reactnativestripesdk.customersheet
|
|
|
3
3
|
import android.util.Log
|
|
4
4
|
import com.facebook.react.bridge.Arguments
|
|
5
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
-
import com.facebook.react.bridge.ReadableMap
|
|
7
6
|
import com.facebook.react.bridge.WritableMap
|
|
8
7
|
import com.reactnativestripesdk.StripeSdkModule
|
|
9
8
|
import com.stripe.android.customersheet.CustomerAdapter
|
|
10
9
|
import com.stripe.android.model.PaymentMethod
|
|
11
10
|
import kotlinx.coroutines.CompletableDeferred
|
|
12
11
|
|
|
13
|
-
class ReactNativeCustomerAdapter
|
|
12
|
+
class ReactNativeCustomerAdapter(
|
|
14
13
|
private val context: ReactApplicationContext,
|
|
15
14
|
private val adapter: CustomerAdapter,
|
|
16
15
|
private val overridesFetchPaymentMethods: Boolean,
|
|
@@ -18,7 +17,7 @@ class ReactNativeCustomerAdapter (
|
|
|
18
17
|
private val overridesDetachPaymentMethod: Boolean,
|
|
19
18
|
private val overridesSetSelectedPaymentOption: Boolean,
|
|
20
19
|
private val overridesFetchSelectedPaymentOption: Boolean,
|
|
21
|
-
private val overridesSetupIntentClientSecretForCustomerAttach: Boolean
|
|
20
|
+
private val overridesSetupIntentClientSecretForCustomerAttach: Boolean,
|
|
22
21
|
) : CustomerAdapter by adapter {
|
|
23
22
|
internal var fetchPaymentMethodsCallback: CompletableDeferred<List<PaymentMethod>>? = null
|
|
24
23
|
internal var attachPaymentMethodCallback: CompletableDeferred<PaymentMethod>? = null
|
|
@@ -44,9 +43,7 @@ class ReactNativeCustomerAdapter (
|
|
|
44
43
|
if (overridesAttachPaymentMethod) {
|
|
45
44
|
CompletableDeferred<PaymentMethod>().also {
|
|
46
45
|
attachPaymentMethodCallback = it
|
|
47
|
-
val params = Arguments.createMap().also {
|
|
48
|
-
it.putString("paymentMethodId", paymentMethodId)
|
|
49
|
-
}
|
|
46
|
+
val params = Arguments.createMap().also { it.putString("paymentMethodId", paymentMethodId) }
|
|
50
47
|
emitEvent("onCustomerAdapterAttachPaymentMethodCallback", params)
|
|
51
48
|
val resultFromJavascript = it.await()
|
|
52
49
|
return CustomerAdapter.Result.success(resultFromJavascript)
|
|
@@ -60,9 +57,7 @@ class ReactNativeCustomerAdapter (
|
|
|
60
57
|
if (overridesDetachPaymentMethod) {
|
|
61
58
|
CompletableDeferred<PaymentMethod>().also {
|
|
62
59
|
detachPaymentMethodCallback = it
|
|
63
|
-
val params = Arguments.createMap().also {
|
|
64
|
-
it.putString("paymentMethodId", paymentMethodId)
|
|
65
|
-
}
|
|
60
|
+
val params = Arguments.createMap().also { it.putString("paymentMethodId", paymentMethodId) }
|
|
66
61
|
emitEvent("onCustomerAdapterDetachPaymentMethodCallback", params)
|
|
67
62
|
val resultFromJavascript = it.await()
|
|
68
63
|
return CustomerAdapter.Result.success(resultFromJavascript)
|
|
@@ -76,9 +71,7 @@ class ReactNativeCustomerAdapter (
|
|
|
76
71
|
if (overridesSetSelectedPaymentOption) {
|
|
77
72
|
CompletableDeferred<Unit>().also {
|
|
78
73
|
setSelectedPaymentOptionCallback = it
|
|
79
|
-
val params = Arguments.createMap().also {
|
|
80
|
-
it.putString("paymentOption", paymentOption?.id)
|
|
81
|
-
}
|
|
74
|
+
val params = Arguments.createMap().also { it.putString("paymentOption", paymentOption?.id) }
|
|
82
75
|
emitEvent("onCustomerAdapterSetSelectedPaymentOptionCallback", params)
|
|
83
76
|
val resultFromJavascript = it.await()
|
|
84
77
|
return CustomerAdapter.Result.success(resultFromJavascript)
|
|
@@ -99,7 +92,7 @@ class ReactNativeCustomerAdapter (
|
|
|
99
92
|
CustomerAdapter.PaymentOption.fromId(resultFromJavascript)
|
|
100
93
|
} else {
|
|
101
94
|
null
|
|
102
|
-
}
|
|
95
|
+
},
|
|
103
96
|
)
|
|
104
97
|
}
|
|
105
98
|
}
|
|
@@ -111,7 +104,10 @@ class ReactNativeCustomerAdapter (
|
|
|
111
104
|
if (overridesSetupIntentClientSecretForCustomerAttach) {
|
|
112
105
|
CompletableDeferred<String>().also {
|
|
113
106
|
setupIntentClientSecretForCustomerAttachCallback = it
|
|
114
|
-
emitEvent(
|
|
107
|
+
emitEvent(
|
|
108
|
+
"onCustomerAdapterSetupIntentClientSecretForCustomerAttachCallback",
|
|
109
|
+
Arguments.createMap(),
|
|
110
|
+
)
|
|
115
111
|
val resultFromJavascript = it.await()
|
|
116
112
|
return CustomerAdapter.Result.success(resultFromJavascript)
|
|
117
113
|
}
|
|
@@ -120,17 +116,18 @@ class ReactNativeCustomerAdapter (
|
|
|
120
116
|
return adapter.setupIntentClientSecretForCustomerAttach()
|
|
121
117
|
}
|
|
122
118
|
|
|
123
|
-
private fun emitEvent(
|
|
119
|
+
private fun emitEvent(
|
|
120
|
+
eventName: String,
|
|
121
|
+
params: WritableMap,
|
|
122
|
+
) {
|
|
124
123
|
val stripeSdkModule: StripeSdkModule? = context.getNativeModule(StripeSdkModule::class.java)
|
|
125
124
|
if (stripeSdkModule == null || stripeSdkModule.eventListenerCount == 0) {
|
|
126
125
|
Log.e(
|
|
127
126
|
"StripeReactNative",
|
|
128
|
-
"Tried to call $eventName, but no callback was found. Please file an issue: https://github.com/stripe/stripe-react-native/issues"
|
|
127
|
+
"Tried to call $eventName, but no callback was found. Please file an issue: https://github.com/stripe/stripe-react-native/issues",
|
|
129
128
|
)
|
|
130
129
|
}
|
|
131
130
|
|
|
132
131
|
stripeSdkModule?.sendEvent(context, eventName, params)
|
|
133
132
|
}
|
|
134
133
|
}
|
|
135
|
-
|
|
136
|
-
|