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