@stripe/stripe-react-native 0.44.0 → 0.45.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/.clang-format +90 -0
- package/.editorconfig +3 -0
- package/CHANGELOG.md +7 -1
- package/android/build.gradle +89 -18
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormViewManager.kt +15 -6
- package/android/src/main/java/com/reactnativestripesdk/CardChangeEvent.kt +56 -0
- package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +4 -4
- package/android/src/main/java/com/reactnativestripesdk/CardFieldViewManager.kt +55 -45
- package/android/src/main/java/com/reactnativestripesdk/{CardFocusEvent.kt → CardFocusChangeEvent.kt} +2 -2
- package/android/src/main/java/com/reactnativestripesdk/CardFormCompleteEvent.kt +17 -16
- package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +5 -5
- package/android/src/main/java/com/reactnativestripesdk/CardFormViewManager.kt +39 -33
- package/android/src/main/java/com/reactnativestripesdk/CollectBankAccountLauncherFragment.kt +4 -2
- package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementView.kt +182 -0
- package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +231 -0
- package/android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetFragment.kt +8 -5
- package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonManager.kt +14 -6
- package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +3 -1
- package/android/src/main/java/com/reactnativestripesdk/PaymentOptionDisplayDataMapper.kt +17 -0
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +266 -0
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +8 -13
- package/android/src/main/java/com/reactnativestripesdk/StripeContainerManager.kt +11 -3
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +106 -59
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +34 -4
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +33 -27
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetViewManager.kt +49 -24
- package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetFragment.kt +16 -3
- package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerAdapter.kt +11 -29
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonManager.kt +36 -12
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt +5 -3
- package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +4 -0
- package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +21 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/AddToWalletButtonManagerDelegate.java +49 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/AddToWalletButtonManagerInterface.java +25 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/AddressSheetViewManagerDelegate.java +64 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/AddressSheetViewManagerInterface.java +30 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerDelegate.java +41 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerInterface.java +20 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/AuBECSDebitFormManagerDelegate.java +36 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/AuBECSDebitFormManagerInterface.java +20 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFieldManagerDelegate.java +73 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFieldManagerInterface.java +31 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFormManagerDelegate.java +67 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFormManagerInterface.java +29 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerDelegate.java +49 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerInterface.java +21 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/GooglePayButtonManagerDelegate.java +38 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/GooglePayButtonManagerInterface.java +19 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/StripeContainerManagerDelegate.java +32 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/StripeContainerManagerInterface.java +17 -0
- package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +311 -0
- package/ios/AddressSheet/AddressSheetUtils.swift +21 -19
- package/ios/AddressSheet/AddressSheetView.swift +23 -17
- package/ios/ApplePayButtonManager.m +0 -1
- package/ios/ApplePayButtonManager.swift +1 -3
- package/ios/ApplePayButtonView.swift +25 -20
- package/ios/ApplePayViewController.swift +22 -22
- package/ios/AuBECSDebitFormView.swift +14 -8
- package/ios/CardFieldManager.swift +1 -4
- package/ios/CardFieldView.swift +28 -25
- package/ios/CardFormManager.swift +1 -4
- package/ios/CardFormView.swift +25 -16
- package/ios/CustomerSheet/CustomerSheetUtils.swift +12 -16
- package/ios/CustomerSheet/ReactNativeCustomerAdapter.swift +8 -8
- package/ios/EmbeddedPaymentElementManager.m +6 -0
- package/ios/EmbeddedPaymentElementView.swift +48 -0
- package/ios/NewArch/AddToWalletButtonComponentView.h +10 -0
- package/ios/NewArch/AddToWalletButtonComponentView.mm +93 -0
- package/ios/NewArch/AddressSheetViewComponentView.h +10 -0
- package/ios/NewArch/AddressSheetViewComponentView.mm +109 -0
- package/ios/NewArch/ApplePayButtonComponentView.h +10 -0
- package/ios/NewArch/ApplePayButtonComponentView.mm +124 -0
- package/ios/NewArch/AuBECSDebitFormComponentView.h +10 -0
- package/ios/NewArch/AuBECSDebitFormComponentView.mm +95 -0
- package/ios/NewArch/CardFieldComponentView.h +10 -0
- package/ios/NewArch/CardFieldComponentView.mm +125 -0
- package/ios/NewArch/CardFormComponentView.h +10 -0
- package/ios/NewArch/CardFormComponentView.mm +108 -0
- package/ios/NewArch/StripeContainerComponentView.h +10 -0
- package/ios/NewArch/StripeContainerComponentView.mm +74 -0
- package/ios/NewArch/StripeNewArchConversions.h +20 -0
- package/ios/NewArch/StripeNewArchConversions.mm +47 -0
- package/ios/OldArch/StripeSdkEventEmitterCompat.h +27 -0
- package/ios/OldArch/StripeSdkEventEmitterCompat.m +105 -0
- package/ios/PaymentOptionDisplayData+ReactNative.swift +55 -0
- package/ios/PaymentSheetAppearance.swift +194 -1
- package/ios/PushProvisioning/AddToWalletButtonView.swift +19 -13
- package/ios/StripeContainerView.swift +5 -3
- package/ios/StripeSdk.h +21 -0
- package/ios/StripeSdk.mm +415 -0
- package/ios/StripeSdkEmitter.swift +19 -0
- package/ios/{StripeSdk+CustomerSheet.swift → StripeSdkImpl+CustomerSheet.swift} +24 -25
- package/ios/StripeSdkImpl+Embedded.swift +327 -0
- package/ios/{StripeSdk+PaymentSheet.swift → StripeSdkImpl+PaymentSheet.swift} +18 -29
- package/ios/{StripeSdk.swift → StripeSdkImpl.swift} +50 -72
- package/ios/StripeSwiftInterop.h +25 -0
- package/ios/stripe_react_native.h +2 -0
- 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/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/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/events.js +2 -0
- package/lib/commonjs/events.js.map +1 -0
- package/lib/commonjs/functions.js +1 -1
- package/lib/commonjs/functions.js.map +1 -1
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeAddToWalletButton.js +2 -0
- package/lib/commonjs/specs/NativeAddToWalletButton.js.map +1 -0
- package/lib/commonjs/specs/NativeAddressSheet.js +2 -0
- package/lib/commonjs/specs/NativeAddressSheet.js.map +1 -0
- package/lib/commonjs/specs/NativeApplePayButton.js +2 -0
- package/lib/commonjs/specs/NativeApplePayButton.js.map +1 -0
- package/lib/commonjs/specs/NativeAuBECSDebitForm.js +2 -0
- package/lib/commonjs/specs/NativeAuBECSDebitForm.js.map +1 -0
- package/lib/commonjs/specs/NativeCardField.js +2 -0
- package/lib/commonjs/specs/NativeCardField.js.map +1 -0
- package/lib/commonjs/specs/NativeCardForm.js +2 -0
- package/lib/commonjs/specs/NativeCardForm.js.map +1 -0
- package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js +2 -0
- package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js.map +1 -0
- package/lib/commonjs/specs/NativeGooglePayButton.js +2 -0
- package/lib/commonjs/specs/NativeGooglePayButton.js.map +1 -0
- package/lib/commonjs/specs/NativeStripeContainer.js +2 -0
- package/lib/commonjs/specs/NativeStripeContainer.js.map +1 -0
- package/lib/commonjs/specs/NativeStripeSdkModule.js +2 -0
- package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -0
- package/lib/commonjs/specs/utils.js +2 -0
- package/lib/commonjs/specs/utils.js.map +1 -0
- package/lib/commonjs/types/EmbeddedPaymentElement.js +2 -0
- package/lib/commonjs/types/EmbeddedPaymentElement.js.map +1 -0
- package/lib/commonjs/types/PaymentSheet.js +1 -1
- package/lib/commonjs/types/PaymentSheet.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/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/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/events.js +2 -0
- package/lib/module/events.js.map +1 -0
- package/lib/module/functions.js +1 -1
- package/lib/module/functions.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeAddToWalletButton.js +2 -0
- package/lib/module/specs/NativeAddToWalletButton.js.map +1 -0
- package/lib/module/specs/NativeAddressSheet.js +2 -0
- package/lib/module/specs/NativeAddressSheet.js.map +1 -0
- package/lib/module/specs/NativeApplePayButton.js +2 -0
- package/lib/module/specs/NativeApplePayButton.js.map +1 -0
- package/lib/module/specs/NativeAuBECSDebitForm.js +2 -0
- package/lib/module/specs/NativeAuBECSDebitForm.js.map +1 -0
- package/lib/module/specs/NativeCardField.js +2 -0
- package/lib/module/specs/NativeCardField.js.map +1 -0
- package/lib/module/specs/NativeCardForm.js +2 -0
- package/lib/module/specs/NativeCardForm.js.map +1 -0
- package/lib/module/specs/NativeEmbeddedPaymentElement.js +2 -0
- package/lib/module/specs/NativeEmbeddedPaymentElement.js.map +1 -0
- package/lib/module/specs/NativeGooglePayButton.js +2 -0
- package/lib/module/specs/NativeGooglePayButton.js.map +1 -0
- package/lib/module/specs/NativeStripeContainer.js +2 -0
- package/lib/module/specs/NativeStripeContainer.js.map +1 -0
- package/lib/module/specs/NativeStripeSdkModule.js +2 -0
- package/lib/module/specs/NativeStripeSdkModule.js.map +1 -0
- package/lib/module/specs/utils.js +2 -0
- package/lib/module/specs/utils.js.map +1 -0
- package/lib/module/types/EmbeddedPaymentElement.js +2 -0
- package/lib/module/types/EmbeddedPaymentElement.js.map +1 -0
- package/lib/module/types/PaymentSheet.js +1 -1
- package/lib/module/types/PaymentSheet.js.map +1 -1
- package/lib/typescript/src/components/AddToWalletButton.d.ts.map +1 -1
- package/lib/typescript/src/components/AddressSheet.d.ts.map +1 -1
- package/lib/typescript/src/components/AuBECSDebitForm.d.ts.map +1 -1
- package/lib/typescript/src/components/CardField.d.ts +1 -1
- package/lib/typescript/src/components/CardField.d.ts.map +1 -1
- package/lib/typescript/src/components/CardForm.d.ts +1 -1
- package/lib/typescript/src/components/CardForm.d.ts.map +1 -1
- package/lib/typescript/src/components/CustomerSheet.d.ts +1 -1
- package/lib/typescript/src/components/CustomerSheet.d.ts.map +1 -1
- package/lib/typescript/src/components/StripeContainer.d.ts.map +1 -1
- package/lib/typescript/src/events.d.ts +13 -0
- package/lib/typescript/src/events.d.ts.map +1 -0
- package/lib/typescript/src/functions.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useFinancialConnectionsSheet.d.ts +4 -4
- package/lib/typescript/src/hooks/useFinancialConnectionsSheet.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useStripe.d.ts +2 -2
- package/lib/typescript/src/hooks/useStripe.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeAddToWalletButton.d.ts +27 -0
- package/lib/typescript/src/specs/NativeAddToWalletButton.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeAddressSheet.d.ts +34 -0
- package/lib/typescript/src/specs/NativeAddressSheet.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeApplePayButton.d.ts +28 -0
- package/lib/typescript/src/specs/NativeApplePayButton.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeAuBECSDebitForm.d.ts +19 -0
- package/lib/typescript/src/specs/NativeAuBECSDebitForm.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeCardField.d.ts +33 -0
- package/lib/typescript/src/specs/NativeCardField.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeCardForm.d.ts +31 -0
- package/lib/typescript/src/specs/NativeCardForm.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeEmbeddedPaymentElement.d.ts +22 -0
- package/lib/typescript/src/specs/NativeEmbeddedPaymentElement.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeGooglePayButton.d.ts +11 -0
- package/lib/typescript/src/specs/NativeGooglePayButton.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeStripeContainer.d.ts +8 -0
- package/lib/typescript/src/specs/NativeStripeContainer.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +93 -0
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -0
- package/lib/typescript/src/specs/utils.d.ts +20 -0
- package/lib/typescript/src/specs/utils.d.ts.map +1 -0
- package/lib/typescript/src/types/CustomerSheet.d.ts +1 -5
- package/lib/typescript/src/types/CustomerSheet.d.ts.map +1 -1
- package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts +161 -0
- package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts.map +1 -0
- package/lib/typescript/src/types/PaymentSheet.d.ts +97 -4
- package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -1
- package/lib/typescript/src/types/components/CardFieldInput.d.ts +3 -2
- package/lib/typescript/src/types/components/CardFieldInput.d.ts.map +1 -1
- package/lib/typescript/src/types/components/CardFormView.d.ts +3 -1
- package/lib/typescript/src/types/components/CardFormView.d.ts.map +1 -1
- package/package.json +20 -1
- package/src/components/AddToWalletButton.tsx +2 -5
- package/src/components/AddressSheet.tsx +5 -16
- package/src/components/AuBECSDebitForm.tsx +3 -12
- package/src/components/CardField.tsx +20 -30
- package/src/components/CardForm.tsx +14 -29
- package/src/components/CustomerSheet.tsx +23 -25
- package/src/components/PlatformPayButton.tsx +6 -6
- package/src/components/StripeContainer.tsx +5 -12
- package/src/components/StripeProvider.tsx +1 -1
- package/src/events.ts +49 -0
- package/src/functions.ts +13 -24
- package/src/hooks/useFinancialConnectionsSheet.tsx +2 -2
- package/src/hooks/useStripe.tsx +2 -2
- package/src/index.tsx +3 -0
- package/src/specs/NativeAddToWalletButton.ts +40 -0
- package/src/specs/NativeAddressSheet.ts +50 -0
- package/src/specs/NativeApplePayButton.ts +40 -0
- package/src/specs/NativeAuBECSDebitForm.ts +24 -0
- package/src/specs/NativeCardField.ts +51 -0
- package/src/specs/NativeCardForm.ts +43 -0
- package/src/specs/NativeEmbeddedPaymentElement.ts +37 -0
- package/src/specs/NativeGooglePayButton.ts +20 -0
- package/src/specs/NativeStripeContainer.ts +12 -0
- package/src/specs/NativeStripeSdkModule.ts +219 -0
- package/src/specs/utils.ts +22 -0
- package/src/types/CustomerSheet.ts +1 -5
- package/src/types/EmbeddedPaymentElement.tsx +467 -0
- package/src/types/PaymentSheet.ts +114 -4
- package/src/types/components/CardFieldInput.ts +1 -2
- package/src/types/components/CardFormView.ts +1 -1
- package/stripe-react-native.podspec +27 -2
- 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/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.11.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.11.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/src/main/java/com/reactnativestripesdk/CardChangedEvent.kt +0 -54
- package/ios/StripeSdk.m +0 -244
- package/lib/commonjs/NativeStripeSdk.js +0 -2
- package/lib/commonjs/NativeStripeSdk.js.map +0 -1
- package/lib/commonjs/components/ApplePayButtonNative.js +0 -2
- package/lib/commonjs/components/ApplePayButtonNative.js.map +0 -1
- package/lib/commonjs/components/GooglePayButtonNative.js +0 -2
- package/lib/commonjs/components/GooglePayButtonNative.js.map +0 -1
- package/lib/module/NativeStripeSdk.js +0 -2
- package/lib/module/NativeStripeSdk.js.map +0 -1
- package/lib/module/components/ApplePayButtonNative.js +0 -2
- package/lib/module/components/ApplePayButtonNative.js.map +0 -1
- package/lib/module/components/GooglePayButtonNative.js +0 -2
- package/lib/module/components/GooglePayButtonNative.js.map +0 -1
- package/lib/typescript/src/NativeStripeSdk.d.ts +0 -58
- package/lib/typescript/src/NativeStripeSdk.d.ts.map +0 -1
- package/lib/typescript/src/components/ApplePayButtonNative.d.ts +0 -4
- package/lib/typescript/src/components/ApplePayButtonNative.d.ts.map +0 -1
- package/lib/typescript/src/components/GooglePayButtonNative.d.ts +0 -4
- package/lib/typescript/src/components/GooglePayButtonNative.d.ts.map +0 -1
- package/src/NativeStripeSdk.tsx +0 -159
- package/src/components/ApplePayButtonNative.tsx +0 -5
- package/src/components/GooglePayButtonNative.tsx +0 -7
|
@@ -10,29 +10,30 @@ internal class CardFormCompleteEvent(
|
|
|
10
10
|
private val cardDetails: MutableMap<String, Any>?,
|
|
11
11
|
private val complete: Boolean,
|
|
12
12
|
private val dangerouslyGetFullCardDetails: Boolean,
|
|
13
|
-
) : Event<
|
|
13
|
+
) : Event<CardChangeEvent>(surfaceId, viewTag) {
|
|
14
14
|
override fun getEventName() = EVENT_NAME
|
|
15
15
|
|
|
16
16
|
override fun getEventData(): WritableMap? {
|
|
17
|
-
val
|
|
17
|
+
val cardData = Arguments.createMap()
|
|
18
18
|
|
|
19
|
-
if (cardDetails
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
eventData.putBoolean("complete", complete)
|
|
28
|
-
eventData.putString("postalCode", cardDetails["postalCode"]?.toString())
|
|
19
|
+
if (cardDetails != null) {
|
|
20
|
+
cardData.putString("brand", cardDetails["brand"]?.toString())
|
|
21
|
+
cardData.putString("last4", cardDetails["last4"]?.toString())
|
|
22
|
+
cardData.putString("country", cardDetails["country"]?.toString())
|
|
23
|
+
cardData.putInt("expiryMonth", cardDetails["expiryMonth"] as Int)
|
|
24
|
+
cardData.putInt("expiryYear", cardDetails["expiryYear"] as Int)
|
|
25
|
+
cardData.putBoolean("complete", complete)
|
|
26
|
+
cardData.putString("postalCode", cardDetails["postalCode"]?.toString())
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
if (dangerouslyGetFullCardDetails) {
|
|
29
|
+
cardData.putString("number", cardDetails["number"]?.toString()?.replace(" ", ""))
|
|
30
|
+
cardData.putString("cvc", cardDetails["cvc"]?.toString())
|
|
31
|
+
}
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
return
|
|
34
|
+
return Arguments.createMap().apply {
|
|
35
|
+
putMap("card", cardData)
|
|
36
|
+
}
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
companion object {
|
|
@@ -65,8 +65,8 @@ class CardFormView(
|
|
|
65
65
|
cardFormViewBinding.postalCodeContainer.visibility = visibility
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
fun setDefaultValues(defaults: ReadableMap) {
|
|
69
|
-
setCountry(defaults
|
|
68
|
+
fun setDefaultValues(defaults: ReadableMap?) {
|
|
69
|
+
setCountry(defaults?.getString("countryCode"))
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
fun setDisabled(isDisabled: Boolean) {
|
|
@@ -86,7 +86,7 @@ class CardFormView(
|
|
|
86
86
|
setPostalCodeFilter()
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
fun setPlaceHolders(value: ReadableMap) {
|
|
89
|
+
fun setPlaceHolders(value: ReadableMap?) {
|
|
90
90
|
val numberPlaceholder = getValOr(value, "number", null)
|
|
91
91
|
val expirationPlaceholder = getValOr(value, "expiration", null)
|
|
92
92
|
val cvcPlaceholder = getValOr(value, "cvc", null)
|
|
@@ -136,11 +136,11 @@ class CardFormView(
|
|
|
136
136
|
private fun onChangeFocus() {
|
|
137
137
|
UIManagerHelper
|
|
138
138
|
.getEventDispatcherForReactTag(context, id)
|
|
139
|
-
?.dispatchEvent(
|
|
139
|
+
?.dispatchEvent(CardFocusChangeEvent(context.surfaceId, id, currentFocusedField))
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
@SuppressLint("RestrictedApi")
|
|
143
|
-
fun setCardStyle(value: ReadableMap) {
|
|
143
|
+
fun setCardStyle(value: ReadableMap?) {
|
|
144
144
|
val backgroundColor = getValOr(value, "backgroundColor", null)
|
|
145
145
|
val textColor = getValOr(value, "textColor", null)
|
|
146
146
|
val borderWidth = getIntOrNull(value, "borderWidth")
|
|
@@ -1,86 +1,82 @@
|
|
|
1
1
|
package com.reactnativestripesdk
|
|
2
2
|
|
|
3
|
+
import com.facebook.react.bridge.Dynamic
|
|
3
4
|
import com.facebook.react.bridge.ReadableArray
|
|
4
|
-
import com.facebook.react.bridge.ReadableMap
|
|
5
5
|
import com.facebook.react.module.annotations.ReactModule
|
|
6
6
|
import com.facebook.react.uimanager.SimpleViewManager
|
|
7
7
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
8
8
|
import com.facebook.react.uimanager.annotations.ReactProp
|
|
9
|
+
import com.facebook.react.viewmanagers.CardFormManagerDelegate
|
|
10
|
+
import com.facebook.react.viewmanagers.CardFormManagerInterface
|
|
11
|
+
import com.reactnativestripesdk.utils.asMapOrNull
|
|
9
12
|
|
|
10
13
|
@ReactModule(name = CardFormViewManager.REACT_CLASS)
|
|
11
|
-
class CardFormViewManager :
|
|
14
|
+
class CardFormViewManager :
|
|
15
|
+
SimpleViewManager<CardFormView>(),
|
|
16
|
+
CardFormManagerInterface<CardFormView> {
|
|
17
|
+
private val delegate = CardFormManagerDelegate(this)
|
|
18
|
+
private var reactContextRef: ThemedReactContext? = null
|
|
19
|
+
|
|
12
20
|
override fun getName() = REACT_CLASS
|
|
13
21
|
|
|
14
|
-
|
|
22
|
+
override fun getDelegate() = delegate
|
|
15
23
|
|
|
16
24
|
override fun getExportedCustomDirectEventTypeConstants() =
|
|
17
25
|
mutableMapOf(
|
|
18
|
-
|
|
26
|
+
CardFocusChangeEvent.EVENT_NAME to mutableMapOf("registrationName" to "onFocusChange"),
|
|
19
27
|
CardFormCompleteEvent.EVENT_NAME to mutableMapOf("registrationName" to "onFormComplete"),
|
|
20
28
|
)
|
|
21
29
|
|
|
22
|
-
override fun receiveCommand(
|
|
23
|
-
root: CardFormView,
|
|
24
|
-
commandId: String?,
|
|
25
|
-
args: ReadableArray?,
|
|
26
|
-
) {
|
|
27
|
-
when (commandId) {
|
|
28
|
-
"focus" -> root.requestFocusFromJS()
|
|
29
|
-
"blur" -> root.requestBlurFromJS()
|
|
30
|
-
"clear" -> root.requestClearFromJS()
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
30
|
@ReactProp(name = "dangerouslyGetFullCardDetails")
|
|
35
|
-
fun setDangerouslyGetFullCardDetails(
|
|
31
|
+
override fun setDangerouslyGetFullCardDetails(
|
|
36
32
|
view: CardFormView,
|
|
37
|
-
dangerouslyGetFullCardDetails: Boolean
|
|
33
|
+
dangerouslyGetFullCardDetails: Boolean,
|
|
38
34
|
) {
|
|
39
35
|
view.setDangerouslyGetFullCardDetails(dangerouslyGetFullCardDetails)
|
|
40
36
|
}
|
|
41
37
|
|
|
42
38
|
@ReactProp(name = "postalCodeEnabled")
|
|
43
|
-
fun setPostalCodeEnabled(
|
|
39
|
+
override fun setPostalCodeEnabled(
|
|
44
40
|
view: CardFormView,
|
|
45
|
-
postalCodeEnabled: Boolean
|
|
41
|
+
postalCodeEnabled: Boolean,
|
|
46
42
|
) {
|
|
47
43
|
view.setPostalCodeEnabled(postalCodeEnabled)
|
|
48
44
|
}
|
|
49
45
|
|
|
50
46
|
@ReactProp(name = "placeholders")
|
|
51
|
-
fun
|
|
47
|
+
override fun setPlaceholders(
|
|
52
48
|
view: CardFormView,
|
|
53
|
-
placeholders:
|
|
49
|
+
placeholders: Dynamic,
|
|
54
50
|
) {
|
|
55
|
-
view.setPlaceHolders(placeholders)
|
|
51
|
+
view.setPlaceHolders(placeholders.asMapOrNull())
|
|
56
52
|
}
|
|
57
53
|
|
|
58
54
|
@ReactProp(name = "autofocus")
|
|
59
|
-
fun setAutofocus(
|
|
55
|
+
override fun setAutofocus(
|
|
60
56
|
view: CardFormView,
|
|
61
|
-
autofocus: Boolean
|
|
57
|
+
autofocus: Boolean,
|
|
62
58
|
) {
|
|
63
59
|
view.setAutofocus(autofocus)
|
|
64
60
|
}
|
|
65
61
|
|
|
66
62
|
@ReactProp(name = "cardStyle")
|
|
67
|
-
fun setCardStyle(
|
|
63
|
+
override fun setCardStyle(
|
|
68
64
|
view: CardFormView,
|
|
69
|
-
cardStyle:
|
|
65
|
+
cardStyle: Dynamic,
|
|
70
66
|
) {
|
|
71
|
-
view.setCardStyle(cardStyle)
|
|
67
|
+
view.setCardStyle(cardStyle.asMapOrNull())
|
|
72
68
|
}
|
|
73
69
|
|
|
74
70
|
@ReactProp(name = "defaultValues")
|
|
75
|
-
fun setDefaultValues(
|
|
71
|
+
override fun setDefaultValues(
|
|
76
72
|
view: CardFormView,
|
|
77
|
-
defaults:
|
|
73
|
+
defaults: Dynamic,
|
|
78
74
|
) {
|
|
79
|
-
view.setDefaultValues(defaults)
|
|
75
|
+
view.setDefaultValues(defaults.asMapOrNull())
|
|
80
76
|
}
|
|
81
77
|
|
|
82
78
|
@ReactProp(name = "disabled")
|
|
83
|
-
fun setDisabled(
|
|
79
|
+
override fun setDisabled(
|
|
84
80
|
view: CardFormView,
|
|
85
81
|
isDisabled: Boolean,
|
|
86
82
|
) {
|
|
@@ -88,7 +84,7 @@ class CardFormViewManager : SimpleViewManager<CardFormView>() {
|
|
|
88
84
|
}
|
|
89
85
|
|
|
90
86
|
@ReactProp(name = "preferredNetworks")
|
|
91
|
-
fun setPreferredNetworks(
|
|
87
|
+
override fun setPreferredNetworks(
|
|
92
88
|
view: CardFormView,
|
|
93
89
|
preferredNetworks: ReadableArray?,
|
|
94
90
|
) {
|
|
@@ -116,6 +112,16 @@ class CardFormViewManager : SimpleViewManager<CardFormView>() {
|
|
|
116
112
|
reactContextRef = null
|
|
117
113
|
}
|
|
118
114
|
|
|
115
|
+
// Native commands
|
|
116
|
+
|
|
117
|
+
override fun blur(view: CardFormView) {
|
|
118
|
+
view.requestBlurFromJS()
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
override fun focus(view: CardFormView) {
|
|
122
|
+
view.requestFocusFromJS()
|
|
123
|
+
}
|
|
124
|
+
|
|
119
125
|
companion object {
|
|
120
126
|
const val REACT_CLASS = "CardForm"
|
|
121
127
|
}
|
package/android/src/main/java/com/reactnativestripesdk/CollectBankAccountLauncherFragment.kt
CHANGED
|
@@ -38,10 +38,10 @@ class CollectBankAccountLauncherFragment(
|
|
|
38
38
|
super.onCreate(savedInstanceState)
|
|
39
39
|
|
|
40
40
|
val stripeSdkModule: StripeSdkModule? = context.getNativeModule(StripeSdkModule::class.java)
|
|
41
|
-
if (stripeSdkModule != null
|
|
41
|
+
if (stripeSdkModule != null) {
|
|
42
42
|
FinancialConnections.setEventListener { event ->
|
|
43
43
|
val params = mapFromFinancialConnectionsEvent(event)
|
|
44
|
-
stripeSdkModule.
|
|
44
|
+
stripeSdkModule.emitOnFinancialConnectionsEvent(params)
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -108,11 +108,13 @@ class CollectBankAccountLauncherFragment(
|
|
|
108
108
|
)
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
+
|
|
111
112
|
is CollectBankAccountResult.Cancelled -> {
|
|
112
113
|
promise.resolve(
|
|
113
114
|
createError(ErrorType.Canceled.toString(), "Bank account collection was canceled."),
|
|
114
115
|
)
|
|
115
116
|
}
|
|
117
|
+
|
|
116
118
|
is CollectBankAccountResult.Failed -> {
|
|
117
119
|
promise.resolve(createError(ErrorType.Failed.toString(), result.error))
|
|
118
120
|
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
package com.reactnativestripesdk
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import androidx.compose.runtime.Composable
|
|
5
|
+
import androidx.compose.runtime.LaunchedEffect
|
|
6
|
+
import androidx.compose.ui.platform.AbstractComposeView
|
|
7
|
+
import com.facebook.react.bridge.Arguments
|
|
8
|
+
import com.facebook.react.bridge.ReactContext
|
|
9
|
+
import com.reactnativestripesdk.utils.mapFromPaymentMethod
|
|
10
|
+
import com.stripe.android.paymentelement.EmbeddedPaymentElement
|
|
11
|
+
import com.stripe.android.paymentelement.ExperimentalEmbeddedPaymentElementApi
|
|
12
|
+
import com.stripe.android.paymentelement.rememberEmbeddedPaymentElement
|
|
13
|
+
import com.stripe.android.paymentsheet.CreateIntentResult
|
|
14
|
+
import com.stripe.android.paymentsheet.PaymentSheet
|
|
15
|
+
import kotlinx.coroutines.CompletableDeferred
|
|
16
|
+
import kotlinx.coroutines.channels.Channel
|
|
17
|
+
import kotlinx.coroutines.flow.consumeAsFlow
|
|
18
|
+
import toWritableMap
|
|
19
|
+
|
|
20
|
+
@OptIn(ExperimentalEmbeddedPaymentElementApi::class)
|
|
21
|
+
class EmbeddedPaymentElementView(
|
|
22
|
+
context: Context,
|
|
23
|
+
) : AbstractComposeView(context) {
|
|
24
|
+
private sealed interface Event {
|
|
25
|
+
data class Configure(
|
|
26
|
+
val configuration: EmbeddedPaymentElement.Configuration,
|
|
27
|
+
val intentConfiguration: PaymentSheet.IntentConfiguration,
|
|
28
|
+
) : Event
|
|
29
|
+
|
|
30
|
+
data object Confirm : Event
|
|
31
|
+
|
|
32
|
+
data object ClearPaymentOption : Event
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var latestIntentConfig: PaymentSheet.IntentConfiguration? = null
|
|
36
|
+
var latestElementConfig: EmbeddedPaymentElement.Configuration? = null
|
|
37
|
+
|
|
38
|
+
private val reactContext get() = context as ReactContext
|
|
39
|
+
private val events = Channel<Event>(Channel.UNLIMITED)
|
|
40
|
+
|
|
41
|
+
private val builder by lazy {
|
|
42
|
+
EmbeddedPaymentElement.Builder(
|
|
43
|
+
createIntentCallback = { paymentMethod, shouldSavePaymentMethod ->
|
|
44
|
+
val stripeSdkModule =
|
|
45
|
+
try {
|
|
46
|
+
requireStripeSdkModule()
|
|
47
|
+
} catch (ex: IllegalArgumentException) {
|
|
48
|
+
return@Builder CreateIntentResult.Failure(
|
|
49
|
+
cause =
|
|
50
|
+
Exception(
|
|
51
|
+
"Tried to call confirmHandler, but no callback was found. Please file an issue: https://github.com/stripe/stripe-react-native/issues",
|
|
52
|
+
),
|
|
53
|
+
displayMessage = "An unexpected error occurred",
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
val params =
|
|
57
|
+
Arguments.createMap().apply {
|
|
58
|
+
putMap("paymentMethod", mapFromPaymentMethod(paymentMethod))
|
|
59
|
+
putBoolean("shouldSavePaymentMethod", shouldSavePaymentMethod)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
stripeSdkModule.emitOnConfirmHandlerCallback(params)
|
|
63
|
+
|
|
64
|
+
val resultFromJavascript = stripeSdkModule.embeddedIntentCreationCallback.await()
|
|
65
|
+
// reset the completable
|
|
66
|
+
stripeSdkModule.embeddedIntentCreationCallback = CompletableDeferred()
|
|
67
|
+
|
|
68
|
+
resultFromJavascript.getString("clientSecret")?.let {
|
|
69
|
+
CreateIntentResult.Success(clientSecret = it)
|
|
70
|
+
} ?: run {
|
|
71
|
+
val errorMap = resultFromJavascript.getMap("error")
|
|
72
|
+
CreateIntentResult.Failure(
|
|
73
|
+
cause = Exception(errorMap?.getString("message")),
|
|
74
|
+
displayMessage = errorMap?.getString("localizedMessage"),
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
resultCallback = { result ->
|
|
79
|
+
val map =
|
|
80
|
+
Arguments.createMap().apply {
|
|
81
|
+
when (result) {
|
|
82
|
+
is EmbeddedPaymentElement.Result.Completed -> {
|
|
83
|
+
putString("status", "completed")
|
|
84
|
+
}
|
|
85
|
+
is EmbeddedPaymentElement.Result.Canceled -> {
|
|
86
|
+
putString("status", "canceled")
|
|
87
|
+
}
|
|
88
|
+
is EmbeddedPaymentElement.Result.Failed -> {
|
|
89
|
+
putString("status", "failed")
|
|
90
|
+
putString("error", result.error.message ?: "Unknown error")
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
requireStripeSdkModule().emitEmbeddedPaymentElementFormSheetConfirmComplete(map)
|
|
95
|
+
},
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@Composable
|
|
100
|
+
override fun Content() {
|
|
101
|
+
val embedded = rememberEmbeddedPaymentElement(builder)
|
|
102
|
+
|
|
103
|
+
// collect events: configure, confirm, clear
|
|
104
|
+
LaunchedEffect(Unit) {
|
|
105
|
+
events.consumeAsFlow().collect { ev ->
|
|
106
|
+
when (ev) {
|
|
107
|
+
is Event.Configure -> {
|
|
108
|
+
// call configure and grab the result
|
|
109
|
+
val result =
|
|
110
|
+
embedded.configure(
|
|
111
|
+
intentConfiguration = ev.intentConfiguration,
|
|
112
|
+
configuration = ev.configuration,
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
when (result) {
|
|
116
|
+
is EmbeddedPaymentElement.ConfigureResult.Succeeded -> {
|
|
117
|
+
reportHeightChange(450)
|
|
118
|
+
}
|
|
119
|
+
is EmbeddedPaymentElement.ConfigureResult.Failed -> {
|
|
120
|
+
// send the error back to JS
|
|
121
|
+
val err = result.error
|
|
122
|
+
val msg = err.localizedMessage ?: err.toString()
|
|
123
|
+
// build a RN map
|
|
124
|
+
val payload =
|
|
125
|
+
Arguments.createMap().apply {
|
|
126
|
+
putString("message", msg)
|
|
127
|
+
}
|
|
128
|
+
requireStripeSdkModule().emitEmbeddedPaymentElementLoadingFailed(payload)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
is Event.Confirm -> {
|
|
134
|
+
embedded.confirm()
|
|
135
|
+
}
|
|
136
|
+
is Event.ClearPaymentOption -> {
|
|
137
|
+
embedded.clearPaymentOption()
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
LaunchedEffect(embedded) {
|
|
144
|
+
embedded.paymentOption.collect { opt ->
|
|
145
|
+
val optMap = opt?.toWritableMap()
|
|
146
|
+
val payload =
|
|
147
|
+
Arguments.createMap().apply {
|
|
148
|
+
putMap("paymentOption", optMap)
|
|
149
|
+
}
|
|
150
|
+
requireStripeSdkModule().emitEmbeddedPaymentElementDidUpdatePaymentOption(payload)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
embedded.Content()
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private fun reportHeightChange(height: Int) {
|
|
158
|
+
val params =
|
|
159
|
+
Arguments.createMap().apply {
|
|
160
|
+
putInt("height", height)
|
|
161
|
+
}
|
|
162
|
+
requireStripeSdkModule().emitEmbeddedPaymentElementDidUpdateHeight(params)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// APIs
|
|
166
|
+
fun configure(
|
|
167
|
+
config: EmbeddedPaymentElement.Configuration,
|
|
168
|
+
intentConfig: PaymentSheet.IntentConfiguration,
|
|
169
|
+
) {
|
|
170
|
+
events.trySend(Event.Configure(config, intentConfig))
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
fun confirm() {
|
|
174
|
+
events.trySend(Event.Confirm)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
fun clearPaymentOption() {
|
|
178
|
+
events.trySend(Event.ClearPaymentOption)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private fun requireStripeSdkModule() = requireNotNull(reactContext.getNativeModule(StripeSdkModule::class.java))
|
|
182
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
package com.reactnativestripesdk
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import androidx.compose.ui.platform.ViewCompositionStrategy
|
|
6
|
+
import com.facebook.react.bridge.Dynamic
|
|
7
|
+
import com.facebook.react.bridge.ReadableArray
|
|
8
|
+
import com.facebook.react.bridge.ReadableMap
|
|
9
|
+
import com.facebook.react.bridge.ReadableType
|
|
10
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
11
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
12
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
13
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
14
|
+
import com.facebook.react.viewmanagers.EmbeddedPaymentElementViewManagerDelegate
|
|
15
|
+
import com.facebook.react.viewmanagers.EmbeddedPaymentElementViewManagerInterface
|
|
16
|
+
import com.reactnativestripesdk.PaymentSheetFragment.Companion.buildCustomerConfiguration
|
|
17
|
+
import com.reactnativestripesdk.PaymentSheetFragment.Companion.buildGooglePayConfig
|
|
18
|
+
import com.reactnativestripesdk.addresssheet.AddressSheetView
|
|
19
|
+
import com.reactnativestripesdk.utils.PaymentSheetAppearanceException
|
|
20
|
+
import com.reactnativestripesdk.utils.PaymentSheetException
|
|
21
|
+
import com.reactnativestripesdk.utils.mapToPreferredNetworks
|
|
22
|
+
import com.reactnativestripesdk.utils.toBundleObject
|
|
23
|
+
import com.stripe.android.ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi
|
|
24
|
+
import com.stripe.android.paymentelement.EmbeddedPaymentElement
|
|
25
|
+
import com.stripe.android.paymentelement.ExperimentalEmbeddedPaymentElementApi
|
|
26
|
+
import com.stripe.android.paymentsheet.PaymentSheet
|
|
27
|
+
|
|
28
|
+
@OptIn(ExperimentalEmbeddedPaymentElementApi::class)
|
|
29
|
+
@ReactModule(name = EmbeddedPaymentElementViewManager.NAME)
|
|
30
|
+
class EmbeddedPaymentElementViewManager :
|
|
31
|
+
ViewGroupManager<EmbeddedPaymentElementView>(),
|
|
32
|
+
EmbeddedPaymentElementViewManagerInterface<EmbeddedPaymentElementView> {
|
|
33
|
+
companion object {
|
|
34
|
+
const val NAME = "EmbeddedPaymentElementView"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private val delegate = EmbeddedPaymentElementViewManagerDelegate(this)
|
|
38
|
+
|
|
39
|
+
override fun getName() = NAME
|
|
40
|
+
|
|
41
|
+
override fun getDelegate() = delegate
|
|
42
|
+
|
|
43
|
+
override fun createViewInstance(ctx: ThemedReactContext): EmbeddedPaymentElementView =
|
|
44
|
+
EmbeddedPaymentElementView(ctx).apply {
|
|
45
|
+
setViewCompositionStrategy(
|
|
46
|
+
ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed,
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
override fun needsCustomLayoutForChildren(): Boolean = true
|
|
51
|
+
|
|
52
|
+
@ReactProp(name = "configuration")
|
|
53
|
+
override fun setConfiguration(
|
|
54
|
+
view: EmbeddedPaymentElementView,
|
|
55
|
+
cfg: Dynamic,
|
|
56
|
+
) {
|
|
57
|
+
val elementConfig = parseElementConfiguration(cfg.asMap(), view.context)
|
|
58
|
+
view.latestElementConfig = elementConfig
|
|
59
|
+
// if intentConfig is already set, configure immediately:
|
|
60
|
+
view.latestIntentConfig?.let { intentCfg ->
|
|
61
|
+
view.configure(elementConfig, intentCfg)
|
|
62
|
+
view.post {
|
|
63
|
+
view.requestLayout()
|
|
64
|
+
view.invalidate()
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@ReactProp(name = "intentConfiguration")
|
|
70
|
+
override fun setIntentConfiguration(
|
|
71
|
+
view: EmbeddedPaymentElementView,
|
|
72
|
+
cfg: Dynamic,
|
|
73
|
+
) {
|
|
74
|
+
val intentConfig = parseIntentConfiguration(cfg.asMap())
|
|
75
|
+
view.latestIntentConfig = intentConfig
|
|
76
|
+
view.latestElementConfig?.let { elemCfg ->
|
|
77
|
+
view.configure(elemCfg, intentConfig)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@SuppressLint("RestrictedApi")
|
|
82
|
+
@OptIn(ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class)
|
|
83
|
+
private fun parseElementConfiguration(
|
|
84
|
+
map: ReadableMap,
|
|
85
|
+
context: Context,
|
|
86
|
+
): EmbeddedPaymentElement.Configuration {
|
|
87
|
+
val merchantDisplayName = map.getString("merchantDisplayName").orEmpty()
|
|
88
|
+
val allowsDelayedPaymentMethods = map.getBoolean("allowsDelayedPaymentMethods")
|
|
89
|
+
var defaultBillingDetails: PaymentSheet.BillingDetails? = null
|
|
90
|
+
val billingDetailsMap = map.getMap("defaultBillingDetails")
|
|
91
|
+
if (billingDetailsMap != null) {
|
|
92
|
+
val addressBundle = billingDetailsMap.getMap("address")
|
|
93
|
+
val address =
|
|
94
|
+
PaymentSheet.Address(
|
|
95
|
+
addressBundle?.getString("city"),
|
|
96
|
+
addressBundle?.getString("country"),
|
|
97
|
+
addressBundle?.getString("line1"),
|
|
98
|
+
addressBundle?.getString("line2"),
|
|
99
|
+
addressBundle?.getString("postalCode"),
|
|
100
|
+
addressBundle?.getString("state"),
|
|
101
|
+
)
|
|
102
|
+
defaultBillingDetails =
|
|
103
|
+
PaymentSheet.BillingDetails(
|
|
104
|
+
address,
|
|
105
|
+
billingDetailsMap.getString("email"),
|
|
106
|
+
billingDetailsMap.getString("name"),
|
|
107
|
+
billingDetailsMap.getString("phone"),
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
val customerConfiguration =
|
|
112
|
+
try {
|
|
113
|
+
buildCustomerConfiguration(toBundleObject(map))
|
|
114
|
+
} catch (error: PaymentSheetException) {
|
|
115
|
+
throw Error() // TODO handle error
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
val googlePayConfig = buildGooglePayConfig(toBundleObject(map.getMap("googlePay")))
|
|
119
|
+
val shippingDetails =
|
|
120
|
+
map.getMap("defaultShippingDetails")?.let {
|
|
121
|
+
AddressSheetView.buildAddressDetails(it)
|
|
122
|
+
}
|
|
123
|
+
val appearance =
|
|
124
|
+
try {
|
|
125
|
+
buildPaymentSheetAppearance(toBundleObject(map.getMap("appearance")), context)
|
|
126
|
+
} catch (error: PaymentSheetAppearanceException) {
|
|
127
|
+
throw Error() // TODO handle error
|
|
128
|
+
}
|
|
129
|
+
val billingConfigParams = map.getMap("billingDetailsCollectionConfiguration")
|
|
130
|
+
val billingDetailsConfig =
|
|
131
|
+
PaymentSheet.BillingDetailsCollectionConfiguration(
|
|
132
|
+
name = mapToCollectionMode(billingConfigParams?.getString("name")),
|
|
133
|
+
phone = mapToCollectionMode(billingConfigParams?.getString("phone")),
|
|
134
|
+
email = mapToCollectionMode(billingConfigParams?.getString("email")),
|
|
135
|
+
address = mapToAddressCollectionMode(billingConfigParams?.getString("address")),
|
|
136
|
+
attachDefaultsToPaymentMethod =
|
|
137
|
+
billingConfigParams?.getBoolean("attachDefaultsToPaymentMethod") ?: false,
|
|
138
|
+
)
|
|
139
|
+
val allowsRemovalOfLastSavedPaymentMethod =
|
|
140
|
+
if (map.hasKey("allowsRemovalOfLastSavedPaymentMethod")) {
|
|
141
|
+
map.getBoolean("allowsRemovalOfLastSavedPaymentMethod")
|
|
142
|
+
} else {
|
|
143
|
+
true
|
|
144
|
+
}
|
|
145
|
+
val primaryButtonLabel = map.getString("primaryButtonLabel")
|
|
146
|
+
val paymentMethodOrder = map.getStringArrayList("paymentMethodOrder")
|
|
147
|
+
|
|
148
|
+
val formSheetAction =
|
|
149
|
+
map
|
|
150
|
+
.getMap("formSheetAction")
|
|
151
|
+
?.getString("type")
|
|
152
|
+
?.let { type ->
|
|
153
|
+
when (type) {
|
|
154
|
+
"confirm" -> EmbeddedPaymentElement.FormSheetAction.Confirm
|
|
155
|
+
else -> EmbeddedPaymentElement.FormSheetAction.Continue
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
?: EmbeddedPaymentElement.FormSheetAction.Continue
|
|
159
|
+
|
|
160
|
+
val configurationBuilder =
|
|
161
|
+
EmbeddedPaymentElement.Configuration
|
|
162
|
+
.Builder(merchantDisplayName)
|
|
163
|
+
.formSheetAction(formSheetAction)
|
|
164
|
+
.allowsDelayedPaymentMethods(allowsDelayedPaymentMethods ?: false)
|
|
165
|
+
.defaultBillingDetails(defaultBillingDetails)
|
|
166
|
+
.customer(customerConfiguration)
|
|
167
|
+
.googlePay(googlePayConfig)
|
|
168
|
+
.appearance(appearance)
|
|
169
|
+
.shippingDetails(shippingDetails)
|
|
170
|
+
.billingDetailsCollectionConfiguration(billingDetailsConfig)
|
|
171
|
+
.preferredNetworks(
|
|
172
|
+
mapToPreferredNetworks(
|
|
173
|
+
map
|
|
174
|
+
.getIntegerArrayList("preferredNetworks")
|
|
175
|
+
?.let { ArrayList(it) },
|
|
176
|
+
),
|
|
177
|
+
).allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod)
|
|
178
|
+
.cardBrandAcceptance(mapToCardBrandAcceptance(toBundleObject(map)))
|
|
179
|
+
|
|
180
|
+
primaryButtonLabel?.let { configurationBuilder.primaryButtonLabel(it) }
|
|
181
|
+
paymentMethodOrder?.let { configurationBuilder.paymentMethodOrder(it) }
|
|
182
|
+
|
|
183
|
+
return configurationBuilder.build()
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private fun parseIntentConfiguration(map: ReadableMap): PaymentSheet.IntentConfiguration {
|
|
187
|
+
val intentConfig = PaymentSheetFragment.buildIntentConfiguration(toBundleObject(map))
|
|
188
|
+
return intentConfig ?: throw IllegalArgumentException("IntentConfiguration is null")
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
override fun confirm(view: EmbeddedPaymentElementView) {
|
|
192
|
+
view.confirm()
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
override fun clearPaymentOption(view: EmbeddedPaymentElementView) {
|
|
196
|
+
view.clearPaymentOption()
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Returns a List of Strings if the key exists and points to an array of strings, or null otherwise.
|
|
202
|
+
*/
|
|
203
|
+
fun ReadableMap.getStringArrayList(key: String): List<String>? {
|
|
204
|
+
if (!hasKey(key) || getType(key) != ReadableType.Array) return null
|
|
205
|
+
val array: ReadableArray = getArray(key) ?: return null
|
|
206
|
+
|
|
207
|
+
val result = mutableListOf<String>()
|
|
208
|
+
for (i in 0 until array.size()) {
|
|
209
|
+
// getString returns null if the element isn't actually a string
|
|
210
|
+
array.getString(i)?.let { result.add(it) }
|
|
211
|
+
}
|
|
212
|
+
return result
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Returns a List of Ints if the key exists and points to an array of numbers, or null otherwise.
|
|
217
|
+
*/
|
|
218
|
+
fun ReadableMap.getIntegerArrayList(key: String): List<Int>? {
|
|
219
|
+
if (!hasKey(key) || getType(key) != ReadableType.Array) return null
|
|
220
|
+
val array: ReadableArray = getArray(key) ?: return null
|
|
221
|
+
|
|
222
|
+
val result = mutableListOf<Int>()
|
|
223
|
+
for (i in 0 until array.size()) {
|
|
224
|
+
// getType check to skip non-number entries
|
|
225
|
+
if (array.getType(i) == ReadableType.Number) {
|
|
226
|
+
// if it's actually a float/double, this will truncate; adjust as needed
|
|
227
|
+
result.add(array.getInt(i))
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return result
|
|
231
|
+
}
|