@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
|
@@ -2,20 +2,63 @@ package com.reactnativestripesdk
|
|
|
2
2
|
|
|
3
3
|
import android.app.Activity
|
|
4
4
|
import android.content.Intent
|
|
5
|
-
import android.os.Parcelable
|
|
6
5
|
import android.util.Log
|
|
7
6
|
import androidx.fragment.app.FragmentActivity
|
|
8
|
-
import com.facebook.react.bridge
|
|
7
|
+
import com.facebook.react.bridge.BaseActivityEventListener
|
|
8
|
+
import com.facebook.react.bridge.Promise
|
|
9
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
10
|
+
import com.facebook.react.bridge.ReactContext
|
|
11
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
12
|
+
import com.facebook.react.bridge.ReactMethod
|
|
13
|
+
import com.facebook.react.bridge.ReadableArray
|
|
14
|
+
import com.facebook.react.bridge.ReadableMap
|
|
15
|
+
import com.facebook.react.bridge.WritableMap
|
|
16
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
9
17
|
import com.facebook.react.module.annotations.ReactModule
|
|
10
18
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
11
19
|
import com.reactnativestripesdk.addresssheet.AddressLauncherFragment
|
|
12
20
|
import com.reactnativestripesdk.pushprovisioning.PushProvisioningProxy
|
|
13
|
-
import com.reactnativestripesdk.utils
|
|
14
|
-
import com.
|
|
21
|
+
import com.reactnativestripesdk.utils.ConfirmPaymentErrorType
|
|
22
|
+
import com.reactnativestripesdk.utils.CreateTokenErrorType
|
|
23
|
+
import com.reactnativestripesdk.utils.ErrorType
|
|
24
|
+
import com.reactnativestripesdk.utils.GooglePayErrorType
|
|
25
|
+
import com.reactnativestripesdk.utils.createCanAddCardResult
|
|
26
|
+
import com.reactnativestripesdk.utils.createError
|
|
27
|
+
import com.reactnativestripesdk.utils.createMissingActivityError
|
|
28
|
+
import com.reactnativestripesdk.utils.createMissingInitError
|
|
29
|
+
import com.reactnativestripesdk.utils.createResult
|
|
30
|
+
import com.reactnativestripesdk.utils.getBooleanOr
|
|
31
|
+
import com.reactnativestripesdk.utils.getBooleanOrFalse
|
|
32
|
+
import com.reactnativestripesdk.utils.getMapOrNull
|
|
33
|
+
import com.reactnativestripesdk.utils.getValOr
|
|
34
|
+
import com.reactnativestripesdk.utils.mapFromPaymentIntentResult
|
|
35
|
+
import com.reactnativestripesdk.utils.mapFromPaymentMethod
|
|
36
|
+
import com.reactnativestripesdk.utils.mapFromSetupIntentResult
|
|
37
|
+
import com.reactnativestripesdk.utils.mapFromToken
|
|
38
|
+
import com.reactnativestripesdk.utils.mapToAddress
|
|
39
|
+
import com.reactnativestripesdk.utils.mapToBankAccountType
|
|
40
|
+
import com.reactnativestripesdk.utils.mapToPaymentMethodType
|
|
41
|
+
import com.reactnativestripesdk.utils.mapToReturnURL
|
|
42
|
+
import com.reactnativestripesdk.utils.mapToShippingDetails
|
|
43
|
+
import com.reactnativestripesdk.utils.mapToUICustomization
|
|
44
|
+
import com.reactnativestripesdk.utils.removeFragment
|
|
45
|
+
import com.reactnativestripesdk.utils.toBundleObject
|
|
46
|
+
import com.stripe.android.ApiResultCallback
|
|
47
|
+
import com.stripe.android.GooglePayJsonFactory
|
|
48
|
+
import com.stripe.android.PaymentAuthConfig
|
|
49
|
+
import com.stripe.android.PaymentConfiguration
|
|
50
|
+
import com.stripe.android.Stripe
|
|
15
51
|
import com.stripe.android.core.ApiVersion
|
|
16
52
|
import com.stripe.android.core.AppInfo
|
|
17
53
|
import com.stripe.android.googlepaylauncher.GooglePayLauncher
|
|
18
|
-
import com.stripe.android.model
|
|
54
|
+
import com.stripe.android.model.BankAccountTokenParams
|
|
55
|
+
import com.stripe.android.model.CardParams
|
|
56
|
+
import com.stripe.android.model.ConfirmPaymentIntentParams
|
|
57
|
+
import com.stripe.android.model.ConfirmSetupIntentParams
|
|
58
|
+
import com.stripe.android.model.PaymentIntent
|
|
59
|
+
import com.stripe.android.model.PaymentMethod
|
|
60
|
+
import com.stripe.android.model.SetupIntent
|
|
61
|
+
import com.stripe.android.model.Token
|
|
19
62
|
import com.stripe.android.payments.bankaccount.CollectBankAccountConfiguration
|
|
20
63
|
import com.stripe.android.paymentsheet.PaymentSheet
|
|
21
64
|
import kotlinx.coroutines.CoroutineScope
|
|
@@ -23,12 +66,11 @@ import kotlinx.coroutines.Dispatchers
|
|
|
23
66
|
import kotlinx.coroutines.launch
|
|
24
67
|
import org.json.JSONObject
|
|
25
68
|
|
|
26
|
-
|
|
27
69
|
@ReactModule(name = StripeSdkModule.NAME)
|
|
28
|
-
class StripeSdkModule(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
70
|
+
class StripeSdkModule(
|
|
71
|
+
reactContext: ReactApplicationContext,
|
|
72
|
+
) : ReactContextBaseJavaModule(reactContext) {
|
|
73
|
+
override fun getName(): String = NAME
|
|
32
74
|
|
|
33
75
|
var cardFieldView: CardFieldView? = null
|
|
34
76
|
var cardFormView: CardFormView? = null
|
|
@@ -38,8 +80,6 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
38
80
|
private var stripeAccountId: String? = null
|
|
39
81
|
private var urlScheme: String? = null
|
|
40
82
|
|
|
41
|
-
private var confirmPromise: Promise? = null
|
|
42
|
-
private var confirmPaymentClientSecret: String? = null
|
|
43
83
|
private var createPlatformPayPaymentMethodPromise: Promise? = null
|
|
44
84
|
private var platformPayUsesDeprecatedTokenFlow = false
|
|
45
85
|
|
|
@@ -54,40 +94,63 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
54
94
|
// If you create a new Fragment, you must put the tag here, otherwise result callbacks for that
|
|
55
95
|
// Fragment will not work on RN < 0.65
|
|
56
96
|
private val allStripeFragmentTags: List<String>
|
|
57
|
-
get() =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
97
|
+
get() =
|
|
98
|
+
listOf(
|
|
99
|
+
PaymentSheetFragment.TAG,
|
|
100
|
+
PaymentLauncherFragment.TAG,
|
|
101
|
+
CollectBankAccountLauncherFragment.TAG,
|
|
102
|
+
FinancialConnectionsSheetFragment.TAG,
|
|
103
|
+
AddressLauncherFragment.TAG,
|
|
104
|
+
GooglePayLauncherFragment.TAG,
|
|
105
|
+
CustomerSheetFragment.TAG,
|
|
106
|
+
)
|
|
66
107
|
|
|
67
|
-
private val mActivityEventListener =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
108
|
+
private val mActivityEventListener =
|
|
109
|
+
object : BaseActivityEventListener() {
|
|
110
|
+
override fun onActivityResult(
|
|
111
|
+
activity: Activity,
|
|
112
|
+
requestCode: Int,
|
|
113
|
+
resultCode: Int,
|
|
114
|
+
data: Intent?,
|
|
115
|
+
) {
|
|
116
|
+
if (::stripe.isInitialized) {
|
|
117
|
+
when (requestCode) {
|
|
118
|
+
GooglePayRequestHelper.LOAD_PAYMENT_DATA_REQUEST_CODE -> {
|
|
119
|
+
createPlatformPayPaymentMethodPromise?.let {
|
|
120
|
+
GooglePayRequestHelper.handleGooglePaymentMethodResult(
|
|
121
|
+
resultCode,
|
|
122
|
+
data,
|
|
123
|
+
stripe,
|
|
124
|
+
platformPayUsesDeprecatedTokenFlow,
|
|
125
|
+
it,
|
|
126
|
+
)
|
|
127
|
+
createPlatformPayPaymentMethodPromise = null
|
|
128
|
+
} ?: run {
|
|
129
|
+
Log.d(
|
|
130
|
+
"StripeReactNative",
|
|
131
|
+
"No promise was found, Google Pay result went unhandled,",
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
else -> {
|
|
137
|
+
dispatchActivityResultsToFragments(requestCode, resultCode, data)
|
|
138
|
+
}
|
|
79
139
|
}
|
|
80
140
|
}
|
|
81
141
|
}
|
|
82
142
|
}
|
|
83
|
-
}
|
|
84
143
|
|
|
85
144
|
init {
|
|
86
145
|
reactContext.addActivityEventListener(mActivityEventListener)
|
|
87
146
|
}
|
|
88
147
|
|
|
89
148
|
// Necessary on older versions of React Native (~0.65 and below)
|
|
90
|
-
private fun dispatchActivityResultsToFragments(
|
|
149
|
+
private fun dispatchActivityResultsToFragments(
|
|
150
|
+
requestCode: Int,
|
|
151
|
+
resultCode: Int,
|
|
152
|
+
data: Intent?,
|
|
153
|
+
) {
|
|
91
154
|
getCurrentActivityOrResolveWithError(null)?.supportFragmentManager?.let { fragmentManager ->
|
|
92
155
|
for (tag in allStripeFragmentTags) {
|
|
93
156
|
fragmentManager.findFragmentByTag(tag)?.let {
|
|
@@ -103,26 +166,30 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
103
166
|
val uiCustomization = mapToUICustomization(params)
|
|
104
167
|
|
|
105
168
|
PaymentAuthConfig.init(
|
|
106
|
-
PaymentAuthConfig
|
|
169
|
+
PaymentAuthConfig
|
|
170
|
+
.Builder()
|
|
107
171
|
.set3ds2Config(
|
|
108
172
|
stripe3dsConfigBuilder
|
|
109
173
|
.setUiCustomization(uiCustomization)
|
|
110
|
-
.build()
|
|
111
|
-
)
|
|
112
|
-
.build()
|
|
174
|
+
.build(),
|
|
175
|
+
).build(),
|
|
113
176
|
)
|
|
114
177
|
}
|
|
115
178
|
|
|
116
179
|
override fun getConstants(): MutableMap<String, Any> =
|
|
117
180
|
hashMapOf(
|
|
118
|
-
"API_VERSIONS" to
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
181
|
+
"API_VERSIONS" to
|
|
182
|
+
hashMapOf(
|
|
183
|
+
"CORE" to ApiVersion.API_VERSION_CODE,
|
|
184
|
+
"ISSUING" to PushProvisioningProxy.getApiVersion(),
|
|
185
|
+
),
|
|
122
186
|
)
|
|
123
187
|
|
|
124
188
|
@ReactMethod
|
|
125
|
-
fun initialise(
|
|
189
|
+
fun initialise(
|
|
190
|
+
params: ReadableMap,
|
|
191
|
+
promise: Promise,
|
|
192
|
+
) {
|
|
126
193
|
val publishableKey = getValOr(params, "publishableKey", null) as String
|
|
127
194
|
val appInfo = getMapOrNull(params, "appInfo") as ReadableMap
|
|
128
195
|
this.stripeAccountId = getValOr(params, "stripeAccountId", null)
|
|
@@ -150,15 +217,20 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
150
217
|
}
|
|
151
218
|
|
|
152
219
|
@ReactMethod
|
|
153
|
-
fun initPaymentSheet(
|
|
220
|
+
fun initPaymentSheet(
|
|
221
|
+
params: ReadableMap,
|
|
222
|
+
promise: Promise,
|
|
223
|
+
) {
|
|
154
224
|
getCurrentActivityOrResolveWithError(promise)?.let { activity ->
|
|
155
225
|
paymentSheetFragment?.removeFragment(reactApplicationContext)
|
|
156
|
-
paymentSheetFragment =
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
226
|
+
paymentSheetFragment =
|
|
227
|
+
PaymentSheetFragment(reactApplicationContext, promise).also {
|
|
228
|
+
val bundle = toBundleObject(params)
|
|
229
|
+
it.arguments = bundle
|
|
230
|
+
}
|
|
160
231
|
try {
|
|
161
|
-
activity.supportFragmentManager
|
|
232
|
+
activity.supportFragmentManager
|
|
233
|
+
.beginTransaction()
|
|
162
234
|
.add(paymentSheetFragment!!, PaymentSheetFragment.TAG)
|
|
163
235
|
.commit()
|
|
164
236
|
} catch (error: IllegalStateException) {
|
|
@@ -168,7 +240,10 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
168
240
|
}
|
|
169
241
|
|
|
170
242
|
@ReactMethod
|
|
171
|
-
fun presentPaymentSheet(
|
|
243
|
+
fun presentPaymentSheet(
|
|
244
|
+
options: ReadableMap,
|
|
245
|
+
promise: Promise,
|
|
246
|
+
) {
|
|
172
247
|
if (paymentSheetFragment == null) {
|
|
173
248
|
promise.resolve(PaymentSheetFragment.createMissingInitError())
|
|
174
249
|
return
|
|
@@ -177,7 +252,8 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
177
252
|
val timeoutKey = "timeout"
|
|
178
253
|
if (options.hasKey(timeoutKey)) {
|
|
179
254
|
paymentSheetFragment?.presentWithTimeout(
|
|
180
|
-
options.getInt(timeoutKey).toLong(),
|
|
255
|
+
options.getInt(timeoutKey).toLong(),
|
|
256
|
+
promise,
|
|
181
257
|
)
|
|
182
258
|
} else {
|
|
183
259
|
paymentSheetFragment?.present(promise)
|
|
@@ -201,7 +277,10 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
201
277
|
}
|
|
202
278
|
|
|
203
279
|
@ReactMethod
|
|
204
|
-
fun intentCreationCallback(
|
|
280
|
+
fun intentCreationCallback(
|
|
281
|
+
params: ReadableMap,
|
|
282
|
+
promise: Promise,
|
|
283
|
+
) {
|
|
205
284
|
if (paymentSheetFragment == null) {
|
|
206
285
|
promise.resolve(PaymentSheetFragment.createMissingInitError())
|
|
207
286
|
return
|
|
@@ -211,27 +290,39 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
211
290
|
}
|
|
212
291
|
|
|
213
292
|
@ReactMethod
|
|
214
|
-
fun createPaymentMethod(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
293
|
+
fun createPaymentMethod(
|
|
294
|
+
data: ReadableMap,
|
|
295
|
+
options: ReadableMap,
|
|
296
|
+
promise: Promise,
|
|
297
|
+
) {
|
|
298
|
+
val paymentMethodType =
|
|
299
|
+
getValOr(data, "paymentMethodType")?.let { mapToPaymentMethodType(it) } ?: run {
|
|
300
|
+
promise.resolve(
|
|
301
|
+
createError(
|
|
302
|
+
ConfirmPaymentErrorType.Failed.toString(),
|
|
303
|
+
"You must provide paymentMethodType",
|
|
304
|
+
),
|
|
305
|
+
)
|
|
306
|
+
return
|
|
307
|
+
}
|
|
219
308
|
val paymentMethodData = getMapOrNull(data, "paymentMethodData")
|
|
220
|
-
val factory =
|
|
309
|
+
val factory =
|
|
310
|
+
PaymentMethodCreateParamsFactory(paymentMethodData, options, cardFieldView, cardFormView)
|
|
221
311
|
try {
|
|
222
312
|
val paymentMethodCreateParams = factory.createPaymentMethodParams(paymentMethodType)
|
|
223
313
|
stripe.createPaymentMethod(
|
|
224
314
|
paymentMethodCreateParams,
|
|
225
|
-
callback =
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
315
|
+
callback =
|
|
316
|
+
object : ApiResultCallback<PaymentMethod> {
|
|
317
|
+
override fun onError(e: Exception) {
|
|
318
|
+
promise.resolve(createError("Failed", e))
|
|
319
|
+
}
|
|
229
320
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
321
|
+
override fun onSuccess(result: PaymentMethod) {
|
|
322
|
+
val paymentMethodMap: WritableMap = mapFromPaymentMethod(result)
|
|
323
|
+
promise.resolve(createResult("paymentMethod", paymentMethodMap))
|
|
324
|
+
}
|
|
325
|
+
},
|
|
235
326
|
)
|
|
236
327
|
} catch (error: PaymentMethodCreateParamsException) {
|
|
237
328
|
promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), error))
|
|
@@ -239,10 +330,18 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
239
330
|
}
|
|
240
331
|
|
|
241
332
|
@ReactMethod
|
|
242
|
-
fun createToken(
|
|
333
|
+
fun createToken(
|
|
334
|
+
params: ReadableMap,
|
|
335
|
+
promise: Promise,
|
|
336
|
+
) {
|
|
243
337
|
val type = getValOr(params, "type", null)
|
|
244
338
|
if (type == null) {
|
|
245
|
-
promise.resolve(
|
|
339
|
+
promise.resolve(
|
|
340
|
+
createError(
|
|
341
|
+
CreateTokenErrorType.Failed.toString(),
|
|
342
|
+
"type parameter is required",
|
|
343
|
+
),
|
|
344
|
+
)
|
|
246
345
|
return
|
|
247
346
|
}
|
|
248
347
|
|
|
@@ -250,34 +349,53 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
250
349
|
"BankAccount" -> {
|
|
251
350
|
createTokenFromBankAccount(params, promise)
|
|
252
351
|
}
|
|
352
|
+
|
|
253
353
|
"Card" -> {
|
|
254
354
|
createTokenFromCard(params, promise)
|
|
255
355
|
}
|
|
356
|
+
|
|
256
357
|
"Pii" -> {
|
|
257
358
|
createTokenFromPii(params, promise)
|
|
258
359
|
}
|
|
360
|
+
|
|
259
361
|
else -> {
|
|
260
|
-
promise.resolve(
|
|
362
|
+
promise.resolve(
|
|
363
|
+
createError(
|
|
364
|
+
CreateTokenErrorType.Failed.toString(),
|
|
365
|
+
"$type type is not supported yet",
|
|
366
|
+
),
|
|
367
|
+
)
|
|
261
368
|
}
|
|
262
369
|
}
|
|
263
370
|
}
|
|
264
371
|
|
|
265
|
-
private fun createTokenFromPii(
|
|
372
|
+
private fun createTokenFromPii(
|
|
373
|
+
params: ReadableMap,
|
|
374
|
+
promise: Promise,
|
|
375
|
+
) {
|
|
266
376
|
getValOr(params, "personalId", null)?.let {
|
|
267
377
|
CoroutineScope(Dispatchers.IO).launch {
|
|
268
378
|
runCatching {
|
|
269
|
-
val token = stripe.
|
|
379
|
+
val token = stripe.createPiiTokenSynchronous(it, null, stripeAccountId)
|
|
270
380
|
promise.resolve(createResult("token", mapFromToken(token)))
|
|
271
381
|
}.onFailure {
|
|
272
382
|
promise.resolve(createError(CreateTokenErrorType.Failed.toString(), it.message))
|
|
273
383
|
}
|
|
274
384
|
}
|
|
275
385
|
} ?: run {
|
|
276
|
-
promise.resolve(
|
|
386
|
+
promise.resolve(
|
|
387
|
+
createError(
|
|
388
|
+
CreateTokenErrorType.Failed.toString(),
|
|
389
|
+
"personalId parameter is required",
|
|
390
|
+
),
|
|
391
|
+
)
|
|
277
392
|
}
|
|
278
393
|
}
|
|
279
394
|
|
|
280
|
-
private fun createTokenFromBankAccount(
|
|
395
|
+
private fun createTokenFromBankAccount(
|
|
396
|
+
params: ReadableMap,
|
|
397
|
+
promise: Promise,
|
|
398
|
+
) {
|
|
281
399
|
val accountHolderName = getValOr(params, "accountHolderName", null)
|
|
282
400
|
val accountHolderType = getValOr(params, "accountHolderType", null)
|
|
283
401
|
val accountNumber = getValOr(params, "accountNumber", null)
|
|
@@ -285,50 +403,62 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
285
403
|
val currency = getValOr(params, "currency", null)
|
|
286
404
|
val routingNumber = getValOr(params, "routingNumber", null)
|
|
287
405
|
|
|
288
|
-
val bankAccountParams =
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
406
|
+
val bankAccountParams =
|
|
407
|
+
BankAccountTokenParams(
|
|
408
|
+
country = country!!,
|
|
409
|
+
currency = currency!!,
|
|
410
|
+
accountNumber = accountNumber!!,
|
|
411
|
+
accountHolderName = accountHolderName,
|
|
412
|
+
routingNumber = routingNumber,
|
|
413
|
+
accountHolderType = mapToBankAccountType(accountHolderType),
|
|
414
|
+
)
|
|
296
415
|
CoroutineScope(Dispatchers.IO).launch {
|
|
297
416
|
runCatching {
|
|
298
|
-
val token =
|
|
417
|
+
val token =
|
|
418
|
+
stripe.createBankAccountTokenSynchronous(bankAccountParams, null, stripeAccountId)
|
|
299
419
|
promise.resolve(createResult("token", mapFromToken(token)))
|
|
300
420
|
}.onFailure {
|
|
301
421
|
promise.resolve(createError(CreateTokenErrorType.Failed.toString(), it.message))
|
|
302
422
|
}
|
|
303
423
|
}
|
|
304
|
-
|
|
305
424
|
}
|
|
306
425
|
|
|
307
|
-
private fun createTokenFromCard(
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
426
|
+
private fun createTokenFromCard(
|
|
427
|
+
params: ReadableMap,
|
|
428
|
+
promise: Promise,
|
|
429
|
+
) {
|
|
430
|
+
val cardParamsMap =
|
|
431
|
+
(cardFieldView?.cardParams ?: cardFormView?.cardParams)?.toParamMap()
|
|
432
|
+
?: run {
|
|
433
|
+
promise.resolve(
|
|
434
|
+
createError(
|
|
435
|
+
CreateTokenErrorType.Failed.toString(),
|
|
436
|
+
"Card details not complete",
|
|
437
|
+
),
|
|
438
|
+
)
|
|
439
|
+
return
|
|
440
|
+
}
|
|
313
441
|
|
|
314
442
|
val cardAddress = cardFieldView?.cardAddress ?: cardFormView?.cardAddress
|
|
315
443
|
val address = getMapOrNull(params, "address")
|
|
316
|
-
val cardParams =
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
444
|
+
val cardParams =
|
|
445
|
+
CardParams(
|
|
446
|
+
number = cardParamsMap["number"] as String,
|
|
447
|
+
expMonth = cardParamsMap["exp_month"] as Int,
|
|
448
|
+
expYear = cardParamsMap["exp_year"] as Int,
|
|
449
|
+
cvc = cardParamsMap["cvc"] as String,
|
|
450
|
+
address = mapToAddress(address, cardAddress),
|
|
451
|
+
name = getValOr(params, "name", null),
|
|
452
|
+
currency = getValOr(params, "currency", null),
|
|
453
|
+
)
|
|
325
454
|
|
|
326
455
|
CoroutineScope(Dispatchers.IO).launch {
|
|
327
456
|
try {
|
|
328
|
-
val token =
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
457
|
+
val token =
|
|
458
|
+
stripe.createCardTokenSynchronous(
|
|
459
|
+
cardParams = cardParams,
|
|
460
|
+
stripeAccountId = stripeAccountId,
|
|
461
|
+
)
|
|
332
462
|
promise.resolve(createResult("token", mapFromToken(token)))
|
|
333
463
|
} catch (e: Exception) {
|
|
334
464
|
promise.resolve(createError(CreateTokenErrorType.Failed.toString(), e.message))
|
|
@@ -337,46 +467,58 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
337
467
|
}
|
|
338
468
|
|
|
339
469
|
@ReactMethod
|
|
340
|
-
fun createTokenForCVCUpdate(
|
|
470
|
+
fun createTokenForCVCUpdate(
|
|
471
|
+
cvc: String,
|
|
472
|
+
promise: Promise,
|
|
473
|
+
) {
|
|
341
474
|
stripe.createCvcUpdateToken(
|
|
342
475
|
cvc,
|
|
343
|
-
callback =
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
476
|
+
callback =
|
|
477
|
+
object : ApiResultCallback<Token> {
|
|
478
|
+
override fun onSuccess(result: Token) {
|
|
479
|
+
val tokenId = result.id
|
|
480
|
+
val res = WritableNativeMap()
|
|
481
|
+
res.putString("tokenId", tokenId)
|
|
482
|
+
promise.resolve(res)
|
|
483
|
+
}
|
|
350
484
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
485
|
+
override fun onError(e: Exception) {
|
|
486
|
+
promise.resolve(createError("Failed", e))
|
|
487
|
+
}
|
|
488
|
+
},
|
|
355
489
|
)
|
|
356
490
|
}
|
|
357
491
|
|
|
358
492
|
@ReactMethod
|
|
359
|
-
fun handleNextAction(
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
493
|
+
fun handleNextAction(
|
|
494
|
+
paymentIntentClientSecret: String,
|
|
495
|
+
promise: Promise,
|
|
496
|
+
) {
|
|
497
|
+
paymentLauncherFragment =
|
|
498
|
+
PaymentLauncherFragment.forNextActionPayment(
|
|
499
|
+
context = reactApplicationContext,
|
|
500
|
+
stripe,
|
|
501
|
+
publishableKey,
|
|
502
|
+
stripeAccountId,
|
|
503
|
+
promise,
|
|
504
|
+
paymentIntentClientSecret,
|
|
505
|
+
)
|
|
368
506
|
}
|
|
369
507
|
|
|
370
508
|
@ReactMethod
|
|
371
|
-
fun handleNextActionForSetup(
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
509
|
+
fun handleNextActionForSetup(
|
|
510
|
+
setupIntentClientSecret: String,
|
|
511
|
+
promise: Promise,
|
|
512
|
+
) {
|
|
513
|
+
paymentLauncherFragment =
|
|
514
|
+
PaymentLauncherFragment.forNextActionSetup(
|
|
515
|
+
context = reactApplicationContext,
|
|
516
|
+
stripe,
|
|
517
|
+
publishableKey,
|
|
518
|
+
stripeAccountId,
|
|
519
|
+
promise,
|
|
520
|
+
setupIntentClientSecret,
|
|
521
|
+
)
|
|
380
522
|
}
|
|
381
523
|
|
|
382
524
|
// TODO: Uncomment when WeChat is re-enabled in stripe-ios
|
|
@@ -399,15 +541,27 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
399
541
|
// }
|
|
400
542
|
|
|
401
543
|
@ReactMethod
|
|
402
|
-
fun confirmPayment(
|
|
544
|
+
fun confirmPayment(
|
|
545
|
+
paymentIntentClientSecret: String,
|
|
546
|
+
params: ReadableMap?,
|
|
547
|
+
options: ReadableMap,
|
|
548
|
+
promise: Promise,
|
|
549
|
+
) {
|
|
403
550
|
val paymentMethodData = getMapOrNull(params, "paymentMethodData")
|
|
404
|
-
val paymentMethodType =
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
551
|
+
val paymentMethodType =
|
|
552
|
+
if (params != null) {
|
|
553
|
+
mapToPaymentMethodType(params.getString("paymentMethodType")) ?: run {
|
|
554
|
+
promise.resolve(
|
|
555
|
+
createError(
|
|
556
|
+
ConfirmPaymentErrorType.Failed.toString(),
|
|
557
|
+
"You must provide paymentMethodType",
|
|
558
|
+
),
|
|
559
|
+
)
|
|
560
|
+
return
|
|
561
|
+
}
|
|
562
|
+
} else {
|
|
563
|
+
null // Expect that payment method was attached on the server
|
|
408
564
|
}
|
|
409
|
-
else
|
|
410
|
-
null // Expect that payment method was attached on the server
|
|
411
565
|
|
|
412
566
|
// if (paymentMethodType == PaymentMethod.Type.WeChatPay) {
|
|
413
567
|
// val appId = getValOr(params, "appId") ?: run {
|
|
@@ -419,30 +573,41 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
419
573
|
// return
|
|
420
574
|
// }
|
|
421
575
|
|
|
422
|
-
val factory =
|
|
576
|
+
val factory =
|
|
577
|
+
PaymentMethodCreateParamsFactory(paymentMethodData, options, cardFieldView, cardFormView)
|
|
423
578
|
|
|
424
579
|
try {
|
|
425
|
-
val confirmParams =
|
|
580
|
+
val confirmParams =
|
|
581
|
+
factory.createParams(
|
|
582
|
+
paymentIntentClientSecret,
|
|
583
|
+
paymentMethodType,
|
|
584
|
+
isPaymentIntent = true,
|
|
585
|
+
) as ConfirmPaymentIntentParams
|
|
426
586
|
urlScheme?.let {
|
|
427
587
|
confirmParams.returnUrl = mapToReturnURL(urlScheme)
|
|
428
588
|
}
|
|
429
|
-
confirmParams.shipping =
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
589
|
+
confirmParams.shipping =
|
|
590
|
+
mapToShippingDetails(getMapOrNull(paymentMethodData, "shippingDetails"))
|
|
591
|
+
paymentLauncherFragment =
|
|
592
|
+
PaymentLauncherFragment.forPayment(
|
|
593
|
+
context = reactApplicationContext,
|
|
594
|
+
stripe,
|
|
595
|
+
publishableKey,
|
|
596
|
+
stripeAccountId,
|
|
597
|
+
promise,
|
|
598
|
+
paymentIntentClientSecret,
|
|
599
|
+
confirmParams,
|
|
600
|
+
)
|
|
439
601
|
} catch (error: PaymentMethodCreateParamsException) {
|
|
440
602
|
promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), error))
|
|
441
603
|
}
|
|
442
604
|
}
|
|
443
605
|
|
|
444
606
|
@ReactMethod
|
|
445
|
-
fun retrievePaymentIntent(
|
|
607
|
+
fun retrievePaymentIntent(
|
|
608
|
+
clientSecret: String,
|
|
609
|
+
promise: Promise,
|
|
610
|
+
) {
|
|
446
611
|
CoroutineScope(Dispatchers.IO).launch {
|
|
447
612
|
val paymentIntent = stripe.retrievePaymentIntentSynchronous(clientSecret)
|
|
448
613
|
promise.resolve(createResult("paymentIntent", mapFromPaymentIntentResult(paymentIntent)))
|
|
@@ -450,7 +615,10 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
450
615
|
}
|
|
451
616
|
|
|
452
617
|
@ReactMethod
|
|
453
|
-
fun retrieveSetupIntent(
|
|
618
|
+
fun retrieveSetupIntent(
|
|
619
|
+
clientSecret: String,
|
|
620
|
+
promise: Promise,
|
|
621
|
+
) {
|
|
454
622
|
CoroutineScope(Dispatchers.IO).launch {
|
|
455
623
|
val setupIntent = stripe.retrieveSetupIntentSynchronous(clientSecret)
|
|
456
624
|
promise.resolve(createResult("setupIntent", mapFromSetupIntentResult(setupIntent)))
|
|
@@ -458,46 +626,74 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
458
626
|
}
|
|
459
627
|
|
|
460
628
|
@ReactMethod
|
|
461
|
-
fun confirmSetupIntent(
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
629
|
+
fun confirmSetupIntent(
|
|
630
|
+
setupIntentClientSecret: String,
|
|
631
|
+
params: ReadableMap,
|
|
632
|
+
options: ReadableMap,
|
|
633
|
+
promise: Promise,
|
|
634
|
+
) {
|
|
635
|
+
val paymentMethodType =
|
|
636
|
+
getValOr(params, "paymentMethodType")?.let { mapToPaymentMethodType(it) } ?: run {
|
|
637
|
+
promise.resolve(
|
|
638
|
+
createError(
|
|
639
|
+
ConfirmPaymentErrorType.Failed.toString(),
|
|
640
|
+
"You must provide paymentMethodType",
|
|
641
|
+
),
|
|
642
|
+
)
|
|
643
|
+
return
|
|
644
|
+
}
|
|
466
645
|
|
|
467
|
-
val factory =
|
|
646
|
+
val factory =
|
|
647
|
+
PaymentMethodCreateParamsFactory(
|
|
648
|
+
getMapOrNull(params, "paymentMethodData"),
|
|
649
|
+
options,
|
|
650
|
+
cardFieldView,
|
|
651
|
+
cardFormView,
|
|
652
|
+
)
|
|
468
653
|
|
|
469
654
|
try {
|
|
470
|
-
val confirmParams =
|
|
655
|
+
val confirmParams =
|
|
656
|
+
factory.createParams(
|
|
657
|
+
setupIntentClientSecret,
|
|
658
|
+
paymentMethodType,
|
|
659
|
+
isPaymentIntent = false,
|
|
660
|
+
) as ConfirmSetupIntentParams
|
|
471
661
|
urlScheme?.let {
|
|
472
662
|
confirmParams.returnUrl = mapToReturnURL(urlScheme)
|
|
473
663
|
}
|
|
474
|
-
paymentLauncherFragment =
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
664
|
+
paymentLauncherFragment =
|
|
665
|
+
PaymentLauncherFragment.forSetup(
|
|
666
|
+
context = reactApplicationContext,
|
|
667
|
+
stripe,
|
|
668
|
+
publishableKey,
|
|
669
|
+
stripeAccountId,
|
|
670
|
+
promise,
|
|
671
|
+
setupIntentClientSecret,
|
|
672
|
+
confirmParams,
|
|
673
|
+
)
|
|
483
674
|
} catch (error: PaymentMethodCreateParamsException) {
|
|
484
675
|
promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), error))
|
|
485
676
|
}
|
|
486
677
|
}
|
|
487
678
|
|
|
488
679
|
@ReactMethod
|
|
489
|
-
fun isPlatformPaySupported(
|
|
680
|
+
fun isPlatformPaySupported(
|
|
681
|
+
params: ReadableMap?,
|
|
682
|
+
promise: Promise,
|
|
683
|
+
) {
|
|
490
684
|
val googlePayParams = params?.getMap("googlePay")
|
|
491
|
-
val fragment =
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
685
|
+
val fragment =
|
|
686
|
+
GooglePayPaymentMethodLauncherFragment(
|
|
687
|
+
reactApplicationContext,
|
|
688
|
+
getBooleanOrFalse(googlePayParams, "testEnv"),
|
|
689
|
+
getBooleanOrFalse(googlePayParams, "existingPaymentMethodRequired"),
|
|
690
|
+
promise,
|
|
691
|
+
)
|
|
497
692
|
|
|
498
693
|
getCurrentActivityOrResolveWithError(promise)?.let {
|
|
499
694
|
try {
|
|
500
|
-
it.supportFragmentManager
|
|
695
|
+
it.supportFragmentManager
|
|
696
|
+
.beginTransaction()
|
|
501
697
|
.add(fragment, GooglePayPaymentMethodLauncherFragment.TAG)
|
|
502
698
|
.commit()
|
|
503
699
|
} catch (error: IllegalStateException) {
|
|
@@ -507,23 +703,34 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
507
703
|
}
|
|
508
704
|
|
|
509
705
|
@ReactMethod
|
|
510
|
-
fun confirmPlatformPay(
|
|
706
|
+
fun confirmPlatformPay(
|
|
707
|
+
clientSecret: String,
|
|
708
|
+
params: ReadableMap,
|
|
709
|
+
isPaymentIntent: Boolean,
|
|
710
|
+
promise: Promise,
|
|
711
|
+
) {
|
|
511
712
|
if (!::stripe.isInitialized) {
|
|
512
713
|
promise.resolve(createMissingInitError())
|
|
513
714
|
return
|
|
514
715
|
}
|
|
515
716
|
|
|
516
|
-
val googlePayParams: ReadableMap =
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
717
|
+
val googlePayParams: ReadableMap =
|
|
718
|
+
params.getMap("googlePay") ?: run {
|
|
719
|
+
promise.resolve(
|
|
720
|
+
createError(
|
|
721
|
+
GooglePayErrorType.Failed.toString(),
|
|
722
|
+
"You must provide the `googlePay` parameter.",
|
|
723
|
+
),
|
|
724
|
+
)
|
|
725
|
+
return
|
|
726
|
+
}
|
|
520
727
|
|
|
521
728
|
GooglePayLauncherFragment().also {
|
|
522
729
|
it.presentGooglePaySheet(
|
|
523
730
|
clientSecret,
|
|
524
731
|
if (isPaymentIntent) GooglePayLauncherFragment.Mode.ForPayment else GooglePayLauncherFragment.Mode.ForSetup,
|
|
525
732
|
googlePayParams,
|
|
526
|
-
reactApplicationContext
|
|
733
|
+
reactApplicationContext,
|
|
527
734
|
) { launcherResult, errorMap ->
|
|
528
735
|
if (errorMap != null) {
|
|
529
736
|
promise.resolve(errorMap)
|
|
@@ -531,30 +738,59 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
531
738
|
when (launcherResult) {
|
|
532
739
|
GooglePayLauncher.Result.Completed -> {
|
|
533
740
|
if (isPaymentIntent) {
|
|
534
|
-
stripe.retrievePaymentIntent(
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
741
|
+
stripe.retrievePaymentIntent(
|
|
742
|
+
clientSecret,
|
|
743
|
+
stripeAccountId,
|
|
744
|
+
expand = listOf("payment_method"),
|
|
745
|
+
object : ApiResultCallback<PaymentIntent> {
|
|
746
|
+
override fun onError(e: Exception) {
|
|
747
|
+
promise.resolve(createResult("paymentIntent", WritableNativeMap()))
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
override fun onSuccess(result: PaymentIntent) {
|
|
751
|
+
promise.resolve(
|
|
752
|
+
createResult(
|
|
753
|
+
"paymentIntent",
|
|
754
|
+
mapFromPaymentIntentResult(result),
|
|
755
|
+
),
|
|
756
|
+
)
|
|
757
|
+
}
|
|
758
|
+
},
|
|
759
|
+
)
|
|
542
760
|
} else {
|
|
543
|
-
stripe.retrieveSetupIntent(
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
761
|
+
stripe.retrieveSetupIntent(
|
|
762
|
+
clientSecret,
|
|
763
|
+
stripeAccountId,
|
|
764
|
+
expand = listOf("payment_method"),
|
|
765
|
+
object : ApiResultCallback<SetupIntent> {
|
|
766
|
+
override fun onError(e: Exception) {
|
|
767
|
+
promise.resolve(createResult("setupIntent", WritableNativeMap()))
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
override fun onSuccess(result: SetupIntent) {
|
|
771
|
+
promise.resolve(createResult("setupIntent", mapFromSetupIntentResult(result)))
|
|
772
|
+
}
|
|
773
|
+
},
|
|
774
|
+
)
|
|
551
775
|
}
|
|
552
776
|
}
|
|
777
|
+
|
|
553
778
|
GooglePayLauncher.Result.Canceled -> {
|
|
554
|
-
promise.resolve(
|
|
779
|
+
promise.resolve(
|
|
780
|
+
createError(
|
|
781
|
+
GooglePayErrorType.Canceled.toString(),
|
|
782
|
+
"Google Pay has been canceled",
|
|
783
|
+
),
|
|
784
|
+
)
|
|
555
785
|
}
|
|
786
|
+
|
|
556
787
|
is GooglePayLauncher.Result.Failed -> {
|
|
557
|
-
promise.resolve(
|
|
788
|
+
promise.resolve(
|
|
789
|
+
createError(
|
|
790
|
+
GooglePayErrorType.Failed.toString(),
|
|
791
|
+
launcherResult.error,
|
|
792
|
+
),
|
|
793
|
+
)
|
|
558
794
|
}
|
|
559
795
|
}
|
|
560
796
|
}
|
|
@@ -563,73 +799,108 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
563
799
|
}
|
|
564
800
|
|
|
565
801
|
@ReactMethod
|
|
566
|
-
fun createPlatformPayPaymentMethod(
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
802
|
+
fun createPlatformPayPaymentMethod(
|
|
803
|
+
params: ReadableMap,
|
|
804
|
+
usesDeprecatedTokenFlow: Boolean,
|
|
805
|
+
promise: Promise,
|
|
806
|
+
) {
|
|
807
|
+
val googlePayParams: ReadableMap =
|
|
808
|
+
params.getMap("googlePay") ?: run {
|
|
809
|
+
promise.resolve(
|
|
810
|
+
createError(
|
|
811
|
+
GooglePayErrorType.Failed.toString(),
|
|
812
|
+
"You must provide the `googlePay` parameter.",
|
|
813
|
+
),
|
|
814
|
+
)
|
|
815
|
+
return
|
|
816
|
+
}
|
|
571
817
|
platformPayUsesDeprecatedTokenFlow = usesDeprecatedTokenFlow
|
|
572
818
|
createPlatformPayPaymentMethodPromise = promise
|
|
573
819
|
getCurrentActivityOrResolveWithError(promise)?.let {
|
|
574
|
-
val request =
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
820
|
+
val request =
|
|
821
|
+
GooglePayRequestHelper.createPaymentRequest(
|
|
822
|
+
it,
|
|
823
|
+
GooglePayJsonFactory(reactApplicationContext),
|
|
824
|
+
googlePayParams,
|
|
825
|
+
)
|
|
579
826
|
GooglePayRequestHelper.createPaymentMethod(request, it)
|
|
580
827
|
}
|
|
581
828
|
}
|
|
582
829
|
|
|
583
830
|
@ReactMethod
|
|
584
|
-
fun canAddCardToWallet(
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
831
|
+
fun canAddCardToWallet(
|
|
832
|
+
params: ReadableMap,
|
|
833
|
+
promise: Promise,
|
|
834
|
+
) {
|
|
835
|
+
val last4 =
|
|
836
|
+
getValOr(params, "cardLastFour", null) ?: run {
|
|
837
|
+
promise.resolve(createError("Failed", "You must provide cardLastFour"))
|
|
838
|
+
return
|
|
839
|
+
}
|
|
589
840
|
|
|
590
|
-
if (params.getBooleanOr("supportsTapToPay", true) &&
|
|
841
|
+
if (params.getBooleanOr("supportsTapToPay", true) &&
|
|
842
|
+
!PushProvisioningProxy.isNFCEnabled(
|
|
843
|
+
reactApplicationContext,
|
|
844
|
+
)
|
|
845
|
+
) {
|
|
591
846
|
promise.resolve(createCanAddCardResult(false, "UNSUPPORTED_DEVICE"))
|
|
592
847
|
return
|
|
593
848
|
}
|
|
594
849
|
|
|
595
850
|
getCurrentActivityOrResolveWithError(promise)?.let {
|
|
596
851
|
PushProvisioningProxy.isCardInWallet(it, last4) { isCardInWallet, token, error ->
|
|
597
|
-
val result =
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
852
|
+
val result =
|
|
853
|
+
error?.let {
|
|
854
|
+
createCanAddCardResult(false, "MISSING_CONFIGURATION", null)
|
|
855
|
+
} ?: run {
|
|
856
|
+
val status = if (isCardInWallet) "CARD_ALREADY_EXISTS" else null
|
|
857
|
+
createCanAddCardResult(!isCardInWallet, status, token)
|
|
858
|
+
}
|
|
603
859
|
promise.resolve(result)
|
|
604
860
|
}
|
|
605
861
|
}
|
|
606
862
|
}
|
|
607
863
|
|
|
608
864
|
@ReactMethod
|
|
609
|
-
fun isCardInWallet(
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
865
|
+
fun isCardInWallet(
|
|
866
|
+
params: ReadableMap,
|
|
867
|
+
promise: Promise,
|
|
868
|
+
) {
|
|
869
|
+
val last4 =
|
|
870
|
+
getValOr(params, "cardLastFour", null) ?: run {
|
|
871
|
+
promise.resolve(createError("Failed", "You must provide cardLastFour"))
|
|
872
|
+
return
|
|
873
|
+
}
|
|
614
874
|
getCurrentActivityOrResolveWithError(promise)?.let {
|
|
615
875
|
PushProvisioningProxy.isCardInWallet(it, last4) { isCardInWallet, token, error ->
|
|
616
|
-
val result: WritableMap =
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
876
|
+
val result: WritableMap =
|
|
877
|
+
error ?: run {
|
|
878
|
+
val map = WritableNativeMap()
|
|
879
|
+
map.putBoolean("isInWallet", isCardInWallet)
|
|
880
|
+
map.putMap("token", token)
|
|
881
|
+
map
|
|
882
|
+
}
|
|
622
883
|
promise.resolve(result)
|
|
623
884
|
}
|
|
624
885
|
}
|
|
625
886
|
}
|
|
626
887
|
|
|
627
888
|
@ReactMethod
|
|
628
|
-
fun collectBankAccount(
|
|
889
|
+
fun collectBankAccount(
|
|
890
|
+
isPaymentIntent: Boolean,
|
|
891
|
+
clientSecret: String,
|
|
892
|
+
params: ReadableMap,
|
|
893
|
+
promise: Promise,
|
|
894
|
+
) {
|
|
629
895
|
val paymentMethodData = getMapOrNull(params, "paymentMethodData")
|
|
630
896
|
val paymentMethodType = mapToPaymentMethodType(getValOr(params, "paymentMethodType", null))
|
|
631
897
|
if (paymentMethodType != PaymentMethod.Type.USBankAccount) {
|
|
632
|
-
promise.resolve(
|
|
898
|
+
promise.resolve(
|
|
899
|
+
createError(
|
|
900
|
+
ErrorType.Failed.toString(),
|
|
901
|
+
"collectBankAccount currently only accepts the USBankAccount payment method type.",
|
|
902
|
+
),
|
|
903
|
+
)
|
|
633
904
|
return
|
|
634
905
|
}
|
|
635
906
|
|
|
@@ -637,27 +908,35 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
637
908
|
|
|
638
909
|
val name = billingDetails?.getString("name")
|
|
639
910
|
if (name.isNullOrEmpty()) {
|
|
640
|
-
promise.resolve(
|
|
911
|
+
promise.resolve(
|
|
912
|
+
createError(
|
|
913
|
+
ErrorType.Failed.toString(),
|
|
914
|
+
"You must provide a name when collecting US bank account details.",
|
|
915
|
+
),
|
|
916
|
+
)
|
|
641
917
|
return
|
|
642
918
|
}
|
|
643
919
|
|
|
644
|
-
val collectParams =
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
920
|
+
val collectParams =
|
|
921
|
+
CollectBankAccountConfiguration.USBankAccount(
|
|
922
|
+
name,
|
|
923
|
+
billingDetails.getString("email"),
|
|
924
|
+
)
|
|
648
925
|
|
|
649
|
-
collectBankAccountLauncherFragment =
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
926
|
+
collectBankAccountLauncherFragment =
|
|
927
|
+
CollectBankAccountLauncherFragment(
|
|
928
|
+
reactApplicationContext,
|
|
929
|
+
publishableKey,
|
|
930
|
+
stripeAccountId,
|
|
931
|
+
clientSecret,
|
|
932
|
+
isPaymentIntent,
|
|
933
|
+
collectParams,
|
|
934
|
+
promise,
|
|
935
|
+
)
|
|
658
936
|
getCurrentActivityOrResolveWithError(promise)?.let {
|
|
659
937
|
try {
|
|
660
|
-
it.supportFragmentManager
|
|
938
|
+
it.supportFragmentManager
|
|
939
|
+
.beginTransaction()
|
|
661
940
|
.add(collectBankAccountLauncherFragment!!, "collect_bank_account_launcher_fragment")
|
|
662
941
|
.commit()
|
|
663
942
|
} catch (error: IllegalStateException) {
|
|
@@ -667,38 +946,55 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
667
946
|
}
|
|
668
947
|
|
|
669
948
|
@ReactMethod
|
|
670
|
-
fun verifyMicrodeposits(
|
|
949
|
+
fun verifyMicrodeposits(
|
|
950
|
+
isPaymentIntent: Boolean,
|
|
951
|
+
clientSecret: String,
|
|
952
|
+
params: ReadableMap,
|
|
953
|
+
promise: Promise,
|
|
954
|
+
) {
|
|
671
955
|
val amounts = params.getArray("amounts")
|
|
672
956
|
val descriptorCode = params.getString("descriptorCode")
|
|
673
957
|
|
|
674
958
|
if ((amounts != null && descriptorCode != null) || (amounts == null && descriptorCode == null)) {
|
|
675
|
-
promise.resolve(
|
|
959
|
+
promise.resolve(
|
|
960
|
+
createError(
|
|
961
|
+
ErrorType.Failed.toString(),
|
|
962
|
+
"You must provide either amounts OR descriptorCode, not both.",
|
|
963
|
+
),
|
|
964
|
+
)
|
|
676
965
|
return
|
|
677
966
|
}
|
|
678
967
|
|
|
679
|
-
val paymentCallback =
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
968
|
+
val paymentCallback =
|
|
969
|
+
object : ApiResultCallback<PaymentIntent> {
|
|
970
|
+
override fun onError(e: Exception) {
|
|
971
|
+
promise.resolve(createError(ErrorType.Failed.toString(), e))
|
|
972
|
+
}
|
|
683
973
|
|
|
684
|
-
|
|
685
|
-
|
|
974
|
+
override fun onSuccess(result: PaymentIntent) {
|
|
975
|
+
promise.resolve(createResult("paymentIntent", mapFromPaymentIntentResult(result)))
|
|
976
|
+
}
|
|
686
977
|
}
|
|
687
|
-
}
|
|
688
978
|
|
|
689
|
-
val setupCallback =
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
979
|
+
val setupCallback =
|
|
980
|
+
object : ApiResultCallback<SetupIntent> {
|
|
981
|
+
override fun onError(e: Exception) {
|
|
982
|
+
promise.resolve(createError(ErrorType.Failed.toString(), e))
|
|
983
|
+
}
|
|
693
984
|
|
|
694
|
-
|
|
695
|
-
|
|
985
|
+
override fun onSuccess(result: SetupIntent) {
|
|
986
|
+
promise.resolve(createResult("setupIntent", mapFromSetupIntentResult(result)))
|
|
987
|
+
}
|
|
696
988
|
}
|
|
697
|
-
}
|
|
698
989
|
|
|
699
990
|
amounts?.let {
|
|
700
991
|
if (it.size() != 2) {
|
|
701
|
-
promise.resolve(
|
|
992
|
+
promise.resolve(
|
|
993
|
+
createError(
|
|
994
|
+
ErrorType.Failed.toString(),
|
|
995
|
+
"Expected 2 integers in the amounts array, but received ${it.size()}",
|
|
996
|
+
),
|
|
997
|
+
)
|
|
702
998
|
return
|
|
703
999
|
}
|
|
704
1000
|
|
|
@@ -707,14 +1003,14 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
707
1003
|
clientSecret,
|
|
708
1004
|
it.getInt(0),
|
|
709
1005
|
it.getInt(1),
|
|
710
|
-
paymentCallback
|
|
1006
|
+
paymentCallback,
|
|
711
1007
|
)
|
|
712
1008
|
} else {
|
|
713
1009
|
stripe.verifySetupIntentWithMicrodeposits(
|
|
714
1010
|
clientSecret,
|
|
715
1011
|
it.getInt(0),
|
|
716
1012
|
it.getInt(1),
|
|
717
|
-
setupCallback
|
|
1013
|
+
setupCallback,
|
|
718
1014
|
)
|
|
719
1015
|
}
|
|
720
1016
|
} ?: descriptorCode?.let {
|
|
@@ -722,42 +1018,66 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
722
1018
|
stripe.verifyPaymentIntentWithMicrodeposits(
|
|
723
1019
|
clientSecret,
|
|
724
1020
|
it,
|
|
725
|
-
paymentCallback
|
|
1021
|
+
paymentCallback,
|
|
726
1022
|
)
|
|
727
1023
|
} else {
|
|
728
1024
|
stripe.verifySetupIntentWithMicrodeposits(
|
|
729
1025
|
clientSecret,
|
|
730
1026
|
it,
|
|
731
|
-
setupCallback
|
|
1027
|
+
setupCallback,
|
|
732
1028
|
)
|
|
733
1029
|
}
|
|
734
1030
|
}
|
|
735
1031
|
}
|
|
736
1032
|
|
|
737
1033
|
@ReactMethod
|
|
738
|
-
fun collectBankAccountToken(
|
|
1034
|
+
fun collectBankAccountToken(
|
|
1035
|
+
clientSecret: String,
|
|
1036
|
+
promise: Promise,
|
|
1037
|
+
) {
|
|
739
1038
|
if (!::stripe.isInitialized) {
|
|
740
1039
|
promise.resolve(createMissingInitError())
|
|
741
1040
|
return
|
|
742
1041
|
}
|
|
743
1042
|
FinancialConnectionsSheetFragment().also {
|
|
744
|
-
it.presentFinancialConnectionsSheet(
|
|
1043
|
+
it.presentFinancialConnectionsSheet(
|
|
1044
|
+
clientSecret,
|
|
1045
|
+
FinancialConnectionsSheetFragment.Mode.ForToken,
|
|
1046
|
+
publishableKey,
|
|
1047
|
+
stripeAccountId,
|
|
1048
|
+
promise,
|
|
1049
|
+
reactApplicationContext,
|
|
1050
|
+
)
|
|
745
1051
|
}
|
|
746
1052
|
}
|
|
747
1053
|
|
|
748
1054
|
@ReactMethod
|
|
749
|
-
fun collectFinancialConnectionsAccounts(
|
|
1055
|
+
fun collectFinancialConnectionsAccounts(
|
|
1056
|
+
clientSecret: String,
|
|
1057
|
+
promise: Promise,
|
|
1058
|
+
) {
|
|
750
1059
|
if (!::stripe.isInitialized) {
|
|
751
1060
|
promise.resolve(createMissingInitError())
|
|
752
1061
|
return
|
|
753
1062
|
}
|
|
754
1063
|
FinancialConnectionsSheetFragment().also {
|
|
755
|
-
it.presentFinancialConnectionsSheet(
|
|
1064
|
+
it.presentFinancialConnectionsSheet(
|
|
1065
|
+
clientSecret,
|
|
1066
|
+
FinancialConnectionsSheetFragment.Mode.ForSession,
|
|
1067
|
+
publishableKey,
|
|
1068
|
+
stripeAccountId,
|
|
1069
|
+
promise,
|
|
1070
|
+
reactApplicationContext,
|
|
1071
|
+
)
|
|
756
1072
|
}
|
|
757
1073
|
}
|
|
758
1074
|
|
|
759
1075
|
@ReactMethod
|
|
760
|
-
fun initCustomerSheet(
|
|
1076
|
+
fun initCustomerSheet(
|
|
1077
|
+
params: ReadableMap,
|
|
1078
|
+
customerAdapterOverrides: ReadableMap,
|
|
1079
|
+
promise: Promise,
|
|
1080
|
+
) {
|
|
761
1081
|
if (!::stripe.isInitialized) {
|
|
762
1082
|
promise.resolve(createMissingInitError())
|
|
763
1083
|
return
|
|
@@ -765,15 +1085,17 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
765
1085
|
|
|
766
1086
|
getCurrentActivityOrResolveWithError(promise)?.let { activity ->
|
|
767
1087
|
customerSheetFragment?.removeFragment(reactApplicationContext)
|
|
768
|
-
customerSheetFragment =
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
1088
|
+
customerSheetFragment =
|
|
1089
|
+
CustomerSheetFragment().also {
|
|
1090
|
+
it.context = reactApplicationContext
|
|
1091
|
+
it.initPromise = promise
|
|
1092
|
+
val bundle = toBundleObject(params)
|
|
1093
|
+
bundle.putBundle("customerAdapter", toBundleObject(customerAdapterOverrides))
|
|
1094
|
+
it.arguments = bundle
|
|
1095
|
+
}
|
|
775
1096
|
try {
|
|
776
|
-
activity.supportFragmentManager
|
|
1097
|
+
activity.supportFragmentManager
|
|
1098
|
+
.beginTransaction()
|
|
777
1099
|
.add(customerSheetFragment!!, CustomerSheetFragment.TAG)
|
|
778
1100
|
.commit()
|
|
779
1101
|
} catch (error: IllegalStateException) {
|
|
@@ -783,7 +1105,10 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
783
1105
|
}
|
|
784
1106
|
|
|
785
1107
|
@ReactMethod
|
|
786
|
-
fun presentCustomerSheet(
|
|
1108
|
+
fun presentCustomerSheet(
|
|
1109
|
+
params: ReadableMap,
|
|
1110
|
+
promise: Promise,
|
|
1111
|
+
) {
|
|
787
1112
|
var timeout: Long? = null
|
|
788
1113
|
if (params.hasKey("timeout")) {
|
|
789
1114
|
timeout = params.getInt("timeout").toLong()
|
|
@@ -801,14 +1126,20 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
801
1126
|
}
|
|
802
1127
|
|
|
803
1128
|
@ReactMethod
|
|
804
|
-
fun customerAdapterFetchPaymentMethodsCallback(
|
|
1129
|
+
fun customerAdapterFetchPaymentMethodsCallback(
|
|
1130
|
+
paymentMethodJsonObjects: ReadableArray,
|
|
1131
|
+
promise: Promise,
|
|
1132
|
+
) {
|
|
805
1133
|
customerSheetFragment?.let { fragment ->
|
|
806
1134
|
val paymentMethods = mutableListOf<PaymentMethod>()
|
|
807
1135
|
for (paymentMethodJson in paymentMethodJsonObjects.toArrayList()) {
|
|
808
1136
|
PaymentMethod.fromJson(JSONObject((paymentMethodJson as HashMap<*, *>)))?.let {
|
|
809
1137
|
paymentMethods.add(it)
|
|
810
1138
|
} ?: run {
|
|
811
|
-
Log.e(
|
|
1139
|
+
Log.e(
|
|
1140
|
+
"StripeReactNative",
|
|
1141
|
+
"There was an error converting Payment Method JSON to a Stripe Payment Method",
|
|
1142
|
+
)
|
|
812
1143
|
}
|
|
813
1144
|
}
|
|
814
1145
|
fragment.customerAdapter?.fetchPaymentMethodsCallback?.complete(paymentMethods)
|
|
@@ -819,11 +1150,18 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
819
1150
|
}
|
|
820
1151
|
|
|
821
1152
|
@ReactMethod
|
|
822
|
-
fun customerAdapterAttachPaymentMethodCallback(
|
|
1153
|
+
fun customerAdapterAttachPaymentMethodCallback(
|
|
1154
|
+
paymentMethodJson: ReadableMap,
|
|
1155
|
+
promise: Promise,
|
|
1156
|
+
) {
|
|
823
1157
|
customerSheetFragment?.let {
|
|
824
|
-
val paymentMethod =
|
|
1158
|
+
val paymentMethod =
|
|
1159
|
+
PaymentMethod.fromJson(JSONObject(paymentMethodJson.toHashMap() as HashMap<*, *>))
|
|
825
1160
|
if (paymentMethod == null) {
|
|
826
|
-
Log.e(
|
|
1161
|
+
Log.e(
|
|
1162
|
+
"StripeReactNative",
|
|
1163
|
+
"There was an error converting Payment Method JSON to a Stripe Payment Method",
|
|
1164
|
+
)
|
|
827
1165
|
return
|
|
828
1166
|
}
|
|
829
1167
|
it.customerAdapter?.attachPaymentMethodCallback?.complete(paymentMethod)
|
|
@@ -834,11 +1172,18 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
834
1172
|
}
|
|
835
1173
|
|
|
836
1174
|
@ReactMethod
|
|
837
|
-
fun customerAdapterDetachPaymentMethodCallback(
|
|
1175
|
+
fun customerAdapterDetachPaymentMethodCallback(
|
|
1176
|
+
paymentMethodJson: ReadableMap,
|
|
1177
|
+
promise: Promise,
|
|
1178
|
+
) {
|
|
838
1179
|
customerSheetFragment?.let {
|
|
839
|
-
val paymentMethod =
|
|
1180
|
+
val paymentMethod =
|
|
1181
|
+
PaymentMethod.fromJson(JSONObject(paymentMethodJson.toHashMap() as HashMap<*, *>))
|
|
840
1182
|
if (paymentMethod == null) {
|
|
841
|
-
Log.e(
|
|
1183
|
+
Log.e(
|
|
1184
|
+
"StripeReactNative",
|
|
1185
|
+
"There was an error converting Payment Method JSON to a Stripe Payment Method",
|
|
1186
|
+
)
|
|
842
1187
|
return
|
|
843
1188
|
}
|
|
844
1189
|
it.customerAdapter?.detachPaymentMethodCallback?.complete(paymentMethod)
|
|
@@ -859,7 +1204,10 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
859
1204
|
}
|
|
860
1205
|
|
|
861
1206
|
@ReactMethod
|
|
862
|
-
fun customerAdapterFetchSelectedPaymentOptionCallback(
|
|
1207
|
+
fun customerAdapterFetchSelectedPaymentOptionCallback(
|
|
1208
|
+
paymentOption: String?,
|
|
1209
|
+
promise: Promise,
|
|
1210
|
+
) {
|
|
863
1211
|
customerSheetFragment?.let {
|
|
864
1212
|
it.customerAdapter?.fetchSelectedPaymentOptionCallback?.complete(paymentOption)
|
|
865
1213
|
} ?: run {
|
|
@@ -869,7 +1217,10 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
869
1217
|
}
|
|
870
1218
|
|
|
871
1219
|
@ReactMethod
|
|
872
|
-
fun customerAdapterSetupIntentClientSecretForCustomerAttachCallback(
|
|
1220
|
+
fun customerAdapterSetupIntentClientSecretForCustomerAttachCallback(
|
|
1221
|
+
clientSecret: String,
|
|
1222
|
+
promise: Promise,
|
|
1223
|
+
) {
|
|
873
1224
|
customerSheetFragment?.let {
|
|
874
1225
|
it.customerAdapter?.setupIntentClientSecretForCustomerAttachCallback?.complete(clientSecret)
|
|
875
1226
|
} ?: run {
|
|
@@ -891,7 +1242,11 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
|
|
|
891
1242
|
}
|
|
892
1243
|
}
|
|
893
1244
|
|
|
894
|
-
internal fun sendEvent(
|
|
1245
|
+
internal fun sendEvent(
|
|
1246
|
+
reactContext: ReactContext,
|
|
1247
|
+
eventName: String,
|
|
1248
|
+
params: WritableMap,
|
|
1249
|
+
) {
|
|
895
1250
|
reactContext
|
|
896
1251
|
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
897
1252
|
.emit(eventName, params)
|