@stripe/stripe-react-native 0.42.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/pre-commit +0 -3
- package/CHANGELOG.md +26 -0
- package/android/.gradle/8.11.1/checksums/checksums.lock +0 -0
- package/android/.gradle/8.11.1/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/8.11.1/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/8.11.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/8.11.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
- package/android/.project +0 -11
- package/android/.settings/org.eclipse.buildship.core.prefs +3 -3
- package/android/build.gradle +8 -1
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/android/gradle.properties +4 -1
- package/android/gradlew +249 -0
- package/android/gradlew.bat +92 -0
- package/android/spotless.gradle +19 -0
- package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormView.kt +30 -34
- package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormViewManager.kt +20 -10
- package/android/src/main/java/com/reactnativestripesdk/CardChangedEvent.kt +12 -13
- package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +242 -105
- package/android/src/main/java/com/reactnativestripesdk/CardFieldViewManager.kt +58 -20
- package/android/src/main/java/com/reactnativestripesdk/CardFocusEvent.kt +8 -11
- package/android/src/main/java/com/reactnativestripesdk/CardFormCompleteEvent.kt +10 -12
- package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +135 -87
- package/android/src/main/java/com/reactnativestripesdk/CardFormViewManager.kt +57 -22
- package/android/src/main/java/com/reactnativestripesdk/CollectBankAccountLauncherFragment.kt +33 -24
- package/android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetFragment.kt +107 -85
- package/android/src/main/java/com/reactnativestripesdk/FormCompleteEvent.kt +9 -11
- package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonManager.kt +16 -9
- package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonView.kt +36 -28
- package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherFragment.kt +67 -43
- package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherFragment.kt +21 -16
- package/android/src/main/java/com/reactnativestripesdk/GooglePayRequestHelper.kt +101 -56
- package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherFragment.kt +244 -166
- package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +137 -156
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +181 -57
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +422 -258
- package/android/src/main/java/com/reactnativestripesdk/StripeContainerManager.kt +11 -4
- package/android/src/main/java/com/reactnativestripesdk/StripeContainerView.kt +5 -1
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +656 -299
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +12 -14
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherFragment.kt +42 -37
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetEvent.kt +12 -11
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +29 -29
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetViewManager.kt +50 -18
- package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetFragment.kt +227 -147
- package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerAdapter.kt +15 -18
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonManager.kt +33 -15
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt +63 -37
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletCompleteEvent.kt +9 -13
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/EphemeralKeyProvider.kt +15 -17
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/PushProvisioningProxy.kt +76 -60
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/TapAndPayProxy.kt +71 -47
- package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +117 -51
- package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +4 -3
- package/android/src/main/java/com/reactnativestripesdk/utils/KeepJsAwakeTask.kt +39 -0
- package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +295 -258
- package/android/src/main/java/com/reactnativestripesdk/utils/PostalCodeUtilities.kt +2 -11
- package/ios/CustomerSheet/CustomerSheetUtils.swift +13 -7
- package/ios/FinancialConnections.swift +6 -2
- package/ios/StripeSdk+CustomerSheet.swift +3 -1
- package/ios/StripeSdk+PaymentSheet.swift +86 -21
- package/ios/StripeSdk.m +2 -0
- package/ios/StripeSdk.swift +72 -11
- package/lib/commonjs/NativeStripeSdk.js +1 -1
- package/lib/commonjs/NativeStripeSdk.js.map +1 -1
- package/lib/commonjs/components/AddToWalletButton.js +1 -1
- package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
- package/lib/commonjs/components/AddressSheet.js +1 -1
- package/lib/commonjs/components/AddressSheet.js.map +1 -1
- package/lib/commonjs/components/ApplePayButtonNative.js +1 -1
- package/lib/commonjs/components/ApplePayButtonNative.js.map +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
- package/lib/commonjs/components/CardField.js +1 -1
- package/lib/commonjs/components/CardField.js.map +1 -1
- package/lib/commonjs/components/CardForm.js +1 -1
- package/lib/commonjs/components/CardForm.js.map +1 -1
- package/lib/commonjs/components/CustomerSheet.js +1 -1
- package/lib/commonjs/components/CustomerSheet.js.map +1 -1
- package/lib/commonjs/components/GooglePayButtonNative.js +1 -1
- package/lib/commonjs/components/GooglePayButtonNative.js.map +1 -1
- package/lib/commonjs/components/PlatformPayButton.js +1 -1
- package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
- package/lib/commonjs/components/StripeContainer.js +1 -1
- package/lib/commonjs/components/StripeContainer.js.map +1 -1
- package/lib/commonjs/components/StripeProvider.js +1 -1
- package/lib/commonjs/components/StripeProvider.js.map +1 -1
- package/lib/commonjs/functions.js +1 -1
- package/lib/commonjs/functions.js.map +1 -1
- package/lib/commonjs/helpers.js +1 -1
- package/lib/commonjs/helpers.js.map +1 -1
- package/lib/commonjs/hooks/useConfirmPayment.js.map +1 -1
- package/lib/commonjs/hooks/useConfirmSetupIntent.js.map +1 -1
- package/lib/commonjs/hooks/useFinancialConnectionsSheet.js.map +1 -1
- package/lib/commonjs/hooks/usePaymentSheet.js.map +1 -1
- package/lib/commonjs/hooks/usePlatformPay.js.map +1 -1
- package/lib/commonjs/hooks/useStripe.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/plugin/withStripe.js +1 -1
- package/lib/commonjs/plugin/withStripe.js.map +1 -1
- package/lib/commonjs/types/ApplePay.js.map +1 -1
- package/lib/commonjs/types/Common.js +1 -1
- package/lib/commonjs/types/Common.js.map +1 -1
- package/lib/commonjs/types/CustomerSheet.js.map +1 -1
- package/lib/commonjs/types/Errors.js +1 -1
- package/lib/commonjs/types/Errors.js.map +1 -1
- package/lib/commonjs/types/FinancialConnections.js +1 -1
- package/lib/commonjs/types/FinancialConnections.js.map +1 -1
- package/lib/commonjs/types/NextAction.js.map +1 -1
- package/lib/commonjs/types/PaymentIntent.js +1 -1
- package/lib/commonjs/types/PaymentIntent.js.map +1 -1
- package/lib/commonjs/types/PaymentMethod.js.map +1 -1
- package/lib/commonjs/types/PaymentSheet.js +1 -1
- package/lib/commonjs/types/PaymentSheet.js.map +1 -1
- package/lib/commonjs/types/PlatformPay.js +1 -1
- package/lib/commonjs/types/PlatformPay.js.map +1 -1
- package/lib/commonjs/types/PushProvisioning.js +1 -1
- package/lib/commonjs/types/PushProvisioning.js.map +1 -1
- package/lib/commonjs/types/SetupIntent.js +1 -1
- package/lib/commonjs/types/SetupIntent.js.map +1 -1
- package/lib/commonjs/types/ThreeDSecure.js +1 -1
- package/lib/commonjs/types/ThreeDSecure.js.map +1 -1
- package/lib/commonjs/types/Token.js.map +1 -1
- package/lib/commonjs/types/components/ApplePayButtonComponent.js.map +1 -1
- package/lib/commonjs/types/components/AuBECSDebitFormComponent.js.map +1 -1
- package/lib/commonjs/types/components/CardFieldInput.js +1 -1
- package/lib/commonjs/types/components/CardFieldInput.js.map +1 -1
- package/lib/commonjs/types/components/CardFormView.js.map +1 -1
- package/lib/commonjs/types/components/GooglePayButtonComponent.js.map +1 -1
- package/lib/commonjs/types/index.js +1 -1
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/module/NativeStripeSdk.js +1 -1
- package/lib/module/NativeStripeSdk.js.map +1 -1
- package/lib/module/components/AddToWalletButton.js +1 -1
- package/lib/module/components/AddToWalletButton.js.map +1 -1
- package/lib/module/components/AddressSheet.js +1 -1
- package/lib/module/components/AddressSheet.js.map +1 -1
- package/lib/module/components/ApplePayButtonNative.js +1 -1
- package/lib/module/components/ApplePayButtonNative.js.map +1 -1
- package/lib/module/components/AuBECSDebitForm.js +1 -1
- package/lib/module/components/AuBECSDebitForm.js.map +1 -1
- package/lib/module/components/CardField.js +1 -1
- package/lib/module/components/CardField.js.map +1 -1
- package/lib/module/components/CardForm.js +1 -1
- package/lib/module/components/CardForm.js.map +1 -1
- package/lib/module/components/CustomerSheet.js +1 -1
- package/lib/module/components/CustomerSheet.js.map +1 -1
- package/lib/module/components/GooglePayButtonNative.js +1 -1
- package/lib/module/components/GooglePayButtonNative.js.map +1 -1
- package/lib/module/components/PlatformPayButton.js +1 -1
- package/lib/module/components/PlatformPayButton.js.map +1 -1
- package/lib/module/components/StripeContainer.js +1 -1
- package/lib/module/components/StripeContainer.js.map +1 -1
- package/lib/module/components/StripeProvider.js +1 -1
- package/lib/module/components/StripeProvider.js.map +1 -1
- package/lib/module/functions.js +1 -1
- package/lib/module/functions.js.map +1 -1
- package/lib/module/helpers.js +1 -1
- package/lib/module/helpers.js.map +1 -1
- package/lib/module/hooks/useConfirmPayment.js.map +1 -1
- package/lib/module/hooks/useConfirmSetupIntent.js.map +1 -1
- package/lib/module/hooks/useFinancialConnectionsSheet.js.map +1 -1
- package/lib/module/hooks/usePaymentSheet.js.map +1 -1
- package/lib/module/hooks/usePlatformPay.js.map +1 -1
- package/lib/module/hooks/useStripe.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/module/plugin/withStripe.js +1 -1
- package/lib/module/plugin/withStripe.js.map +1 -1
- package/lib/module/types/ApplePay.js.map +1 -1
- package/lib/module/types/Common.js +1 -1
- package/lib/module/types/Common.js.map +1 -1
- package/lib/module/types/CustomerSheet.js.map +1 -1
- package/lib/module/types/Errors.js +1 -1
- package/lib/module/types/Errors.js.map +1 -1
- package/lib/module/types/FinancialConnections.js +1 -1
- package/lib/module/types/FinancialConnections.js.map +1 -1
- package/lib/module/types/NextAction.js.map +1 -1
- package/lib/module/types/PaymentIntent.js +1 -1
- package/lib/module/types/PaymentIntent.js.map +1 -1
- package/lib/module/types/PaymentMethod.js.map +1 -1
- package/lib/module/types/PaymentSheet.js +1 -1
- package/lib/module/types/PaymentSheet.js.map +1 -1
- package/lib/module/types/PlatformPay.js +1 -1
- package/lib/module/types/PlatformPay.js.map +1 -1
- package/lib/module/types/PushProvisioning.js +1 -1
- package/lib/module/types/PushProvisioning.js.map +1 -1
- package/lib/module/types/SetupIntent.js +1 -1
- package/lib/module/types/SetupIntent.js.map +1 -1
- package/lib/module/types/ThreeDSecure.js +1 -1
- package/lib/module/types/ThreeDSecure.js.map +1 -1
- package/lib/module/types/Token.js.map +1 -1
- package/lib/module/types/components/ApplePayButtonComponent.js.map +1 -1
- package/lib/module/types/components/AuBECSDebitFormComponent.js.map +1 -1
- package/lib/module/types/components/CardFieldInput.js +1 -1
- package/lib/module/types/components/CardFieldInput.js.map +1 -1
- package/lib/module/types/components/CardFormView.js.map +1 -1
- package/lib/module/types/components/GooglePayButtonComponent.js.map +1 -1
- package/lib/module/types/index.js +1 -1
- package/lib/module/types/index.js.map +1 -1
- package/lib/typescript/src/NativeStripeSdk.d.ts +4 -3
- package/lib/typescript/src/NativeStripeSdk.d.ts.map +1 -0
- package/lib/typescript/src/components/AddToWalletButton.d.ts +3 -1
- package/lib/typescript/src/components/AddToWalletButton.d.ts.map +1 -0
- package/lib/typescript/src/components/AddressSheet.d.ts +4 -2
- package/lib/typescript/src/components/AddressSheet.d.ts.map +1 -0
- package/lib/typescript/src/components/ApplePayButtonNative.d.ts +1 -0
- package/lib/typescript/src/components/ApplePayButtonNative.d.ts.map +1 -0
- package/lib/typescript/src/components/AuBECSDebitForm.d.ts +3 -1
- package/lib/typescript/src/components/AuBECSDebitForm.d.ts.map +1 -0
- package/lib/typescript/src/components/CardField.d.ts +1 -0
- package/lib/typescript/src/components/CardField.d.ts.map +1 -0
- package/lib/typescript/src/components/CardForm.d.ts +1 -0
- package/lib/typescript/src/components/CardForm.d.ts.map +1 -0
- package/lib/typescript/src/components/CustomerSheet.d.ts +2 -1
- package/lib/typescript/src/components/CustomerSheet.d.ts.map +1 -0
- package/lib/typescript/src/components/GooglePayButtonNative.d.ts +1 -0
- package/lib/typescript/src/components/GooglePayButtonNative.d.ts.map +1 -0
- package/lib/typescript/src/components/PlatformPayButton.d.ts +3 -1
- package/lib/typescript/src/components/PlatformPayButton.d.ts.map +1 -0
- package/lib/typescript/src/components/StripeContainer.d.ts +2 -1
- package/lib/typescript/src/components/StripeContainer.d.ts.map +1 -0
- package/lib/typescript/src/components/StripeProvider.d.ts +3 -2
- package/lib/typescript/src/components/StripeProvider.d.ts.map +1 -0
- package/lib/typescript/src/functions.d.ts +6 -5
- package/lib/typescript/src/functions.d.ts.map +1 -0
- package/lib/typescript/src/helpers.d.ts +1 -0
- package/lib/typescript/src/helpers.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useConfirmPayment.d.ts +2 -1
- package/lib/typescript/src/hooks/useConfirmPayment.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useConfirmSetupIntent.d.ts +1 -0
- package/lib/typescript/src/hooks/useConfirmSetupIntent.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useFinancialConnectionsSheet.d.ts +3 -2
- package/lib/typescript/src/hooks/useFinancialConnectionsSheet.d.ts.map +1 -0
- package/lib/typescript/src/hooks/usePaymentSheet.d.ts +2 -1
- package/lib/typescript/src/hooks/usePaymentSheet.d.ts.map +1 -0
- package/lib/typescript/src/hooks/usePlatformPay.d.ts +4 -3
- package/lib/typescript/src/hooks/usePlatformPay.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useStripe.d.ts +11 -8
- package/lib/typescript/src/hooks/useStripe.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/plugin/withStripe.d.ts +2 -1
- package/lib/typescript/src/plugin/withStripe.d.ts.map +1 -0
- package/lib/typescript/src/types/ApplePay.d.ts +6 -5
- package/lib/typescript/src/types/ApplePay.d.ts.map +1 -0
- package/lib/typescript/src/types/Common.d.ts +4 -1
- package/lib/typescript/src/types/Common.d.ts.map +1 -0
- package/lib/typescript/src/types/CustomerSheet.d.ts +16 -4
- package/lib/typescript/src/types/CustomerSheet.d.ts.map +1 -0
- package/lib/typescript/src/types/Errors.d.ts +2 -1
- package/lib/typescript/src/types/Errors.d.ts.map +1 -0
- package/lib/typescript/src/types/FinancialConnections.d.ts +21 -17
- package/lib/typescript/src/types/FinancialConnections.d.ts.map +1 -0
- package/lib/typescript/src/types/NextAction.d.ts +9 -8
- package/lib/typescript/src/types/NextAction.d.ts.map +1 -0
- package/lib/typescript/src/types/PaymentIntent.d.ts +16 -15
- package/lib/typescript/src/types/PaymentIntent.d.ts.map +1 -0
- package/lib/typescript/src/types/PaymentMethod.d.ts +21 -16
- package/lib/typescript/src/types/PaymentMethod.d.ts.map +1 -0
- package/lib/typescript/src/types/PaymentSheet.d.ts +91 -22
- package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -0
- package/lib/typescript/src/types/PlatformPay.d.ts +22 -21
- package/lib/typescript/src/types/PlatformPay.d.ts.map +1 -0
- package/lib/typescript/src/types/PushProvisioning.d.ts +5 -4
- package/lib/typescript/src/types/PushProvisioning.d.ts.map +1 -0
- package/lib/typescript/src/types/SetupIntent.d.ts +4 -3
- package/lib/typescript/src/types/SetupIntent.d.ts.map +1 -0
- package/lib/typescript/src/types/ThreeDSecure.d.ts +1 -0
- package/lib/typescript/src/types/ThreeDSecure.d.ts.map +1 -0
- package/lib/typescript/src/types/Token.d.ts +10 -9
- package/lib/typescript/src/types/Token.d.ts.map +1 -0
- package/lib/typescript/src/types/components/ApplePayButtonComponent.d.ts +3 -2
- package/lib/typescript/src/types/components/ApplePayButtonComponent.d.ts.map +1 -0
- package/lib/typescript/src/types/components/AuBECSDebitFormComponent.d.ts +1 -0
- package/lib/typescript/src/types/components/AuBECSDebitFormComponent.d.ts.map +1 -0
- package/lib/typescript/src/types/components/CardFieldInput.d.ts +8 -5
- package/lib/typescript/src/types/components/CardFieldInput.d.ts.map +1 -0
- package/lib/typescript/src/types/components/CardFormView.d.ts +9 -6
- package/lib/typescript/src/types/components/CardFormView.d.ts.map +1 -0
- package/lib/typescript/src/types/components/GooglePayButtonComponent.d.ts +1 -0
- package/lib/typescript/src/types/components/GooglePayButtonComponent.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +24 -23
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/package.json +32 -40
- package/src/NativeStripeSdk.tsx +4 -2
- package/src/components/CardField.tsx +1 -1
- package/src/components/CardForm.tsx +12 -9
- package/src/components/CustomerSheet.tsx +4 -6
- package/src/components/StripeProvider.tsx +17 -0
- package/src/functions.ts +13 -14
- package/src/helpers.ts +2 -1
- package/src/types/Common.ts +3 -0
- package/src/types/CustomerSheet.ts +11 -0
- package/src/types/FinancialConnections.ts +3 -0
- package/src/types/PaymentMethod.ts +5 -1
- package/src/types/PaymentSheet.ts +85 -4
- package/src/types/components/CardFieldInput.ts +8 -4
- package/src/types/components/CardFormView.ts +8 -4
- package/stripe-react-native.podspec +2 -1
- package/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.9/gc.properties +0 -0
- /package/android/.gradle/{8.9 → 8.11.1}/fileChanges/last-build.bin +0 -0
- /package/android/.gradle/{8.9/dependencies-accessors → 8.11.1}/gc.properties +0 -0
|
@@ -18,13 +18,31 @@ import android.widget.FrameLayout
|
|
|
18
18
|
import androidx.appcompat.content.res.AppCompatResources
|
|
19
19
|
import androidx.core.graphics.drawable.DrawableCompat
|
|
20
20
|
import androidx.fragment.app.Fragment
|
|
21
|
-
import com.facebook.react.bridge
|
|
21
|
+
import com.facebook.react.bridge.Arguments
|
|
22
|
+
import com.facebook.react.bridge.Promise
|
|
23
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
24
|
+
import com.facebook.react.bridge.ReadableMap
|
|
25
|
+
import com.facebook.react.bridge.WritableMap
|
|
26
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
22
27
|
import com.reactnativestripesdk.addresssheet.AddressSheetView
|
|
23
|
-
import com.reactnativestripesdk.utils
|
|
28
|
+
import com.reactnativestripesdk.utils.ErrorType
|
|
29
|
+
import com.reactnativestripesdk.utils.KeepJsAwakeTask
|
|
30
|
+
import com.reactnativestripesdk.utils.PaymentSheetAppearanceException
|
|
31
|
+
import com.reactnativestripesdk.utils.PaymentSheetErrorType
|
|
32
|
+
import com.reactnativestripesdk.utils.PaymentSheetException
|
|
24
33
|
import com.reactnativestripesdk.utils.createError
|
|
25
34
|
import com.reactnativestripesdk.utils.createResult
|
|
35
|
+
import com.reactnativestripesdk.utils.mapFromPaymentMethod
|
|
36
|
+
import com.reactnativestripesdk.utils.mapToPreferredNetworks
|
|
37
|
+
import com.reactnativestripesdk.utils.removeFragment
|
|
26
38
|
import com.stripe.android.ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi
|
|
27
|
-
import com.stripe.android.paymentsheet
|
|
39
|
+
import com.stripe.android.paymentsheet.CreateIntentCallback
|
|
40
|
+
import com.stripe.android.paymentsheet.CreateIntentResult
|
|
41
|
+
import com.stripe.android.paymentsheet.ExperimentalCustomerSessionApi
|
|
42
|
+
import com.stripe.android.paymentsheet.PaymentOptionCallback
|
|
43
|
+
import com.stripe.android.paymentsheet.PaymentSheet
|
|
44
|
+
import com.stripe.android.paymentsheet.PaymentSheetResult
|
|
45
|
+
import com.stripe.android.paymentsheet.PaymentSheetResultCallback
|
|
28
46
|
import kotlinx.coroutines.CompletableDeferred
|
|
29
47
|
import java.io.ByteArrayOutputStream
|
|
30
48
|
import kotlin.Exception
|
|
@@ -32,7 +50,7 @@ import kotlin.Exception
|
|
|
32
50
|
@OptIn(ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class)
|
|
33
51
|
class PaymentSheetFragment(
|
|
34
52
|
private val context: ReactApplicationContext,
|
|
35
|
-
private val initPromise: Promise
|
|
53
|
+
private val initPromise: Promise,
|
|
36
54
|
) : Fragment() {
|
|
37
55
|
private var paymentSheet: PaymentSheet? = null
|
|
38
56
|
private var flowController: PaymentSheet.FlowController? = null
|
|
@@ -44,263 +62,318 @@ class PaymentSheetFragment(
|
|
|
44
62
|
private var presentPromise: Promise? = null
|
|
45
63
|
private var paymentSheetTimedOut = false
|
|
46
64
|
internal var paymentSheetIntentCreationCallback = CompletableDeferred<ReadableMap>()
|
|
65
|
+
private var keepJsAwake: KeepJsAwakeTask? = null
|
|
47
66
|
|
|
48
67
|
override fun onCreateView(
|
|
49
68
|
inflater: LayoutInflater,
|
|
50
69
|
container: ViewGroup?,
|
|
51
|
-
savedInstanceState: Bundle
|
|
52
|
-
): View {
|
|
53
|
-
return FrameLayout(requireActivity()).also {
|
|
54
|
-
it.visibility = View.GONE
|
|
55
|
-
}
|
|
56
|
-
}
|
|
70
|
+
savedInstanceState: Bundle?,
|
|
71
|
+
): View = FrameLayout(requireActivity()).also { it.visibility = View.GONE }
|
|
57
72
|
|
|
58
|
-
|
|
59
|
-
|
|
73
|
+
override fun onViewCreated(
|
|
74
|
+
view: View,
|
|
75
|
+
savedInstanceState: Bundle?,
|
|
76
|
+
) {
|
|
60
77
|
super.onViewCreated(view, savedInstanceState)
|
|
61
78
|
val merchantDisplayName = arguments?.getString("merchantDisplayName").orEmpty()
|
|
62
79
|
if (merchantDisplayName.isEmpty()) {
|
|
63
|
-
initPromise.resolve(
|
|
80
|
+
initPromise.resolve(
|
|
81
|
+
createError(ErrorType.Failed.toString(), "merchantDisplayName cannot be empty or null."),
|
|
82
|
+
)
|
|
64
83
|
return
|
|
65
84
|
}
|
|
66
85
|
val primaryButtonLabel = arguments?.getString("primaryButtonLabel")
|
|
67
86
|
val googlePayConfig = buildGooglePayConfig(arguments?.getBundle("googlePay"))
|
|
87
|
+
val linkConfig = buildLinkConfig(arguments?.getBundle("link"))
|
|
68
88
|
val allowsDelayedPaymentMethods = arguments?.getBoolean("allowsDelayedPaymentMethods")
|
|
69
89
|
val billingDetailsBundle = arguments?.getBundle("defaultBillingDetails")
|
|
70
90
|
val billingConfigParams = arguments?.getBundle("billingDetailsCollectionConfiguration")
|
|
71
91
|
val paymentMethodOrder = arguments?.getStringArrayList("paymentMethodOrder")
|
|
72
|
-
val allowsRemovalOfLastSavedPaymentMethod =
|
|
92
|
+
val allowsRemovalOfLastSavedPaymentMethod =
|
|
93
|
+
arguments?.getBoolean("allowsRemovalOfLastSavedPaymentMethod", true) ?: true
|
|
73
94
|
paymentIntentClientSecret = arguments?.getString("paymentIntentClientSecret").orEmpty()
|
|
74
95
|
setupIntentClientSecret = arguments?.getString("setupIntentClientSecret").orEmpty()
|
|
75
|
-
intentConfiguration =
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
96
|
+
intentConfiguration =
|
|
97
|
+
try {
|
|
98
|
+
buildIntentConfiguration(arguments?.getBundle("intentConfiguration"))
|
|
99
|
+
} catch (error: PaymentSheetException) {
|
|
100
|
+
initPromise.resolve(createError(ErrorType.Failed.toString(), error))
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
val appearance =
|
|
104
|
+
try {
|
|
105
|
+
buildPaymentSheetAppearance(arguments?.getBundle("appearance"), context)
|
|
106
|
+
} catch (error: PaymentSheetAppearanceException) {
|
|
107
|
+
initPromise.resolve(createError(ErrorType.Failed.toString(), error))
|
|
108
|
+
return
|
|
109
|
+
}
|
|
87
110
|
|
|
88
|
-
val customerConfiguration =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
111
|
+
val customerConfiguration =
|
|
112
|
+
try {
|
|
113
|
+
buildCustomerConfiguration(arguments)
|
|
114
|
+
} catch (error: PaymentSheetException) {
|
|
115
|
+
initPromise.resolve(createError(ErrorType.Failed.toString(), error))
|
|
116
|
+
return
|
|
117
|
+
}
|
|
94
118
|
|
|
95
|
-
val shippingDetails =
|
|
96
|
-
|
|
97
|
-
|
|
119
|
+
val shippingDetails =
|
|
120
|
+
arguments?.getBundle("defaultShippingDetails")?.let {
|
|
121
|
+
AddressSheetView.buildAddressDetails(it)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
val paymentOptionCallback =
|
|
125
|
+
PaymentOptionCallback { paymentOption ->
|
|
126
|
+
val result =
|
|
127
|
+
paymentOption?.let {
|
|
128
|
+
val bitmap = getBitmapFromVectorDrawable(context, it.drawableResourceId)
|
|
129
|
+
val imageString = getBase64FromBitmap(bitmap)
|
|
130
|
+
val option: WritableMap = WritableNativeMap()
|
|
131
|
+
option.putString("label", it.label)
|
|
132
|
+
option.putString("image", imageString)
|
|
133
|
+
createResult("paymentOption", option)
|
|
134
|
+
}
|
|
135
|
+
?: run {
|
|
136
|
+
if (paymentSheetTimedOut) {
|
|
137
|
+
paymentSheetTimedOut = false
|
|
138
|
+
createError(PaymentSheetErrorType.Timeout.toString(), "The payment has timed out")
|
|
139
|
+
} else {
|
|
140
|
+
createError(
|
|
141
|
+
PaymentSheetErrorType.Canceled.toString(),
|
|
142
|
+
"The payment option selection flow has been canceled",
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
resolvePresentPromise(result)
|
|
147
|
+
}
|
|
98
148
|
|
|
99
|
-
val
|
|
100
|
-
|
|
101
|
-
val bitmap = getBitmapFromVectorDrawable(context, it.drawableResourceId)
|
|
102
|
-
val imageString = getBase64FromBitmap(bitmap)
|
|
103
|
-
val option: WritableMap = WritableNativeMap()
|
|
104
|
-
option.putString("label", it.label)
|
|
105
|
-
option.putString("image", imageString)
|
|
106
|
-
createResult("paymentOption", option)
|
|
107
|
-
} ?: run {
|
|
149
|
+
val paymentResultCallback =
|
|
150
|
+
PaymentSheetResultCallback { paymentResult ->
|
|
108
151
|
if (paymentSheetTimedOut) {
|
|
109
152
|
paymentSheetTimedOut = false
|
|
110
|
-
|
|
153
|
+
resolvePaymentResult(
|
|
154
|
+
createError(PaymentSheetErrorType.Timeout.toString(), "The payment has timed out"),
|
|
155
|
+
)
|
|
111
156
|
} else {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
paymentSheet = null
|
|
135
|
-
flowController = null
|
|
157
|
+
when (paymentResult) {
|
|
158
|
+
is PaymentSheetResult.Canceled -> {
|
|
159
|
+
resolvePaymentResult(
|
|
160
|
+
createError(
|
|
161
|
+
PaymentSheetErrorType.Canceled.toString(),
|
|
162
|
+
"The payment flow has been canceled",
|
|
163
|
+
),
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
is PaymentSheetResult.Failed -> {
|
|
167
|
+
resolvePaymentResult(
|
|
168
|
+
createError(PaymentSheetErrorType.Failed.toString(), paymentResult.error),
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
is PaymentSheetResult.Completed -> {
|
|
172
|
+
resolvePaymentResult(WritableNativeMap())
|
|
173
|
+
// Remove the fragment now, we can be sure it won't be needed again if an intent is
|
|
174
|
+
// successful
|
|
175
|
+
removeFragment(context)
|
|
176
|
+
paymentSheet = null
|
|
177
|
+
flowController = null
|
|
178
|
+
}
|
|
136
179
|
}
|
|
137
180
|
}
|
|
138
181
|
}
|
|
139
|
-
}
|
|
140
182
|
|
|
141
|
-
val createIntentCallback =
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
183
|
+
val createIntentCallback =
|
|
184
|
+
CreateIntentCallback { paymentMethod, shouldSavePaymentMethod ->
|
|
185
|
+
val stripeSdkModule: StripeSdkModule? = context.getNativeModule(StripeSdkModule::class.java)
|
|
186
|
+
if (stripeSdkModule == null || stripeSdkModule.eventListenerCount == 0) {
|
|
187
|
+
return@CreateIntentCallback CreateIntentResult.Failure(
|
|
188
|
+
cause =
|
|
189
|
+
Exception(
|
|
190
|
+
"Tried to call confirmHandler, but no callback was found. Please file an issue: https://github.com/stripe/stripe-react-native/issues",
|
|
191
|
+
),
|
|
192
|
+
displayMessage = "An unexpected error occurred",
|
|
147
193
|
)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
194
|
+
}
|
|
195
|
+
val params =
|
|
196
|
+
Arguments.createMap().apply {
|
|
197
|
+
putMap("paymentMethod", mapFromPaymentMethod(paymentMethod))
|
|
198
|
+
putBoolean("shouldSavePaymentMethod", shouldSavePaymentMethod)
|
|
199
|
+
}
|
|
153
200
|
|
|
154
|
-
|
|
201
|
+
stripeSdkModule.sendEvent(context, "onConfirmHandlerCallback", params)
|
|
155
202
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
203
|
+
val resultFromJavascript = paymentSheetIntentCreationCallback.await()
|
|
204
|
+
// reset the completable
|
|
205
|
+
paymentSheetIntentCreationCallback = CompletableDeferred<ReadableMap>()
|
|
159
206
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
207
|
+
return@CreateIntentCallback resultFromJavascript.getString("clientSecret")?.let {
|
|
208
|
+
CreateIntentResult.Success(clientSecret = it)
|
|
209
|
+
}
|
|
210
|
+
?: run {
|
|
211
|
+
val errorMap = resultFromJavascript.getMap("error")
|
|
212
|
+
CreateIntentResult.Failure(
|
|
213
|
+
cause = Exception(errorMap?.getString("message")),
|
|
214
|
+
displayMessage = errorMap?.getString("localizedMessage"),
|
|
215
|
+
)
|
|
216
|
+
}
|
|
168
217
|
}
|
|
169
|
-
}
|
|
170
218
|
|
|
171
|
-
val billingDetailsConfig =
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
219
|
+
val billingDetailsConfig =
|
|
220
|
+
PaymentSheet.BillingDetailsCollectionConfiguration(
|
|
221
|
+
name = mapToCollectionMode(billingConfigParams?.getString("name")),
|
|
222
|
+
phone = mapToCollectionMode(billingConfigParams?.getString("phone")),
|
|
223
|
+
email = mapToCollectionMode(billingConfigParams?.getString("email")),
|
|
224
|
+
address = mapToAddressCollectionMode(billingConfigParams?.getString("address")),
|
|
225
|
+
attachDefaultsToPaymentMethod =
|
|
226
|
+
billingConfigParams?.getBoolean("attachDefaultsToPaymentMethod") ?: false,
|
|
227
|
+
)
|
|
179
228
|
|
|
180
229
|
var defaultBillingDetails: PaymentSheet.BillingDetails? = null
|
|
181
230
|
if (billingDetailsBundle != null) {
|
|
182
231
|
val addressBundle = billingDetailsBundle.getBundle("address")
|
|
183
|
-
val address =
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
.customer(customerConfiguration)
|
|
200
|
-
.googlePay(googlePayConfig)
|
|
201
|
-
.appearance(appearance)
|
|
202
|
-
.shippingDetails(shippingDetails)
|
|
203
|
-
.billingDetailsCollectionConfiguration(billingDetailsConfig)
|
|
204
|
-
.preferredNetworks(mapToPreferredNetworks(arguments?.getIntegerArrayList("preferredNetworks")))
|
|
205
|
-
.allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod)
|
|
206
|
-
primaryButtonLabel?.let {
|
|
207
|
-
configurationBuilder.primaryButtonLabel(it)
|
|
208
|
-
}
|
|
209
|
-
paymentMethodOrder?.let {
|
|
210
|
-
configurationBuilder.paymentMethodOrder(it)
|
|
232
|
+
val address =
|
|
233
|
+
PaymentSheet.Address(
|
|
234
|
+
addressBundle?.getString("city"),
|
|
235
|
+
addressBundle?.getString("country"),
|
|
236
|
+
addressBundle?.getString("line1"),
|
|
237
|
+
addressBundle?.getString("line2"),
|
|
238
|
+
addressBundle?.getString("postalCode"),
|
|
239
|
+
addressBundle?.getString("state"),
|
|
240
|
+
)
|
|
241
|
+
defaultBillingDetails =
|
|
242
|
+
PaymentSheet.BillingDetails(
|
|
243
|
+
address,
|
|
244
|
+
billingDetailsBundle.getString("email"),
|
|
245
|
+
billingDetailsBundle.getString("name"),
|
|
246
|
+
billingDetailsBundle.getString("phone"),
|
|
247
|
+
)
|
|
211
248
|
}
|
|
249
|
+
val configurationBuilder =
|
|
250
|
+
PaymentSheet.Configuration
|
|
251
|
+
.Builder(merchantDisplayName)
|
|
252
|
+
.allowsDelayedPaymentMethods(allowsDelayedPaymentMethods ?: false)
|
|
253
|
+
.defaultBillingDetails(defaultBillingDetails)
|
|
254
|
+
.customer(customerConfiguration)
|
|
255
|
+
.googlePay(googlePayConfig)
|
|
256
|
+
.appearance(appearance)
|
|
257
|
+
.shippingDetails(shippingDetails)
|
|
258
|
+
.billingDetailsCollectionConfiguration(billingDetailsConfig)
|
|
259
|
+
.preferredNetworks(
|
|
260
|
+
mapToPreferredNetworks(arguments?.getIntegerArrayList("preferredNetworks")),
|
|
261
|
+
).allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod)
|
|
262
|
+
.cardBrandAcceptance(mapToCardBrandAcceptance(arguments))
|
|
263
|
+
|
|
264
|
+
primaryButtonLabel?.let { configurationBuilder.primaryButtonLabel(it) }
|
|
265
|
+
paymentMethodOrder?.let { configurationBuilder.paymentMethodOrder(it) }
|
|
212
266
|
|
|
213
267
|
configurationBuilder.paymentMethodLayout(
|
|
214
|
-
mapToPaymentMethodLayout(arguments?.getString("paymentMethodLayout"))
|
|
268
|
+
mapToPaymentMethodLayout(arguments?.getString("paymentMethodLayout")),
|
|
215
269
|
)
|
|
216
270
|
|
|
217
271
|
paymentSheetConfiguration = configurationBuilder.build()
|
|
218
272
|
|
|
219
273
|
if (arguments?.getBoolean("customFlow") == true) {
|
|
220
|
-
flowController =
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
274
|
+
flowController =
|
|
275
|
+
if (intentConfiguration != null) {
|
|
276
|
+
PaymentSheet.FlowController.create(
|
|
277
|
+
this,
|
|
278
|
+
paymentOptionCallback = paymentOptionCallback,
|
|
279
|
+
createIntentCallback = createIntentCallback,
|
|
280
|
+
paymentResultCallback = paymentResultCallback,
|
|
281
|
+
)
|
|
282
|
+
} else {
|
|
283
|
+
PaymentSheet.FlowController.create(
|
|
284
|
+
this,
|
|
285
|
+
paymentOptionCallback = paymentOptionCallback,
|
|
286
|
+
paymentResultCallback = paymentResultCallback,
|
|
287
|
+
)
|
|
288
|
+
}
|
|
234
289
|
configureFlowController()
|
|
235
290
|
} else {
|
|
236
|
-
paymentSheet =
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
this,
|
|
245
|
-
|
|
246
|
-
)
|
|
247
|
-
}
|
|
291
|
+
paymentSheet =
|
|
292
|
+
if (intentConfiguration != null) {
|
|
293
|
+
PaymentSheet(
|
|
294
|
+
this,
|
|
295
|
+
createIntentCallback = createIntentCallback,
|
|
296
|
+
paymentResultCallback = paymentResultCallback,
|
|
297
|
+
)
|
|
298
|
+
} else {
|
|
299
|
+
PaymentSheet(this, callback = paymentResultCallback)
|
|
300
|
+
}
|
|
248
301
|
initPromise.resolve(WritableNativeMap())
|
|
249
302
|
}
|
|
250
303
|
}
|
|
251
304
|
|
|
252
305
|
fun present(promise: Promise) {
|
|
253
|
-
|
|
254
|
-
|
|
306
|
+
keepJsAwake = KeepJsAwakeTask(context).apply { start() }
|
|
307
|
+
presentPromise = promise
|
|
308
|
+
if (paymentSheet != null) {
|
|
255
309
|
if (!paymentIntentClientSecret.isNullOrEmpty()) {
|
|
256
|
-
paymentSheet?.presentWithPaymentIntent(
|
|
310
|
+
paymentSheet?.presentWithPaymentIntent(
|
|
311
|
+
paymentIntentClientSecret!!,
|
|
312
|
+
paymentSheetConfiguration,
|
|
313
|
+
)
|
|
257
314
|
} else if (!setupIntentClientSecret.isNullOrEmpty()) {
|
|
258
315
|
paymentSheet?.presentWithSetupIntent(setupIntentClientSecret!!, paymentSheetConfiguration)
|
|
259
316
|
} else if (intentConfiguration != null) {
|
|
260
317
|
paymentSheet?.presentWithIntentConfiguration(
|
|
261
318
|
intentConfiguration = intentConfiguration!!,
|
|
262
|
-
configuration = paymentSheetConfiguration
|
|
319
|
+
configuration = paymentSheetConfiguration,
|
|
263
320
|
)
|
|
264
321
|
}
|
|
265
|
-
} else if(flowController != null) {
|
|
322
|
+
} else if (flowController != null) {
|
|
266
323
|
flowController?.presentPaymentOptions()
|
|
267
324
|
} else {
|
|
268
325
|
promise.resolve(createMissingInitError())
|
|
269
326
|
}
|
|
270
327
|
}
|
|
271
328
|
|
|
272
|
-
fun presentWithTimeout(
|
|
329
|
+
fun presentWithTimeout(
|
|
330
|
+
timeout: Long,
|
|
331
|
+
promise: Promise,
|
|
332
|
+
) {
|
|
273
333
|
var paymentSheetActivity: Activity? = null
|
|
274
334
|
|
|
275
|
-
val activityLifecycleCallbacks =
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
335
|
+
val activityLifecycleCallbacks =
|
|
336
|
+
object : Application.ActivityLifecycleCallbacks {
|
|
337
|
+
override fun onActivityCreated(
|
|
338
|
+
activity: Activity,
|
|
339
|
+
savedInstanceState: Bundle?,
|
|
340
|
+
) {
|
|
341
|
+
paymentSheetActivity = activity
|
|
342
|
+
}
|
|
279
343
|
|
|
280
|
-
|
|
344
|
+
override fun onActivityStarted(activity: Activity) {}
|
|
281
345
|
|
|
282
|
-
|
|
346
|
+
override fun onActivityResumed(activity: Activity) {}
|
|
283
347
|
|
|
284
|
-
|
|
348
|
+
override fun onActivityPaused(activity: Activity) {}
|
|
285
349
|
|
|
286
|
-
|
|
350
|
+
override fun onActivityStopped(activity: Activity) {}
|
|
287
351
|
|
|
288
|
-
|
|
352
|
+
override fun onActivitySaveInstanceState(
|
|
353
|
+
activity: Activity,
|
|
354
|
+
outState: Bundle,
|
|
355
|
+
) {}
|
|
289
356
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
357
|
+
override fun onActivityDestroyed(activity: Activity) {
|
|
358
|
+
paymentSheetActivity = null
|
|
359
|
+
context.currentActivity?.application?.unregisterActivityLifecycleCallbacks(this)
|
|
360
|
+
}
|
|
293
361
|
}
|
|
294
|
-
}
|
|
295
362
|
|
|
296
|
-
Handler(Looper.getMainLooper())
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
363
|
+
Handler(Looper.getMainLooper())
|
|
364
|
+
.postDelayed(
|
|
365
|
+
{
|
|
366
|
+
paymentSheetActivity?.let {
|
|
367
|
+
it.finish()
|
|
368
|
+
paymentSheetTimedOut = true
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
timeout,
|
|
372
|
+
)
|
|
302
373
|
|
|
303
|
-
context.currentActivity
|
|
374
|
+
context.currentActivity
|
|
375
|
+
?.application
|
|
376
|
+
?.registerActivityLifecycleCallbacks(activityLifecycleCallbacks)
|
|
304
377
|
|
|
305
378
|
this.present(promise)
|
|
306
379
|
}
|
|
@@ -311,70 +384,81 @@ class PaymentSheetFragment(
|
|
|
311
384
|
}
|
|
312
385
|
|
|
313
386
|
private fun configureFlowController() {
|
|
314
|
-
val onFlowControllerConfigure =
|
|
315
|
-
|
|
316
|
-
val
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
387
|
+
val onFlowControllerConfigure =
|
|
388
|
+
PaymentSheet.FlowController.ConfigCallback { _, _ ->
|
|
389
|
+
val result =
|
|
390
|
+
flowController?.getPaymentOption()?.let {
|
|
391
|
+
val bitmap = getBitmapFromVectorDrawable(context, it.drawableResourceId)
|
|
392
|
+
val imageString = getBase64FromBitmap(bitmap)
|
|
393
|
+
val option: WritableMap = WritableNativeMap()
|
|
394
|
+
option.putString("label", it.label)
|
|
395
|
+
option.putString("image", imageString)
|
|
396
|
+
createResult("paymentOption", option)
|
|
397
|
+
} ?: run { WritableNativeMap() }
|
|
398
|
+
initPromise.resolve(result)
|
|
324
399
|
}
|
|
325
|
-
initPromise.resolve(result)
|
|
326
|
-
}
|
|
327
400
|
|
|
328
401
|
if (!paymentIntentClientSecret.isNullOrEmpty()) {
|
|
329
402
|
flowController?.configureWithPaymentIntent(
|
|
330
403
|
paymentIntentClientSecret = paymentIntentClientSecret!!,
|
|
331
404
|
configuration = paymentSheetConfiguration,
|
|
332
|
-
callback = onFlowControllerConfigure
|
|
405
|
+
callback = onFlowControllerConfigure,
|
|
333
406
|
)
|
|
334
407
|
} else if (!setupIntentClientSecret.isNullOrEmpty()) {
|
|
335
408
|
flowController?.configureWithSetupIntent(
|
|
336
409
|
setupIntentClientSecret = setupIntentClientSecret!!,
|
|
337
410
|
configuration = paymentSheetConfiguration,
|
|
338
|
-
callback = onFlowControllerConfigure
|
|
411
|
+
callback = onFlowControllerConfigure,
|
|
339
412
|
)
|
|
340
413
|
} else if (intentConfiguration != null) {
|
|
341
414
|
flowController?.configureWithIntentConfiguration(
|
|
342
415
|
intentConfiguration = intentConfiguration!!,
|
|
343
416
|
configuration = paymentSheetConfiguration,
|
|
344
|
-
callback = onFlowControllerConfigure
|
|
417
|
+
callback = onFlowControllerConfigure,
|
|
345
418
|
)
|
|
346
419
|
} else {
|
|
347
|
-
initPromise.resolve(
|
|
420
|
+
initPromise.resolve(
|
|
421
|
+
createError(
|
|
422
|
+
ErrorType.Failed.toString(),
|
|
423
|
+
"One of `paymentIntentClientSecret`, `setupIntentClientSecret`, or `intentConfiguration` is required",
|
|
424
|
+
),
|
|
425
|
+
)
|
|
348
426
|
return
|
|
349
427
|
}
|
|
350
428
|
}
|
|
351
429
|
|
|
430
|
+
private fun resolvePresentPromise(value: Any?) {
|
|
431
|
+
keepJsAwake?.stop()
|
|
432
|
+
presentPromise?.resolve(value)
|
|
433
|
+
}
|
|
434
|
+
|
|
352
435
|
private fun resolvePaymentResult(map: WritableMap) {
|
|
353
436
|
confirmPromise?.let {
|
|
354
437
|
it.resolve(map)
|
|
355
438
|
confirmPromise = null
|
|
356
|
-
} ?: run {
|
|
357
|
-
presentPromise?.resolve(map)
|
|
358
|
-
}
|
|
439
|
+
} ?: run { resolvePresentPromise(map) }
|
|
359
440
|
}
|
|
360
441
|
|
|
361
442
|
companion object {
|
|
362
443
|
internal const val TAG = "payment_sheet_launch_fragment"
|
|
363
444
|
|
|
364
|
-
private val mapIntToButtonType =
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
445
|
+
private val mapIntToButtonType =
|
|
446
|
+
mapOf(
|
|
447
|
+
1 to PaymentSheet.GooglePayConfiguration.ButtonType.Buy,
|
|
448
|
+
6 to PaymentSheet.GooglePayConfiguration.ButtonType.Book,
|
|
449
|
+
5 to PaymentSheet.GooglePayConfiguration.ButtonType.Checkout,
|
|
450
|
+
4 to PaymentSheet.GooglePayConfiguration.ButtonType.Donate,
|
|
451
|
+
11 to PaymentSheet.GooglePayConfiguration.ButtonType.Order,
|
|
452
|
+
1000 to PaymentSheet.GooglePayConfiguration.ButtonType.Pay,
|
|
453
|
+
7 to PaymentSheet.GooglePayConfiguration.ButtonType.Subscribe,
|
|
454
|
+
1001 to PaymentSheet.GooglePayConfiguration.ButtonType.Plain,
|
|
455
|
+
)
|
|
374
456
|
|
|
375
|
-
internal fun createMissingInitError(): WritableMap
|
|
376
|
-
|
|
377
|
-
|
|
457
|
+
internal fun createMissingInitError(): WritableMap =
|
|
458
|
+
createError(
|
|
459
|
+
PaymentSheetErrorType.Failed.toString(),
|
|
460
|
+
"No payment sheet has been initialized yet. You must call `initPaymentSheet` before `presentPaymentSheet`.",
|
|
461
|
+
)
|
|
378
462
|
|
|
379
463
|
internal fun buildGooglePayConfig(params: Bundle?): PaymentSheet.GooglePayConfiguration? {
|
|
380
464
|
if (params == null) {
|
|
@@ -386,36 +470,69 @@ class PaymentSheetFragment(
|
|
|
386
470
|
val testEnv = params.getBoolean("testEnv")
|
|
387
471
|
val amount = params.getString("amount")?.toLongOrNull()
|
|
388
472
|
val label = params.getString("label")
|
|
389
|
-
val buttonType =
|
|
390
|
-
|
|
473
|
+
val buttonType =
|
|
474
|
+
mapIntToButtonType.get(params.getInt("buttonType"))
|
|
475
|
+
?: PaymentSheet.GooglePayConfiguration.ButtonType.Pay
|
|
391
476
|
|
|
392
477
|
return PaymentSheet.GooglePayConfiguration(
|
|
393
|
-
environment =
|
|
478
|
+
environment =
|
|
479
|
+
if (testEnv) {
|
|
480
|
+
PaymentSheet.GooglePayConfiguration.Environment.Test
|
|
481
|
+
} else {
|
|
482
|
+
PaymentSheet.GooglePayConfiguration.Environment.Production
|
|
483
|
+
},
|
|
394
484
|
countryCode = countryCode,
|
|
395
485
|
currencyCode = currencyCode,
|
|
396
486
|
amount = amount,
|
|
397
487
|
label = label,
|
|
398
|
-
buttonType = buttonType
|
|
488
|
+
buttonType = buttonType,
|
|
489
|
+
)
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
internal fun buildLinkConfig(params: Bundle?): PaymentSheet.LinkConfiguration {
|
|
493
|
+
if (params == null) {
|
|
494
|
+
return PaymentSheet.LinkConfiguration()
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
val display = mapStringToLinkDisplay(params.getString("display"))
|
|
498
|
+
|
|
499
|
+
return PaymentSheet.LinkConfiguration(
|
|
500
|
+
display = display,
|
|
399
501
|
)
|
|
400
502
|
}
|
|
401
503
|
|
|
504
|
+
private fun mapStringToLinkDisplay(value: String?): PaymentSheet.LinkConfiguration.Display =
|
|
505
|
+
when (value) {
|
|
506
|
+
"automatic" -> PaymentSheet.LinkConfiguration.Display.Automatic
|
|
507
|
+
"never" -> PaymentSheet.LinkConfiguration.Display.Never
|
|
508
|
+
else -> PaymentSheet.LinkConfiguration.Display.Automatic
|
|
509
|
+
}
|
|
510
|
+
|
|
402
511
|
@Throws(PaymentSheetException::class)
|
|
403
512
|
private fun buildIntentConfiguration(intentConfigurationParams: Bundle?): PaymentSheet.IntentConfiguration? {
|
|
404
513
|
if (intentConfigurationParams == null) {
|
|
405
514
|
return null
|
|
406
515
|
}
|
|
407
|
-
val modeParams =
|
|
408
|
-
|
|
516
|
+
val modeParams =
|
|
517
|
+
intentConfigurationParams.getBundle("mode")
|
|
518
|
+
?: throw PaymentSheetException(
|
|
519
|
+
"If `intentConfiguration` is provided, `intentConfiguration.mode` is required",
|
|
520
|
+
)
|
|
409
521
|
|
|
410
522
|
return PaymentSheet.IntentConfiguration(
|
|
411
523
|
mode = buildIntentConfigurationMode(modeParams),
|
|
412
|
-
paymentMethodTypes =
|
|
524
|
+
paymentMethodTypes =
|
|
525
|
+
intentConfigurationParams.getStringArrayList("paymentMethodTypes")?.toList()
|
|
526
|
+
?: emptyList(),
|
|
413
527
|
)
|
|
414
528
|
}
|
|
415
529
|
|
|
416
530
|
private fun buildIntentConfigurationMode(modeParams: Bundle): PaymentSheet.IntentConfiguration.Mode {
|
|
417
|
-
val currencyCode =
|
|
418
|
-
|
|
531
|
+
val currencyCode =
|
|
532
|
+
modeParams.getString("currencyCode")
|
|
533
|
+
?: throw PaymentSheetException(
|
|
534
|
+
"You must provide a value to intentConfiguration.mode.currencyCode",
|
|
535
|
+
)
|
|
419
536
|
|
|
420
537
|
return if (modeParams.containsKey("amount")) {
|
|
421
538
|
PaymentSheet.IntentConfiguration.Mode.Payment(
|
|
@@ -425,11 +542,14 @@ class PaymentSheetFragment(
|
|
|
425
542
|
captureMethod = mapToCaptureMethod(modeParams.getString("captureMethod")),
|
|
426
543
|
)
|
|
427
544
|
} else {
|
|
428
|
-
val setupFutureUsage =
|
|
429
|
-
|
|
545
|
+
val setupFutureUsage =
|
|
546
|
+
mapToSetupFutureUse(modeParams.getString("setupFutureUsage"))
|
|
547
|
+
?: throw PaymentSheetException(
|
|
548
|
+
"You must provide a value to intentConfiguration.mode.setupFutureUsage",
|
|
549
|
+
)
|
|
430
550
|
PaymentSheet.IntentConfiguration.Mode.Setup(
|
|
431
551
|
currency = currencyCode,
|
|
432
|
-
setupFutureUse = setupFutureUsage
|
|
552
|
+
setupFutureUse = setupFutureUsage,
|
|
433
553
|
)
|
|
434
554
|
}
|
|
435
555
|
}
|
|
@@ -440,25 +560,33 @@ class PaymentSheetFragment(
|
|
|
440
560
|
val customerId = bundle?.getString("customerId").orEmpty()
|
|
441
561
|
val customerEphemeralKeySecret = bundle?.getString("customerEphemeralKeySecret").orEmpty()
|
|
442
562
|
val customerSessionClientSecret = bundle?.getString("customerSessionClientSecret").orEmpty()
|
|
443
|
-
return if (customerSessionClientSecret.isNotEmpty() &&
|
|
444
|
-
|
|
563
|
+
return if (customerSessionClientSecret.isNotEmpty() &&
|
|
564
|
+
customerEphemeralKeySecret.isNotEmpty()
|
|
565
|
+
) {
|
|
566
|
+
throw PaymentSheetException(
|
|
567
|
+
"`customerEphemeralKeySecret` and `customerSessionClientSecret` cannot both be set",
|
|
568
|
+
)
|
|
445
569
|
} else if (customerId.isNotEmpty() && customerSessionClientSecret.isNotEmpty()) {
|
|
446
570
|
PaymentSheet.CustomerConfiguration.createWithCustomerSession(
|
|
447
571
|
id = customerId,
|
|
448
|
-
clientSecret = customerSessionClientSecret
|
|
572
|
+
clientSecret = customerSessionClientSecret,
|
|
449
573
|
)
|
|
450
|
-
}
|
|
451
|
-
else if (customerId.isNotEmpty() && customerEphemeralKeySecret.isNotEmpty()) {
|
|
574
|
+
} else if (customerId.isNotEmpty() && customerEphemeralKeySecret.isNotEmpty()) {
|
|
452
575
|
PaymentSheet.CustomerConfiguration(
|
|
453
576
|
id = customerId,
|
|
454
|
-
ephemeralKeySecret = customerEphemeralKeySecret
|
|
577
|
+
ephemeralKeySecret = customerEphemeralKeySecret,
|
|
455
578
|
)
|
|
456
|
-
} else
|
|
579
|
+
} else {
|
|
580
|
+
null
|
|
581
|
+
}
|
|
457
582
|
}
|
|
458
583
|
}
|
|
459
584
|
}
|
|
460
585
|
|
|
461
|
-
fun getBitmapFromVectorDrawable(
|
|
586
|
+
fun getBitmapFromVectorDrawable(
|
|
587
|
+
context: Context?,
|
|
588
|
+
drawableId: Int,
|
|
589
|
+
): Bitmap? {
|
|
462
590
|
val drawable = AppCompatResources.getDrawable(context!!, drawableId) ?: return null
|
|
463
591
|
return getBitmapFromDrawable(drawable)
|
|
464
592
|
}
|
|
@@ -468,7 +596,12 @@ fun getBitmapFromDrawable(drawable: Drawable): Bitmap? {
|
|
|
468
596
|
if (drawableCompat.intrinsicWidth <= 0 || drawableCompat.intrinsicHeight <= 0) {
|
|
469
597
|
return null
|
|
470
598
|
}
|
|
471
|
-
val bitmap =
|
|
599
|
+
val bitmap =
|
|
600
|
+
Bitmap.createBitmap(
|
|
601
|
+
drawableCompat.intrinsicWidth,
|
|
602
|
+
drawableCompat.intrinsicHeight,
|
|
603
|
+
Bitmap.Config.ARGB_8888,
|
|
604
|
+
)
|
|
472
605
|
bitmap.eraseColor(Color.WHITE)
|
|
473
606
|
val canvas = Canvas(bitmap)
|
|
474
607
|
drawable.setBounds(0, 0, canvas.width, canvas.height)
|
|
@@ -486,45 +619,76 @@ fun getBase64FromBitmap(bitmap: Bitmap?): String? {
|
|
|
486
619
|
return Base64.encodeToString(imageBytes, Base64.DEFAULT)
|
|
487
620
|
}
|
|
488
621
|
|
|
489
|
-
fun mapToCollectionMode(str: String?): PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode
|
|
490
|
-
|
|
622
|
+
fun mapToCollectionMode(str: String?): PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode =
|
|
623
|
+
when (str) {
|
|
491
624
|
"automatic" -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic
|
|
492
625
|
"never" -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Never
|
|
493
626
|
"always" -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
|
|
494
627
|
else -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic
|
|
495
628
|
}
|
|
496
|
-
}
|
|
497
629
|
|
|
498
|
-
fun mapToPaymentMethodLayout(str: String?): PaymentSheet.PaymentMethodLayout
|
|
499
|
-
|
|
630
|
+
fun mapToPaymentMethodLayout(str: String?): PaymentSheet.PaymentMethodLayout =
|
|
631
|
+
when (str) {
|
|
500
632
|
"Horizontal" -> PaymentSheet.PaymentMethodLayout.Horizontal
|
|
501
633
|
"Vertical" -> PaymentSheet.PaymentMethodLayout.Vertical
|
|
502
634
|
else -> PaymentSheet.PaymentMethodLayout.Automatic
|
|
503
635
|
}
|
|
504
|
-
}
|
|
505
636
|
|
|
506
|
-
fun mapToAddressCollectionMode(str: String?): PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode
|
|
507
|
-
|
|
508
|
-
"automatic" ->
|
|
637
|
+
fun mapToAddressCollectionMode(str: String?): PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode =
|
|
638
|
+
when (str) {
|
|
639
|
+
"automatic" ->
|
|
640
|
+
PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic
|
|
509
641
|
"never" -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Never
|
|
510
642
|
"full" -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Full
|
|
511
643
|
else -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic
|
|
512
644
|
}
|
|
513
|
-
}
|
|
514
645
|
|
|
515
|
-
fun mapToSetupFutureUse(type: String?): PaymentSheet.IntentConfiguration.SetupFutureUse?
|
|
516
|
-
|
|
517
|
-
"OffSession" ->
|
|
518
|
-
"OnSession" ->
|
|
519
|
-
else ->
|
|
646
|
+
fun mapToSetupFutureUse(type: String?): PaymentSheet.IntentConfiguration.SetupFutureUse? =
|
|
647
|
+
when (type) {
|
|
648
|
+
"OffSession" -> PaymentSheet.IntentConfiguration.SetupFutureUse.OffSession
|
|
649
|
+
"OnSession" -> PaymentSheet.IntentConfiguration.SetupFutureUse.OnSession
|
|
650
|
+
else -> null
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
fun mapToCaptureMethod(type: String?): PaymentSheet.IntentConfiguration.CaptureMethod =
|
|
654
|
+
when (type) {
|
|
655
|
+
"Automatic" -> PaymentSheet.IntentConfiguration.CaptureMethod.Automatic
|
|
656
|
+
"Manual" -> PaymentSheet.IntentConfiguration.CaptureMethod.Manual
|
|
657
|
+
"AutomaticAsync" -> PaymentSheet.IntentConfiguration.CaptureMethod.AutomaticAsync
|
|
658
|
+
else -> PaymentSheet.IntentConfiguration.CaptureMethod.Automatic
|
|
520
659
|
}
|
|
521
|
-
}
|
|
522
660
|
|
|
523
|
-
fun
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
661
|
+
fun mapToCardBrandAcceptance(params: Bundle?): PaymentSheet.CardBrandAcceptance {
|
|
662
|
+
val cardBrandAcceptanceParams = params?.getBundle("cardBrandAcceptance") ?: return PaymentSheet.CardBrandAcceptance.all()
|
|
663
|
+
val filter = cardBrandAcceptanceParams.getString("filter") ?: return PaymentSheet.CardBrandAcceptance.all()
|
|
664
|
+
|
|
665
|
+
return when (filter) {
|
|
666
|
+
"all" -> PaymentSheet.CardBrandAcceptance.all()
|
|
667
|
+
"allowed" -> {
|
|
668
|
+
val brands = cardBrandAcceptanceParams.getStringArrayList("brands") ?: return PaymentSheet.CardBrandAcceptance.all()
|
|
669
|
+
val brandCategories = brands.mapNotNull { mapToCardBrandCategory(it) }
|
|
670
|
+
if (brandCategories.isEmpty()) {
|
|
671
|
+
return PaymentSheet.CardBrandAcceptance.all()
|
|
672
|
+
}
|
|
673
|
+
PaymentSheet.CardBrandAcceptance.allowed(brandCategories)
|
|
674
|
+
}
|
|
675
|
+
"disallowed" -> {
|
|
676
|
+
val brands = cardBrandAcceptanceParams.getStringArrayList("brands") ?: return PaymentSheet.CardBrandAcceptance.all()
|
|
677
|
+
val brandCategories = brands.mapNotNull { mapToCardBrandCategory(it) }
|
|
678
|
+
if (brandCategories.isEmpty()) {
|
|
679
|
+
return PaymentSheet.CardBrandAcceptance.all()
|
|
680
|
+
}
|
|
681
|
+
PaymentSheet.CardBrandAcceptance.disallowed(brandCategories)
|
|
682
|
+
}
|
|
683
|
+
else -> PaymentSheet.CardBrandAcceptance.all()
|
|
529
684
|
}
|
|
530
685
|
}
|
|
686
|
+
|
|
687
|
+
fun mapToCardBrandCategory(brand: String): PaymentSheet.CardBrandAcceptance.BrandCategory? =
|
|
688
|
+
when (brand) {
|
|
689
|
+
"visa" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Visa
|
|
690
|
+
"mastercard" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Mastercard
|
|
691
|
+
"amex" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Amex
|
|
692
|
+
"discover" -> PaymentSheet.CardBrandAcceptance.BrandCategory.Discover
|
|
693
|
+
else -> null
|
|
694
|
+
}
|