@stripe/stripe-react-native 0.57.0 → 0.57.2
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/README.md +0 -8
- package/android/.idea/AndroidProjectSystem.xml +6 -0
- package/android/.idea/caches/deviceStreaming.xml +1029 -0
- package/android/.idea/compiler.xml +6 -0
- package/android/.idea/gradle.xml +19 -0
- package/android/.idea/migrations.xml +10 -0
- package/android/.idea/misc.xml +10 -0
- package/android/.idea/runConfigurations.xml +17 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/build.gradle +76 -118
- package/android/gradle.properties +1 -1
- package/android/local.properties +8 -0
- package/android/settings.gradle +2 -0
- package/android/spotless.gradle +1 -1
- package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormView.kt +20 -17
- package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +13 -11
- package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +17 -21
- package/android/src/main/java/com/reactnativestripesdk/CollectBankAccountLauncherManager.kt +2 -0
- package/android/src/main/java/com/reactnativestripesdk/CustomPaymentMethodActivity.kt +2 -0
- package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementView.kt +53 -11
- package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +105 -117
- package/android/src/main/java/com/reactnativestripesdk/EventEmitterCompat.kt +4 -8
- package/android/src/main/java/com/reactnativestripesdk/FakeOnrampSdkModule.kt +154 -0
- package/android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetManager.kt +13 -15
- package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonView.kt +1 -1
- package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherManager.kt +1 -1
- 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/PaymentLauncherManager.kt +1 -0
- package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +3 -0
- package/android/src/main/java/com/reactnativestripesdk/PaymentOptionDisplayDataMapper.kt +4 -6
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +73 -30
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetManager.kt +19 -245
- package/android/src/main/java/com/reactnativestripesdk/StripeAbstractComposeView.kt +53 -17
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +52 -14
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +21 -2
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +4 -4
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetViewManager.kt +2 -2
- package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetManager.kt +15 -35
- package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerSessionProvider.kt +2 -1
- 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 +41 -0
- package/android/src/main/java/com/reactnativestripesdk/utils/KeepJsAwakeTask.kt +1 -1
- package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +92 -44
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerDelegate.java +3 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerInterface.java +2 -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 +25 -25
- 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 +210 -71
- 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 -24
- 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 +15 -17
- 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/StripeSdk.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/StripeSdk.xcodeproj/project.xcworkspace/xcuserdata/tianzhao.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/StripeSdk.xcodeproj/xcuserdata/tianzhao.xcuserdatad/xcschemes/xcschememanagement.plist +19 -0
- package/ios/StripeSdkEmitter.swift +4 -0
- package/ios/StripeSdkImpl+CustomerSheet.swift +30 -25
- package/ios/StripeSdkImpl+Embedded.swift +11 -9
- package/ios/StripeSdkImpl+PaymentSheet.swift +36 -34
- package/ios/StripeSdkImpl.swift +913 -185
- 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/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/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 +4 -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/NativeEmbeddedPaymentElement.d.ts +1 -0
- package/lib/typescript/src/specs/NativeEmbeddedPaymentElement.d.ts.map +1 -1
- 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/EmbeddedPaymentElement.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/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 +25 -14
- 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 +23 -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/NativeEmbeddedPaymentElement.ts +5 -1
- package/src/specs/NativeNavigationBar.ts +16 -0
- package/src/specs/NativeOnrampSdkModule.ts +47 -0
- package/src/specs/NativeStripeSdkModule.ts +5 -0
- package/src/types/EmbeddedPaymentElement.tsx +24 -3
- package/src/types/Errors.ts +6 -0
- package/src/types/Onramp.ts +317 -0
- package/src/types/PaymentSheet.ts +7 -0
- package/src/types/index.ts +8 -0
- package/stripe-react-native.podspec +20 -7
|
@@ -7,6 +7,7 @@ import android.content.Intent
|
|
|
7
7
|
import android.os.Bundle
|
|
8
8
|
import android.util.Log
|
|
9
9
|
import android.view.ViewGroup
|
|
10
|
+
import androidx.browser.customtabs.CustomTabsIntent
|
|
10
11
|
import androidx.fragment.app.FragmentActivity
|
|
11
12
|
import com.facebook.react.ReactActivity
|
|
12
13
|
import com.facebook.react.bridge.Arguments
|
|
@@ -18,7 +19,6 @@ import com.facebook.react.bridge.ReadableArray
|
|
|
18
19
|
import com.facebook.react.bridge.ReadableMap
|
|
19
20
|
import com.facebook.react.bridge.UiThreadUtil
|
|
20
21
|
import com.facebook.react.bridge.WritableMap
|
|
21
|
-
import com.facebook.react.bridge.WritableNativeMap
|
|
22
22
|
import com.facebook.react.module.annotations.ReactModule
|
|
23
23
|
import com.reactnativestripesdk.addresssheet.AddressLauncherManager
|
|
24
24
|
import com.reactnativestripesdk.customersheet.CustomerSheetManager
|
|
@@ -35,6 +35,7 @@ import com.reactnativestripesdk.utils.createMissingInitError
|
|
|
35
35
|
import com.reactnativestripesdk.utils.createResult
|
|
36
36
|
import com.reactnativestripesdk.utils.getBooleanOr
|
|
37
37
|
import com.reactnativestripesdk.utils.getIntOrNull
|
|
38
|
+
import com.reactnativestripesdk.utils.getLongOrNull
|
|
38
39
|
import com.reactnativestripesdk.utils.getValOr
|
|
39
40
|
import com.reactnativestripesdk.utils.mapFromPaymentIntentResult
|
|
40
41
|
import com.reactnativestripesdk.utils.mapFromPaymentMethod
|
|
@@ -163,7 +164,7 @@ class StripeSdkModule(
|
|
|
163
164
|
|
|
164
165
|
private fun configure3dSecure(params: ReadableMap) {
|
|
165
166
|
val stripe3dsConfigBuilder = PaymentAuthConfig.Stripe3ds2Config.Builder()
|
|
166
|
-
|
|
167
|
+
params.getIntOrNull("timeout")?.let { stripe3dsConfigBuilder.setTimeout(it) }
|
|
167
168
|
val uiCustomization = mapToUICustomization(params)
|
|
168
169
|
|
|
169
170
|
PaymentAuthConfig.init(
|
|
@@ -244,10 +245,10 @@ class StripeSdkModule(
|
|
|
244
245
|
return
|
|
245
246
|
}
|
|
246
247
|
|
|
247
|
-
val
|
|
248
|
-
if (
|
|
248
|
+
val timeout = options.getLongOrNull("timeout")
|
|
249
|
+
if (timeout != null) {
|
|
249
250
|
paymentSheetManager?.presentWithTimeout(
|
|
250
|
-
|
|
251
|
+
timeout,
|
|
251
252
|
promise,
|
|
252
253
|
)
|
|
253
254
|
} else {
|
|
@@ -502,7 +503,7 @@ class StripeSdkModule(
|
|
|
502
503
|
object : ApiResultCallback<Token> {
|
|
503
504
|
override fun onSuccess(result: Token) {
|
|
504
505
|
val tokenId = result.id
|
|
505
|
-
val res =
|
|
506
|
+
val res = Arguments.createMap()
|
|
506
507
|
res.putString("tokenId", tokenId)
|
|
507
508
|
promise.resolve(res)
|
|
508
509
|
}
|
|
@@ -760,6 +761,7 @@ class StripeSdkModule(
|
|
|
760
761
|
return
|
|
761
762
|
}
|
|
762
763
|
|
|
764
|
+
unregisterStripeUIManager(googlePayLauncherManager)
|
|
763
765
|
googlePayLauncherManager =
|
|
764
766
|
GooglePayLauncherManager(
|
|
765
767
|
reactApplicationContext,
|
|
@@ -779,7 +781,7 @@ class StripeSdkModule(
|
|
|
779
781
|
expand = listOf("payment_method"),
|
|
780
782
|
object : ApiResultCallback<PaymentIntent> {
|
|
781
783
|
override fun onError(e: Exception) {
|
|
782
|
-
promise.resolve(createResult("paymentIntent",
|
|
784
|
+
promise.resolve(createResult("paymentIntent", Arguments.createMap()))
|
|
783
785
|
}
|
|
784
786
|
|
|
785
787
|
override fun onSuccess(result: PaymentIntent) {
|
|
@@ -799,7 +801,7 @@ class StripeSdkModule(
|
|
|
799
801
|
expand = listOf("payment_method"),
|
|
800
802
|
object : ApiResultCallback<SetupIntent> {
|
|
801
803
|
override fun onError(e: Exception) {
|
|
802
|
-
promise.resolve(createResult("setupIntent",
|
|
804
|
+
promise.resolve(createResult("setupIntent", Arguments.createMap()))
|
|
803
805
|
}
|
|
804
806
|
|
|
805
807
|
override fun onSuccess(result: SetupIntent) {
|
|
@@ -829,6 +831,9 @@ class StripeSdkModule(
|
|
|
829
831
|
}
|
|
830
832
|
}
|
|
831
833
|
}
|
|
834
|
+
}.also {
|
|
835
|
+
registerStripeUIManager(it)
|
|
836
|
+
it.present()
|
|
832
837
|
}
|
|
833
838
|
}
|
|
834
839
|
|
|
@@ -909,7 +914,7 @@ class StripeSdkModule(
|
|
|
909
914
|
PushProvisioningProxy.isCardInWallet(it, last4) { isCardInWallet, token, error ->
|
|
910
915
|
val result: WritableMap =
|
|
911
916
|
error ?: run {
|
|
912
|
-
val map =
|
|
917
|
+
val map = Arguments.createMap()
|
|
913
918
|
map.putBoolean("isInWallet", isCardInWallet)
|
|
914
919
|
map.putMap("token", token)
|
|
915
920
|
map
|
|
@@ -1129,7 +1134,7 @@ class StripeSdkModule(
|
|
|
1129
1134
|
params: ReadableMap,
|
|
1130
1135
|
promise: Promise,
|
|
1131
1136
|
) {
|
|
1132
|
-
val timeout = params.
|
|
1137
|
+
val timeout = params.getLongOrNull("timeout")
|
|
1133
1138
|
customerSheetManager?.present(promise, timeout) ?: run {
|
|
1134
1139
|
promise.resolve(CustomerSheetManager.createMissingInitError())
|
|
1135
1140
|
}
|
|
@@ -1329,6 +1334,39 @@ class StripeSdkModule(
|
|
|
1329
1334
|
// noop, iOS only
|
|
1330
1335
|
}
|
|
1331
1336
|
|
|
1337
|
+
@ReactMethod
|
|
1338
|
+
override fun openAuthenticatedWebView(
|
|
1339
|
+
id: String,
|
|
1340
|
+
url: String,
|
|
1341
|
+
promise: Promise,
|
|
1342
|
+
) {
|
|
1343
|
+
val activity = getCurrentActivityOrResolveWithError(promise) ?: return
|
|
1344
|
+
|
|
1345
|
+
UiThreadUtil.runOnUiThread {
|
|
1346
|
+
try {
|
|
1347
|
+
val uri = android.net.Uri.parse(url)
|
|
1348
|
+
val builder =
|
|
1349
|
+
androidx.browser.customtabs.CustomTabsIntent
|
|
1350
|
+
.Builder()
|
|
1351
|
+
|
|
1352
|
+
// Set toolbar color for better UX
|
|
1353
|
+
builder.setShowTitle(true)
|
|
1354
|
+
builder.setUrlBarHidingEnabled(true)
|
|
1355
|
+
|
|
1356
|
+
val customTabsIntent = builder.build()
|
|
1357
|
+
|
|
1358
|
+
// Note: Custom Tabs doesn't have built-in redirect handling like iOS ASWebAuthenticationSession.
|
|
1359
|
+
// The redirect will be handled via deep linking when the auth server redirects to stripe-connect://
|
|
1360
|
+
// The React Native Linking module will capture the deep link and pass it back to the JS layer.
|
|
1361
|
+
customTabsIntent.launchUrl(activity, uri)
|
|
1362
|
+
|
|
1363
|
+
promise.resolve(null)
|
|
1364
|
+
} catch (e: Exception) {
|
|
1365
|
+
promise.resolve(createError("Failed", e))
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1332
1370
|
override fun addListener(eventType: String?) {
|
|
1333
1371
|
// noop, iOS only
|
|
1334
1372
|
}
|
|
@@ -1376,7 +1414,7 @@ class StripeSdkModule(
|
|
|
1376
1414
|
* provided will be resolved with an error message instructing the user to retry the method.
|
|
1377
1415
|
*/
|
|
1378
1416
|
private fun getCurrentActivityOrResolveWithError(promise: Promise?): FragmentActivity? {
|
|
1379
|
-
(currentActivity as? FragmentActivity)?.let {
|
|
1417
|
+
(reactApplicationContext.currentActivity as? FragmentActivity)?.let {
|
|
1380
1418
|
return it
|
|
1381
1419
|
}
|
|
1382
1420
|
promise?.resolve(createMissingActivityError())
|
|
@@ -1430,14 +1468,14 @@ class StripeSdkModule(
|
|
|
1430
1468
|
*/
|
|
1431
1469
|
private fun preventActivityRecreation() {
|
|
1432
1470
|
isRecreatingReactActivity = false
|
|
1433
|
-
currentActivity?.application?.unregisterActivityLifecycleCallbacks(activityLifecycleCallbacks)
|
|
1434
|
-
currentActivity?.application?.registerActivityLifecycleCallbacks(activityLifecycleCallbacks)
|
|
1471
|
+
reactApplicationContext.currentActivity?.application?.unregisterActivityLifecycleCallbacks(activityLifecycleCallbacks)
|
|
1472
|
+
reactApplicationContext.currentActivity?.application?.registerActivityLifecycleCallbacks(activityLifecycleCallbacks)
|
|
1435
1473
|
}
|
|
1436
1474
|
|
|
1437
1475
|
private fun setupComposeCompatView() {
|
|
1438
1476
|
UiThreadUtil.runOnUiThread {
|
|
1439
1477
|
composeCompatView = composeCompatView ?: StripeAbstractComposeView.CompatView(context = reactApplicationContext).also {
|
|
1440
|
-
currentActivity?.findViewById<ViewGroup>(android.R.id.content)?.addView(
|
|
1478
|
+
reactApplicationContext.currentActivity?.findViewById<ViewGroup>(android.R.id.content)?.addView(
|
|
1441
1479
|
it,
|
|
1442
1480
|
)
|
|
1443
1481
|
}
|
|
@@ -19,11 +19,20 @@ class StripeSdkPackage : BaseReactPackage() {
|
|
|
19
19
|
): NativeModule? =
|
|
20
20
|
when (name) {
|
|
21
21
|
StripeSdkModule.NAME -> StripeSdkModule(reactContext)
|
|
22
|
+
NativeOnrampSdkModuleSpec.NAME -> {
|
|
23
|
+
val onrampModuleClass = getOnrampModuleClass()
|
|
24
|
+
val constructor = onrampModuleClass.getConstructor(ReactApplicationContext::class.java)
|
|
25
|
+
constructor.newInstance(reactContext) as NativeModule
|
|
26
|
+
}
|
|
22
27
|
else -> null
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
26
|
-
val moduleList: Array<Class<out NativeModule?>> =
|
|
31
|
+
val moduleList: Array<Class<out NativeModule?>> =
|
|
32
|
+
arrayOf(
|
|
33
|
+
StripeSdkModule::class.java,
|
|
34
|
+
getOnrampModuleClass(),
|
|
35
|
+
)
|
|
27
36
|
val reactModuleInfoMap: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
28
37
|
for (moduleClass in moduleList) {
|
|
29
38
|
val reactModule = moduleClass.getAnnotation(ReactModule::class.java) ?: continue
|
|
@@ -47,8 +56,18 @@ class StripeSdkPackage : BaseReactPackage() {
|
|
|
47
56
|
StripeContainerManager(),
|
|
48
57
|
CardFormViewManager(),
|
|
49
58
|
GooglePayButtonManager(),
|
|
50
|
-
AddToWalletButtonManager(
|
|
59
|
+
AddToWalletButtonManager(),
|
|
51
60
|
AddressSheetViewManager(),
|
|
52
61
|
EmbeddedPaymentElementViewManager(),
|
|
62
|
+
NavigationBarManager(),
|
|
53
63
|
)
|
|
64
|
+
|
|
65
|
+
private fun getOnrampModuleClass(): Class<out NativeModule?> {
|
|
66
|
+
if (BuildConfig.IS_ONRAMP_INCLUDED) {
|
|
67
|
+
@Suppress("UNCHECKED_CAST")
|
|
68
|
+
return Class.forName("com.reactnativestripesdk.OnrampSdkModule") as Class<out NativeModule?>
|
|
69
|
+
} else {
|
|
70
|
+
return FakeOnrampSdkModule::class.java
|
|
71
|
+
}
|
|
72
|
+
}
|
|
54
73
|
}
|
|
@@ -3,9 +3,9 @@ package com.reactnativestripesdk.addresssheet
|
|
|
3
3
|
import android.annotation.SuppressLint
|
|
4
4
|
import android.util.Log
|
|
5
5
|
import android.widget.FrameLayout
|
|
6
|
+
import com.facebook.react.bridge.Arguments
|
|
6
7
|
import com.facebook.react.bridge.ReadableMap
|
|
7
8
|
import com.facebook.react.bridge.WritableMap
|
|
8
|
-
import com.facebook.react.bridge.WritableNativeMap
|
|
9
9
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
10
10
|
import com.facebook.react.uimanager.UIManagerHelper
|
|
11
11
|
import com.reactnativestripesdk.buildPaymentSheetAppearance
|
|
@@ -172,14 +172,14 @@ class AddressSheetView(
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
internal fun buildResult(addressDetails: AddressDetails): WritableMap =
|
|
175
|
-
|
|
175
|
+
Arguments.createMap().apply {
|
|
176
176
|
putMap(
|
|
177
177
|
"result",
|
|
178
|
-
|
|
178
|
+
Arguments.createMap().apply {
|
|
179
179
|
putString("name", addressDetails.name)
|
|
180
180
|
putMap(
|
|
181
181
|
"address",
|
|
182
|
-
|
|
182
|
+
Arguments.createMap().apply {
|
|
183
183
|
putString("city", addressDetails.address?.city)
|
|
184
184
|
putString("country", addressDetails.address?.country)
|
|
185
185
|
putString("line1", addressDetails.address?.line1)
|
package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetViewManager.kt
CHANGED
|
@@ -41,7 +41,7 @@ class AddressSheetViewManager :
|
|
|
41
41
|
view: AddressSheetView,
|
|
42
42
|
appearance: Dynamic,
|
|
43
43
|
) {
|
|
44
|
-
view.setAppearance(appearance.
|
|
44
|
+
view.setAppearance(appearance.asMapOrNull())
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
@ReactProp(name = "defaultValues")
|
|
@@ -49,7 +49,7 @@ class AddressSheetViewManager :
|
|
|
49
49
|
view: AddressSheetView,
|
|
50
50
|
defaults: Dynamic,
|
|
51
51
|
) {
|
|
52
|
-
view.setDefaultValues(defaults.
|
|
52
|
+
view.setDefaultValues(defaults.asMapOrNull())
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
@ReactProp(name = "additionalFields")
|
package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetManager.kt
CHANGED
|
@@ -12,17 +12,14 @@ import com.facebook.react.bridge.Promise
|
|
|
12
12
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
13
13
|
import com.facebook.react.bridge.ReadableMap
|
|
14
14
|
import com.facebook.react.bridge.WritableMap
|
|
15
|
-
import com.facebook.react.bridge.WritableNativeMap
|
|
16
15
|
import com.reactnativestripesdk.ReactNativeCustomerAdapter
|
|
17
16
|
import com.reactnativestripesdk.ReactNativeCustomerSessionProvider
|
|
17
|
+
import com.reactnativestripesdk.buildBillingDetails
|
|
18
|
+
import com.reactnativestripesdk.buildBillingDetailsCollectionConfiguration
|
|
18
19
|
import com.reactnativestripesdk.buildPaymentSheetAppearance
|
|
19
20
|
import com.reactnativestripesdk.getBase64FromBitmap
|
|
20
21
|
import com.reactnativestripesdk.getBitmapFromDrawable
|
|
21
|
-
import com.reactnativestripesdk.getIntegerArrayList
|
|
22
|
-
import com.reactnativestripesdk.getStringArrayList
|
|
23
|
-
import com.reactnativestripesdk.mapToAddressCollectionMode
|
|
24
22
|
import com.reactnativestripesdk.mapToCardBrandAcceptance
|
|
25
|
-
import com.reactnativestripesdk.mapToCollectionMode
|
|
26
23
|
import com.reactnativestripesdk.utils.CreateTokenErrorType
|
|
27
24
|
import com.reactnativestripesdk.utils.ErrorType
|
|
28
25
|
import com.reactnativestripesdk.utils.KeepJsAwakeTask
|
|
@@ -30,6 +27,8 @@ import com.reactnativestripesdk.utils.PaymentSheetAppearanceException
|
|
|
30
27
|
import com.reactnativestripesdk.utils.StripeUIManager
|
|
31
28
|
import com.reactnativestripesdk.utils.createError
|
|
32
29
|
import com.reactnativestripesdk.utils.getBooleanOr
|
|
30
|
+
import com.reactnativestripesdk.utils.getIntegerList
|
|
31
|
+
import com.reactnativestripesdk.utils.getStringList
|
|
33
32
|
import com.reactnativestripesdk.utils.mapFromPaymentMethod
|
|
34
33
|
import com.reactnativestripesdk.utils.mapToPreferredNetworks
|
|
35
34
|
import com.stripe.android.ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi
|
|
@@ -66,7 +65,7 @@ class CustomerSheetManager(
|
|
|
66
65
|
val billingConfigParams = arguments.getMap("billingDetailsCollectionConfiguration")
|
|
67
66
|
val allowsRemovalOfLastSavedPaymentMethod =
|
|
68
67
|
arguments.getBooleanOr("allowsRemovalOfLastSavedPaymentMethod", true)
|
|
69
|
-
val paymentMethodOrder = arguments.
|
|
68
|
+
val paymentMethodOrder = arguments.getStringList("paymentMethodOrder")
|
|
70
69
|
|
|
71
70
|
val appearance =
|
|
72
71
|
try {
|
|
@@ -83,7 +82,7 @@ class CustomerSheetManager(
|
|
|
83
82
|
.googlePayEnabled(googlePayEnabled)
|
|
84
83
|
.headerTextForSelectionScreen(headerTextForSelectionScreen)
|
|
85
84
|
.preferredNetworks(
|
|
86
|
-
mapToPreferredNetworks(arguments.
|
|
85
|
+
mapToPreferredNetworks(arguments.getIntegerList("preferredNetworks")),
|
|
87
86
|
).allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod)
|
|
88
87
|
.cardBrandAcceptance(mapToCardBrandAcceptance(arguments))
|
|
89
88
|
|
|
@@ -126,7 +125,10 @@ class CustomerSheetManager(
|
|
|
126
125
|
val customerId = arguments.getString("customerId")
|
|
127
126
|
if (customerId == null) {
|
|
128
127
|
initPromise.resolve(
|
|
129
|
-
createError(
|
|
128
|
+
createError(
|
|
129
|
+
ErrorType.Failed.toString(),
|
|
130
|
+
"When using `customerEphemeralKeySecret` you must provide a value for `customerId`",
|
|
131
|
+
),
|
|
130
132
|
)
|
|
131
133
|
return
|
|
132
134
|
}
|
|
@@ -157,7 +159,7 @@ class CustomerSheetManager(
|
|
|
157
159
|
|
|
158
160
|
customerSheet?.configure(configuration.build())
|
|
159
161
|
|
|
160
|
-
initPromise.resolve(
|
|
162
|
+
initPromise.resolve(Arguments.createMap())
|
|
161
163
|
}
|
|
162
164
|
|
|
163
165
|
private fun handleResult(result: CustomerSheetResult) {
|
|
@@ -295,33 +297,11 @@ class CustomerSheetManager(
|
|
|
295
297
|
internal fun createMissingInitError(): WritableMap =
|
|
296
298
|
createError(ErrorType.Failed.toString(), "No customer sheet has been initialized yet.")
|
|
297
299
|
|
|
298
|
-
internal fun createDefaultBillingDetails(map: ReadableMap): PaymentSheet.BillingDetails
|
|
299
|
-
|
|
300
|
-
val address =
|
|
301
|
-
PaymentSheet.Address(
|
|
302
|
-
addressMap?.getString("city"),
|
|
303
|
-
addressMap?.getString("country"),
|
|
304
|
-
addressMap?.getString("line1"),
|
|
305
|
-
addressMap?.getString("line2"),
|
|
306
|
-
addressMap?.getString("postalCode"),
|
|
307
|
-
addressMap?.getString("state"),
|
|
308
|
-
)
|
|
309
|
-
return PaymentSheet.BillingDetails(
|
|
310
|
-
address,
|
|
311
|
-
map.getString("email"),
|
|
312
|
-
map.getString("name"),
|
|
313
|
-
map.getString("phone"),
|
|
314
|
-
)
|
|
315
|
-
}
|
|
300
|
+
internal fun createDefaultBillingDetails(map: ReadableMap): PaymentSheet.BillingDetails =
|
|
301
|
+
buildBillingDetails(map) ?: PaymentSheet.BillingDetails()
|
|
316
302
|
|
|
317
303
|
internal fun createBillingDetailsCollectionConfiguration(map: ReadableMap): PaymentSheet.BillingDetailsCollectionConfiguration =
|
|
318
|
-
|
|
319
|
-
name = mapToCollectionMode(map.getString("name")),
|
|
320
|
-
phone = mapToCollectionMode(map.getString("phone")),
|
|
321
|
-
email = mapToCollectionMode(map.getString("email")),
|
|
322
|
-
address = mapToAddressCollectionMode(map.getString("address")),
|
|
323
|
-
attachDefaultsToPaymentMethod = map.getBooleanOr("attachDefaultsToPaymentMethod", false),
|
|
324
|
-
)
|
|
304
|
+
buildBillingDetailsCollectionConfiguration(map)
|
|
325
305
|
|
|
326
306
|
internal fun createCustomerAdapter(
|
|
327
307
|
context: ReactApplicationContext,
|
|
@@ -404,7 +384,7 @@ class CustomerSheetManager(
|
|
|
404
384
|
val onBehalfOf = bundle.getString("onBehalfOf")
|
|
405
385
|
CustomerSheet.IntentConfiguration
|
|
406
386
|
.Builder()
|
|
407
|
-
.paymentMethodTypes(bundle.
|
|
387
|
+
.paymentMethodTypes(bundle.getStringList("paymentMethodTypes") ?: emptyList())
|
|
408
388
|
.apply {
|
|
409
389
|
if (onBehalfOf != null) {
|
|
410
390
|
this.onBehalfOf(onBehalfOf)
|
|
@@ -11,7 +11,8 @@ class ReactNativeCustomerSessionProvider(
|
|
|
11
11
|
private val stripeSdkModule = context.getNativeModule(StripeSdkModule::class.java)
|
|
12
12
|
|
|
13
13
|
internal var provideSetupIntentClientSecretCallback: CompletableDeferred<String>? = null
|
|
14
|
-
internal var providesCustomerSessionClientSecretCallback:
|
|
14
|
+
internal var providesCustomerSessionClientSecretCallback:
|
|
15
|
+
CompletableDeferred<CustomerSheet.CustomerSessionClientSecret>? = null
|
|
15
16
|
|
|
16
17
|
override suspend fun intentConfiguration(): Result<CustomerSheet.IntentConfiguration> = Result.success(intentConfiguration)
|
|
17
18
|
|
package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonManager.kt
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
package com.reactnativestripesdk.pushprovisioning
|
|
2
2
|
|
|
3
|
-
import android.content.Context
|
|
4
|
-
import com.bumptech.glide.Glide
|
|
5
3
|
import com.facebook.react.bridge.Dynamic
|
|
6
4
|
import com.facebook.react.bridge.ReadableMap
|
|
7
5
|
import com.facebook.react.module.annotations.ReactModule
|
|
@@ -13,12 +11,10 @@ import com.facebook.react.viewmanagers.AddToWalletButtonManagerInterface
|
|
|
13
11
|
import com.reactnativestripesdk.utils.asMapOrNull
|
|
14
12
|
|
|
15
13
|
@ReactModule(name = AddToWalletButtonManager.REACT_CLASS)
|
|
16
|
-
class AddToWalletButtonManager
|
|
17
|
-
|
|
18
|
-
) : SimpleViewManager<AddToWalletButtonView>(),
|
|
14
|
+
class AddToWalletButtonManager :
|
|
15
|
+
SimpleViewManager<AddToWalletButtonView>(),
|
|
19
16
|
AddToWalletButtonManagerInterface<AddToWalletButtonView> {
|
|
20
17
|
private val delegate = AddToWalletButtonManagerDelegate(this)
|
|
21
|
-
private val requestManager = Glide.with(applicationContext)
|
|
22
18
|
|
|
23
19
|
override fun getName() = REACT_CLASS
|
|
24
20
|
|
|
@@ -34,8 +30,7 @@ class AddToWalletButtonManager(
|
|
|
34
30
|
view.onAfterUpdateTransaction()
|
|
35
31
|
}
|
|
36
32
|
|
|
37
|
-
override fun createViewInstance(reactContext: ThemedReactContext): AddToWalletButtonView =
|
|
38
|
-
AddToWalletButtonView(reactContext, requestManager)
|
|
33
|
+
override fun createViewInstance(reactContext: ThemedReactContext): AddToWalletButtonView = AddToWalletButtonView(reactContext)
|
|
39
34
|
|
|
40
35
|
override fun getExportedCustomDirectEventTypeConstants() =
|
|
41
36
|
mutableMapOf(
|
|
@@ -64,7 +59,7 @@ class AddToWalletButtonManager(
|
|
|
64
59
|
view: AddToWalletButtonView,
|
|
65
60
|
ephemeralKey: Dynamic,
|
|
66
61
|
) {
|
|
67
|
-
val map = ephemeralKey.
|
|
62
|
+
val map = ephemeralKey.asMapOrNull()
|
|
68
63
|
if (map == null) return
|
|
69
64
|
view.setEphemeralKey(map)
|
|
70
65
|
}
|
|
@@ -74,7 +69,7 @@ class AddToWalletButtonManager(
|
|
|
74
69
|
view: AddToWalletButtonView,
|
|
75
70
|
token: Dynamic,
|
|
76
71
|
) {
|
|
77
|
-
val map = token.
|
|
72
|
+
val map = token.asMapOrNull()
|
|
78
73
|
if (map == null) return
|
|
79
74
|
view.setToken(map)
|
|
80
75
|
}
|
package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt
CHANGED
|
@@ -2,37 +2,45 @@ package com.reactnativestripesdk.pushprovisioning
|
|
|
2
2
|
|
|
3
3
|
import android.annotation.SuppressLint
|
|
4
4
|
import android.content.res.ColorStateList
|
|
5
|
-
import android.graphics.Color
|
|
6
5
|
import android.graphics.drawable.Drawable
|
|
7
6
|
import android.graphics.drawable.RippleDrawable
|
|
8
7
|
import android.view.MotionEvent
|
|
9
8
|
import android.webkit.URLUtil
|
|
10
9
|
import androidx.appcompat.widget.AppCompatImageView
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import com.
|
|
15
|
-
import com.
|
|
16
|
-
import com.
|
|
10
|
+
import androidx.core.graphics.drawable.toDrawable
|
|
11
|
+
import androidx.core.graphics.toColorInt
|
|
12
|
+
import androidx.core.net.toUri
|
|
13
|
+
import com.facebook.common.executors.UiThreadImmediateExecutorService
|
|
14
|
+
import com.facebook.common.references.CloseableReference
|
|
15
|
+
import com.facebook.datasource.BaseDataSubscriber
|
|
16
|
+
import com.facebook.datasource.DataSource
|
|
17
|
+
import com.facebook.drawee.backends.pipeline.Fresco
|
|
18
|
+
import com.facebook.imagepipeline.image.CloseableBitmap
|
|
19
|
+
import com.facebook.imagepipeline.image.CloseableImage
|
|
20
|
+
import com.facebook.imagepipeline.request.ImageRequestBuilder
|
|
17
21
|
import com.facebook.react.bridge.ReadableMap
|
|
18
22
|
import com.facebook.react.bridge.WritableMap
|
|
19
23
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
20
24
|
import com.facebook.react.uimanager.UIManagerHelper
|
|
25
|
+
import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper
|
|
21
26
|
import com.reactnativestripesdk.utils.createError
|
|
22
27
|
|
|
23
28
|
@SuppressLint("ViewConstructor")
|
|
24
29
|
class AddToWalletButtonView(
|
|
25
30
|
private val context: ThemedReactContext,
|
|
26
|
-
private val requestManager: RequestManager,
|
|
27
31
|
) : AppCompatImageView(context) {
|
|
28
32
|
private var cardDetails: ReadableMap? = null
|
|
29
33
|
private var ephemeralKey: String? = null
|
|
30
34
|
private var sourceMap: ReadableMap? = null
|
|
31
35
|
private var token: ReadableMap? = null
|
|
32
36
|
|
|
33
|
-
private var loadedSource:
|
|
34
|
-
private var
|
|
35
|
-
|
|
37
|
+
private var loadedSource: String? = null
|
|
38
|
+
private var currentDataSource: DataSource<CloseableReference<CloseableImage>>? = null
|
|
39
|
+
|
|
40
|
+
init {
|
|
41
|
+
scaleType = ScaleType.CENTER_CROP
|
|
42
|
+
clipToOutline = true
|
|
43
|
+
}
|
|
36
44
|
|
|
37
45
|
override fun performClick(): Boolean {
|
|
38
46
|
super.performClick()
|
|
@@ -78,85 +86,90 @@ class AddToWalletButtonView(
|
|
|
78
86
|
}
|
|
79
87
|
|
|
80
88
|
fun onAfterUpdateTransaction() {
|
|
81
|
-
val
|
|
82
|
-
if (
|
|
83
|
-
|
|
89
|
+
val uri = sourceMap?.getString("uri")
|
|
90
|
+
if (uri == null) {
|
|
91
|
+
cancelCurrentRequest()
|
|
84
92
|
setImageDrawable(null)
|
|
85
93
|
loadedSource = null
|
|
86
|
-
|
|
87
|
-
loadedSource = sourceToLoad
|
|
88
|
-
val scale = sourceMap?.getDouble("scale") ?: 1.0
|
|
89
|
-
|
|
90
|
-
requestManager
|
|
91
|
-
.load(sourceToLoad)
|
|
92
|
-
.addListener(
|
|
93
|
-
object : RequestListener<Drawable> {
|
|
94
|
-
override fun onLoadFailed(
|
|
95
|
-
e: GlideException?,
|
|
96
|
-
model: Any?,
|
|
97
|
-
target: Target<Drawable>?,
|
|
98
|
-
isFirstResource: Boolean,
|
|
99
|
-
): Boolean {
|
|
100
|
-
dispatchEvent(
|
|
101
|
-
createError("Failed", "Failed to load the source from $sourceToLoad"),
|
|
102
|
-
)
|
|
103
|
-
return true
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
override fun onResourceReady(
|
|
107
|
-
resource: Drawable?,
|
|
108
|
-
model: Any?,
|
|
109
|
-
target: Target<Drawable>?,
|
|
110
|
-
dataSource: DataSource?,
|
|
111
|
-
isFirstResource: Boolean,
|
|
112
|
-
): Boolean {
|
|
113
|
-
setImageDrawable(
|
|
114
|
-
RippleDrawable(
|
|
115
|
-
ColorStateList.valueOf(Color.parseColor("#e0e0e0")),
|
|
116
|
-
resource,
|
|
117
|
-
null,
|
|
118
|
-
),
|
|
119
|
-
)
|
|
120
|
-
return true
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
).centerCrop()
|
|
124
|
-
.override((widthOverride * scale).toInt(), (heightOverride * scale).toInt())
|
|
125
|
-
.into(this)
|
|
94
|
+
return
|
|
126
95
|
}
|
|
127
|
-
}
|
|
128
96
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// Debug mode
|
|
133
|
-
|
|
97
|
+
if (uri != loadedSource) {
|
|
98
|
+
loadedSource = uri
|
|
99
|
+
if (URLUtil.isValidUrl(uri)) {
|
|
100
|
+
// Debug mode: Image.resolveAssetSource resolves to local http:// URL
|
|
101
|
+
loadImageFromUrl(uri)
|
|
134
102
|
} else {
|
|
135
|
-
// Release mode
|
|
136
|
-
|
|
103
|
+
// Release mode: Image.resolveAssetSource resolves to a drawable resource name
|
|
104
|
+
loadImageFromDrawable(uri)
|
|
137
105
|
}
|
|
138
106
|
}
|
|
139
|
-
return null
|
|
140
107
|
}
|
|
141
108
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
109
|
+
private fun loadImageFromUrl(url: String) {
|
|
110
|
+
cancelCurrentRequest()
|
|
111
|
+
|
|
112
|
+
val imageRequest =
|
|
113
|
+
ImageRequestBuilder
|
|
114
|
+
.newBuilderWithSource(url.toUri())
|
|
115
|
+
.build()
|
|
116
|
+
|
|
117
|
+
val dataSource = Fresco.getImagePipeline().fetchDecodedImage(imageRequest, context)
|
|
118
|
+
currentDataSource = dataSource
|
|
119
|
+
|
|
120
|
+
dataSource.subscribe(
|
|
121
|
+
object : BaseDataSubscriber<CloseableReference<CloseableImage>>() {
|
|
122
|
+
override fun onNewResultImpl(dataSource: DataSource<CloseableReference<CloseableImage>>) {
|
|
123
|
+
if (!dataSource.isFinished) return
|
|
124
|
+
val imageRef = dataSource.result ?: return
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
val image = imageRef.get()
|
|
128
|
+
if (image is CloseableBitmap) {
|
|
129
|
+
val drawable = image.underlyingBitmap.toDrawable(resources)
|
|
130
|
+
setImageWithRipple(drawable)
|
|
131
|
+
}
|
|
132
|
+
} finally {
|
|
133
|
+
CloseableReference.closeSafely(imageRef)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
override fun onFailureImpl(dataSource: DataSource<CloseableReference<CloseableImage>>) {
|
|
138
|
+
dispatchEvent(createError("Failed", "Failed to load the source from $url"))
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
UiThreadImmediateExecutorService.getInstance(),
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private fun loadImageFromDrawable(resourceName: String) {
|
|
146
|
+
// Instance is deprecated, but have to use until we drop support for RN 0.79
|
|
147
|
+
@Suppress("DEPRECATION")
|
|
148
|
+
val drawable = ResourceDrawableIdHelper.instance.getResourceDrawable(context, resourceName)
|
|
149
|
+
if (drawable != null) {
|
|
150
|
+
setImageWithRipple(drawable)
|
|
151
|
+
} else {
|
|
152
|
+
dispatchEvent(createError("Failed", "Failed to load drawable resource: $resourceName"))
|
|
155
153
|
}
|
|
156
154
|
}
|
|
157
155
|
|
|
156
|
+
private fun setImageWithRipple(drawable: Drawable) {
|
|
157
|
+
setImageDrawable(
|
|
158
|
+
RippleDrawable(
|
|
159
|
+
ColorStateList.valueOf("#e0e0e0".toColorInt()),
|
|
160
|
+
drawable,
|
|
161
|
+
null,
|
|
162
|
+
),
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private fun cancelCurrentRequest() {
|
|
167
|
+
currentDataSource?.close()
|
|
168
|
+
currentDataSource = null
|
|
169
|
+
}
|
|
170
|
+
|
|
158
171
|
fun onDropViewInstance() {
|
|
159
|
-
|
|
172
|
+
cancelCurrentRequest()
|
|
160
173
|
}
|
|
161
174
|
|
|
162
175
|
fun setSourceMap(map: ReadableMap?) {
|