@stripe/stripe-react-native 0.56.0 → 0.57.1
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/android/build.gradle +76 -118
- package/android/gradle.properties +1 -1
- package/android/settings.gradle +2 -0
- package/android/spotless.gradle +1 -1
- package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormView.kt +24 -20
- package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +20 -17
- package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +28 -32
- package/android/src/main/java/com/reactnativestripesdk/{CollectBankAccountLauncherFragment.kt → CollectBankAccountLauncherManager.kt} +23 -44
- package/android/src/main/java/com/reactnativestripesdk/CustomPaymentMethodActivity.kt +2 -0
- package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementView.kt +4 -11
- package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +52 -132
- package/android/src/main/java/com/reactnativestripesdk/EventEmitterCompat.kt +0 -8
- package/android/src/main/java/com/reactnativestripesdk/FakeOnrampSdkModule.kt +154 -0
- package/android/src/main/java/com/reactnativestripesdk/{FinancialConnectionsSheetFragment.kt → FinancialConnectionsSheetManager.kt} +43 -92
- package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonView.kt +1 -1
- package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherManager.kt +107 -0
- package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherManager.kt +37 -0
- package/android/src/main/java/com/reactnativestripesdk/GooglePayRequestHelper.kt +7 -5
- package/android/src/main/java/com/reactnativestripesdk/NavigationBarManager.kt +31 -0
- package/android/src/main/java/com/reactnativestripesdk/NavigationBarView.kt +120 -0
- package/android/src/main/java/com/reactnativestripesdk/PaymentElementConfig.kt +228 -0
- package/android/src/main/java/com/reactnativestripesdk/{PaymentLauncherFragment.kt → PaymentLauncherManager.kt} +40 -77
- package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +11 -20
- package/android/src/main/java/com/reactnativestripesdk/PaymentOptionDisplayDataMapper.kt +4 -6
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +409 -483
- package/android/src/main/java/com/reactnativestripesdk/{PaymentSheetFragment.kt → PaymentSheetManager.kt} +65 -300
- package/android/src/main/java/com/reactnativestripesdk/StripeAbstractComposeView.kt +53 -17
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +227 -232
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +21 -2
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherManager.kt +78 -0
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +52 -39
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetViewManager.kt +2 -2
- package/android/src/main/java/com/reactnativestripesdk/customersheet/{CustomerSheetFragment.kt → CustomerSheetManager.kt} +64 -99
- package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerSessionProvider.kt +2 -3
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonManager.kt +5 -10
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt +90 -77
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/TapAndPayProxy.kt +6 -4
- package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +13 -3
- package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +87 -11
- package/android/src/main/java/com/reactnativestripesdk/utils/KeepJsAwakeTask.kt +1 -1
- package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +178 -185
- package/android/src/main/java/com/reactnativestripesdk/utils/StripeUIManager.kt +62 -0
- package/android/src/oldarch/java/com/reactnativestripesdk/NativeOnrampSdkModuleSpec.java +118 -0
- package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +4 -0
- package/android/src/onramp/java/com/reactnativestripesdk/OnrampSdkModule.kt +922 -0
- package/android/src/test/java/com/facebook/testutils/shadows/ShadowArguments.kt +29 -0
- package/android/src/test/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManagerTest.kt +163 -0
- package/android/src/test/java/com/reactnativestripesdk/PaymentElementConfigTest.kt +976 -0
- package/android/src/test/java/com/reactnativestripesdk/PaymentSheetAppearanceTest.kt +801 -0
- package/android/src/test/java/com/reactnativestripesdk/PaymentSheetManagerTest.kt +523 -0
- package/android/src/test/java/com/reactnativestripesdk/addresssheet/AddressSheetViewTest.kt +551 -0
- package/android/src/test/java/com/reactnativestripesdk/mappers/MappersTest.kt +567 -0
- package/android/src/test/java/com/reactnativestripesdk/mappers/PaymentOptionDisplayDataMapperTest.kt +456 -0
- package/android/src/test/java/com/reactnativestripesdk/pushprovisioning/PushProvisioningProxyTest.kt +43 -0
- package/android/src/test/resources/robolectric.properties +2 -0
- package/ios/AddressSheet/AddressSheetUtils.swift +3 -3
- package/ios/AddressSheet/AddressSheetView.swift +26 -26
- package/ios/AddressSheet/AddressSheetViewManager.swift +2 -2
- package/ios/ApplePayButtonManager.swift +1 -1
- package/ios/ApplePayButtonView.swift +9 -10
- package/ios/ApplePayUtils.swift +51 -51
- package/ios/ApplePayViewController.swift +25 -29
- package/ios/AuBECSDebitFormManager.swift +1 -1
- package/ios/AuBECSDebitFormView.swift +13 -15
- package/ios/CardFieldManager.swift +4 -4
- package/ios/CardFieldView.swift +9 -9
- package/ios/CardFormManager.swift +3 -3
- package/ios/CardFormView.swift +28 -28
- package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingView.swift +97 -0
- package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewController.swift +133 -0
- package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewManager.m +16 -0
- package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewManager.swift +17 -0
- package/ios/CustomerSheet/CustomerSheetUtils.swift +15 -16
- package/ios/CustomerSheet/ReactNativeCustomerAdapter.swift +19 -19
- package/ios/EmbeddedPaymentElementView.swift +2 -2
- package/ios/Errors.swift +22 -23
- package/ios/FinancialConnections.swift +37 -37
- package/ios/Mappers.swift +212 -75
- package/ios/NavigationBarManager.m +13 -0
- package/ios/NavigationBarManager.swift +17 -0
- package/ios/NavigationBarView.swift +65 -0
- package/ios/NewArch/NavigationBarComponentView.h +10 -0
- package/ios/NewArch/NavigationBarComponentView.mm +86 -0
- package/ios/OldArch/StripeSdkEventEmitterCompat.h +1 -0
- package/ios/OldArch/StripeSdkEventEmitterCompat.m +7 -1
- package/ios/PaymentMethodFactory.swift +24 -41
- package/ios/PaymentOptionDisplayData+ReactNative.swift +4 -4
- package/ios/PaymentPassFinder.swift +9 -10
- package/ios/PaymentSheetAppearance.swift +137 -138
- package/ios/PushProvisioning/AddToWalletButtonManager.swift +2 -2
- package/ios/PushProvisioning/AddToWalletButtonView.swift +16 -18
- package/ios/PushProvisioning/PushProvisioningUtils.swift +11 -11
- package/ios/StripeContainerManager.swift +1 -1
- package/ios/StripeContainerView.swift +3 -3
- package/ios/StripeOnrampSdk.h +17 -0
- package/ios/StripeOnrampSdk.mm +158 -0
- package/ios/StripeSdk.mm +8 -0
- package/ios/StripeSdkEmitter.swift +4 -0
- package/ios/StripeSdkImpl+CustomerSheet.swift +31 -26
- package/ios/StripeSdkImpl+Embedded.swift +11 -9
- package/ios/StripeSdkImpl+PaymentSheet.swift +51 -42
- package/ios/StripeSdkImpl.swift +919 -191
- package/ios/UIColorExtension.swift +72 -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/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/connect/Components.js +2 -0
- package/lib/commonjs/connect/Components.js.map +1 -0
- package/lib/commonjs/connect/ConnectComponentsProvider.js +2 -0
- package/lib/commonjs/connect/ConnectComponentsProvider.js.map +1 -0
- package/lib/commonjs/connect/EmbeddedComponent.js +19 -0
- package/lib/commonjs/connect/EmbeddedComponent.js.map +1 -0
- package/lib/commonjs/connect/ModalCloseButton.js +2 -0
- package/lib/commonjs/connect/ModalCloseButton.js.map +1 -0
- package/lib/commonjs/connect/NavigationBar.js +2 -0
- package/lib/commonjs/connect/NavigationBar.js.map +1 -0
- package/lib/commonjs/connect/connectTypes.js +2 -0
- package/lib/commonjs/connect/connectTypes.js.map +1 -0
- package/lib/commonjs/events.js +1 -1
- package/lib/commonjs/events.js.map +1 -1
- package/lib/commonjs/helpers.js +1 -1
- package/lib/commonjs/helpers.js.map +1 -1
- package/lib/commonjs/hooks/useOnramp.js +2 -0
- package/lib/commonjs/hooks/useOnramp.js.map +1 -0
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/plugin/withStripe.js +1 -1
- package/lib/commonjs/plugin/withStripe.js.map +1 -1
- package/lib/commonjs/specs/NativeAddToWalletButton.js +1 -1
- package/lib/commonjs/specs/NativeAddToWalletButton.js.map +1 -1
- package/lib/commonjs/specs/NativeAddressSheet.js +1 -1
- package/lib/commonjs/specs/NativeAddressSheet.js.map +1 -1
- package/lib/commonjs/specs/NativeApplePayButton.js +1 -1
- package/lib/commonjs/specs/NativeApplePayButton.js.map +1 -1
- package/lib/commonjs/specs/NativeAuBECSDebitForm.js +1 -1
- package/lib/commonjs/specs/NativeAuBECSDebitForm.js.map +1 -1
- package/lib/commonjs/specs/NativeCardField.js +1 -1
- package/lib/commonjs/specs/NativeCardField.js.map +1 -1
- package/lib/commonjs/specs/NativeCardForm.js +1 -1
- package/lib/commonjs/specs/NativeCardForm.js.map +1 -1
- package/lib/commonjs/specs/NativeConnectAccountOnboardingView.js +2 -0
- package/lib/commonjs/specs/NativeConnectAccountOnboardingView.js.map +1 -0
- package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js +1 -1
- package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js.map +1 -1
- package/lib/commonjs/specs/NativeGooglePayButton.js +1 -1
- package/lib/commonjs/specs/NativeGooglePayButton.js.map +1 -1
- package/lib/commonjs/specs/NativeNavigationBar.js +2 -0
- package/lib/commonjs/specs/NativeNavigationBar.js.map +1 -0
- package/lib/commonjs/specs/NativeOnrampSdkModule.js +2 -0
- package/lib/commonjs/specs/NativeOnrampSdkModule.js.map +1 -0
- package/lib/commonjs/specs/NativeStripeContainer.js +1 -1
- package/lib/commonjs/specs/NativeStripeContainer.js.map +1 -1
- package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
- package/lib/commonjs/types/EmbeddedPaymentElement.js +1 -1
- package/lib/commonjs/types/EmbeddedPaymentElement.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/Onramp.js +2 -0
- package/lib/commonjs/types/Onramp.js.map +1 -0
- package/lib/commonjs/types/PaymentIntent.js.map +1 -1
- package/lib/commonjs/types/PaymentSheet.js.map +1 -1
- package/lib/commonjs/types/index.js +1 -1
- package/lib/commonjs/types/index.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/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/connect/Components.js +2 -0
- package/lib/module/connect/Components.js.map +1 -0
- package/lib/module/connect/ConnectComponentsProvider.js +2 -0
- package/lib/module/connect/ConnectComponentsProvider.js.map +1 -0
- package/lib/module/connect/EmbeddedComponent.js +19 -0
- package/lib/module/connect/EmbeddedComponent.js.map +1 -0
- package/lib/module/connect/ModalCloseButton.js +2 -0
- package/lib/module/connect/ModalCloseButton.js.map +1 -0
- package/lib/module/connect/NavigationBar.js +2 -0
- package/lib/module/connect/NavigationBar.js.map +1 -0
- package/lib/module/connect/connectTypes.js +2 -0
- package/lib/module/connect/connectTypes.js.map +1 -0
- package/lib/module/events.js +1 -1
- package/lib/module/events.js.map +1 -1
- package/lib/module/helpers.js +1 -1
- package/lib/module/helpers.js.map +1 -1
- package/lib/module/hooks/useOnramp.js +2 -0
- package/lib/module/hooks/useOnramp.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/plugin/withStripe.js +1 -1
- package/lib/module/plugin/withStripe.js.map +1 -1
- package/lib/module/specs/NativeAddToWalletButton.js +1 -1
- package/lib/module/specs/NativeAddToWalletButton.js.map +1 -1
- package/lib/module/specs/NativeAddressSheet.js +1 -1
- package/lib/module/specs/NativeAddressSheet.js.map +1 -1
- package/lib/module/specs/NativeApplePayButton.js +1 -1
- package/lib/module/specs/NativeApplePayButton.js.map +1 -1
- package/lib/module/specs/NativeAuBECSDebitForm.js +1 -1
- package/lib/module/specs/NativeAuBECSDebitForm.js.map +1 -1
- package/lib/module/specs/NativeCardField.js +1 -1
- package/lib/module/specs/NativeCardField.js.map +1 -1
- package/lib/module/specs/NativeCardForm.js +1 -1
- package/lib/module/specs/NativeCardForm.js.map +1 -1
- package/lib/module/specs/NativeConnectAccountOnboardingView.js +2 -0
- package/lib/module/specs/NativeConnectAccountOnboardingView.js.map +1 -0
- package/lib/module/specs/NativeEmbeddedPaymentElement.js +1 -1
- package/lib/module/specs/NativeEmbeddedPaymentElement.js.map +1 -1
- package/lib/module/specs/NativeGooglePayButton.js +1 -1
- package/lib/module/specs/NativeGooglePayButton.js.map +1 -1
- package/lib/module/specs/NativeNavigationBar.js +2 -0
- package/lib/module/specs/NativeNavigationBar.js.map +1 -0
- package/lib/module/specs/NativeOnrampSdkModule.js +2 -0
- package/lib/module/specs/NativeOnrampSdkModule.js.map +1 -0
- package/lib/module/specs/NativeStripeContainer.js +1 -1
- package/lib/module/specs/NativeStripeContainer.js.map +1 -1
- package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
- package/lib/module/types/EmbeddedPaymentElement.js +1 -1
- package/lib/module/types/EmbeddedPaymentElement.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/Onramp.js +2 -0
- package/lib/module/types/Onramp.js.map +1 -0
- package/lib/module/types/PaymentIntent.js.map +1 -1
- package/lib/module/types/PaymentSheet.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/components/StripeProvider.d.ts.map +1 -1
- package/lib/typescript/src/connect/Components.d.ts +23 -0
- package/lib/typescript/src/connect/Components.d.ts.map +1 -0
- package/lib/typescript/src/connect/ConnectComponentsProvider.d.ts +22 -0
- package/lib/typescript/src/connect/ConnectComponentsProvider.d.ts.map +1 -0
- package/lib/typescript/src/connect/EmbeddedComponent.d.ts +18 -0
- package/lib/typescript/src/connect/EmbeddedComponent.d.ts.map +1 -0
- package/lib/typescript/src/connect/ModalCloseButton.d.ts +7 -0
- package/lib/typescript/src/connect/ModalCloseButton.d.ts.map +1 -0
- package/lib/typescript/src/connect/NavigationBar.d.ts +8 -0
- package/lib/typescript/src/connect/NavigationBar.d.ts.map +1 -0
- package/lib/typescript/src/connect/connectTypes.d.ts +464 -0
- package/lib/typescript/src/connect/connectTypes.d.ts.map +1 -0
- package/lib/typescript/src/events.d.ts +3 -0
- package/lib/typescript/src/events.d.ts.map +1 -1
- package/lib/typescript/src/functions.d.ts.map +1 -1
- package/lib/typescript/src/helpers.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useOnramp.d.ts +158 -0
- package/lib/typescript/src/hooks/useOnramp.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/plugin/withStripe.d.ts +15 -0
- package/lib/typescript/src/plugin/withStripe.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeConnectAccountOnboardingView.d.ts +14 -0
- package/lib/typescript/src/specs/NativeConnectAccountOnboardingView.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeNavigationBar.d.ts +11 -0
- package/lib/typescript/src/specs/NativeNavigationBar.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts +28 -0
- package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +3 -0
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
- package/lib/typescript/src/types/Errors.d.ts +5 -0
- package/lib/typescript/src/types/Errors.d.ts.map +1 -1
- package/lib/typescript/src/types/Onramp.d.ts +275 -0
- package/lib/typescript/src/types/Onramp.d.ts.map +1 -0
- package/lib/typescript/src/types/PaymentIntent.d.ts +1 -9
- package/lib/typescript/src/types/PaymentIntent.d.ts.map +1 -1
- package/lib/typescript/src/types/PaymentMethod.d.ts +2 -8
- package/lib/typescript/src/types/PaymentMethod.d.ts.map +1 -1
- package/lib/typescript/src/types/PaymentSheet.d.ts +7 -0
- package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +7 -1
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/package.json +24 -12
- package/src/components/StripeProvider.tsx +5 -0
- package/src/connect/Components.tsx +279 -0
- package/src/connect/ConnectComponentsProvider.tsx +93 -0
- package/src/connect/EmbeddedComponent.tsx +407 -0
- package/src/connect/ModalCloseButton.tsx +44 -0
- package/src/connect/NavigationBar.tsx +29 -0
- package/src/connect/connectTypes.ts +626 -0
- package/src/events.ts +22 -0
- package/src/hooks/useOnramp.tsx +334 -0
- package/src/index.tsx +13 -0
- package/src/plugin/withStripe.ts +104 -7
- package/src/specs/NativeConnectAccountOnboardingView.ts +19 -0
- package/src/specs/NativeNavigationBar.ts +16 -0
- package/src/specs/NativeOnrampSdkModule.ts +47 -0
- package/src/specs/NativeStripeSdkModule.ts +5 -0
- package/src/types/Errors.ts +6 -0
- package/src/types/Onramp.ts +317 -0
- package/src/types/PaymentIntent.ts +0 -10
- package/src/types/PaymentMethod.ts +0 -9
- package/src/types/PaymentSheet.ts +7 -0
- package/src/types/index.ts +8 -0
- package/stripe-react-native.podspec +21 -8
- package/android/.idea/AndroidProjectSystem.xml +0 -6
- package/android/.idea/caches/deviceStreaming.xml +0 -703
- package/android/.idea/compiler.xml +0 -6
- package/android/.idea/gradle.xml +0 -18
- package/android/.idea/migrations.xml +0 -10
- package/android/.idea/misc.xml +0 -10
- package/android/.idea/runConfigurations.xml +0 -17
- package/android/.idea/vcs.xml +0 -6
- package/android/local.properties +0 -8
- package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherFragment.kt +0 -146
- package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherFragment.kt +0 -68
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherFragment.kt +0 -102
- package/android/src/main/java/com/reactnativestripesdk/utils/StripeFragment.kt +0 -52
|
@@ -3,7 +3,6 @@ package com.reactnativestripesdk
|
|
|
3
3
|
import android.annotation.SuppressLint
|
|
4
4
|
import android.app.Activity
|
|
5
5
|
import android.app.Application
|
|
6
|
-
import android.content.Context
|
|
7
6
|
import android.content.Intent
|
|
8
7
|
import android.graphics.Bitmap
|
|
9
8
|
import android.graphics.Canvas
|
|
@@ -14,30 +13,33 @@ import android.os.Handler
|
|
|
14
13
|
import android.os.Looper
|
|
15
14
|
import android.util.Base64
|
|
16
15
|
import android.util.Log
|
|
17
|
-
import androidx.
|
|
16
|
+
import androidx.core.graphics.createBitmap
|
|
18
17
|
import androidx.core.graphics.drawable.DrawableCompat
|
|
19
18
|
import com.facebook.react.bridge.Arguments
|
|
20
19
|
import com.facebook.react.bridge.Promise
|
|
21
20
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
22
21
|
import com.facebook.react.bridge.ReadableMap
|
|
23
22
|
import com.facebook.react.bridge.WritableMap
|
|
24
|
-
import com.facebook.react.bridge.WritableNativeMap
|
|
25
23
|
import com.reactnativestripesdk.addresssheet.AddressSheetView
|
|
26
24
|
import com.reactnativestripesdk.utils.ErrorType
|
|
27
25
|
import com.reactnativestripesdk.utils.KeepJsAwakeTask
|
|
28
26
|
import com.reactnativestripesdk.utils.PaymentSheetAppearanceException
|
|
29
27
|
import com.reactnativestripesdk.utils.PaymentSheetErrorType
|
|
30
28
|
import com.reactnativestripesdk.utils.PaymentSheetException
|
|
31
|
-
import com.reactnativestripesdk.utils.
|
|
29
|
+
import com.reactnativestripesdk.utils.StripeUIManager
|
|
32
30
|
import com.reactnativestripesdk.utils.createError
|
|
33
31
|
import com.reactnativestripesdk.utils.createResult
|
|
32
|
+
import com.reactnativestripesdk.utils.forEachKey
|
|
33
|
+
import com.reactnativestripesdk.utils.getBooleanOr
|
|
34
|
+
import com.reactnativestripesdk.utils.getIntegerList
|
|
35
|
+
import com.reactnativestripesdk.utils.getStringList
|
|
34
36
|
import com.reactnativestripesdk.utils.mapFromConfirmationToken
|
|
35
37
|
import com.reactnativestripesdk.utils.mapFromCustomPaymentMethod
|
|
36
38
|
import com.reactnativestripesdk.utils.mapFromPaymentMethod
|
|
37
39
|
import com.reactnativestripesdk.utils.mapToPreferredNetworks
|
|
38
40
|
import com.reactnativestripesdk.utils.parseCustomPaymentMethods
|
|
39
|
-
import com.reactnativestripesdk.utils.removeFragment
|
|
40
41
|
import com.stripe.android.ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi
|
|
42
|
+
import com.stripe.android.core.reactnative.ReactNativeSdkInternal
|
|
41
43
|
import com.stripe.android.model.PaymentMethod
|
|
42
44
|
import com.stripe.android.paymentelement.ConfirmCustomPaymentMethodCallback
|
|
43
45
|
import com.stripe.android.paymentelement.CreateIntentWithConfirmationTokenCallback
|
|
@@ -47,7 +49,6 @@ import com.stripe.android.paymentelement.ExperimentalCustomPaymentMethodsApi
|
|
|
47
49
|
import com.stripe.android.paymentelement.PaymentMethodOptionsSetupFutureUsagePreview
|
|
48
50
|
import com.stripe.android.paymentsheet.CreateIntentCallback
|
|
49
51
|
import com.stripe.android.paymentsheet.CreateIntentResult
|
|
50
|
-
import com.stripe.android.paymentsheet.ExperimentalCustomerSessionApi
|
|
51
52
|
import com.stripe.android.paymentsheet.PaymentOptionResultCallback
|
|
52
53
|
import com.stripe.android.paymentsheet.PaymentSheet
|
|
53
54
|
import com.stripe.android.paymentsheet.PaymentSheetResult
|
|
@@ -60,12 +61,17 @@ import kotlinx.coroutines.launch
|
|
|
60
61
|
import java.io.ByteArrayOutputStream
|
|
61
62
|
import kotlin.Exception
|
|
62
63
|
|
|
63
|
-
@OptIn(
|
|
64
|
-
class
|
|
65
|
-
|
|
64
|
+
@OptIn(
|
|
65
|
+
ReactNativeSdkInternal::class,
|
|
66
|
+
ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class,
|
|
67
|
+
ExperimentalCustomPaymentMethodsApi::class,
|
|
68
|
+
)
|
|
69
|
+
class PaymentSheetManager(
|
|
70
|
+
context: ReactApplicationContext,
|
|
71
|
+
private val arguments: ReadableMap,
|
|
72
|
+
private val initPromise: Promise,
|
|
73
|
+
) : StripeUIManager(context),
|
|
66
74
|
ConfirmCustomPaymentMethodCallback {
|
|
67
|
-
private lateinit var context: ReactApplicationContext
|
|
68
|
-
private lateinit var initPromise: Promise
|
|
69
75
|
private var paymentSheet: PaymentSheet? = null
|
|
70
76
|
private var flowController: PaymentSheet.FlowController? = null
|
|
71
77
|
private var paymentIntentClientSecret: String? = null
|
|
@@ -73,7 +79,6 @@ class PaymentSheetFragment :
|
|
|
73
79
|
private var intentConfiguration: PaymentSheet.IntentConfiguration? = null
|
|
74
80
|
private lateinit var paymentSheetConfiguration: PaymentSheet.Configuration
|
|
75
81
|
private var confirmPromise: Promise? = null
|
|
76
|
-
private var presentPromise: Promise? = null
|
|
77
82
|
private var paymentSheetTimedOut = false
|
|
78
83
|
internal var paymentSheetIntentCreationCallback = CompletableDeferred<ReadableMap>()
|
|
79
84
|
internal var paymentSheetConfirmationTokenCreationCallback = CompletableDeferred<ReadableMap>()
|
|
@@ -81,39 +86,40 @@ class PaymentSheetFragment :
|
|
|
81
86
|
|
|
82
87
|
@SuppressLint("RestrictedApi")
|
|
83
88
|
@OptIn(ExperimentalCustomPaymentMethodsApi::class)
|
|
84
|
-
override fun
|
|
85
|
-
val
|
|
89
|
+
override fun onCreate() {
|
|
90
|
+
val activity = getCurrentActivityOrResolveWithError(initPromise) ?: return
|
|
91
|
+
val merchantDisplayName = arguments.getString("merchantDisplayName").orEmpty()
|
|
86
92
|
if (merchantDisplayName.isEmpty()) {
|
|
87
93
|
initPromise.resolve(
|
|
88
94
|
createError(ErrorType.Failed.toString(), "merchantDisplayName cannot be empty or null."),
|
|
89
95
|
)
|
|
90
96
|
return
|
|
91
97
|
}
|
|
92
|
-
val primaryButtonLabel = arguments
|
|
93
|
-
val googlePayConfig = buildGooglePayConfig(arguments
|
|
94
|
-
val linkConfig = buildLinkConfig(arguments
|
|
95
|
-
val allowsDelayedPaymentMethods = arguments
|
|
96
|
-
val
|
|
97
|
-
val billingConfigParams = arguments
|
|
98
|
-
val paymentMethodOrder = arguments
|
|
98
|
+
val primaryButtonLabel = arguments.getString("primaryButtonLabel")
|
|
99
|
+
val googlePayConfig = buildGooglePayConfig(arguments.getMap("googlePay"))
|
|
100
|
+
val linkConfig = buildLinkConfig(arguments.getMap("link"))
|
|
101
|
+
val allowsDelayedPaymentMethods = arguments.getBooleanOr("allowsDelayedPaymentMethods", false)
|
|
102
|
+
val billingDetailsMap = arguments.getMap("defaultBillingDetails")
|
|
103
|
+
val billingConfigParams = arguments.getMap("billingDetailsCollectionConfiguration")
|
|
104
|
+
val paymentMethodOrder = arguments.getStringList("paymentMethodOrder")
|
|
99
105
|
val allowsRemovalOfLastSavedPaymentMethod =
|
|
100
|
-
arguments
|
|
101
|
-
paymentIntentClientSecret = arguments
|
|
102
|
-
setupIntentClientSecret = arguments
|
|
106
|
+
arguments.getBooleanOr("allowsRemovalOfLastSavedPaymentMethod", true)
|
|
107
|
+
paymentIntentClientSecret = arguments.getString("paymentIntentClientSecret").orEmpty()
|
|
108
|
+
setupIntentClientSecret = arguments.getString("setupIntentClientSecret").orEmpty()
|
|
103
109
|
intentConfiguration =
|
|
104
110
|
try {
|
|
105
|
-
buildIntentConfiguration(arguments
|
|
111
|
+
buildIntentConfiguration(arguments.getMap("intentConfiguration"))
|
|
106
112
|
} catch (error: PaymentSheetException) {
|
|
107
113
|
initPromise.resolve(createError(ErrorType.Failed.toString(), error))
|
|
108
114
|
return
|
|
109
115
|
}
|
|
110
116
|
|
|
111
117
|
// Determine which callback type to use based on what's provided
|
|
112
|
-
val
|
|
113
|
-
val useConfirmationTokenCallback =
|
|
118
|
+
val intentConfigMap = arguments.getMap("intentConfiguration")
|
|
119
|
+
val useConfirmationTokenCallback = intentConfigMap?.hasKey("confirmationTokenConfirmHandler") == true
|
|
114
120
|
val appearance =
|
|
115
121
|
try {
|
|
116
|
-
buildPaymentSheetAppearance(arguments
|
|
122
|
+
buildPaymentSheetAppearance(arguments.getMap("appearance"), context)
|
|
117
123
|
} catch (error: PaymentSheetAppearanceException) {
|
|
118
124
|
initPromise.resolve(createError(ErrorType.Failed.toString(), error))
|
|
119
125
|
return
|
|
@@ -128,7 +134,7 @@ class PaymentSheetFragment :
|
|
|
128
134
|
}
|
|
129
135
|
|
|
130
136
|
val shippingDetails =
|
|
131
|
-
arguments
|
|
137
|
+
arguments.getMap("defaultShippingDetails")?.let {
|
|
132
138
|
AddressSheetView.buildAddressDetails(it)
|
|
133
139
|
}
|
|
134
140
|
|
|
@@ -136,9 +142,9 @@ class PaymentSheetFragment :
|
|
|
136
142
|
PaymentOptionResultCallback { paymentOptionResult ->
|
|
137
143
|
val result =
|
|
138
144
|
paymentOptionResult.paymentOption?.let {
|
|
139
|
-
val bitmap =
|
|
145
|
+
val bitmap = getBitmapFromDrawable(it.icon())
|
|
140
146
|
val imageString = getBase64FromBitmap(bitmap)
|
|
141
|
-
val option: WritableMap =
|
|
147
|
+
val option: WritableMap = Arguments.createMap()
|
|
142
148
|
option.putString("label", it.label)
|
|
143
149
|
option.putString("image", imageString)
|
|
144
150
|
val additionalFields: Map<String, Any> = mapOf("didCancel" to paymentOptionResult.didCancel)
|
|
@@ -183,10 +189,7 @@ class PaymentSheetFragment :
|
|
|
183
189
|
}
|
|
184
190
|
|
|
185
191
|
is PaymentSheetResult.Completed -> {
|
|
186
|
-
resolvePaymentResult(
|
|
187
|
-
// Remove the fragment now, we can be sure it won't be needed again if an intent is
|
|
188
|
-
// successful
|
|
189
|
-
removeFragment(context)
|
|
192
|
+
resolvePaymentResult(Arguments.createMap())
|
|
190
193
|
paymentSheet = null
|
|
191
194
|
flowController = null
|
|
192
195
|
}
|
|
@@ -247,40 +250,13 @@ class PaymentSheetFragment :
|
|
|
247
250
|
}
|
|
248
251
|
}
|
|
249
252
|
|
|
250
|
-
val billingDetailsConfig =
|
|
251
|
-
PaymentSheet.BillingDetailsCollectionConfiguration(
|
|
252
|
-
name = mapToCollectionMode(billingConfigParams?.getString("name")),
|
|
253
|
-
phone = mapToCollectionMode(billingConfigParams?.getString("phone")),
|
|
254
|
-
email = mapToCollectionMode(billingConfigParams?.getString("email")),
|
|
255
|
-
address = mapToAddressCollectionMode(billingConfigParams?.getString("address")),
|
|
256
|
-
attachDefaultsToPaymentMethod =
|
|
257
|
-
billingConfigParams?.getBoolean("attachDefaultsToPaymentMethod", false) ?: false,
|
|
258
|
-
)
|
|
253
|
+
val billingDetailsConfig = buildBillingDetailsCollectionConfiguration(billingConfigParams)
|
|
259
254
|
|
|
260
|
-
|
|
261
|
-
if (billingDetailsBundle != null) {
|
|
262
|
-
val addressBundle = billingDetailsBundle.getBundle("address")
|
|
263
|
-
val address =
|
|
264
|
-
PaymentSheet.Address(
|
|
265
|
-
addressBundle?.getString("city"),
|
|
266
|
-
addressBundle?.getString("country"),
|
|
267
|
-
addressBundle?.getString("line1"),
|
|
268
|
-
addressBundle?.getString("line2"),
|
|
269
|
-
addressBundle?.getString("postalCode"),
|
|
270
|
-
addressBundle?.getString("state"),
|
|
271
|
-
)
|
|
272
|
-
defaultBillingDetails =
|
|
273
|
-
PaymentSheet.BillingDetails(
|
|
274
|
-
address,
|
|
275
|
-
billingDetailsBundle.getString("email"),
|
|
276
|
-
billingDetailsBundle.getString("name"),
|
|
277
|
-
billingDetailsBundle.getString("phone"),
|
|
278
|
-
)
|
|
279
|
-
}
|
|
255
|
+
val defaultBillingDetails = buildBillingDetails(billingDetailsMap)
|
|
280
256
|
val configurationBuilder =
|
|
281
257
|
PaymentSheet.Configuration
|
|
282
258
|
.Builder(merchantDisplayName)
|
|
283
|
-
.allowsDelayedPaymentMethods(allowsDelayedPaymentMethods
|
|
259
|
+
.allowsDelayedPaymentMethods(allowsDelayedPaymentMethods)
|
|
284
260
|
.defaultBillingDetails(defaultBillingDetails)
|
|
285
261
|
.customer(customerConfiguration)
|
|
286
262
|
.googlePay(googlePayConfig)
|
|
@@ -289,21 +265,21 @@ class PaymentSheetFragment :
|
|
|
289
265
|
.link(linkConfig)
|
|
290
266
|
.billingDetailsCollectionConfiguration(billingDetailsConfig)
|
|
291
267
|
.preferredNetworks(
|
|
292
|
-
mapToPreferredNetworks(arguments
|
|
268
|
+
mapToPreferredNetworks(arguments.getIntegerList("preferredNetworks")),
|
|
293
269
|
).allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod)
|
|
294
270
|
.cardBrandAcceptance(mapToCardBrandAcceptance(arguments))
|
|
295
|
-
.customPaymentMethods(parseCustomPaymentMethods(arguments))
|
|
271
|
+
.customPaymentMethods(parseCustomPaymentMethods(arguments.getMap("customPaymentMethodConfiguration")))
|
|
296
272
|
|
|
297
273
|
primaryButtonLabel?.let { configurationBuilder.primaryButtonLabel(it) }
|
|
298
274
|
paymentMethodOrder?.let { configurationBuilder.paymentMethodOrder(it) }
|
|
299
275
|
|
|
300
276
|
configurationBuilder.paymentMethodLayout(
|
|
301
|
-
mapToPaymentMethodLayout(arguments
|
|
277
|
+
mapToPaymentMethodLayout(arguments.getString("paymentMethodLayout")),
|
|
302
278
|
)
|
|
303
279
|
|
|
304
280
|
paymentSheetConfiguration = configurationBuilder.build()
|
|
305
281
|
|
|
306
|
-
if (arguments
|
|
282
|
+
if (arguments.getBooleanOr("customFlow", false)) {
|
|
307
283
|
flowController =
|
|
308
284
|
if (intentConfiguration != null) {
|
|
309
285
|
val builder =
|
|
@@ -319,14 +295,14 @@ class PaymentSheetFragment :
|
|
|
319
295
|
}
|
|
320
296
|
builder
|
|
321
297
|
.confirmCustomPaymentMethodCallback(this)
|
|
322
|
-
.build(
|
|
298
|
+
.build(activity)
|
|
323
299
|
} else {
|
|
324
300
|
PaymentSheet.FlowController
|
|
325
301
|
.Builder(
|
|
326
302
|
resultCallback = paymentResultCallback,
|
|
327
303
|
paymentOptionResultCallback = paymentOptionCallback,
|
|
328
304
|
).confirmCustomPaymentMethodCallback(this)
|
|
329
|
-
.build(
|
|
305
|
+
.build(activity)
|
|
330
306
|
}
|
|
331
307
|
configureFlowController()
|
|
332
308
|
} else {
|
|
@@ -338,22 +314,23 @@ class PaymentSheetFragment :
|
|
|
338
314
|
} else {
|
|
339
315
|
builder.createIntentCallback(createIntentCallback)
|
|
340
316
|
}
|
|
317
|
+
@SuppressLint("RestrictedApi")
|
|
341
318
|
builder
|
|
342
319
|
.confirmCustomPaymentMethodCallback(this)
|
|
343
|
-
.build(
|
|
320
|
+
.build(activity, signal)
|
|
344
321
|
} else {
|
|
322
|
+
@SuppressLint("RestrictedApi")
|
|
345
323
|
PaymentSheet
|
|
346
324
|
.Builder(paymentResultCallback)
|
|
347
325
|
.confirmCustomPaymentMethodCallback(this)
|
|
348
|
-
.build(
|
|
326
|
+
.build(activity, signal)
|
|
349
327
|
}
|
|
350
|
-
initPromise.resolve(
|
|
328
|
+
initPromise.resolve(Arguments.createMap())
|
|
351
329
|
}
|
|
352
330
|
}
|
|
353
331
|
|
|
354
|
-
fun
|
|
332
|
+
override fun onPresent() {
|
|
355
333
|
keepJsAwake = KeepJsAwakeTask(context).apply { start() }
|
|
356
|
-
presentPromise = promise
|
|
357
334
|
if (paymentSheet != null) {
|
|
358
335
|
if (!paymentIntentClientSecret.isNullOrEmpty()) {
|
|
359
336
|
paymentSheet?.presentWithPaymentIntent(
|
|
@@ -371,7 +348,7 @@ class PaymentSheetFragment :
|
|
|
371
348
|
} else if (flowController != null) {
|
|
372
349
|
flowController?.presentPaymentOptions()
|
|
373
350
|
} else {
|
|
374
|
-
promise
|
|
351
|
+
promise?.resolve(createMissingInitError())
|
|
375
352
|
}
|
|
376
353
|
}
|
|
377
354
|
|
|
@@ -438,13 +415,13 @@ class PaymentSheetFragment :
|
|
|
438
415
|
PaymentSheet.FlowController.ConfigCallback { _, _ ->
|
|
439
416
|
val result =
|
|
440
417
|
flowController?.getPaymentOption()?.let {
|
|
441
|
-
val bitmap =
|
|
418
|
+
val bitmap = getBitmapFromDrawable(it.icon())
|
|
442
419
|
val imageString = getBase64FromBitmap(bitmap)
|
|
443
|
-
val option: WritableMap =
|
|
420
|
+
val option: WritableMap = Arguments.createMap()
|
|
444
421
|
option.putString("label", it.label)
|
|
445
422
|
option.putString("image", imageString)
|
|
446
423
|
createResult("paymentOption", option)
|
|
447
|
-
} ?: run {
|
|
424
|
+
} ?: run { Arguments.createMap() }
|
|
448
425
|
initPromise.resolve(result)
|
|
449
426
|
}
|
|
450
427
|
|
|
@@ -479,7 +456,7 @@ class PaymentSheetFragment :
|
|
|
479
456
|
|
|
480
457
|
private fun resolvePresentPromise(value: Any?) {
|
|
481
458
|
keepJsAwake?.stop()
|
|
482
|
-
|
|
459
|
+
promise?.resolve(value)
|
|
483
460
|
}
|
|
484
461
|
|
|
485
462
|
private fun resolvePaymentResult(map: WritableMap) {
|
|
@@ -565,180 +542,21 @@ class PaymentSheetFragment :
|
|
|
565
542
|
}
|
|
566
543
|
|
|
567
544
|
companion object {
|
|
568
|
-
internal const val TAG = "payment_sheet_launch_fragment"
|
|
569
|
-
|
|
570
|
-
internal fun create(
|
|
571
|
-
context: ReactApplicationContext,
|
|
572
|
-
arguments: Bundle,
|
|
573
|
-
initPromise: Promise,
|
|
574
|
-
): PaymentSheetFragment {
|
|
575
|
-
val instance = PaymentSheetFragment()
|
|
576
|
-
instance.context = context
|
|
577
|
-
instance.initPromise = initPromise
|
|
578
|
-
instance.arguments = arguments
|
|
579
|
-
return instance
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
private val mapIntToButtonType =
|
|
583
|
-
mapOf(
|
|
584
|
-
1 to PaymentSheet.GooglePayConfiguration.ButtonType.Buy,
|
|
585
|
-
6 to PaymentSheet.GooglePayConfiguration.ButtonType.Book,
|
|
586
|
-
5 to PaymentSheet.GooglePayConfiguration.ButtonType.Checkout,
|
|
587
|
-
4 to PaymentSheet.GooglePayConfiguration.ButtonType.Donate,
|
|
588
|
-
11 to PaymentSheet.GooglePayConfiguration.ButtonType.Order,
|
|
589
|
-
1000 to PaymentSheet.GooglePayConfiguration.ButtonType.Pay,
|
|
590
|
-
7 to PaymentSheet.GooglePayConfiguration.ButtonType.Subscribe,
|
|
591
|
-
1001 to PaymentSheet.GooglePayConfiguration.ButtonType.Plain,
|
|
592
|
-
)
|
|
593
|
-
|
|
594
545
|
internal fun createMissingInitError(): WritableMap =
|
|
595
546
|
createError(
|
|
596
547
|
PaymentSheetErrorType.Failed.toString(),
|
|
597
548
|
"No payment sheet has been initialized yet. You must call `initPaymentSheet` before `presentPaymentSheet`.",
|
|
598
549
|
)
|
|
599
|
-
|
|
600
|
-
internal fun buildGooglePayConfig(params: Bundle?): PaymentSheet.GooglePayConfiguration? {
|
|
601
|
-
if (params == null || params.isEmpty) {
|
|
602
|
-
return null
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
val countryCode = params.getString("merchantCountryCode").orEmpty()
|
|
606
|
-
val currencyCode = params.getString("currencyCode").orEmpty()
|
|
607
|
-
val testEnv = params.getBoolean("testEnv")
|
|
608
|
-
val amount = params.getString("amount")?.toLongOrNull()
|
|
609
|
-
val label = params.getString("label")
|
|
610
|
-
val buttonType =
|
|
611
|
-
mapIntToButtonType.get(params.getInt("buttonType"))
|
|
612
|
-
?: PaymentSheet.GooglePayConfiguration.ButtonType.Pay
|
|
613
|
-
|
|
614
|
-
return PaymentSheet.GooglePayConfiguration(
|
|
615
|
-
environment =
|
|
616
|
-
if (testEnv) {
|
|
617
|
-
PaymentSheet.GooglePayConfiguration.Environment.Test
|
|
618
|
-
} else {
|
|
619
|
-
PaymentSheet.GooglePayConfiguration.Environment.Production
|
|
620
|
-
},
|
|
621
|
-
countryCode = countryCode,
|
|
622
|
-
currencyCode = currencyCode,
|
|
623
|
-
amount = amount,
|
|
624
|
-
label = label,
|
|
625
|
-
buttonType = buttonType,
|
|
626
|
-
)
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
internal fun buildLinkConfig(params: Bundle?): PaymentSheet.LinkConfiguration {
|
|
630
|
-
if (params == null) {
|
|
631
|
-
return PaymentSheet.LinkConfiguration()
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
val display = mapStringToLinkDisplay(params.getString("display"))
|
|
635
|
-
|
|
636
|
-
return PaymentSheet.LinkConfiguration(
|
|
637
|
-
display = display,
|
|
638
|
-
)
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
private fun mapStringToLinkDisplay(value: String?): PaymentSheet.LinkConfiguration.Display =
|
|
642
|
-
when (value) {
|
|
643
|
-
"automatic" -> PaymentSheet.LinkConfiguration.Display.Automatic
|
|
644
|
-
"never" -> PaymentSheet.LinkConfiguration.Display.Never
|
|
645
|
-
else -> PaymentSheet.LinkConfiguration.Display.Automatic
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
@Throws(PaymentSheetException::class)
|
|
649
|
-
internal fun buildIntentConfiguration(intentConfigurationParams: Bundle?): PaymentSheet.IntentConfiguration? {
|
|
650
|
-
if (intentConfigurationParams == null) {
|
|
651
|
-
return null
|
|
652
|
-
}
|
|
653
|
-
val modeParams =
|
|
654
|
-
intentConfigurationParams.getBundle("mode")
|
|
655
|
-
?: throw PaymentSheetException(
|
|
656
|
-
"If `intentConfiguration` is provided, `intentConfiguration.mode` is required",
|
|
657
|
-
)
|
|
658
|
-
|
|
659
|
-
return PaymentSheet.IntentConfiguration(
|
|
660
|
-
mode = buildIntentConfigurationMode(modeParams),
|
|
661
|
-
paymentMethodTypes =
|
|
662
|
-
intentConfigurationParams.getStringArrayList("paymentMethodTypes")?.toList()
|
|
663
|
-
?: emptyList(),
|
|
664
|
-
)
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
@OptIn(PaymentMethodOptionsSetupFutureUsagePreview::class)
|
|
668
|
-
private fun buildIntentConfigurationMode(modeParams: Bundle): PaymentSheet.IntentConfiguration.Mode =
|
|
669
|
-
if (modeParams.containsKey("amount")) {
|
|
670
|
-
val currencyCode =
|
|
671
|
-
modeParams.getString("currencyCode")
|
|
672
|
-
?: throw PaymentSheetException(
|
|
673
|
-
"You must provide a value to intentConfiguration.mode.currencyCode",
|
|
674
|
-
)
|
|
675
|
-
PaymentSheet.IntentConfiguration.Mode.Payment(
|
|
676
|
-
amount = modeParams.getInt("amount").toLong(),
|
|
677
|
-
currency = currencyCode,
|
|
678
|
-
setupFutureUse = mapToSetupFutureUse(modeParams.getString("setupFutureUsage")),
|
|
679
|
-
captureMethod = mapToCaptureMethod(modeParams.getString("captureMethod")),
|
|
680
|
-
paymentMethodOptions = mapToPaymentMethodOptions(modeParams.getBundle("paymentMethodOptions")),
|
|
681
|
-
)
|
|
682
|
-
} else {
|
|
683
|
-
val setupFutureUsage =
|
|
684
|
-
mapToSetupFutureUse(modeParams.getString("setupFutureUsage"))
|
|
685
|
-
?: throw PaymentSheetException(
|
|
686
|
-
"You must provide a value to intentConfiguration.mode.setupFutureUsage",
|
|
687
|
-
)
|
|
688
|
-
PaymentSheet.IntentConfiguration.Mode.Setup(
|
|
689
|
-
currency = modeParams.getString("currencyCode"),
|
|
690
|
-
setupFutureUse = setupFutureUsage,
|
|
691
|
-
)
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
@OptIn(ExperimentalCustomerSessionApi::class)
|
|
695
|
-
@Throws(PaymentSheetException::class)
|
|
696
|
-
internal fun buildCustomerConfiguration(bundle: Bundle?): PaymentSheet.CustomerConfiguration? {
|
|
697
|
-
val customerId = bundle?.getString("customerId").orEmpty()
|
|
698
|
-
val customerEphemeralKeySecret = bundle?.getString("customerEphemeralKeySecret").orEmpty()
|
|
699
|
-
val customerSessionClientSecret = bundle?.getString("customerSessionClientSecret").orEmpty()
|
|
700
|
-
return if (customerSessionClientSecret.isNotEmpty() &&
|
|
701
|
-
customerEphemeralKeySecret.isNotEmpty()
|
|
702
|
-
) {
|
|
703
|
-
throw PaymentSheetException(
|
|
704
|
-
"`customerEphemeralKeySecret` and `customerSessionClientSecret` cannot both be set",
|
|
705
|
-
)
|
|
706
|
-
} else if (customerId.isNotEmpty() && customerSessionClientSecret.isNotEmpty()) {
|
|
707
|
-
PaymentSheet.CustomerConfiguration.createWithCustomerSession(
|
|
708
|
-
id = customerId,
|
|
709
|
-
clientSecret = customerSessionClientSecret,
|
|
710
|
-
)
|
|
711
|
-
} else if (customerId.isNotEmpty() && customerEphemeralKeySecret.isNotEmpty()) {
|
|
712
|
-
PaymentSheet.CustomerConfiguration(
|
|
713
|
-
id = customerId,
|
|
714
|
-
ephemeralKeySecret = customerEphemeralKeySecret,
|
|
715
|
-
)
|
|
716
|
-
} else {
|
|
717
|
-
null
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
550
|
}
|
|
721
551
|
}
|
|
722
552
|
|
|
723
|
-
fun getBitmapFromVectorDrawable(
|
|
724
|
-
context: Context?,
|
|
725
|
-
drawableId: Int,
|
|
726
|
-
): Bitmap? {
|
|
727
|
-
val drawable = AppCompatResources.getDrawable(context!!, drawableId) ?: return null
|
|
728
|
-
return getBitmapFromDrawable(drawable)
|
|
729
|
-
}
|
|
730
|
-
|
|
731
553
|
fun getBitmapFromDrawable(drawable: Drawable): Bitmap? {
|
|
732
554
|
val drawableCompat = DrawableCompat.wrap(drawable).mutate()
|
|
733
555
|
if (drawableCompat.intrinsicWidth <= 0 || drawableCompat.intrinsicHeight <= 0) {
|
|
734
556
|
return null
|
|
735
557
|
}
|
|
736
558
|
val bitmap =
|
|
737
|
-
|
|
738
|
-
drawableCompat.intrinsicWidth,
|
|
739
|
-
drawableCompat.intrinsicHeight,
|
|
740
|
-
Bitmap.Config.ARGB_8888,
|
|
741
|
-
)
|
|
559
|
+
createBitmap(drawableCompat.intrinsicWidth, drawableCompat.intrinsicHeight)
|
|
742
560
|
bitmap.eraseColor(Color.TRANSPARENT)
|
|
743
561
|
val canvas = Canvas(bitmap)
|
|
744
562
|
drawable.setBounds(0, 0, canvas.width, canvas.height)
|
|
@@ -756,14 +574,6 @@ fun getBase64FromBitmap(bitmap: Bitmap?): String? {
|
|
|
756
574
|
return Base64.encodeToString(imageBytes, Base64.DEFAULT)
|
|
757
575
|
}
|
|
758
576
|
|
|
759
|
-
fun mapToCollectionMode(str: String?): PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode =
|
|
760
|
-
when (str) {
|
|
761
|
-
"automatic" -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic
|
|
762
|
-
"never" -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Never
|
|
763
|
-
"always" -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
|
|
764
|
-
else -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic
|
|
765
|
-
}
|
|
766
|
-
|
|
767
577
|
fun mapToPaymentMethodLayout(str: String?): PaymentSheet.PaymentMethodLayout =
|
|
768
578
|
when (str) {
|
|
769
579
|
"Horizontal" -> PaymentSheet.PaymentMethodLayout.Horizontal
|
|
@@ -771,17 +581,7 @@ fun mapToPaymentMethodLayout(str: String?): PaymentSheet.PaymentMethodLayout =
|
|
|
771
581
|
else -> PaymentSheet.PaymentMethodLayout.Automatic
|
|
772
582
|
}
|
|
773
583
|
|
|
774
|
-
fun
|
|
775
|
-
when (str) {
|
|
776
|
-
"automatic" ->
|
|
777
|
-
PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic
|
|
778
|
-
|
|
779
|
-
"never" -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Never
|
|
780
|
-
"full" -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Full
|
|
781
|
-
else -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
fun mapToSetupFutureUse(type: String?): PaymentSheet.IntentConfiguration.SetupFutureUse? =
|
|
584
|
+
internal fun mapToSetupFutureUse(type: String?): PaymentSheet.IntentConfiguration.SetupFutureUse? =
|
|
785
585
|
when (type) {
|
|
786
586
|
"OffSession" -> PaymentSheet.IntentConfiguration.SetupFutureUse.OffSession
|
|
787
587
|
"OnSession" -> PaymentSheet.IntentConfiguration.SetupFutureUse.OnSession
|
|
@@ -789,7 +589,7 @@ fun mapToSetupFutureUse(type: String?): PaymentSheet.IntentConfiguration.SetupFu
|
|
|
789
589
|
else -> null
|
|
790
590
|
}
|
|
791
591
|
|
|
792
|
-
fun mapToCaptureMethod(type: String?): PaymentSheet.IntentConfiguration.CaptureMethod =
|
|
592
|
+
internal fun mapToCaptureMethod(type: String?): PaymentSheet.IntentConfiguration.CaptureMethod =
|
|
793
593
|
when (type) {
|
|
794
594
|
"Automatic" -> PaymentSheet.IntentConfiguration.CaptureMethod.Automatic
|
|
795
595
|
"Manual" -> PaymentSheet.IntentConfiguration.CaptureMethod.Manual
|
|
@@ -798,11 +598,11 @@ fun mapToCaptureMethod(type: String?): PaymentSheet.IntentConfiguration.CaptureM
|
|
|
798
598
|
}
|
|
799
599
|
|
|
800
600
|
@OptIn(PaymentMethodOptionsSetupFutureUsagePreview::class)
|
|
801
|
-
fun mapToPaymentMethodOptions(options:
|
|
802
|
-
val
|
|
601
|
+
internal fun mapToPaymentMethodOptions(options: ReadableMap?): PaymentSheet.IntentConfiguration.Mode.Payment.PaymentMethodOptions? {
|
|
602
|
+
val sfuMap = options?.getMap("setupFutureUsageValues")
|
|
803
603
|
val paymentMethodToSfuMap = mutableMapOf<PaymentMethod.Type, PaymentSheet.IntentConfiguration.SetupFutureUse>()
|
|
804
|
-
|
|
805
|
-
val sfuValue = mapToSetupFutureUse(
|
|
604
|
+
sfuMap?.forEachKey { code ->
|
|
605
|
+
val sfuValue = mapToSetupFutureUse(sfuMap.getString(code))
|
|
806
606
|
val paymentMethodType = PaymentMethod.Type.fromCode(code)
|
|
807
607
|
if (paymentMethodType != null && sfuValue != null) {
|
|
808
608
|
paymentMethodToSfuMap[paymentMethodType] = sfuValue
|
|
@@ -816,38 +616,3 @@ fun mapToPaymentMethodOptions(options: Bundle?): PaymentSheet.IntentConfiguratio
|
|
|
816
616
|
null
|
|
817
617
|
}
|
|
818
618
|
}
|
|
819
|
-
|
|
820
|
-
fun mapToCardBrandAcceptance(params: Bundle?): PaymentSheet.CardBrandAcceptance {
|
|
821
|
-
val cardBrandAcceptanceParams = params?.getBundle("cardBrandAcceptance") ?: return PaymentSheet.CardBrandAcceptance.all()
|
|
822
|
-
val filter = cardBrandAcceptanceParams.getString("filter") ?: return PaymentSheet.CardBrandAcceptance.all()
|
|
823
|
-
|
|
824
|
-
return when (filter) {
|
|
825
|
-
"all" -> PaymentSheet.CardBrandAcceptance.all()
|
|
826
|
-
"allowed" -> {
|
|
827
|
-
val brands = cardBrandAcceptanceParams.getStringArrayList("brands") ?: return PaymentSheet.CardBrandAcceptance.all()
|
|
828
|
-
val brandCategories = brands.mapNotNull { mapToCardBrandCategory(it) }
|
|
829
|
-
if (brandCategories.isEmpty()) {
|
|
830
|
-
return PaymentSheet.CardBrandAcceptance.all()
|
|
831
|
-
}
|
|
832
|
-
PaymentSheet.CardBrandAcceptance.allowed(brandCategories)
|
|
833
|
-
}
|
|
834
|
-
"disallowed" -> {
|
|
835
|
-
val brands = cardBrandAcceptanceParams.getStringArrayList("brands") ?: return PaymentSheet.CardBrandAcceptance.all()
|
|
836
|
-
val brandCategories = brands.mapNotNull { mapToCardBrandCategory(it) }
|
|
837
|
-
if (brandCategories.isEmpty()) {
|
|
838
|
-
return PaymentSheet.CardBrandAcceptance.all()
|
|
839
|
-
}
|
|
840
|
-
PaymentSheet.CardBrandAcceptance.disallowed(brandCategories)
|
|
841
|
-
}
|
|
842
|
-
else -> PaymentSheet.CardBrandAcceptance.all()
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
fun mapToCardBrandCategory(brand: String): PaymentSheet.CardBrandAcceptance.BrandCategory? =
|
|
847
|
-
when (brand) {
|
|
848
|
-
"visa" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Visa
|
|
849
|
-
"mastercard" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Mastercard
|
|
850
|
-
"amex" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Amex
|
|
851
|
-
"discover" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Discover
|
|
852
|
-
else -> null
|
|
853
|
-
}
|