@stripe/stripe-react-native 0.57.0 → 0.57.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -8
- package/android/.idea/AndroidProjectSystem.xml +6 -0
- package/android/.idea/caches/deviceStreaming.xml +1029 -0
- package/android/.idea/compiler.xml +6 -0
- package/android/.idea/gradle.xml +19 -0
- package/android/.idea/migrations.xml +10 -0
- package/android/.idea/misc.xml +10 -0
- package/android/.idea/runConfigurations.xml +17 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/build.gradle +76 -118
- package/android/gradle.properties +1 -1
- package/android/local.properties +8 -0
- package/android/settings.gradle +2 -0
- package/android/spotless.gradle +1 -1
- package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormView.kt +20 -17
- package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +13 -11
- package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +17 -21
- package/android/src/main/java/com/reactnativestripesdk/CollectBankAccountLauncherManager.kt +2 -0
- package/android/src/main/java/com/reactnativestripesdk/CustomPaymentMethodActivity.kt +2 -0
- package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementView.kt +53 -11
- package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +105 -117
- package/android/src/main/java/com/reactnativestripesdk/EventEmitterCompat.kt +4 -8
- package/android/src/main/java/com/reactnativestripesdk/FakeOnrampSdkModule.kt +154 -0
- package/android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetManager.kt +13 -15
- package/android/src/main/java/com/reactnativestripesdk/GooglePayButtonView.kt +1 -1
- package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherManager.kt +1 -1
- package/android/src/main/java/com/reactnativestripesdk/GooglePayRequestHelper.kt +7 -5
- package/android/src/main/java/com/reactnativestripesdk/NavigationBarManager.kt +31 -0
- package/android/src/main/java/com/reactnativestripesdk/NavigationBarView.kt +120 -0
- package/android/src/main/java/com/reactnativestripesdk/PaymentElementConfig.kt +228 -0
- package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherManager.kt +1 -0
- package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +3 -0
- package/android/src/main/java/com/reactnativestripesdk/PaymentOptionDisplayDataMapper.kt +4 -6
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +73 -30
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetManager.kt +19 -245
- package/android/src/main/java/com/reactnativestripesdk/StripeAbstractComposeView.kt +53 -17
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +52 -14
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +21 -2
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +4 -4
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetViewManager.kt +2 -2
- package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetManager.kt +15 -35
- package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerSessionProvider.kt +2 -1
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonManager.kt +5 -10
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt +90 -77
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/TapAndPayProxy.kt +6 -4
- package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +13 -3
- package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +41 -0
- package/android/src/main/java/com/reactnativestripesdk/utils/KeepJsAwakeTask.kt +1 -1
- package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +92 -44
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerDelegate.java +3 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerInterface.java +2 -0
- package/android/src/oldarch/java/com/reactnativestripesdk/NativeOnrampSdkModuleSpec.java +118 -0
- package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +4 -0
- package/android/src/onramp/java/com/reactnativestripesdk/OnrampSdkModule.kt +922 -0
- package/android/src/test/java/com/facebook/testutils/shadows/ShadowArguments.kt +29 -0
- package/android/src/test/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManagerTest.kt +163 -0
- package/android/src/test/java/com/reactnativestripesdk/PaymentElementConfigTest.kt +976 -0
- package/android/src/test/java/com/reactnativestripesdk/PaymentSheetAppearanceTest.kt +801 -0
- package/android/src/test/java/com/reactnativestripesdk/PaymentSheetManagerTest.kt +523 -0
- package/android/src/test/java/com/reactnativestripesdk/addresssheet/AddressSheetViewTest.kt +551 -0
- package/android/src/test/java/com/reactnativestripesdk/mappers/MappersTest.kt +567 -0
- package/android/src/test/java/com/reactnativestripesdk/mappers/PaymentOptionDisplayDataMapperTest.kt +456 -0
- package/android/src/test/java/com/reactnativestripesdk/pushprovisioning/PushProvisioningProxyTest.kt +43 -0
- package/android/src/test/resources/robolectric.properties +2 -0
- package/ios/AddressSheet/AddressSheetUtils.swift +3 -3
- package/ios/AddressSheet/AddressSheetView.swift +25 -25
- package/ios/AddressSheet/AddressSheetViewManager.swift +2 -2
- package/ios/ApplePayButtonManager.swift +1 -1
- package/ios/ApplePayButtonView.swift +9 -10
- package/ios/ApplePayUtils.swift +51 -51
- package/ios/ApplePayViewController.swift +25 -29
- package/ios/AuBECSDebitFormManager.swift +1 -1
- package/ios/AuBECSDebitFormView.swift +13 -15
- package/ios/CardFieldManager.swift +4 -4
- package/ios/CardFieldView.swift +9 -9
- package/ios/CardFormManager.swift +3 -3
- package/ios/CardFormView.swift +28 -28
- package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingView.swift +97 -0
- package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewController.swift +133 -0
- package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewManager.m +16 -0
- package/ios/ConnectAccountOnboarding/ConnectAccountOnboardingViewManager.swift +17 -0
- package/ios/CustomerSheet/CustomerSheetUtils.swift +15 -16
- package/ios/CustomerSheet/ReactNativeCustomerAdapter.swift +19 -19
- package/ios/EmbeddedPaymentElementView.swift +2 -2
- package/ios/Errors.swift +22 -23
- package/ios/FinancialConnections.swift +37 -37
- package/ios/Mappers.swift +210 -71
- package/ios/NavigationBarManager.m +13 -0
- package/ios/NavigationBarManager.swift +17 -0
- package/ios/NavigationBarView.swift +65 -0
- package/ios/NewArch/NavigationBarComponentView.h +10 -0
- package/ios/NewArch/NavigationBarComponentView.mm +86 -0
- package/ios/OldArch/StripeSdkEventEmitterCompat.h +1 -0
- package/ios/OldArch/StripeSdkEventEmitterCompat.m +7 -1
- package/ios/PaymentMethodFactory.swift +24 -24
- package/ios/PaymentOptionDisplayData+ReactNative.swift +4 -4
- package/ios/PaymentPassFinder.swift +9 -10
- package/ios/PaymentSheetAppearance.swift +137 -138
- package/ios/PushProvisioning/AddToWalletButtonManager.swift +2 -2
- package/ios/PushProvisioning/AddToWalletButtonView.swift +15 -17
- package/ios/PushProvisioning/PushProvisioningUtils.swift +11 -11
- package/ios/StripeContainerManager.swift +1 -1
- package/ios/StripeContainerView.swift +3 -3
- package/ios/StripeOnrampSdk.h +17 -0
- package/ios/StripeOnrampSdk.mm +158 -0
- package/ios/StripeSdk.mm +8 -0
- package/ios/StripeSdk.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/StripeSdk.xcodeproj/project.xcworkspace/xcuserdata/tianzhao.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/StripeSdk.xcodeproj/xcuserdata/tianzhao.xcuserdatad/xcschemes/xcschememanagement.plist +19 -0
- package/ios/StripeSdkEmitter.swift +4 -0
- package/ios/StripeSdkImpl+CustomerSheet.swift +30 -25
- package/ios/StripeSdkImpl+Embedded.swift +11 -9
- package/ios/StripeSdkImpl+PaymentSheet.swift +36 -34
- package/ios/StripeSdkImpl.swift +913 -185
- package/ios/UIColorExtension.swift +72 -0
- package/lib/commonjs/components/AddToWalletButton.js +1 -1
- package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
- package/lib/commonjs/components/AddressSheet.js +1 -1
- package/lib/commonjs/components/AddressSheet.js.map +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
- package/lib/commonjs/components/CardField.js +1 -1
- package/lib/commonjs/components/CardField.js.map +1 -1
- package/lib/commonjs/components/CardForm.js +1 -1
- package/lib/commonjs/components/CardForm.js.map +1 -1
- package/lib/commonjs/components/PlatformPayButton.js +1 -1
- package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
- package/lib/commonjs/components/StripeContainer.js +1 -1
- package/lib/commonjs/components/StripeContainer.js.map +1 -1
- package/lib/commonjs/components/StripeProvider.js +1 -1
- package/lib/commonjs/components/StripeProvider.js.map +1 -1
- package/lib/commonjs/connect/Components.js +2 -0
- package/lib/commonjs/connect/Components.js.map +1 -0
- package/lib/commonjs/connect/ConnectComponentsProvider.js +2 -0
- package/lib/commonjs/connect/ConnectComponentsProvider.js.map +1 -0
- package/lib/commonjs/connect/EmbeddedComponent.js +19 -0
- package/lib/commonjs/connect/EmbeddedComponent.js.map +1 -0
- package/lib/commonjs/connect/ModalCloseButton.js +2 -0
- package/lib/commonjs/connect/ModalCloseButton.js.map +1 -0
- package/lib/commonjs/connect/NavigationBar.js +2 -0
- package/lib/commonjs/connect/NavigationBar.js.map +1 -0
- package/lib/commonjs/connect/connectTypes.js +2 -0
- package/lib/commonjs/connect/connectTypes.js.map +1 -0
- package/lib/commonjs/events.js +1 -1
- package/lib/commonjs/events.js.map +1 -1
- package/lib/commonjs/helpers.js +1 -1
- package/lib/commonjs/helpers.js.map +1 -1
- package/lib/commonjs/hooks/useOnramp.js +2 -0
- package/lib/commonjs/hooks/useOnramp.js.map +1 -0
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/plugin/withStripe.js +1 -1
- package/lib/commonjs/plugin/withStripe.js.map +1 -1
- package/lib/commonjs/specs/NativeAddToWalletButton.js +1 -1
- package/lib/commonjs/specs/NativeAddToWalletButton.js.map +1 -1
- package/lib/commonjs/specs/NativeAddressSheet.js +1 -1
- package/lib/commonjs/specs/NativeAddressSheet.js.map +1 -1
- package/lib/commonjs/specs/NativeApplePayButton.js +1 -1
- package/lib/commonjs/specs/NativeApplePayButton.js.map +1 -1
- package/lib/commonjs/specs/NativeAuBECSDebitForm.js +1 -1
- package/lib/commonjs/specs/NativeAuBECSDebitForm.js.map +1 -1
- package/lib/commonjs/specs/NativeCardField.js +1 -1
- package/lib/commonjs/specs/NativeCardField.js.map +1 -1
- package/lib/commonjs/specs/NativeCardForm.js +1 -1
- package/lib/commonjs/specs/NativeCardForm.js.map +1 -1
- package/lib/commonjs/specs/NativeConnectAccountOnboardingView.js +2 -0
- package/lib/commonjs/specs/NativeConnectAccountOnboardingView.js.map +1 -0
- package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js +1 -1
- package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js.map +1 -1
- package/lib/commonjs/specs/NativeGooglePayButton.js +1 -1
- package/lib/commonjs/specs/NativeGooglePayButton.js.map +1 -1
- package/lib/commonjs/specs/NativeNavigationBar.js +2 -0
- package/lib/commonjs/specs/NativeNavigationBar.js.map +1 -0
- package/lib/commonjs/specs/NativeOnrampSdkModule.js +2 -0
- package/lib/commonjs/specs/NativeOnrampSdkModule.js.map +1 -0
- package/lib/commonjs/specs/NativeStripeContainer.js +1 -1
- package/lib/commonjs/specs/NativeStripeContainer.js.map +1 -1
- package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
- package/lib/commonjs/types/EmbeddedPaymentElement.js +1 -1
- package/lib/commonjs/types/EmbeddedPaymentElement.js.map +1 -1
- package/lib/commonjs/types/Errors.js +1 -1
- package/lib/commonjs/types/Errors.js.map +1 -1
- package/lib/commonjs/types/Onramp.js +2 -0
- package/lib/commonjs/types/Onramp.js.map +1 -0
- package/lib/commonjs/types/PaymentSheet.js.map +1 -1
- package/lib/commonjs/types/index.js +1 -1
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/module/components/AddToWalletButton.js +1 -1
- package/lib/module/components/AddToWalletButton.js.map +1 -1
- package/lib/module/components/AddressSheet.js +1 -1
- package/lib/module/components/AddressSheet.js.map +1 -1
- package/lib/module/components/AuBECSDebitForm.js +1 -1
- package/lib/module/components/AuBECSDebitForm.js.map +1 -1
- package/lib/module/components/CardField.js +1 -1
- package/lib/module/components/CardField.js.map +1 -1
- package/lib/module/components/CardForm.js +1 -1
- package/lib/module/components/CardForm.js.map +1 -1
- package/lib/module/components/PlatformPayButton.js +1 -1
- package/lib/module/components/PlatformPayButton.js.map +1 -1
- package/lib/module/components/StripeContainer.js +1 -1
- package/lib/module/components/StripeContainer.js.map +1 -1
- package/lib/module/components/StripeProvider.js +1 -1
- package/lib/module/components/StripeProvider.js.map +1 -1
- package/lib/module/connect/Components.js +2 -0
- package/lib/module/connect/Components.js.map +1 -0
- package/lib/module/connect/ConnectComponentsProvider.js +2 -0
- package/lib/module/connect/ConnectComponentsProvider.js.map +1 -0
- package/lib/module/connect/EmbeddedComponent.js +19 -0
- package/lib/module/connect/EmbeddedComponent.js.map +1 -0
- package/lib/module/connect/ModalCloseButton.js +2 -0
- package/lib/module/connect/ModalCloseButton.js.map +1 -0
- package/lib/module/connect/NavigationBar.js +2 -0
- package/lib/module/connect/NavigationBar.js.map +1 -0
- package/lib/module/connect/connectTypes.js +2 -0
- package/lib/module/connect/connectTypes.js.map +1 -0
- package/lib/module/events.js +1 -1
- package/lib/module/events.js.map +1 -1
- package/lib/module/helpers.js +1 -1
- package/lib/module/helpers.js.map +1 -1
- package/lib/module/hooks/useOnramp.js +2 -0
- package/lib/module/hooks/useOnramp.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/plugin/withStripe.js +1 -1
- package/lib/module/plugin/withStripe.js.map +1 -1
- package/lib/module/specs/NativeAddToWalletButton.js +1 -1
- package/lib/module/specs/NativeAddToWalletButton.js.map +1 -1
- package/lib/module/specs/NativeAddressSheet.js +1 -1
- package/lib/module/specs/NativeAddressSheet.js.map +1 -1
- package/lib/module/specs/NativeApplePayButton.js +1 -1
- package/lib/module/specs/NativeApplePayButton.js.map +1 -1
- package/lib/module/specs/NativeAuBECSDebitForm.js +1 -1
- package/lib/module/specs/NativeAuBECSDebitForm.js.map +1 -1
- package/lib/module/specs/NativeCardField.js +1 -1
- package/lib/module/specs/NativeCardField.js.map +1 -1
- package/lib/module/specs/NativeCardForm.js +1 -1
- package/lib/module/specs/NativeCardForm.js.map +1 -1
- package/lib/module/specs/NativeConnectAccountOnboardingView.js +2 -0
- package/lib/module/specs/NativeConnectAccountOnboardingView.js.map +1 -0
- package/lib/module/specs/NativeEmbeddedPaymentElement.js +1 -1
- package/lib/module/specs/NativeEmbeddedPaymentElement.js.map +1 -1
- package/lib/module/specs/NativeGooglePayButton.js +1 -1
- package/lib/module/specs/NativeGooglePayButton.js.map +1 -1
- package/lib/module/specs/NativeNavigationBar.js +2 -0
- package/lib/module/specs/NativeNavigationBar.js.map +1 -0
- package/lib/module/specs/NativeOnrampSdkModule.js +2 -0
- package/lib/module/specs/NativeOnrampSdkModule.js.map +1 -0
- package/lib/module/specs/NativeStripeContainer.js +1 -1
- package/lib/module/specs/NativeStripeContainer.js.map +1 -1
- package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
- package/lib/module/types/EmbeddedPaymentElement.js +1 -1
- package/lib/module/types/EmbeddedPaymentElement.js.map +1 -1
- package/lib/module/types/Errors.js +1 -1
- package/lib/module/types/Errors.js.map +1 -1
- package/lib/module/types/Onramp.js +2 -0
- package/lib/module/types/Onramp.js.map +1 -0
- package/lib/module/types/PaymentSheet.js.map +1 -1
- package/lib/module/types/index.js +1 -1
- package/lib/module/types/index.js.map +1 -1
- package/lib/typescript/src/components/StripeProvider.d.ts.map +1 -1
- package/lib/typescript/src/connect/Components.d.ts +23 -0
- package/lib/typescript/src/connect/Components.d.ts.map +1 -0
- package/lib/typescript/src/connect/ConnectComponentsProvider.d.ts +22 -0
- package/lib/typescript/src/connect/ConnectComponentsProvider.d.ts.map +1 -0
- package/lib/typescript/src/connect/EmbeddedComponent.d.ts +18 -0
- package/lib/typescript/src/connect/EmbeddedComponent.d.ts.map +1 -0
- package/lib/typescript/src/connect/ModalCloseButton.d.ts +7 -0
- package/lib/typescript/src/connect/ModalCloseButton.d.ts.map +1 -0
- package/lib/typescript/src/connect/NavigationBar.d.ts +8 -0
- package/lib/typescript/src/connect/NavigationBar.d.ts.map +1 -0
- package/lib/typescript/src/connect/connectTypes.d.ts +464 -0
- package/lib/typescript/src/connect/connectTypes.d.ts.map +1 -0
- package/lib/typescript/src/events.d.ts +4 -0
- package/lib/typescript/src/events.d.ts.map +1 -1
- package/lib/typescript/src/functions.d.ts.map +1 -1
- package/lib/typescript/src/helpers.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useOnramp.d.ts +158 -0
- package/lib/typescript/src/hooks/useOnramp.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/plugin/withStripe.d.ts +15 -0
- package/lib/typescript/src/plugin/withStripe.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeConnectAccountOnboardingView.d.ts +14 -0
- package/lib/typescript/src/specs/NativeConnectAccountOnboardingView.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeEmbeddedPaymentElement.d.ts +1 -0
- package/lib/typescript/src/specs/NativeEmbeddedPaymentElement.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeNavigationBar.d.ts +11 -0
- package/lib/typescript/src/specs/NativeNavigationBar.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts +28 -0
- package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +3 -0
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
- package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts.map +1 -1
- package/lib/typescript/src/types/Errors.d.ts +5 -0
- package/lib/typescript/src/types/Errors.d.ts.map +1 -1
- package/lib/typescript/src/types/Onramp.d.ts +275 -0
- package/lib/typescript/src/types/Onramp.d.ts.map +1 -0
- package/lib/typescript/src/types/PaymentSheet.d.ts +7 -0
- package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +7 -1
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/package.json +25 -14
- package/src/components/StripeProvider.tsx +5 -0
- package/src/connect/Components.tsx +279 -0
- package/src/connect/ConnectComponentsProvider.tsx +93 -0
- package/src/connect/EmbeddedComponent.tsx +407 -0
- package/src/connect/ModalCloseButton.tsx +44 -0
- package/src/connect/NavigationBar.tsx +29 -0
- package/src/connect/connectTypes.ts +626 -0
- package/src/events.ts +23 -0
- package/src/hooks/useOnramp.tsx +334 -0
- package/src/index.tsx +13 -0
- package/src/plugin/withStripe.ts +104 -7
- package/src/specs/NativeConnectAccountOnboardingView.ts +19 -0
- package/src/specs/NativeEmbeddedPaymentElement.ts +5 -1
- package/src/specs/NativeNavigationBar.ts +16 -0
- package/src/specs/NativeOnrampSdkModule.ts +47 -0
- package/src/specs/NativeStripeSdkModule.ts +5 -0
- package/src/types/EmbeddedPaymentElement.tsx +24 -3
- package/src/types/Errors.ts +6 -0
- package/src/types/Onramp.ts +317 -0
- package/src/types/PaymentSheet.ts +7 -0
- package/src/types/index.ts +8 -0
- package/stripe-react-native.podspec +20 -7
package/ios/StripeSdkImpl.swift
CHANGED
|
@@ -1,87 +1,114 @@
|
|
|
1
|
+
import AuthenticationServices
|
|
2
|
+
import Foundation
|
|
1
3
|
import PassKit
|
|
2
4
|
@_spi(DashboardOnly) @_spi(STP) import Stripe
|
|
3
|
-
@_spi(EmbeddedPaymentElementPrivateBeta) @_spi(CustomerSessionBetaAccess) import StripePaymentSheet
|
|
4
|
-
@_spi(STP) @_spi(ConfirmationTokensPublicPreview) import StripePayments
|
|
5
5
|
import StripeFinancialConnections
|
|
6
|
-
import
|
|
6
|
+
@_spi(STP) @_spi(ConfirmationTokensPublicPreview) import StripePayments
|
|
7
|
+
#if canImport(StripeCryptoOnramp)
|
|
8
|
+
@_spi(STP) import StripeCryptoOnramp
|
|
9
|
+
|
|
10
|
+
@_spi(STP)
|
|
11
|
+
@_spi(EmbeddedPaymentElementPrivateBeta)
|
|
12
|
+
@_spi(CustomerSessionBetaAccess)
|
|
13
|
+
@_spi(AppearanceAPIAdditionsPreview)
|
|
14
|
+
import StripePaymentSheet
|
|
15
|
+
#else
|
|
16
|
+
@_spi(EmbeddedPaymentElementPrivateBeta) @_spi(CustomerSessionBetaAccess) import StripePaymentSheet
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
@available(iOS 13.0, *)
|
|
20
|
+
class ASWebAuthenticationPresentationContextProvider: NSObject, ASWebAuthenticationPresentationContextProviding {
|
|
21
|
+
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
|
|
22
|
+
return RCTKeyWindow() ?? ASPresentationAnchor()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
7
25
|
|
|
8
26
|
@objc(StripeSdkImpl)
|
|
9
27
|
public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
10
28
|
@objc public static let shared = StripeSdkImpl()
|
|
11
29
|
|
|
12
|
-
@objc public weak var emitter: StripeSdkEmitter?
|
|
13
|
-
weak var
|
|
14
|
-
weak var
|
|
30
|
+
@objc public weak var emitter: StripeSdkEmitter?
|
|
31
|
+
@objc public weak var onrampEmitter: StripeOnrampSdkEmitter?
|
|
32
|
+
weak var cardFieldView: CardFieldView?
|
|
33
|
+
weak var cardFormView: CardFormView?
|
|
15
34
|
|
|
16
|
-
var merchantIdentifier: String?
|
|
35
|
+
var merchantIdentifier: String?
|
|
17
36
|
|
|
18
37
|
internal var paymentSheet: PaymentSheet?
|
|
19
38
|
internal var paymentSheetFlowController: PaymentSheet.FlowController?
|
|
20
39
|
var paymentSheetIntentCreationCallback: ((Result<String, Error>) -> Void)?
|
|
21
40
|
var paymentSheetConfirmationTokenIntentCreationCallback: ((Result<String, Error>) -> Void)?
|
|
22
41
|
|
|
23
|
-
var urlScheme: String?
|
|
42
|
+
var urlScheme: String?
|
|
24
43
|
|
|
25
|
-
var confirmPaymentResolver: RCTPromiseResolveBlock?
|
|
44
|
+
var confirmPaymentResolver: RCTPromiseResolveBlock?
|
|
26
45
|
|
|
27
|
-
var confirmApplePayResolver: RCTPromiseResolveBlock?
|
|
28
|
-
var confirmApplePayPaymentClientSecret: String?
|
|
29
|
-
var confirmApplePaySetupClientSecret: String?
|
|
30
|
-
var confirmApplePayPaymentMethod: STPPaymentMethod?
|
|
46
|
+
var confirmApplePayResolver: RCTPromiseResolveBlock?
|
|
47
|
+
var confirmApplePayPaymentClientSecret: String?
|
|
48
|
+
var confirmApplePaySetupClientSecret: String?
|
|
49
|
+
var confirmApplePayPaymentMethod: STPPaymentMethod?
|
|
31
50
|
|
|
32
|
-
var applePaymentAuthorizationController: PKPaymentAuthorizationViewController?
|
|
33
|
-
var createPlatformPayPaymentMethodResolver: RCTPromiseResolveBlock?
|
|
51
|
+
var applePaymentAuthorizationController: PKPaymentAuthorizationViewController?
|
|
52
|
+
var createPlatformPayPaymentMethodResolver: RCTPromiseResolveBlock?
|
|
34
53
|
var platformPayUsesDeprecatedTokenFlow = false
|
|
35
54
|
var applePaymentMethodFlowCanBeCanceled = false
|
|
36
55
|
|
|
37
|
-
var confirmPaymentClientSecret: String?
|
|
56
|
+
var confirmPaymentClientSecret: String?
|
|
38
57
|
|
|
39
|
-
var shippingMethodUpdateCompletion: ((PKPaymentRequestShippingMethodUpdate) -> Void)?
|
|
40
|
-
var shippingContactUpdateCompletion: ((PKPaymentRequestShippingContactUpdate) -> Void)?
|
|
58
|
+
var shippingMethodUpdateCompletion: ((PKPaymentRequestShippingMethodUpdate) -> Void)?
|
|
59
|
+
var shippingContactUpdateCompletion: ((PKPaymentRequestShippingContactUpdate) -> Void)?
|
|
41
60
|
@available(iOS 15.0, *)
|
|
42
61
|
var couponCodeUpdateCompletion: ((PKPaymentRequestCouponCodeUpdate) -> Void)? {
|
|
43
62
|
get { _couponCodeUpdateCompletion as? ((PKPaymentRequestCouponCodeUpdate) -> Void) }
|
|
44
63
|
set { _couponCodeUpdateCompletion = newValue }
|
|
45
64
|
}
|
|
46
|
-
private var _couponCodeUpdateCompletion: Any?
|
|
47
|
-
var orderTrackingHandler: (result: PKPaymentAuthorizationResult, handler: ((PKPaymentAuthorizationResult) -> Void))?
|
|
48
|
-
var shippingMethodUpdateJSCallback: RCTDirectEventBlock?
|
|
49
|
-
var shippingContactUpdateJSCallback: RCTDirectEventBlock?
|
|
50
|
-
var couponCodeEnteredJSCallback: RCTDirectEventBlock?
|
|
51
|
-
var platformPayOrderTrackingJSCallback: RCTDirectEventBlock?
|
|
65
|
+
private var _couponCodeUpdateCompletion: Any?
|
|
66
|
+
var orderTrackingHandler: (result: PKPaymentAuthorizationResult, handler: ((PKPaymentAuthorizationResult) -> Void))?
|
|
67
|
+
var shippingMethodUpdateJSCallback: RCTDirectEventBlock?
|
|
68
|
+
var shippingContactUpdateJSCallback: RCTDirectEventBlock?
|
|
69
|
+
var couponCodeEnteredJSCallback: RCTDirectEventBlock?
|
|
70
|
+
var platformPayOrderTrackingJSCallback: RCTDirectEventBlock?
|
|
52
71
|
var applePaySummaryItems: [PKPaymentSummaryItem] = []
|
|
53
72
|
var applePayShippingMethods: [PKShippingMethod] = []
|
|
54
|
-
var applePayShippingAddressErrors: [Error]?
|
|
55
|
-
var applePayCouponCodeErrors: [Error]?
|
|
73
|
+
var applePayShippingAddressErrors: [Error]?
|
|
74
|
+
var applePayCouponCodeErrors: [Error]?
|
|
56
75
|
|
|
57
76
|
var customerSheetConfiguration = CustomerSheet.Configuration()
|
|
58
|
-
var customerSheet: CustomerSheet?
|
|
59
|
-
var customerAdapter: StripeCustomerAdapter?
|
|
77
|
+
var customerSheet: CustomerSheet?
|
|
78
|
+
var customerAdapter: StripeCustomerAdapter?
|
|
60
79
|
var customerSheetViewController: UIViewController?
|
|
61
|
-
var fetchPaymentMethodsCallback: (([STPPaymentMethod]) -> Void)?
|
|
62
|
-
var attachPaymentMethodCallback: (() -> Void)?
|
|
63
|
-
var detachPaymentMethodCallback: (() -> Void)?
|
|
64
|
-
var setSelectedPaymentOptionCallback: (() -> Void)?
|
|
65
|
-
var fetchSelectedPaymentOptionCallback: ((CustomerPaymentOption?) -> Void)?
|
|
66
|
-
var setupIntentClientSecretForCustomerAttachCallback: ((String) -> Void)?
|
|
80
|
+
var fetchPaymentMethodsCallback: (([STPPaymentMethod]) -> Void)?
|
|
81
|
+
var attachPaymentMethodCallback: (() -> Void)?
|
|
82
|
+
var detachPaymentMethodCallback: (() -> Void)?
|
|
83
|
+
var setSelectedPaymentOptionCallback: (() -> Void)?
|
|
84
|
+
var fetchSelectedPaymentOptionCallback: ((CustomerPaymentOption?) -> Void)?
|
|
85
|
+
var setupIntentClientSecretForCustomerAttachCallback: ((String) -> Void)?
|
|
67
86
|
var customPaymentMethodResultCallback: ((PaymentSheetResult) -> Void)?
|
|
68
|
-
var clientSecretProviderSetupIntentClientSecretCallback: ((String) -> Void)?
|
|
69
|
-
var clientSecretProviderCustomerSessionClientSecretCallback: ((CustomerSessionClientSecret) -> Void)?
|
|
87
|
+
var clientSecretProviderSetupIntentClientSecretCallback: ((String) -> Void)?
|
|
88
|
+
var clientSecretProviderCustomerSessionClientSecretCallback: ((CustomerSessionClientSecret) -> Void)?
|
|
89
|
+
|
|
90
|
+
#if canImport(StripeCryptoOnramp)
|
|
91
|
+
var cryptoOnrampCoordinator: CryptoOnrampCoordinator?
|
|
92
|
+
var cryptoOnrampCheckoutClientSecretContinuation: CheckedContinuation<String, Error>?
|
|
93
|
+
#endif
|
|
70
94
|
|
|
71
|
-
var embeddedInstance: EmbeddedPaymentElement?
|
|
95
|
+
var embeddedInstance: EmbeddedPaymentElement?
|
|
72
96
|
lazy var embeddedInstanceDelegate = StripeSdkEmbeddedPaymentElementDelegate(sdkImpl: self)
|
|
73
97
|
|
|
74
|
-
|
|
98
|
+
var authenticationSession: ASWebAuthenticationSession?
|
|
99
|
+
var authenticationContextProvider: Any?
|
|
100
|
+
|
|
101
|
+
@objc public func getConstants() -> [AnyHashable: Any] {
|
|
75
102
|
return [
|
|
76
103
|
"API_VERSIONS": [
|
|
77
104
|
"CORE": STPAPIClient.apiVersion,
|
|
78
105
|
"ISSUING": STPAPIClient.apiVersion,
|
|
79
|
-
]
|
|
106
|
+
],
|
|
80
107
|
]
|
|
81
108
|
}
|
|
82
109
|
|
|
83
110
|
@objc(initialise:resolver:rejecter:)
|
|
84
|
-
public func initialise(params: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock)
|
|
111
|
+
public func initialise(params: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
85
112
|
let publishableKey = params["publishableKey"] as! String
|
|
86
113
|
let appInfo = params["appInfo"] as! NSDictionary
|
|
87
114
|
let stripeAccountId = params["stripeAccountId"] as? String
|
|
@@ -114,8 +141,9 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
114
141
|
}
|
|
115
142
|
|
|
116
143
|
@objc(initPaymentSheet:resolver:rejecter:)
|
|
117
|
-
public func initPaymentSheet(params: NSDictionary,
|
|
118
|
-
|
|
144
|
+
public func initPaymentSheet(params: NSDictionary,
|
|
145
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
146
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
119
147
|
let (error, configuration) = buildPaymentSheetConfiguration(params: params)
|
|
120
148
|
guard let configuration = configuration else {
|
|
121
149
|
resolve(error)
|
|
@@ -126,8 +154,9 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
126
154
|
}
|
|
127
155
|
|
|
128
156
|
@objc(intentCreationCallback:resolver:rejecter:)
|
|
129
|
-
@MainActor public func intentCreationCallback(result: NSDictionary,
|
|
130
|
-
|
|
157
|
+
@MainActor public func intentCreationCallback(result: NSDictionary,
|
|
158
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
159
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
131
160
|
guard let paymentSheetIntentCreationCallback = self.paymentSheetIntentCreationCallback else {
|
|
132
161
|
resolve(Errors.createError(ErrorType.Failed, "No intent creation callback was set"))
|
|
133
162
|
return
|
|
@@ -135,15 +164,16 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
135
164
|
if let clientSecret = result["clientSecret"] as? String {
|
|
136
165
|
paymentSheetIntentCreationCallback(.success(clientSecret))
|
|
137
166
|
} else {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
167
|
+
let errorParams = result["error"] as? NSDictionary
|
|
168
|
+
let error = ConfirmationError.init(errorMessage: errorParams?["localizedMessage"] as? String ?? "An unknown error occurred.")
|
|
169
|
+
paymentSheetIntentCreationCallback(.failure(error))
|
|
141
170
|
}
|
|
142
171
|
}
|
|
143
172
|
|
|
144
173
|
@objc(confirmationTokenCreationCallback:resolver:rejecter:)
|
|
145
|
-
@MainActor public func confirmationTokenCreationCallback(result: NSDictionary,
|
|
146
|
-
|
|
174
|
+
@MainActor public func confirmationTokenCreationCallback(result: NSDictionary,
|
|
175
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
176
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
147
177
|
guard let paymentSheetConfirmationTokenIntentCreationCallback = self.paymentSheetConfirmationTokenIntentCreationCallback else {
|
|
148
178
|
resolve(Errors.createError(ErrorType.Failed, "No confirmation token intent creation callback was set"))
|
|
149
179
|
return
|
|
@@ -151,15 +181,16 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
151
181
|
if let clientSecret = result["clientSecret"] as? String {
|
|
152
182
|
paymentSheetConfirmationTokenIntentCreationCallback(.success(clientSecret))
|
|
153
183
|
} else {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
184
|
+
let errorParams = result["error"] as? NSDictionary
|
|
185
|
+
let error = ConfirmationError.init(errorMessage: errorParams?["localizedMessage"] as? String ?? "An unknown error occurred.")
|
|
186
|
+
paymentSheetConfirmationTokenIntentCreationCallback(.failure(error))
|
|
157
187
|
}
|
|
158
188
|
}
|
|
159
189
|
|
|
160
190
|
@objc(customPaymentMethodResultCallback:resolver:rejecter:)
|
|
161
|
-
@MainActor public func customPaymentMethodResultCallback(result: NSDictionary,
|
|
162
|
-
|
|
191
|
+
@MainActor public func customPaymentMethodResultCallback(result: NSDictionary,
|
|
192
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
193
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
163
194
|
guard let customPaymentMethodResultCallback = self.customPaymentMethodResultCallback else {
|
|
164
195
|
resolve(Errors.createError(ErrorType.Failed, "Internal error: no custom payment method callback"))
|
|
165
196
|
return
|
|
@@ -186,9 +217,9 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
186
217
|
|
|
187
218
|
@objc(confirmPaymentSheetPayment:rejecter:)
|
|
188
219
|
public func confirmPaymentSheetPayment(resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
189
|
-
|
|
220
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
190
221
|
DispatchQueue.main.async {
|
|
191
|
-
if
|
|
222
|
+
if self.paymentSheetFlowController != nil {
|
|
192
223
|
self.paymentSheetFlowController?.confirm(from: RCTKeyWindow()?.rootViewController ?? UIViewController()) { paymentResult in
|
|
193
224
|
switch paymentResult {
|
|
194
225
|
case .completed:
|
|
@@ -208,15 +239,15 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
208
239
|
|
|
209
240
|
@objc(resetPaymentSheetCustomer:rejecter:)
|
|
210
241
|
public func resetPaymentSheetCustomer(resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
211
|
-
|
|
242
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
212
243
|
PaymentSheet.resetCustomer()
|
|
213
244
|
resolve(nil)
|
|
214
245
|
}
|
|
215
246
|
|
|
216
247
|
@objc(presentPaymentSheet:resolver:rejecter:)
|
|
217
248
|
public func presentPaymentSheet(options: NSDictionary,
|
|
218
|
-
|
|
219
|
-
|
|
249
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
250
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
220
251
|
var paymentSheetViewController: UIViewController?
|
|
221
252
|
|
|
222
253
|
if let timeout = options["timeout"] as? Double {
|
|
@@ -236,7 +267,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
236
267
|
if let paymentOption = self.paymentSheetFlowController?.paymentOption {
|
|
237
268
|
let option: NSDictionary = [
|
|
238
269
|
"label": paymentOption.label,
|
|
239
|
-
"image": paymentOption.image.pngData()?.base64EncodedString() ?? ""
|
|
270
|
+
"image": paymentOption.image.pngData()?.base64EncodedString() ?? "",
|
|
240
271
|
]
|
|
241
272
|
resolve(Mappers.createResult("paymentOption", option, additionalFields: ["didCancel": didCancel]))
|
|
242
273
|
} else {
|
|
@@ -267,7 +298,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
267
298
|
public func createTokenForCVCUpdate(cvc: String?, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
268
299
|
guard let cvc = cvc else {
|
|
269
300
|
resolve(Errors.createError(ErrorType.Failed, "You must provide CVC"))
|
|
270
|
-
return
|
|
301
|
+
return
|
|
271
302
|
}
|
|
272
303
|
|
|
273
304
|
STPAPIClient.shared.createToken(forCVCUpdate: cvc) { (token, error) in
|
|
@@ -281,9 +312,11 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
281
312
|
}
|
|
282
313
|
|
|
283
314
|
@objc(confirmSetupIntent:data:options:resolver:rejecter:)
|
|
284
|
-
public func confirmSetupIntent (setupIntentClientSecret: String,
|
|
285
|
-
|
|
286
|
-
|
|
315
|
+
public func confirmSetupIntent (setupIntentClientSecret: String,
|
|
316
|
+
params: NSDictionary,
|
|
317
|
+
options: NSDictionary,
|
|
318
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
319
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
287
320
|
let paymentMethodData = params["paymentMethodData"] as? NSDictionary
|
|
288
321
|
let type = Mappers.mapToPaymentMethodType(type: params["paymentMethodType"] as? String)
|
|
289
322
|
guard let paymentMethodType = type else {
|
|
@@ -291,10 +324,10 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
291
324
|
return
|
|
292
325
|
}
|
|
293
326
|
|
|
294
|
-
var err: NSDictionary?
|
|
327
|
+
var err: NSDictionary?
|
|
295
328
|
let setupIntentParams: STPSetupIntentConfirmParams = {
|
|
296
329
|
// If payment method data is not supplied, assume payment method was attached through via collectBankAccount
|
|
297
|
-
if
|
|
330
|
+
if paymentMethodType == .USBankAccount && paymentMethodData == nil {
|
|
298
331
|
return STPSetupIntentConfirmParams(clientSecret: setupIntentClientSecret, paymentMethodType: .USBankAccount)
|
|
299
332
|
} else {
|
|
300
333
|
let factory = PaymentMethodFactory.init(paymentMethodData: paymentMethodData, options: options, cardFieldView: cardFieldView, cardFormView: cardFormView)
|
|
@@ -316,7 +349,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
316
349
|
}
|
|
317
350
|
}()
|
|
318
351
|
|
|
319
|
-
if
|
|
352
|
+
if err != nil {
|
|
320
353
|
resolve(err)
|
|
321
354
|
return
|
|
322
355
|
}
|
|
@@ -327,33 +360,30 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
327
360
|
|
|
328
361
|
let paymentHandler = STPPaymentHandler.shared()
|
|
329
362
|
paymentHandler.confirmSetupIntent(setupIntentParams, with: self) { status, setupIntent, error in
|
|
330
|
-
switch
|
|
363
|
+
switch status {
|
|
331
364
|
case .failed:
|
|
332
365
|
resolve(Errors.createError(ErrorType.Failed, error))
|
|
333
|
-
break
|
|
334
366
|
case .canceled:
|
|
335
367
|
if let lastError = setupIntent?.lastSetupError {
|
|
336
368
|
resolve(Errors.createError(ErrorType.Canceled, lastError))
|
|
337
369
|
} else {
|
|
338
370
|
resolve(Errors.createError(ErrorType.Canceled, "The payment has been canceled"))
|
|
339
371
|
}
|
|
340
|
-
break
|
|
341
372
|
case .succeeded:
|
|
342
373
|
let intent = Mappers.mapFromSetupIntent(setupIntent: setupIntent!)
|
|
343
374
|
resolve(Mappers.createResult("setupIntent", intent))
|
|
344
375
|
@unknown default:
|
|
345
376
|
resolve(Errors.createError(ErrorType.Unknown, error))
|
|
346
|
-
break
|
|
347
377
|
}
|
|
348
378
|
}
|
|
349
379
|
}
|
|
350
380
|
|
|
351
381
|
@objc(updatePlatformPaySheet:shippingMethods:errors:resolver:rejecter:)
|
|
352
382
|
public func updatePlatformPaySheet(summaryItems: NSArray,
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
383
|
+
shippingMethods: NSArray,
|
|
384
|
+
errors: [NSDictionary],
|
|
385
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
386
|
+
rejecter reject: @escaping RCTPromiseRejectBlock)
|
|
357
387
|
{
|
|
358
388
|
let couponUpdateHandlerIsNil: Bool = {
|
|
359
389
|
if #available(iOS 15.0, *), self.couponCodeUpdateCompletion == nil {
|
|
@@ -362,19 +392,19 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
362
392
|
return false
|
|
363
393
|
}()
|
|
364
394
|
|
|
365
|
-
if
|
|
395
|
+
if shippingMethodUpdateCompletion == nil && shippingContactUpdateCompletion == nil && couponUpdateHandlerIsNil {
|
|
366
396
|
resolve(Errors.createError(ErrorType.Failed, "You can use this method only after either onShippingContactSelected, onShippingMethodSelected, or onCouponCodeEntered callbacks are triggered"))
|
|
367
397
|
return
|
|
368
398
|
}
|
|
369
399
|
|
|
370
400
|
do {
|
|
371
|
-
applePaySummaryItems = try ApplePayUtils.buildPaymentSummaryItems(items: summaryItems as? [[String
|
|
401
|
+
applePaySummaryItems = try ApplePayUtils.buildPaymentSummaryItems(items: summaryItems as? [[String: Any]])
|
|
372
402
|
} catch {
|
|
373
403
|
resolve(Errors.createError(ErrorType.Failed, error.localizedDescription))
|
|
374
404
|
return
|
|
375
405
|
}
|
|
376
406
|
|
|
377
|
-
applePayShippingMethods = ApplePayUtils.buildShippingMethods(items: shippingMethods as? [[String
|
|
407
|
+
applePayShippingMethods = ApplePayUtils.buildShippingMethods(items: shippingMethods as? [[String: Any]])
|
|
378
408
|
|
|
379
409
|
do {
|
|
380
410
|
(applePayShippingAddressErrors, applePayCouponCodeErrors) = try ApplePayUtils.buildApplePayErrors(errorItems: errors)
|
|
@@ -383,7 +413,6 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
383
413
|
return
|
|
384
414
|
}
|
|
385
415
|
|
|
386
|
-
|
|
387
416
|
shippingMethodUpdateCompletion?(PKPaymentRequestShippingMethodUpdate.init(paymentSummaryItems: applePaySummaryItems))
|
|
388
417
|
shippingContactUpdateCompletion?(PKPaymentRequestShippingContactUpdate.init(errors: applePayShippingAddressErrors, paymentSummaryItems: applePaySummaryItems, shippingMethods: applePayShippingMethods))
|
|
389
418
|
if #available(iOS 15.0, *) {
|
|
@@ -396,40 +425,40 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
396
425
|
}
|
|
397
426
|
|
|
398
427
|
@objc(openApplePaySetup:rejecter:)
|
|
399
|
-
public func openApplePaySetup(resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock)
|
|
428
|
+
public func openApplePaySetup(resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
400
429
|
PKPassLibrary.init().openPaymentSetup()
|
|
401
430
|
resolve([])
|
|
402
431
|
}
|
|
403
432
|
|
|
404
433
|
@objc(handleURLCallback:resolver:rejecter:)
|
|
405
434
|
public func handleURLCallback(url: String?, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
435
|
+
guard let url = url else {
|
|
436
|
+
resolve(false)
|
|
437
|
+
return
|
|
438
|
+
}
|
|
439
|
+
let urlObj = URL(string: url)
|
|
440
|
+
if urlObj == nil {
|
|
441
|
+
resolve(false)
|
|
442
|
+
} else {
|
|
443
|
+
DispatchQueue.main.async {
|
|
444
|
+
let stripeHandled = StripeAPI.handleURLCallback(with: urlObj!)
|
|
445
|
+
resolve(stripeHandled)
|
|
446
|
+
}
|
|
417
447
|
}
|
|
418
|
-
}
|
|
419
448
|
}
|
|
420
449
|
|
|
421
450
|
@objc(isPlatformPaySupported:resolver:rejecter:)
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
451
|
+
public func isPlatformPaySupported(params: NSDictionary,
|
|
452
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
453
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
425
454
|
resolve(StripeAPI.deviceSupportsApplePay())
|
|
426
455
|
}
|
|
427
456
|
|
|
428
457
|
@objc(createPlatformPayPaymentMethod:usesDeprecatedTokenFlow:resolver:rejecter:)
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
458
|
+
public func createPlatformPayPaymentMethod(params: NSDictionary,
|
|
459
|
+
usesDeprecatedTokenFlow: Bool,
|
|
460
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
461
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
433
462
|
guard let applePayPatams = params["applePay"] as? NSDictionary else {
|
|
434
463
|
resolve(Errors.createError(ErrorType.Failed, "You must provide the `applePay` parameter."))
|
|
435
464
|
return
|
|
@@ -464,19 +493,19 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
464
493
|
}
|
|
465
494
|
|
|
466
495
|
@objc(dismissPlatformPay:rejecter:)
|
|
467
|
-
|
|
496
|
+
public func dismissPlatformPay(resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
468
497
|
let didDismiss = maybeDismissApplePay()
|
|
469
498
|
resolve(didDismiss)
|
|
470
499
|
}
|
|
471
500
|
|
|
472
501
|
@objc(confirmPlatformPay:params:isPaymentIntent:resolver:rejecter:)
|
|
473
|
-
|
|
502
|
+
public func confirmPlatformPay(
|
|
474
503
|
clientSecret: String?,
|
|
475
504
|
params: NSDictionary,
|
|
476
505
|
isPaymentIntent: Bool,
|
|
477
506
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
478
507
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
479
|
-
)
|
|
508
|
+
) {
|
|
480
509
|
guard let applePayPatams = params["applePay"] as? NSDictionary else {
|
|
481
510
|
resolve(Errors.createError(ErrorType.Failed, "You must provide the `applePay` parameter."))
|
|
482
511
|
return
|
|
@@ -499,7 +528,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
499
528
|
self.applePayCouponCodeErrors = nil
|
|
500
529
|
self.orderTrackingHandler = nil
|
|
501
530
|
self.confirmApplePayResolver = resolve
|
|
502
|
-
if
|
|
531
|
+
if isPaymentIntent {
|
|
503
532
|
self.confirmApplePayPaymentClientSecret = clientSecret
|
|
504
533
|
} else {
|
|
505
534
|
self.confirmApplePaySetupClientSecret = clientSecret
|
|
@@ -521,12 +550,12 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
521
550
|
}
|
|
522
551
|
|
|
523
552
|
@objc(createPaymentMethod:options:resolver:rejecter:)
|
|
524
|
-
|
|
553
|
+
public func createPaymentMethod(
|
|
525
554
|
params: NSDictionary,
|
|
526
555
|
options: NSDictionary,
|
|
527
556
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
528
557
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
529
|
-
)
|
|
558
|
+
) {
|
|
530
559
|
let type = Mappers.mapToPaymentMethodType(type: params["paymentMethodType"] as? String)
|
|
531
560
|
guard let paymentMethodType = type else {
|
|
532
561
|
resolve(Errors.createError(ErrorType.Failed, "You must provide paymentMethodType"))
|
|
@@ -563,11 +592,11 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
563
592
|
}
|
|
564
593
|
|
|
565
594
|
@objc(createToken:resolver:rejecter:)
|
|
566
|
-
|
|
595
|
+
public func createToken(
|
|
567
596
|
params: NSDictionary,
|
|
568
597
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
569
598
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
570
|
-
)
|
|
599
|
+
) {
|
|
571
600
|
guard let type = params["type"] as? String else {
|
|
572
601
|
resolve(Errors.createError(ErrorType.Failed, "type parameter is required"))
|
|
573
602
|
return
|
|
@@ -590,7 +619,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
590
619
|
params: NSDictionary,
|
|
591
620
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
592
621
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
593
|
-
)
|
|
622
|
+
) {
|
|
594
623
|
let accountHolderName = params["accountHolderName"] as? String
|
|
595
624
|
let accountHolderType = params["accountHolderType"] as? String
|
|
596
625
|
let accountNumber = params["accountNumber"] as? String
|
|
@@ -606,7 +635,6 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
606
635
|
bankAccountParams.routingNumber = routingNumber
|
|
607
636
|
bankAccountParams.accountHolderType = Mappers.mapToBankAccountHolderType(accountHolderType)
|
|
608
637
|
|
|
609
|
-
|
|
610
638
|
STPAPIClient.shared.createToken(withBankAccount: bankAccountParams) { token, error in
|
|
611
639
|
if let token = token {
|
|
612
640
|
resolve(Mappers.createResult("token", Mappers.mapFromToken(token: token)))
|
|
@@ -620,7 +648,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
620
648
|
params: NSDictionary,
|
|
621
649
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
622
650
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
623
|
-
)
|
|
651
|
+
) {
|
|
624
652
|
guard let personalId = params["personalId"] as? String else {
|
|
625
653
|
resolve(Errors.createError(ErrorType.Failed, "personalId parameter is required"))
|
|
626
654
|
return
|
|
@@ -639,7 +667,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
639
667
|
params: NSDictionary,
|
|
640
668
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
641
669
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
642
|
-
)
|
|
670
|
+
) {
|
|
643
671
|
let address = params["address"] as? NSDictionary
|
|
644
672
|
let cardSourceParams = STPCardParams()
|
|
645
673
|
if let params = cardFieldView?.cardParams as? STPPaymentMethodParams {
|
|
@@ -670,7 +698,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
670
698
|
}
|
|
671
699
|
|
|
672
700
|
@objc(handleNextAction:returnURL:resolver:rejecter:)
|
|
673
|
-
|
|
701
|
+
public func handleNextAction(
|
|
674
702
|
paymentIntentClientSecret: String,
|
|
675
703
|
returnURL: String?,
|
|
676
704
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
@@ -678,25 +706,21 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
678
706
|
){
|
|
679
707
|
let paymentHandler = STPPaymentHandler.shared()
|
|
680
708
|
paymentHandler.handleNextAction(forPayment: paymentIntentClientSecret, with: self, returnURL: returnURL) { status, paymentIntent, handleActionError in
|
|
681
|
-
switch
|
|
709
|
+
switch status {
|
|
682
710
|
case .failed:
|
|
683
711
|
resolve(Errors.createError(ErrorType.Failed, handleActionError))
|
|
684
|
-
break
|
|
685
712
|
case .canceled:
|
|
686
713
|
if let lastError = paymentIntent?.lastPaymentError {
|
|
687
714
|
resolve(Errors.createError(ErrorType.Canceled, lastError))
|
|
688
715
|
} else {
|
|
689
716
|
resolve(Errors.createError(ErrorType.Canceled, "The payment has been canceled"))
|
|
690
717
|
}
|
|
691
|
-
break
|
|
692
718
|
case .succeeded:
|
|
693
719
|
if let paymentIntent = paymentIntent {
|
|
694
720
|
resolve(Mappers.createResult("paymentIntent", Mappers.mapFromPaymentIntent(paymentIntent: paymentIntent)))
|
|
695
721
|
}
|
|
696
|
-
break
|
|
697
722
|
@unknown default:
|
|
698
723
|
resolve(Errors.createError(ErrorType.Unknown, "Cannot complete payment"))
|
|
699
|
-
break
|
|
700
724
|
}
|
|
701
725
|
}
|
|
702
726
|
}
|
|
@@ -710,40 +734,36 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
710
734
|
){
|
|
711
735
|
let paymentHandler = STPPaymentHandler.shared()
|
|
712
736
|
paymentHandler.handleNextAction(forSetupIntent: setupIntentClientSecret, with: self, returnURL: returnURL) { status, setupIntent, handleActionError in
|
|
713
|
-
switch
|
|
737
|
+
switch status {
|
|
714
738
|
case .failed:
|
|
715
739
|
resolve(Errors.createError(ErrorType.Failed, handleActionError))
|
|
716
|
-
break
|
|
717
740
|
case .canceled:
|
|
718
741
|
if let lastError = setupIntent?.lastSetupError {
|
|
719
742
|
resolve(Errors.createError(ErrorType.Canceled, lastError))
|
|
720
743
|
} else {
|
|
721
744
|
resolve(Errors.createError(ErrorType.Canceled, "The setup intent has been canceled"))
|
|
722
745
|
}
|
|
723
|
-
break
|
|
724
746
|
case .succeeded:
|
|
725
747
|
if let setupIntent = setupIntent {
|
|
726
748
|
resolve(Mappers.createResult("setupIntent", Mappers.mapFromSetupIntent(setupIntent: setupIntent)))
|
|
727
749
|
}
|
|
728
|
-
break
|
|
729
750
|
@unknown default:
|
|
730
751
|
resolve(Errors.createError(ErrorType.Unknown, "Cannot complete setup"))
|
|
731
|
-
break
|
|
732
752
|
}
|
|
733
753
|
}
|
|
734
754
|
}
|
|
735
755
|
|
|
736
756
|
@objc(collectBankAccount:clientSecret:params:resolver:rejecter:)
|
|
737
|
-
|
|
757
|
+
public func collectBankAccount(
|
|
738
758
|
isPaymentIntent: Bool,
|
|
739
759
|
clientSecret: NSString,
|
|
740
760
|
params: NSDictionary,
|
|
741
761
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
742
762
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
743
|
-
)
|
|
763
|
+
) {
|
|
744
764
|
let paymentMethodData = params["paymentMethodData"] as? NSDictionary
|
|
745
765
|
let type = Mappers.mapToPaymentMethodType(type: params["paymentMethodType"] as? String)
|
|
746
|
-
if
|
|
766
|
+
if type != STPPaymentMethodType.USBankAccount {
|
|
747
767
|
resolve(Errors.createError(ErrorType.Failed, "collectBankAccount currently only accepts the USBankAccount payment method type."))
|
|
748
768
|
return
|
|
749
769
|
}
|
|
@@ -753,7 +773,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
753
773
|
return
|
|
754
774
|
}
|
|
755
775
|
|
|
756
|
-
if
|
|
776
|
+
if name.isEmpty {
|
|
757
777
|
resolve(Errors.createError(ErrorType.Failed, "You must provide a name when collecting US bank account details."))
|
|
758
778
|
return
|
|
759
779
|
}
|
|
@@ -778,7 +798,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
778
798
|
let style = STPBankAccountCollectorUserInterfaceStyle(from: params)
|
|
779
799
|
let bankAccountCollector = STPBankAccountCollector(style: style)
|
|
780
800
|
|
|
781
|
-
if
|
|
801
|
+
if isPaymentIntent {
|
|
782
802
|
DispatchQueue.main.async {
|
|
783
803
|
bankAccountCollector.collectBankAccountForPayment(
|
|
784
804
|
clientSecret: clientSecret as String,
|
|
@@ -793,7 +813,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
793
813
|
}
|
|
794
814
|
|
|
795
815
|
if let intent = intent {
|
|
796
|
-
if
|
|
816
|
+
if intent.status == .requiresPaymentMethod {
|
|
797
817
|
resolve(Errors.createError(ErrorType.Canceled, "Bank account collection was canceled."))
|
|
798
818
|
} else {
|
|
799
819
|
resolve(
|
|
@@ -820,7 +840,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
820
840
|
}
|
|
821
841
|
|
|
822
842
|
if let intent = intent {
|
|
823
|
-
if
|
|
843
|
+
if intent.status == .requiresPaymentMethod {
|
|
824
844
|
resolve(Errors.createError(ErrorType.Canceled, "Bank account collection was canceled."))
|
|
825
845
|
} else {
|
|
826
846
|
resolve(
|
|
@@ -836,13 +856,13 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
836
856
|
}
|
|
837
857
|
|
|
838
858
|
@objc(confirmPayment:data:options:resolver:rejecter:)
|
|
839
|
-
|
|
859
|
+
public func confirmPayment(
|
|
840
860
|
paymentIntentClientSecret: String,
|
|
841
861
|
params: NSDictionary,
|
|
842
862
|
options: NSDictionary,
|
|
843
863
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
844
864
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
845
|
-
)
|
|
865
|
+
) {
|
|
846
866
|
self.confirmPaymentResolver = resolve
|
|
847
867
|
self.confirmPaymentClientSecret = paymentIntentClientSecret
|
|
848
868
|
|
|
@@ -850,14 +870,14 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
850
870
|
let actualParams = (params == NSNull()) ? nil : params
|
|
851
871
|
let paymentMethodData = actualParams?["paymentMethodData"] as? NSDictionary
|
|
852
872
|
let (missingPaymentMethodError, paymentMethodType) = getPaymentMethodType(params: actualParams)
|
|
853
|
-
if
|
|
873
|
+
if missingPaymentMethodError != nil {
|
|
854
874
|
resolve(missingPaymentMethodError)
|
|
855
875
|
return
|
|
856
876
|
}
|
|
857
877
|
|
|
858
878
|
let (error, paymentIntentParams) = createPaymentIntentParams(paymentIntentClientSecret: paymentIntentClientSecret, paymentMethodType: paymentMethodType, paymentMethodData: paymentMethodData, options: options)
|
|
859
879
|
|
|
860
|
-
if
|
|
880
|
+
if error != nil {
|
|
861
881
|
resolve(error)
|
|
862
882
|
} else {
|
|
863
883
|
STPPaymentHandler.shared().confirmPayment(paymentIntentParams, with: self, completion: onCompleteConfirmPayment)
|
|
@@ -884,11 +904,11 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
884
904
|
paymentMethodData: NSDictionary?,
|
|
885
905
|
options: NSDictionary
|
|
886
906
|
) -> (NSDictionary?, STPPaymentIntentParams) {
|
|
887
|
-
var err: NSDictionary?
|
|
907
|
+
var err: NSDictionary?
|
|
888
908
|
|
|
889
909
|
let paymentIntentParams: STPPaymentIntentParams = {
|
|
890
910
|
// If payment method data is not supplied, assume payment method was attached through via collectBankAccount
|
|
891
|
-
if
|
|
911
|
+
if paymentMethodType == .USBankAccount && paymentMethodData == nil {
|
|
892
912
|
return STPPaymentIntentParams(clientSecret: paymentIntentClientSecret, paymentMethodType: .USBankAccount)
|
|
893
913
|
} else {
|
|
894
914
|
guard let paymentMethodType = paymentMethodType else { return STPPaymentIntentParams(clientSecret: paymentIntentClientSecret) }
|
|
@@ -929,11 +949,11 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
929
949
|
}
|
|
930
950
|
|
|
931
951
|
@objc(retrievePaymentIntent:resolver:rejecter:)
|
|
932
|
-
|
|
952
|
+
public func retrievePaymentIntent(
|
|
933
953
|
clientSecret: String,
|
|
934
954
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
935
955
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
936
|
-
)
|
|
956
|
+
) {
|
|
937
957
|
STPAPIClient.shared.retrievePaymentIntent(withClientSecret: clientSecret) { (paymentIntent, error) in
|
|
938
958
|
guard error == nil else {
|
|
939
959
|
if let lastPaymentError = paymentIntent?.lastPaymentError {
|
|
@@ -953,11 +973,11 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
953
973
|
}
|
|
954
974
|
|
|
955
975
|
@objc(retrieveSetupIntent:resolver:rejecter:)
|
|
956
|
-
|
|
976
|
+
public func retrieveSetupIntent(
|
|
957
977
|
clientSecret: String,
|
|
958
978
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
959
979
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
960
|
-
)
|
|
980
|
+
) {
|
|
961
981
|
STPAPIClient.shared.retrieveSetupIntent(withClientSecret: clientSecret) { (setupIntent, error) in
|
|
962
982
|
guard error == nil else {
|
|
963
983
|
if let lastSetupError = setupIntent?.lastSetupError {
|
|
@@ -977,27 +997,27 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
977
997
|
}
|
|
978
998
|
|
|
979
999
|
@objc(verifyMicrodeposits:clientSecret:params:resolver:rejecter:)
|
|
980
|
-
|
|
1000
|
+
public func verifyMicrodeposits(
|
|
981
1001
|
isPaymentIntent: Bool,
|
|
982
1002
|
clientSecret: NSString,
|
|
983
1003
|
params: NSDictionary,
|
|
984
1004
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
985
1005
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
986
|
-
)
|
|
1006
|
+
) {
|
|
987
1007
|
let amounts = params["amounts"] as? NSArray
|
|
988
1008
|
let descriptorCode = params["descriptorCode"] as? String
|
|
989
1009
|
|
|
990
|
-
if
|
|
1010
|
+
if amounts != nil && descriptorCode != nil || amounts == nil && descriptorCode == nil {
|
|
991
1011
|
resolve(Errors.createError(ErrorType.Failed, "You must provide either amounts OR descriptorCode, not both."))
|
|
992
1012
|
return
|
|
993
1013
|
}
|
|
994
1014
|
|
|
995
1015
|
if let amounts = amounts {
|
|
996
|
-
if
|
|
1016
|
+
if amounts.count != 2 {
|
|
997
1017
|
resolve(Errors.createError(ErrorType.Failed, "Expected 2 integers in the amounts array, but received " + String(amounts.count)))
|
|
998
1018
|
return
|
|
999
1019
|
}
|
|
1000
|
-
if
|
|
1020
|
+
if isPaymentIntent {
|
|
1001
1021
|
STPAPIClient.shared.verifyPaymentIntentWithMicrodeposits(
|
|
1002
1022
|
clientSecret: clientSecret as String,
|
|
1003
1023
|
firstAmount: amounts[0] as! Int,
|
|
@@ -1013,7 +1033,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
1013
1033
|
)
|
|
1014
1034
|
}
|
|
1015
1035
|
} else if let descriptorCode = descriptorCode {
|
|
1016
|
-
if
|
|
1036
|
+
if isPaymentIntent {
|
|
1017
1037
|
STPAPIClient.shared.verifyPaymentIntentWithMicrodeposits(
|
|
1018
1038
|
clientSecret: clientSecret as String,
|
|
1019
1039
|
descriptorCode: descriptorCode,
|
|
@@ -1029,27 +1049,27 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
1029
1049
|
}
|
|
1030
1050
|
|
|
1031
1051
|
func onCompletePaymentVerification(intent: STPPaymentIntent?, error: Error?) {
|
|
1032
|
-
if
|
|
1052
|
+
if error != nil {
|
|
1033
1053
|
resolve(Errors.createError(ErrorType.Failed, error as NSError?))
|
|
1034
1054
|
} else {
|
|
1035
|
-
resolve(Mappers.createResult("paymentIntent", Mappers.mapFromPaymentIntent(paymentIntent:intent!)))
|
|
1055
|
+
resolve(Mappers.createResult("paymentIntent", Mappers.mapFromPaymentIntent(paymentIntent: intent!)))
|
|
1036
1056
|
}
|
|
1037
1057
|
}
|
|
1038
1058
|
func onCompleteSetupVerification(intent: STPSetupIntent?, error: Error?) {
|
|
1039
|
-
if
|
|
1059
|
+
if error != nil {
|
|
1040
1060
|
resolve(Errors.createError(ErrorType.Failed, error as NSError?))
|
|
1041
1061
|
} else {
|
|
1042
|
-
resolve(Mappers.createResult("setupIntent", Mappers.mapFromSetupIntent(setupIntent:intent!)))
|
|
1062
|
+
resolve(Mappers.createResult("setupIntent", Mappers.mapFromSetupIntent(setupIntent: intent!)))
|
|
1043
1063
|
}
|
|
1044
1064
|
}
|
|
1045
1065
|
}
|
|
1046
1066
|
|
|
1047
1067
|
@objc(canAddCardToWallet:resolver:rejecter:)
|
|
1048
|
-
|
|
1068
|
+
public func canAddCardToWallet(
|
|
1049
1069
|
params: NSDictionary,
|
|
1050
1070
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1051
1071
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1052
|
-
)
|
|
1072
|
+
) {
|
|
1053
1073
|
PushProvisioningUtils.canAddCardToWallet(
|
|
1054
1074
|
primaryAccountIdentifier: params["primaryAccountIdentifier"] as? String ?? "",
|
|
1055
1075
|
testEnv: params["testEnv"] as? Bool ?? false,
|
|
@@ -1063,11 +1083,11 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
1063
1083
|
}
|
|
1064
1084
|
|
|
1065
1085
|
@objc(isCardInWallet:resolver:rejecter:)
|
|
1066
|
-
|
|
1086
|
+
public func isCardInWallet(
|
|
1067
1087
|
params: NSDictionary,
|
|
1068
1088
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1069
1089
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1070
|
-
)
|
|
1090
|
+
) {
|
|
1071
1091
|
guard let last4 = params["cardLastFour"] as? String else {
|
|
1072
1092
|
resolve(Errors.createError(ErrorType.Failed, "You must provide `cardLastFour`"))
|
|
1073
1093
|
return
|
|
@@ -1076,13 +1096,13 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
1076
1096
|
}
|
|
1077
1097
|
|
|
1078
1098
|
@objc(collectBankAccountToken:params:resolver:rejecter:)
|
|
1079
|
-
|
|
1099
|
+
public func collectBankAccountToken(
|
|
1080
1100
|
clientSecret: String,
|
|
1081
1101
|
params: NSDictionary,
|
|
1082
1102
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1083
1103
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1084
|
-
)
|
|
1085
|
-
if
|
|
1104
|
+
) {
|
|
1105
|
+
if STPAPIClient.shared.publishableKey == nil {
|
|
1086
1106
|
resolve(Errors.MISSING_INIT_ERROR)
|
|
1087
1107
|
return
|
|
1088
1108
|
}
|
|
@@ -1101,11 +1121,11 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
1101
1121
|
}
|
|
1102
1122
|
|
|
1103
1123
|
FinancialConnections.presentForToken(
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1124
|
+
withClientSecret: clientSecret,
|
|
1125
|
+
returnURL: returnURL,
|
|
1126
|
+
configuration: configuration,
|
|
1127
|
+
onEvent: onEvent,
|
|
1128
|
+
resolve: resolve
|
|
1109
1129
|
)
|
|
1110
1130
|
}
|
|
1111
1131
|
|
|
@@ -1115,8 +1135,8 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
1115
1135
|
params: NSDictionary,
|
|
1116
1136
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1117
1137
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1118
|
-
)
|
|
1119
|
-
if
|
|
1138
|
+
) {
|
|
1139
|
+
if STPAPIClient.shared.publishableKey == nil {
|
|
1120
1140
|
resolve(Errors.MISSING_INIT_ERROR)
|
|
1121
1141
|
return
|
|
1122
1142
|
}
|
|
@@ -1135,16 +1155,16 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
1135
1155
|
}
|
|
1136
1156
|
|
|
1137
1157
|
FinancialConnections.present(
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1158
|
+
withClientSecret: clientSecret,
|
|
1159
|
+
returnURL: returnURL,
|
|
1160
|
+
configuration: configuration,
|
|
1161
|
+
onEvent: onEvent,
|
|
1162
|
+
resolve: resolve
|
|
1143
1163
|
)
|
|
1144
1164
|
}
|
|
1145
1165
|
|
|
1146
1166
|
@objc(configureOrderTracking:orderIdentifier:webServiceUrl:authenticationToken:resolver:rejecter:)
|
|
1147
|
-
|
|
1167
|
+
public func configureOrderTracking(
|
|
1148
1168
|
orderTypeIdentifier: String,
|
|
1149
1169
|
orderIdentifier: String,
|
|
1150
1170
|
webServiceUrl: String,
|
|
@@ -1152,7 +1172,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
1152
1172
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1153
1173
|
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1154
1174
|
) {
|
|
1155
|
-
#if compiler(>=5.7)
|
|
1175
|
+
#if compiler(>=5.7)
|
|
1156
1176
|
if #available(iOS 16.0, *) {
|
|
1157
1177
|
if let orderTrackingHandler = self.orderTrackingHandler {
|
|
1158
1178
|
if let url = URL(string: webServiceUrl) {
|
|
@@ -1166,9 +1186,638 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
1166
1186
|
self.orderTrackingHandler = nil
|
|
1167
1187
|
}
|
|
1168
1188
|
}
|
|
1169
|
-
#endif
|
|
1189
|
+
#endif
|
|
1170
1190
|
}
|
|
1171
1191
|
|
|
1192
|
+
#if canImport(StripeCryptoOnramp)
|
|
1193
|
+
@objc(configureOnramp:resolver:rejecter:)
|
|
1194
|
+
public func configureOnramp(
|
|
1195
|
+
config: NSDictionary,
|
|
1196
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1197
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1198
|
+
) {
|
|
1199
|
+
guard isPublishableKeyAvailable(resolve) else {
|
|
1200
|
+
return
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
let appearance: LinkAppearance = if let appearanceParams = config["appearance"] as? [String: Any?] {
|
|
1204
|
+
Mappers.mapToLinkAppearance(appearanceParams)
|
|
1205
|
+
} else {
|
|
1206
|
+
LinkAppearance()
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
let cryptoCustomerId = config["cryptoCustomerId"] as? String
|
|
1210
|
+
|
|
1211
|
+
Task {
|
|
1212
|
+
do {
|
|
1213
|
+
cryptoOnrampCoordinator = try await CryptoOnrampCoordinator.create(appearance: appearance, cryptoCustomerID: cryptoCustomerId)
|
|
1214
|
+
resolve([:]) // Return empty object on success
|
|
1215
|
+
} catch {
|
|
1216
|
+
let errorResult = Errors.createError(ErrorType.Failed, error)
|
|
1217
|
+
resolve(["error": errorResult["error"]!])
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
@objc(hasLinkAccount:resolver:rejecter:)
|
|
1223
|
+
public func hasLinkAccount(
|
|
1224
|
+
email: String,
|
|
1225
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1226
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1227
|
+
) {
|
|
1228
|
+
guard isPublishableKeyAvailable(resolve), let coordinator = requireOnrampCoordinator(resolve) else {
|
|
1229
|
+
return
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
Task {
|
|
1233
|
+
do {
|
|
1234
|
+
let hasLinkAccount = try await coordinator.hasLinkAccount(with: email)
|
|
1235
|
+
resolve(["hasLinkAccount": hasLinkAccount])
|
|
1236
|
+
} catch {
|
|
1237
|
+
let errorResult = Errors.createError(ErrorType.Failed, error)
|
|
1238
|
+
resolve(["error": errorResult["error"]!])
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
@objc(registerLinkUser:resolver:rejecter:)
|
|
1244
|
+
public func registerLinkUser(
|
|
1245
|
+
info: NSDictionary,
|
|
1246
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1247
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1248
|
+
) {
|
|
1249
|
+
guard isPublishableKeyAvailable(resolve), let coordinator = requireOnrampCoordinator(resolve) else {
|
|
1250
|
+
return
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
let email = info["email"] as? String ?? ""
|
|
1254
|
+
let phone = info["phone"] as? String ?? ""
|
|
1255
|
+
let country = info["country"] as? String ?? ""
|
|
1256
|
+
let fullName = info["fullName"] as? String
|
|
1257
|
+
|
|
1258
|
+
Task {
|
|
1259
|
+
do {
|
|
1260
|
+
let customerId = try await coordinator.registerLinkUser(email: email, fullName: fullName, phone: phone, country: country)
|
|
1261
|
+
resolve(["customerId": customerId])
|
|
1262
|
+
} catch {
|
|
1263
|
+
let errorResult = Errors.createError(ErrorType.Failed, error)
|
|
1264
|
+
resolve(["error": errorResult["error"]!])
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
@objc(authenticateUser:rejecter:)
|
|
1270
|
+
public func authenticateUser(
|
|
1271
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1272
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1273
|
+
) {
|
|
1274
|
+
guard isPublishableKeyAvailable(resolve), let coordinator = requireOnrampCoordinator(resolve) else {
|
|
1275
|
+
return
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
Task {
|
|
1279
|
+
do {
|
|
1280
|
+
let presentingViewController = await MainActor.run {
|
|
1281
|
+
findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController())
|
|
1282
|
+
}
|
|
1283
|
+
let result = try await coordinator.authenticateUser(from: presentingViewController)
|
|
1284
|
+
switch result {
|
|
1285
|
+
case let .completed(customerId):
|
|
1286
|
+
resolve(["customerId": customerId])
|
|
1287
|
+
case .canceled:
|
|
1288
|
+
let errorResult = Errors.createError(ErrorType.Canceled, "Authentication was cancelled")
|
|
1289
|
+
resolve(["error": errorResult["error"]!])
|
|
1290
|
+
}
|
|
1291
|
+
} catch {
|
|
1292
|
+
let errorResult = Errors.createError(ErrorType.Failed, error)
|
|
1293
|
+
resolve(["error": errorResult["error"]!])
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
@objc(authenticateUserWithToken:resolver:rejecter:)
|
|
1299
|
+
public func authenticateUserWithToken(
|
|
1300
|
+
_ linkAuthTokenClientSecret: String,
|
|
1301
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1302
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1303
|
+
) {
|
|
1304
|
+
guard isPublishableKeyAvailable(resolve), let coordinator = requireOnrampCoordinator(resolve) else {
|
|
1305
|
+
return
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
Task {
|
|
1309
|
+
do {
|
|
1310
|
+
try await coordinator.authenticateUserWithToken(linkAuthTokenClientSecret)
|
|
1311
|
+
resolve([:]) // Return empty object on success
|
|
1312
|
+
} catch {
|
|
1313
|
+
let errorResult = Errors.createError(ErrorType.Failed, error)
|
|
1314
|
+
resolve(["error": errorResult["error"]!])
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
@objc(registerWalletAddress:network:resolver:rejecter:)
|
|
1320
|
+
public func registerWalletAddress(
|
|
1321
|
+
address: String,
|
|
1322
|
+
network: String,
|
|
1323
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1324
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1325
|
+
) {
|
|
1326
|
+
guard isPublishableKeyAvailable(resolve), let coordinator = requireOnrampCoordinator(resolve) else {
|
|
1327
|
+
return
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
guard let cryptoNetwork = CryptoNetwork(rawValue: network as String) else {
|
|
1331
|
+
let errorResult = Errors.createError(ErrorType.Unknown, "Invalid network: \(network)")
|
|
1332
|
+
resolve(["error": errorResult["error"]!])
|
|
1333
|
+
return
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
Task {
|
|
1337
|
+
do {
|
|
1338
|
+
try await coordinator.registerWalletAddress(walletAddress: address, network: cryptoNetwork)
|
|
1339
|
+
resolve([:]) // Return empty object on success
|
|
1340
|
+
} catch {
|
|
1341
|
+
let errorResult = Errors.createError(ErrorType.Failed, error)
|
|
1342
|
+
resolve(["error": errorResult["error"]!])
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
@objc(attachKycInfo:resolver:rejecter:)
|
|
1348
|
+
public func attachKycInfo(
|
|
1349
|
+
info: NSDictionary,
|
|
1350
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1351
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1352
|
+
) {
|
|
1353
|
+
guard isPublishableKeyAvailable(resolve), let coordinator = requireOnrampCoordinator(resolve) else {
|
|
1354
|
+
return
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
guard let kycInfoDictionary = info as? [String: Any?] else {
|
|
1358
|
+
let errorResult = Errors.createError(ErrorType.Failed, "Unexpected format of KYC info dictionary. Expected String keys.")
|
|
1359
|
+
resolve(["error": errorResult["error"]!])
|
|
1360
|
+
return
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
Task {
|
|
1364
|
+
do {
|
|
1365
|
+
let kycInfo = try Mappers.mapToKycInfo(kycInfoDictionary)
|
|
1366
|
+
try await coordinator.attachKYCInfo(info: kycInfo)
|
|
1367
|
+
resolve([:]) // Return empty object on success
|
|
1368
|
+
} catch {
|
|
1369
|
+
if let missingFieldError = error as? Mappers.KycInfoError, case let .missingRequiredField(field) = missingFieldError {
|
|
1370
|
+
let errorResult = Errors.createError(ErrorType.Unknown, "Missing required field: \(field)")
|
|
1371
|
+
resolve(["error": errorResult["error"]!])
|
|
1372
|
+
} else {
|
|
1373
|
+
let errorResult = Errors.createError(ErrorType.Failed, error)
|
|
1374
|
+
resolve(["error": errorResult["error"]!])
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
@objc(presentKycInfoVerification:resolver:rejecter:)
|
|
1381
|
+
public func presentKycInfoVerification(
|
|
1382
|
+
updatedAddressDictionary: NSDictionary?,
|
|
1383
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1384
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1385
|
+
) {
|
|
1386
|
+
guard isPublishableKeyAvailable(resolve), let coordinator = requireOnrampCoordinator(resolve) else {
|
|
1387
|
+
return
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
let updatedAddress: Address?
|
|
1391
|
+
if let updatedAddressDictionary {
|
|
1392
|
+
guard let typedDictionary = updatedAddressDictionary as? [String: String] else {
|
|
1393
|
+
let errorResult = Errors.createError(ErrorType.Failed, "Unexpected format of address dictionary. Expected String keys and values.")
|
|
1394
|
+
resolve(["error": errorResult["error"]!])
|
|
1395
|
+
return
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
updatedAddress = Mappers.mapToKycAddress(typedDictionary)
|
|
1399
|
+
} else {
|
|
1400
|
+
updatedAddress = nil
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
Task {
|
|
1404
|
+
do {
|
|
1405
|
+
let presentingViewController = await MainActor.run {
|
|
1406
|
+
findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController())
|
|
1407
|
+
}
|
|
1408
|
+
let result = try await coordinator.verifyKYCInfo(updatedAddress: updatedAddress, from: presentingViewController)
|
|
1409
|
+
switch result {
|
|
1410
|
+
case .confirmed:
|
|
1411
|
+
resolve(["status": "Confirmed"])
|
|
1412
|
+
case .updateAddress:
|
|
1413
|
+
resolve(["status": "UpdateAddress"])
|
|
1414
|
+
case .canceled:
|
|
1415
|
+
let errorResult = Errors.createError(ErrorType.Canceled, "KYC info verification was cancelled")
|
|
1416
|
+
resolve(["error": errorResult["error"]!])
|
|
1417
|
+
}
|
|
1418
|
+
} catch {
|
|
1419
|
+
let errorResult = Errors.createError(ErrorType.Failed, error)
|
|
1420
|
+
resolve(["error": errorResult["error"]!])
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
@objc(updatePhoneNumber:resolver:rejecter:)
|
|
1426
|
+
public func updatePhoneNumber(
|
|
1427
|
+
phone: String,
|
|
1428
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1429
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1430
|
+
) {
|
|
1431
|
+
guard isPublishableKeyAvailable(resolve), let coordinator = requireOnrampCoordinator(resolve) else {
|
|
1432
|
+
return
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
Task {
|
|
1436
|
+
do {
|
|
1437
|
+
try await coordinator.updatePhoneNumber(to: phone)
|
|
1438
|
+
resolve([:]) // Return empty object on success
|
|
1439
|
+
} catch {
|
|
1440
|
+
let errorResult = Errors.createError(ErrorType.Failed, error)
|
|
1441
|
+
resolve(["error": errorResult["error"]!])
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
@objc(logout:rejecter:)
|
|
1447
|
+
public func logout(
|
|
1448
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1449
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1450
|
+
) {
|
|
1451
|
+
guard isPublishableKeyAvailable(resolve), let coordinator = requireOnrampCoordinator(resolve) else {
|
|
1452
|
+
return
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
Task {
|
|
1456
|
+
do {
|
|
1457
|
+
try await coordinator.logOut()
|
|
1458
|
+
resolve([:]) // Return empty object on success
|
|
1459
|
+
} catch {
|
|
1460
|
+
let errorResult = Errors.createError(ErrorType.Failed, error)
|
|
1461
|
+
resolve(["error": errorResult["error"]!])
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
@objc(verifyIdentity:rejecter:)
|
|
1467
|
+
public func verifyIdentity(
|
|
1468
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1469
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1470
|
+
) {
|
|
1471
|
+
guard isPublishableKeyAvailable(resolve), let coordinator = requireOnrampCoordinator(resolve) else {
|
|
1472
|
+
return
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
Task {
|
|
1476
|
+
do {
|
|
1477
|
+
let presentingViewController = await MainActor.run {
|
|
1478
|
+
findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController())
|
|
1479
|
+
}
|
|
1480
|
+
let result = try await coordinator.verifyIdentity(from: presentingViewController)
|
|
1481
|
+
switch result {
|
|
1482
|
+
case .completed:
|
|
1483
|
+
resolve([:]) // Return empty object on success
|
|
1484
|
+
case .canceled:
|
|
1485
|
+
resolve(["error": Errors.createError(ErrorType.Canceled, "Identity verification was cancelled")["error"]!])
|
|
1486
|
+
}
|
|
1487
|
+
} catch {
|
|
1488
|
+
let errorResult = Errors.createError(ErrorType.Failed, error)
|
|
1489
|
+
resolve(["error": errorResult["error"]!])
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
@objc(collectPaymentMethod:platformPayParams:resolver:rejecter:)
|
|
1495
|
+
public func collectPaymentMethod(
|
|
1496
|
+
paymentMethod: String,
|
|
1497
|
+
platformPayParams: NSDictionary,
|
|
1498
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1499
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1500
|
+
) {
|
|
1501
|
+
guard isPublishableKeyAvailable(resolve), let coordinator = requireOnrampCoordinator(resolve) else {
|
|
1502
|
+
return
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
var paymentMethodType: PaymentMethodType?
|
|
1506
|
+
switch paymentMethod {
|
|
1507
|
+
case "Card":
|
|
1508
|
+
paymentMethodType = .card
|
|
1509
|
+
case "BankAccount":
|
|
1510
|
+
paymentMethodType = .bankAccount
|
|
1511
|
+
case "PlatformPay":
|
|
1512
|
+
guard let applePayParams = platformPayParams["applePay"] as? NSDictionary else {
|
|
1513
|
+
resolve(Errors.createError(ErrorType.Failed, "You must provide the `applePay` parameter."))
|
|
1514
|
+
return
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
let (error, paymentRequest) = ApplePayUtils.createPaymentRequest(merchantIdentifier: merchantIdentifier, params: applePayParams)
|
|
1518
|
+
if let paymentRequest {
|
|
1519
|
+
paymentMethodType = .applePay(paymentRequest: paymentRequest)
|
|
1520
|
+
} else {
|
|
1521
|
+
resolve(Errors.createError(ErrorType.Failed, "Unable to create Apple Pay payment request: \(String(describing: error))"))
|
|
1522
|
+
return
|
|
1523
|
+
}
|
|
1524
|
+
default:
|
|
1525
|
+
resolve(Errors.createError(ErrorType.Failed, "Unsupported payment method: \(paymentMethod)"))
|
|
1526
|
+
return
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
guard let paymentMethodType else {
|
|
1530
|
+
// In all non-assignment branches above, we've already called `resolve` with error, so simply return.
|
|
1531
|
+
return
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
Task {
|
|
1535
|
+
do {
|
|
1536
|
+
let presentingViewController = await MainActor.run {
|
|
1537
|
+
findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController())
|
|
1538
|
+
}
|
|
1539
|
+
if let result = try await coordinator.collectPaymentMethod(type: paymentMethodType, from: presentingViewController) {
|
|
1540
|
+
let displayData = Mappers.paymentMethodDisplayDataToMap(result)
|
|
1541
|
+
resolve(["displayData": displayData])
|
|
1542
|
+
} else {
|
|
1543
|
+
let errorResult = Errors.createError(ErrorType.Canceled, "Payment collection was cancelled")
|
|
1544
|
+
resolve(["error": errorResult["error"]!])
|
|
1545
|
+
}
|
|
1546
|
+
} catch {
|
|
1547
|
+
let errorResult = Errors.createError(ErrorType.Failed, error)
|
|
1548
|
+
resolve(["error": errorResult["error"]!])
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
@objc(createCryptoPaymentToken:rejecter:)
|
|
1554
|
+
public func createCryptoPaymentToken(
|
|
1555
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1556
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1557
|
+
) {
|
|
1558
|
+
guard isPublishableKeyAvailable(resolve), let coordinator = requireOnrampCoordinator(resolve) else {
|
|
1559
|
+
return
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
Task {
|
|
1563
|
+
do {
|
|
1564
|
+
let token = try await coordinator.createCryptoPaymentToken()
|
|
1565
|
+
resolve(["cryptoPaymentToken": token])
|
|
1566
|
+
} catch {
|
|
1567
|
+
let errorResult = Errors.createError(ErrorType.Failed, error)
|
|
1568
|
+
resolve(["error": errorResult["error"]!])
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
@objc(performCheckout:resolver:rejecter:)
|
|
1574
|
+
public func performCheckout(
|
|
1575
|
+
onrampSessionId: String,
|
|
1576
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1577
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1578
|
+
) {
|
|
1579
|
+
guard isPublishableKeyAvailable(resolve), let coordinator = requireOnrampCoordinator(resolve) else {
|
|
1580
|
+
return
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
Task {
|
|
1584
|
+
do {
|
|
1585
|
+
let result = try await coordinator.performCheckout(onrampSessionId: onrampSessionId, authenticationContext: self) { [weak self] onrampSessionId in
|
|
1586
|
+
self?.onrampEmitter?.emitOnCheckoutClientSecretRequested(["onrampSessionId": onrampSessionId])
|
|
1587
|
+
|
|
1588
|
+
let clientSecret = try await withCheckedThrowingContinuation { [weak self] continuation in
|
|
1589
|
+
self?.cryptoOnrampCheckoutClientSecretContinuation = continuation
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
return clientSecret
|
|
1593
|
+
}
|
|
1594
|
+
switch result {
|
|
1595
|
+
case .completed:
|
|
1596
|
+
resolve([:]) // Return empty object on success
|
|
1597
|
+
case .canceled:
|
|
1598
|
+
let errorResult = Errors.createError(ErrorType.Canceled, "Checkout was cancelled")
|
|
1599
|
+
resolve(["error": errorResult["error"]!])
|
|
1600
|
+
}
|
|
1601
|
+
} catch {
|
|
1602
|
+
let errorResult = Errors.createError(ErrorType.Failed, error)
|
|
1603
|
+
resolve(["error": errorResult["error"]!])
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
@objc(provideCheckoutClientSecret:)
|
|
1609
|
+
public func provideCheckoutClientSecret(clientSecret: String?) {
|
|
1610
|
+
if let clientSecret {
|
|
1611
|
+
cryptoOnrampCheckoutClientSecretContinuation?.resume(returning: clientSecret)
|
|
1612
|
+
} else {
|
|
1613
|
+
let error = NSError(
|
|
1614
|
+
domain: ErrorType.Failed,
|
|
1615
|
+
code: -1,
|
|
1616
|
+
userInfo: [NSLocalizedDescriptionKey: "Failed to provide checkout client secret"]
|
|
1617
|
+
)
|
|
1618
|
+
cryptoOnrampCheckoutClientSecretContinuation?.resume(throwing: error)
|
|
1619
|
+
}
|
|
1620
|
+
cryptoOnrampCheckoutClientSecretContinuation = nil
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
@objc(onrampAuthorize:resolver:rejecter:)
|
|
1624
|
+
public func onrampAuthorize(
|
|
1625
|
+
linkAuthIntentId: String,
|
|
1626
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1627
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1628
|
+
) {
|
|
1629
|
+
guard isPublishableKeyAvailable(resolve), let coordinator = requireOnrampCoordinator(resolve) else {
|
|
1630
|
+
return
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
Task {
|
|
1634
|
+
do {
|
|
1635
|
+
let presentingViewController = await MainActor.run {
|
|
1636
|
+
findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController())
|
|
1637
|
+
}
|
|
1638
|
+
let authorizationResult = try await coordinator.authorize(linkAuthIntentId: linkAuthIntentId, from: presentingViewController)
|
|
1639
|
+
switch authorizationResult {
|
|
1640
|
+
case let .consented(customerId):
|
|
1641
|
+
resolve(["status": "Consented", "customerId": customerId])
|
|
1642
|
+
case .denied:
|
|
1643
|
+
resolve(["status": "Denied"])
|
|
1644
|
+
case.canceled:
|
|
1645
|
+
let errorResult = Errors.createError(ErrorType.Canceled, "Authorization was cancelled")
|
|
1646
|
+
resolve(["error": errorResult["error"]!])
|
|
1647
|
+
}
|
|
1648
|
+
} catch {
|
|
1649
|
+
let errorResult = Errors.createError(ErrorType.Failed, error)
|
|
1650
|
+
resolve(["error": errorResult["error"]!])
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
@objc(getCryptoTokenDisplayData:resolver:rejecter:)
|
|
1656
|
+
public func getCryptoTokenDisplayData(
|
|
1657
|
+
token: NSDictionary,
|
|
1658
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1659
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1660
|
+
) {
|
|
1661
|
+
let label = STPPaymentMethodType.link.displayName
|
|
1662
|
+
|
|
1663
|
+
if let cardDetails = token["card"] as? [String: Any] {
|
|
1664
|
+
let brand = cardDetails["brand"] as? String ?? ""
|
|
1665
|
+
let funding = cardDetails["funding"] as? String ?? ""
|
|
1666
|
+
let last4 = cardDetails["last4"] as? String ?? ""
|
|
1667
|
+
|
|
1668
|
+
let cardBrand = STPCard.brand(from: brand)
|
|
1669
|
+
let icon = STPImageLibrary.cardBrandImage(for: cardBrand)
|
|
1670
|
+
let brandName = STPCardBrandUtilities.stringFrom(cardBrand)
|
|
1671
|
+
|
|
1672
|
+
let mappedFunding = STPCardFundingType(funding)
|
|
1673
|
+
let formattedBrandName = String(format: mappedFunding.displayNameWithBrand, brandName ?? "")
|
|
1674
|
+
let sublabel = "\(formattedBrandName) •••• \(last4)"
|
|
1675
|
+
|
|
1676
|
+
let result = PaymentMethodDisplayData(icon: icon, label: label, sublabel: sublabel)
|
|
1677
|
+
let displayData = Mappers.paymentMethodDisplayDataToMap(result)
|
|
1678
|
+
|
|
1679
|
+
resolve(["displayData": displayData])
|
|
1680
|
+
} else if let bankDetails = token["us_bank_account"] as? [String: Any] {
|
|
1681
|
+
let bankName = bankDetails["bank_name"] as? String ?? ""
|
|
1682
|
+
let last4 = bankDetails["last4"] as? String ?? ""
|
|
1683
|
+
|
|
1684
|
+
let iconCode = PaymentSheetImageLibrary.bankIconCode(for: bankName)
|
|
1685
|
+
let icon = PaymentSheetImageLibrary.bankIcon(for: iconCode, iconStyle: .filled)
|
|
1686
|
+
let sublabel = "\(bankName) •••• \(last4)"
|
|
1687
|
+
|
|
1688
|
+
let result = PaymentMethodDisplayData(icon: icon, label: label, sublabel: sublabel)
|
|
1689
|
+
let displayData = Mappers.paymentMethodDisplayDataToMap(result)
|
|
1690
|
+
|
|
1691
|
+
resolve(["displayData": displayData])
|
|
1692
|
+
} else {
|
|
1693
|
+
let errorResult = Errors.createError(ErrorType.Unknown, "'type' parameter not unknown.")
|
|
1694
|
+
resolve(["error": errorResult["error"]!])
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
/// Checks for a `publishableKey`. Calls the resolve block with an error when one doesn’t exist.
|
|
1699
|
+
/// - Parameter resolve: The resolve block that is called with an error if no `publishableKey` is found.
|
|
1700
|
+
/// - Returns: `true` if a `publishableKey` was found. `false` otherwise.
|
|
1701
|
+
private func isPublishableKeyAvailable(_ resolve: @escaping RCTPromiseResolveBlock) -> Bool {
|
|
1702
|
+
if STPAPIClient.shared.publishableKey == nil {
|
|
1703
|
+
resolve(["error": Errors.MISSING_INIT_ERROR["error"]!])
|
|
1704
|
+
return false
|
|
1705
|
+
} else {
|
|
1706
|
+
return true
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
/// Returns the shared `CryptoOnrampCoordinator`, calling the resolve block with an error if CryptoOnramp has not yet been configured.
|
|
1711
|
+
/// - Parameter resolve: The resolve block that is called with an error if CryptoOnramp has not yet been configured.
|
|
1712
|
+
/// - Returns: The shared `CryptoOnrampCoordinator`, nor `nil` if CryptoOnramp has not yet been configured.
|
|
1713
|
+
private func requireOnrampCoordinator(_ resolve: @escaping RCTPromiseResolveBlock) -> CryptoOnrampCoordinator? {
|
|
1714
|
+
guard let coordinator = cryptoOnrampCoordinator else {
|
|
1715
|
+
let errorResult = Errors.createError(ErrorType.Failed, "CryptoOnramp not configured. Call -configureOnramp:resolver:rejecter: successfully first")
|
|
1716
|
+
resolve(["error": errorResult["error"]!])
|
|
1717
|
+
return nil
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
return coordinator
|
|
1721
|
+
}
|
|
1722
|
+
#else
|
|
1723
|
+
@objc(configureOnramp:resolver:rejecter:)
|
|
1724
|
+
public func configureOnramp(config: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
1725
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
@objc(hasLinkAccount:resolver:rejecter:)
|
|
1729
|
+
public func hasLinkAccount(email: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
1730
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
@objc(registerLinkUser:resolver:rejecter:)
|
|
1734
|
+
public func registerLinkUser(info: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
1735
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
@objc(authenticateUser:rejecter:)
|
|
1739
|
+
public func authenticateUser(resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
1740
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
@objc(authenticateUserWithToken:resolver:rejecter:)
|
|
1744
|
+
public func authenticateUserWithToken(
|
|
1745
|
+
_ linkAuthTokenClientSecret: String,
|
|
1746
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1747
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1748
|
+
) {
|
|
1749
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
@objc(registerWalletAddress:network:resolver:rejecter:)
|
|
1753
|
+
public func registerWalletAddress(address: String, network: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
1754
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
@objc(attachKycInfo:resolver:rejecter:)
|
|
1758
|
+
public func attachKycInfo(info: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
1759
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
@objc(presentKycInfoVerification:resolver:rejecter:)
|
|
1763
|
+
public func presentKycInfoVerification(
|
|
1764
|
+
updatedAddressDictionary: NSDictionary?,
|
|
1765
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1766
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1767
|
+
) {
|
|
1768
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
@objc(updatePhoneNumber:resolver:rejecter:)
|
|
1772
|
+
public func updatePhoneNumber(phone: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
1773
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
@objc(logout:rejecter:)
|
|
1777
|
+
public func logout(resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
1778
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
@objc(verifyIdentity:rejecter:)
|
|
1782
|
+
public func verifyIdentity(resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
1783
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
@objc(collectPaymentMethod:platformPayParams:resolver:rejecter:)
|
|
1787
|
+
public func collectPaymentMethod(paymentMethod: String, platformPayParams: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
1788
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
@objc(createCryptoPaymentToken:rejecter:)
|
|
1792
|
+
public func createCryptoPaymentToken(resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
1793
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
@objc(performCheckout:resolver:rejecter:)
|
|
1797
|
+
public func performCheckout(onrampSessionId: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
1798
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
@objc(provideCheckoutClientSecret:)
|
|
1802
|
+
public func provideCheckoutClientSecret(clientSecret: String?) {
|
|
1803
|
+
// no-op when Onramp is unavailable
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
@objc(onrampAuthorize:resolver:rejecter:)
|
|
1807
|
+
public func onrampAuthorize(linkAuthIntentId: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
1808
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
@objc(getCryptoTokenDisplayData:resolver:rejecter:)
|
|
1812
|
+
public func getCryptoTokenDisplayData(token: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
1813
|
+
resolveWithCryptoOnrampNotAvailableError(resolve)
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
private func resolveWithCryptoOnrampNotAvailableError(_ resolver: @escaping RCTPromiseResolveBlock) {
|
|
1817
|
+
resolver(Errors.createError(ErrorType.Failed, "StripeCryptoOnramp is not available. To enable, add the 'stripe-react-native/Onramp' subspec to your Podfile."))
|
|
1818
|
+
}
|
|
1819
|
+
#endif
|
|
1820
|
+
|
|
1172
1821
|
@objc(setFinancialConnectionsForceNativeFlow:resolver:rejecter:)
|
|
1173
1822
|
public func setFinancialConnectionsForceNativeFlow(
|
|
1174
1823
|
enabled: Bool,
|
|
@@ -1179,19 +1828,81 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
1179
1828
|
resolve(nil)
|
|
1180
1829
|
}
|
|
1181
1830
|
|
|
1831
|
+
@objc(openAuthenticatedWebView:url:resolver:rejecter:)
|
|
1832
|
+
public func openAuthenticatedWebView(
|
|
1833
|
+
id: String,
|
|
1834
|
+
url: String,
|
|
1835
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1836
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1837
|
+
) {
|
|
1838
|
+
guard let url = URL(string: url) else {
|
|
1839
|
+
resolve(Errors.createError(ErrorType.Failed, "Invalid URL"))
|
|
1840
|
+
return
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
DispatchQueue.main.async { [weak self] in
|
|
1844
|
+
guard let self = self else {
|
|
1845
|
+
resolve(Errors.createError(ErrorType.Failed, "StripeSdkImpl instance deallocated"))
|
|
1846
|
+
return
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
// Create the authentication session with the configured URL scheme
|
|
1850
|
+
self.authenticationSession = ASWebAuthenticationSession(
|
|
1851
|
+
url: url,
|
|
1852
|
+
callbackURLScheme: nil
|
|
1853
|
+
) { callbackURL, error in
|
|
1854
|
+
if let error = error {
|
|
1855
|
+
// User canceled or an error occurred
|
|
1856
|
+
if (error as NSError).code == ASWebAuthenticationSessionError.canceledLogin.rawValue {
|
|
1857
|
+
// User canceled - resolve successfully as this is expected behavior
|
|
1858
|
+
resolve([])
|
|
1859
|
+
} else {
|
|
1860
|
+
resolve(Errors.createError(ErrorType.Failed, error as NSError))
|
|
1861
|
+
}
|
|
1862
|
+
} else if let callbackURL = callbackURL {
|
|
1863
|
+
// Return the callback URL
|
|
1864
|
+
let result: [String: Any] = ["url": callbackURL.absoluteString]
|
|
1865
|
+
resolve(result)
|
|
1866
|
+
} else {
|
|
1867
|
+
// Session completed successfully without a callback URL
|
|
1868
|
+
resolve([])
|
|
1869
|
+
}
|
|
1870
|
+
|
|
1871
|
+
// Clean up the session and context provider
|
|
1872
|
+
self.authenticationSession = nil
|
|
1873
|
+
self.authenticationContextProvider = nil
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
// Configure the session for iOS 13+
|
|
1877
|
+
if #available(iOS 13.0, *) {
|
|
1878
|
+
let contextProvider = ASWebAuthenticationPresentationContextProvider()
|
|
1879
|
+
self.authenticationContextProvider = contextProvider
|
|
1880
|
+
self.authenticationSession?.presentationContextProvider = contextProvider
|
|
1881
|
+
self.authenticationSession?.prefersEphemeralWebBrowserSession = false
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
// Start the session
|
|
1885
|
+
guard self.authenticationSession?.start() == true else {
|
|
1886
|
+
resolve(Errors.createError(ErrorType.Failed, "Failed to start authentication session"))
|
|
1887
|
+
self.authenticationSession = nil
|
|
1888
|
+
self.authenticationContextProvider = nil
|
|
1889
|
+
return
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1182
1894
|
public func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
|
|
1183
1895
|
confirmPaymentResolver?(Errors.createError(ErrorType.Canceled, "FPX Payment has been canceled"))
|
|
1184
1896
|
}
|
|
1185
1897
|
|
|
1186
1898
|
func onCompleteConfirmPayment(status: STPPaymentHandlerActionStatus, paymentIntent: STPPaymentIntent?, error: NSError?) {
|
|
1187
1899
|
self.confirmPaymentClientSecret = nil
|
|
1188
|
-
switch
|
|
1900
|
+
switch status {
|
|
1189
1901
|
case .failed:
|
|
1190
1902
|
confirmPaymentResolver?(Errors.createError(ErrorType.Failed, error))
|
|
1191
|
-
break
|
|
1192
1903
|
case .canceled:
|
|
1193
1904
|
let statusCode: String
|
|
1194
|
-
if
|
|
1905
|
+
if paymentIntent?.status == STPPaymentIntentStatus.requiresPaymentMethod {
|
|
1195
1906
|
statusCode = ErrorType.Failed
|
|
1196
1907
|
} else {
|
|
1197
1908
|
statusCode = ErrorType.Canceled
|
|
@@ -1201,27 +1912,24 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate {
|
|
|
1201
1912
|
} else {
|
|
1202
1913
|
confirmPaymentResolver?(Errors.createError(statusCode, "The payment has been canceled"))
|
|
1203
1914
|
}
|
|
1204
|
-
break
|
|
1205
1915
|
case .succeeded:
|
|
1206
1916
|
if let paymentIntent = paymentIntent {
|
|
1207
1917
|
let intent = Mappers.mapFromPaymentIntent(paymentIntent: paymentIntent)
|
|
1208
1918
|
confirmPaymentResolver?(Mappers.createResult("paymentIntent", intent))
|
|
1209
1919
|
}
|
|
1210
|
-
break
|
|
1211
1920
|
@unknown default:
|
|
1212
1921
|
confirmPaymentResolver?(Errors.createError(ErrorType.Unknown, "Cannot complete the payment"))
|
|
1213
|
-
break
|
|
1214
1922
|
}
|
|
1215
1923
|
}
|
|
1216
1924
|
|
|
1217
1925
|
struct ConfirmationError: Error, LocalizedError {
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1926
|
+
private var errorMessage: String
|
|
1927
|
+
init(errorMessage: String) {
|
|
1928
|
+
self.errorMessage = errorMessage
|
|
1929
|
+
}
|
|
1930
|
+
public var errorDescription: String? {
|
|
1931
|
+
return errorMessage
|
|
1932
|
+
}
|
|
1225
1933
|
}
|
|
1226
1934
|
}
|
|
1227
1935
|
|
|
@@ -1241,7 +1949,7 @@ func findViewControllerPresenter(from uiViewController: UIViewController) -> UIV
|
|
|
1241
1949
|
}
|
|
1242
1950
|
|
|
1243
1951
|
extension StripeSdkImpl: STPAuthenticationContext {
|
|
1244
|
-
|
|
1952
|
+
public func authenticationPresentingViewController() -> UIViewController {
|
|
1245
1953
|
return findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController())
|
|
1246
1954
|
}
|
|
1247
1955
|
}
|
|
@@ -1287,3 +1995,23 @@ extension FinancialConnectionsSheet.Configuration {
|
|
|
1287
1995
|
self.init(style: style)
|
|
1288
1996
|
}
|
|
1289
1997
|
}
|
|
1998
|
+
|
|
1999
|
+
private extension STPCardFundingType {
|
|
2000
|
+
var displayNameWithBrand: String {
|
|
2001
|
+
switch self {
|
|
2002
|
+
case .credit: String.Localized.Funding.credit
|
|
2003
|
+
case .debit: String.Localized.Funding.debit
|
|
2004
|
+
case .prepaid: String.Localized.Funding.prepaid
|
|
2005
|
+
case .other: String.Localized.Funding.default
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
init(_ typeString: String) {
|
|
2010
|
+
self = switch typeString {
|
|
2011
|
+
case "debit": .debit
|
|
2012
|
+
case "credit": .credit
|
|
2013
|
+
case "prepaid": .prepaid
|
|
2014
|
+
default: .other
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
}
|