@stripe/stripe-react-native 0.12.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -9
- package/README.md +2 -2
- package/android/.DS_Store +0 -0
- package/android/.gradle/7.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/.gitignore +3 -0
- package/android/.idea/gradle.xml +13 -0
- package/android/.idea/misc.xml +9 -0
- package/android/.idea/modules/android.iml +18 -0
- package/android/.idea/modules.xml +8 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/.idea/workspace.xml +52 -0
- package/android/build.gradle +11 -0
- package/android/local.properties +8 -0
- package/android/src/.DS_Store +0 -0
- package/android/src/androidTest/.DS_Store +0 -0
- package/android/src/androidTest/java/com/reactnativestripesdk/pushprovisioning/PushProvisioningProxyTest.kt +35 -0
- package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +21 -6
- package/android/src/main/java/com/reactnativestripesdk/CardFieldViewManager.kt +5 -0
- package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +8 -0
- package/android/src/main/java/com/reactnativestripesdk/CardFormViewManager.kt +5 -0
- package/android/src/main/java/com/reactnativestripesdk/Mappers.kt +21 -7
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +9 -3
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +59 -2
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt +0 -1
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/PushProvisioningProxy.kt +19 -7
- package/android/src/main/java/com/reactnativestripesdk/pushprovisioning/TapAndPayProxy.kt +45 -38
- package/ios/.DS_Store +0 -0
- package/ios/CardFieldManager.m +1 -0
- package/ios/CardFieldView.swift +17 -8
- package/ios/Mappers.swift +8 -9
- package/ios/StripeSdk.m +5 -0
- package/ios/StripeSdk.swift +151 -119
- package/ios/StripeSdk.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/StripeSdk.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/StripeSdk.xcodeproj/project.xcworkspace/xcuserdata/charliecruzan.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/StripeSdk.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme +52 -0
- package/ios/StripeSdk.xcodeproj/xcuserdata/charliecruzan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +22 -0
- package/ios/StripeSdk.xcodeproj/xcuserdata/charliecruzan.xcuserdatad/xcschemes/xcschememanagement.plist +27 -0
- package/ios/Tests/PushProvisioningTests.swift +49 -0
- package/ios/pushprovisioning/AddToWalletButtonView.swift +1 -5
- package/ios/pushprovisioning/PushProvisioningUtils.swift +64 -0
- package/lib/commonjs/NativeStripeSdk.js.map +1 -1
- package/lib/commonjs/components/AddToWalletButton.js +1 -1
- package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
- package/lib/commonjs/components/ApplePayButton.js +1 -1
- package/lib/commonjs/components/ApplePayButton.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/GooglePayButton.js +1 -1
- package/lib/commonjs/components/GooglePayButton.js.map +1 -1
- package/lib/commonjs/components/StripeContainer.js +1 -1
- package/lib/commonjs/components/StripeContainer.js.map +1 -1
- package/lib/commonjs/functions.js +1 -1
- package/lib/commonjs/functions.js.map +1 -1
- package/lib/commonjs/hooks/useStripe.js +1 -1
- package/lib/commonjs/hooks/useStripe.js.map +1 -1
- package/lib/commonjs/types/components/CardFieldInput.js.map +1 -1
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/module/NativeStripeSdk.js.map +1 -1
- package/lib/module/components/AddToWalletButton.js +1 -1
- package/lib/module/components/AddToWalletButton.js.map +1 -1
- package/lib/module/components/ApplePayButton.js +1 -1
- package/lib/module/components/ApplePayButton.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/GooglePayButton.js +1 -1
- package/lib/module/components/GooglePayButton.js.map +1 -1
- package/lib/module/components/StripeContainer.js +1 -1
- package/lib/module/components/StripeContainer.js.map +1 -1
- package/lib/module/functions.js +1 -1
- package/lib/module/functions.js.map +1 -1
- package/lib/module/hooks/useStripe.js +1 -1
- package/lib/module/hooks/useStripe.js.map +1 -1
- package/lib/module/types/components/CardFieldInput.js.map +1 -1
- package/lib/module/types/index.js.map +1 -1
- package/lib/typescript/e2e/screenObject/BasicPaymentScreen.d.ts +1 -2
- package/lib/typescript/src/NativeStripeSdk.d.ts +2 -1
- package/lib/typescript/src/components/AddToWalletButton.d.ts +1 -1
- package/lib/typescript/src/components/CardField.d.ts +3 -0
- package/lib/typescript/src/components/CardForm.d.ts +2 -0
- package/lib/typescript/src/functions.d.ts +2 -1
- package/lib/typescript/src/hooks/useStripe.d.ts +2 -1
- package/lib/typescript/src/types/PaymentSheet.d.ts +2 -1
- package/lib/typescript/src/types/Token.d.ts +9 -1
- package/lib/typescript/src/types/components/CardFieldInput.d.ts +1 -0
- package/lib/typescript/src/types/components/CardFormView.d.ts +6 -0
- package/lib/typescript/src/types/index.d.ts +21 -4
- package/package.json +6 -4
- package/src/NativeStripeSdk.tsx +5 -0
- package/src/components/AddToWalletButton.tsx +1 -1
- package/src/components/CardField.tsx +5 -0
- package/src/components/CardForm.tsx +6 -0
- package/src/functions.ts +26 -1
- package/src/hooks/useStripe.tsx +13 -0
- package/src/types/PaymentSheet.ts +2 -1
- package/src/types/Token.ts +13 -1
- package/src/types/components/CardFieldInput.ts +1 -0
- package/src/types/components/CardFormView.ts +7 -0
- package/src/types/index.ts +28 -5
- package/stripe-react-native.podspec +6 -1
package/ios/StripeSdk.swift
CHANGED
|
@@ -7,10 +7,10 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
7
7
|
public var cardFormView: CardFormView? = nil
|
|
8
8
|
|
|
9
9
|
var merchantIdentifier: String? = nil
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
private var paymentSheet: PaymentSheet?
|
|
12
12
|
private var paymentSheetFlowController: PaymentSheet.FlowController?
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
var urlScheme: String? = nil
|
|
15
15
|
|
|
16
16
|
var applePayCompletionCallback: STPIntentClientSecretCompletionBlock? = nil
|
|
@@ -19,20 +19,20 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
19
19
|
var applePayCompletionRejecter: RCTPromiseRejectBlock? = nil
|
|
20
20
|
var confirmApplePayPaymentResolver: RCTPromiseResolveBlock? = nil
|
|
21
21
|
var confirmPaymentResolver: RCTPromiseResolveBlock? = nil
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
var confirmPaymentClientSecret: String? = nil
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
var shippingMethodUpdateHandler: ((PKPaymentRequestShippingMethodUpdate) -> Void)? = nil
|
|
26
26
|
var shippingContactUpdateHandler: ((PKPaymentRequestShippingContactUpdate) -> Void)? = nil
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
override func supportedEvents() -> [String]! {
|
|
29
29
|
return ["onDidSetShippingMethod", "onDidSetShippingContact"]
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
@objc override static func requiresMainQueueSetup() -> Bool {
|
|
33
33
|
return false
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
@objc override func constantsToExport() -> [AnyHashable : Any] {
|
|
37
37
|
return [
|
|
38
38
|
"API_VERSIONS": [
|
|
@@ -41,7 +41,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
41
41
|
]
|
|
42
42
|
]
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
@objc(initialise:resolver:rejecter:)
|
|
46
46
|
func initialise(params: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
47
47
|
let publishableKey = params["publishableKey"] as! String
|
|
@@ -50,21 +50,21 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
50
50
|
let params3ds = params["threeDSecureParams"] as? NSDictionary
|
|
51
51
|
let urlScheme = params["urlScheme"] as? String
|
|
52
52
|
let merchantIdentifier = params["merchantIdentifier"] as? String
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
if let params3ds = params3ds {
|
|
55
55
|
configure3dSecure(params3ds)
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
self.urlScheme = urlScheme
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
STPAPIClient.shared.publishableKey = publishableKey
|
|
61
61
|
STPAPIClient.shared.stripeAccount = stripeAccountId
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
let name = RCTConvert.nsString(appInfo["name"]) ?? ""
|
|
64
64
|
let partnerId = RCTConvert.nsString(appInfo["partnerId"]) ?? ""
|
|
65
65
|
let version = RCTConvert.nsString(appInfo["version"]) ?? ""
|
|
66
66
|
let url = RCTConvert.nsString(appInfo["url"]) ?? ""
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
STPAPIClient.shared.appInfo = STPAppInfo(name: name, partnerId: partnerId, version: version, url: url)
|
|
69
69
|
self.merchantIdentifier = merchantIdentifier
|
|
70
70
|
resolve(NSNull())
|
|
@@ -75,7 +75,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
75
75
|
rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
76
76
|
var configuration = PaymentSheet.Configuration()
|
|
77
77
|
self.paymentSheetFlowController = nil
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
if let appearanceParams = params["appearance"] as? NSDictionary {
|
|
80
80
|
do {
|
|
81
81
|
configuration.appearance = try buildPaymentSheetAppearance(userParams: appearanceParams)
|
|
@@ -84,7 +84,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
84
84
|
return
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
if params["applePay"] as? Bool == true {
|
|
89
89
|
if let merchantIdentifier = self.merchantIdentifier, let merchantCountryCode = params["merchantCountryCode"] as? String {
|
|
90
90
|
configuration.applePay = .init(merchantId: merchantIdentifier,
|
|
@@ -94,24 +94,24 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
94
94
|
return
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
if let merchantDisplayName = params["merchantDisplayName"] as? String {
|
|
99
99
|
configuration.merchantDisplayName = merchantDisplayName
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
if let returnURL = params["returnURL"] as? String {
|
|
103
103
|
configuration.returnURL = returnURL
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
if let allowsDelayedPaymentMethods = params["allowsDelayedPaymentMethods"] as? Bool {
|
|
107
107
|
configuration.allowsDelayedPaymentMethods = allowsDelayedPaymentMethods
|
|
108
108
|
}
|
|
109
|
-
|
|
109
|
+
|
|
110
110
|
if let defaultBillingDetails = params["defaultBillingDetails"] as? [String: Any?] {
|
|
111
111
|
configuration.defaultBillingDetails.name = defaultBillingDetails["name"] as? String
|
|
112
112
|
configuration.defaultBillingDetails.email = defaultBillingDetails["email"] as? String
|
|
113
113
|
configuration.defaultBillingDetails.phone = defaultBillingDetails["phone"] as? String
|
|
114
|
-
|
|
114
|
+
|
|
115
115
|
if let address = defaultBillingDetails["address"] as? [String: String] {
|
|
116
116
|
configuration.defaultBillingDetails.address = .init(city: address["city"],
|
|
117
117
|
country: address["country"],
|
|
@@ -120,9 +120,9 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
120
120
|
postalCode: address["postalCode"],
|
|
121
121
|
state: address["state"])
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
|
|
124
124
|
}
|
|
125
|
-
|
|
125
|
+
|
|
126
126
|
if let customerId = params["customerId"] as? String {
|
|
127
127
|
if let customerEphemeralKeySecret = params["customerEphemeralKeySecret"] as? String {
|
|
128
128
|
if (!Errors.isEKClientSecretValid(clientSecret: customerEphemeralKeySecret)) {
|
|
@@ -132,13 +132,13 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
132
132
|
configuration.customer = .init(id: customerId, ephemeralKeySecret: customerEphemeralKeySecret)
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
|
|
136
136
|
if #available(iOS 13.0, *) {
|
|
137
137
|
if let style = params["style"] as? String {
|
|
138
138
|
configuration.style = Mappers.mapToUserInterfaceStyle(style)
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
-
|
|
141
|
+
|
|
142
142
|
func handlePaymentSheetFlowControllerResult(result: Result<PaymentSheet.FlowController, Error>, stripeSdk: StripeSdk?) {
|
|
143
143
|
switch result {
|
|
144
144
|
case .failure(let error):
|
|
@@ -156,13 +156,13 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
|
|
159
|
+
|
|
160
160
|
if let paymentIntentClientSecret = params["paymentIntentClientSecret"] as? String {
|
|
161
161
|
if (!Errors.isPIClientSecretValid(clientSecret: paymentIntentClientSecret)) {
|
|
162
162
|
resolve(Errors.createError(ErrorType.Failed, "`secret` format does not match expected client secret formatting."))
|
|
163
163
|
return
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
|
|
166
166
|
if params["customFlow"] as? Bool == true {
|
|
167
167
|
PaymentSheet.FlowController.create(paymentIntentClientSecret: paymentIntentClientSecret,
|
|
168
168
|
configuration: configuration) { [weak self] result in
|
|
@@ -177,7 +177,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
177
177
|
resolve(Errors.createError(ErrorType.Failed, "`secret` format does not match expected client secret formatting."))
|
|
178
178
|
return
|
|
179
179
|
}
|
|
180
|
-
|
|
180
|
+
|
|
181
181
|
if params["customFlow"] as? Bool == true {
|
|
182
182
|
PaymentSheet.FlowController.create(setupIntentClientSecret: setupIntentClientSecret,
|
|
183
183
|
configuration: configuration) { [weak self] result in
|
|
@@ -190,7 +190,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
190
190
|
} else {
|
|
191
191
|
resolve(Errors.createError(ErrorType.Failed, "You must provide either paymentIntentClientSecret or setupIntentClientSecret"))
|
|
192
192
|
}
|
|
193
|
-
|
|
193
|
+
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
@objc(confirmPaymentSheetPayment:rejecter:)
|
|
@@ -204,22 +204,22 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
204
204
|
resolve([])
|
|
205
205
|
self.paymentSheetFlowController = nil
|
|
206
206
|
case .canceled:
|
|
207
|
-
resolve(Errors.createError(ErrorType.Canceled, "The payment has been canceled"))
|
|
207
|
+
resolve(Errors.createError(ErrorType.Canceled, "The payment flow has been canceled"))
|
|
208
208
|
case .failed(let error):
|
|
209
209
|
resolve(Errors.createError(ErrorType.Failed, error.localizedDescription))
|
|
210
210
|
}
|
|
211
|
-
|
|
211
|
+
|
|
212
212
|
}
|
|
213
213
|
} else {
|
|
214
214
|
resolve(Errors.createError(ErrorType.Failed, "No payment sheet has been initialized yet"))
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
|
-
|
|
218
|
+
|
|
219
219
|
@objc(presentPaymentSheet:rejecter:)
|
|
220
220
|
func presentPaymentSheet(resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
221
221
|
rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
222
|
-
|
|
222
|
+
|
|
223
223
|
DispatchQueue.main.async {
|
|
224
224
|
if let paymentSheetFlowController = self.paymentSheetFlowController {
|
|
225
225
|
paymentSheetFlowController.presentPaymentOptions(from:
|
|
@@ -232,7 +232,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
232
232
|
]
|
|
233
233
|
resolve(Mappers.createResult("paymentOption", option))
|
|
234
234
|
} else {
|
|
235
|
-
resolve(
|
|
235
|
+
resolve(Errors.createError(ErrorType.Canceled, "The payment option selection flow has been canceled"))
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
} else if let paymentSheet = self.paymentSheet {
|
|
@@ -254,14 +254,14 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
|
-
|
|
257
|
+
|
|
258
258
|
@objc(createTokenForCVCUpdate:resolver:rejecter:)
|
|
259
259
|
func createTokenForCVCUpdate(cvc: String?, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
260
260
|
guard let cvc = cvc else {
|
|
261
261
|
resolve(Errors.createError(ErrorType.Failed, "You must provide CVC"))
|
|
262
262
|
return;
|
|
263
263
|
}
|
|
264
|
-
|
|
264
|
+
|
|
265
265
|
STPAPIClient.shared.createToken(forCVCUpdate: cvc) { (token, error) in
|
|
266
266
|
if error != nil || token == nil {
|
|
267
267
|
resolve(Errors.createError(ErrorType.Failed, error?.localizedDescription ?? ""))
|
|
@@ -271,7 +271,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
|
-
|
|
274
|
+
|
|
275
275
|
@objc(confirmSetupIntent:data:options:resolver:rejecter:)
|
|
276
276
|
func confirmSetupIntent (setupIntentClientSecret: String, params: NSDictionary,
|
|
277
277
|
options: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
@@ -282,11 +282,11 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
282
282
|
resolve(Errors.createError(ErrorType.Failed, "You must provide paymentMethodType."))
|
|
283
283
|
return
|
|
284
284
|
}
|
|
285
|
-
|
|
285
|
+
|
|
286
286
|
if (paymentMethodType == .payPal) {
|
|
287
287
|
resolve(Errors.createError(ErrorType.Failed, "PayPal is not yet supported through SetupIntents."))
|
|
288
288
|
}
|
|
289
|
-
|
|
289
|
+
|
|
290
290
|
var err: NSDictionary? = nil
|
|
291
291
|
let setupIntentParams: STPSetupIntentConfirmParams = {
|
|
292
292
|
// If payment method data is not supplied, assume payment method was attached through via collectBankAccount
|
|
@@ -301,20 +301,20 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
301
301
|
} catch {
|
|
302
302
|
err = Errors.createError(ErrorType.Failed, error as NSError?)
|
|
303
303
|
}
|
|
304
|
-
|
|
304
|
+
|
|
305
305
|
return parameters
|
|
306
306
|
}
|
|
307
307
|
}()
|
|
308
|
-
|
|
308
|
+
|
|
309
309
|
if (err != nil) {
|
|
310
310
|
resolve(err)
|
|
311
311
|
return
|
|
312
312
|
}
|
|
313
|
-
|
|
313
|
+
|
|
314
314
|
if let urlScheme = urlScheme {
|
|
315
315
|
setupIntentParams.returnURL = Mappers.mapToReturnURL(urlScheme: urlScheme)
|
|
316
316
|
}
|
|
317
|
-
|
|
317
|
+
|
|
318
318
|
let paymentHandler = STPPaymentHandler.shared()
|
|
319
319
|
paymentHandler.confirmSetupIntent(setupIntentParams, with: self) { status, setupIntent, error in
|
|
320
320
|
switch (status) {
|
|
@@ -337,7 +337,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
|
-
|
|
340
|
+
|
|
341
341
|
@objc(updateApplePaySummaryItems:errorAddressFields:resolver:rejecter:)
|
|
342
342
|
func updateApplePaySummaryItems(summaryItems: NSArray, errorAddressFields: [NSDictionary], resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
343
343
|
if (shippingMethodUpdateHandler == nil && shippingContactUpdateHandler == nil) {
|
|
@@ -367,7 +367,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
367
367
|
self.shippingContactUpdateHandler = nil
|
|
368
368
|
resolve([])
|
|
369
369
|
}
|
|
370
|
-
|
|
370
|
+
|
|
371
371
|
@objc(openApplePaySetup:rejecter:)
|
|
372
372
|
func openApplePaySetup(resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
373
373
|
let library = PKPassLibrary.init()
|
|
@@ -378,21 +378,21 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
378
378
|
resolve(Errors.createError(ErrorType.Failed, "Cannot open payment setup"))
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
|
-
|
|
382
|
-
|
|
381
|
+
|
|
382
|
+
|
|
383
383
|
func applePayContext(_ context: STPApplePayContext, didSelect shippingMethod: PKShippingMethod, handler: @escaping (PKPaymentRequestShippingMethodUpdate) -> Void) {
|
|
384
384
|
self.shippingMethodUpdateHandler = handler
|
|
385
385
|
sendEvent(withName: "onDidSetShippingMethod", body: ["shippingMethod": Mappers.mapFromShippingMethod(shippingMethod: shippingMethod)])
|
|
386
386
|
}
|
|
387
|
-
|
|
387
|
+
|
|
388
388
|
func applePayContext(_ context: STPApplePayContext, didSelectShippingContact contact: PKContact, handler: @escaping (PKPaymentRequestShippingContactUpdate) -> Void) {
|
|
389
389
|
self.shippingContactUpdateHandler = handler
|
|
390
390
|
sendEvent(withName: "onDidSetShippingContact", body: ["shippingContact": Mappers.mapFromShippingContact(shippingContact: contact)])
|
|
391
391
|
}
|
|
392
|
-
|
|
392
|
+
|
|
393
393
|
func applePayContext(_ context: STPApplePayContext, didCreatePaymentMethod paymentMethod: STPPaymentMethod, paymentInformation: PKPayment, completion: @escaping STPIntentClientSecretCompletionBlock) {
|
|
394
394
|
self.applePayCompletionCallback = completion
|
|
395
|
-
|
|
395
|
+
|
|
396
396
|
let address = paymentMethod.billingDetails?.address?.line1?.split(whereSeparator: \.isNewline)
|
|
397
397
|
if (address?.indices.contains(0) == true) {
|
|
398
398
|
paymentMethod.billingDetails?.address?.line1 = String(address?[0] ?? "")
|
|
@@ -400,19 +400,19 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
400
400
|
if (address?.indices.contains(1) == true) {
|
|
401
401
|
paymentMethod.billingDetails?.address?.line2 = String(address?[1] ?? "")
|
|
402
402
|
}
|
|
403
|
-
|
|
403
|
+
|
|
404
404
|
let method = Mappers.mapFromPaymentMethod(paymentMethod)
|
|
405
405
|
self.applePayRequestResolver?(Mappers.createResult("paymentMethod", method))
|
|
406
406
|
self.applePayRequestRejecter = nil
|
|
407
407
|
}
|
|
408
|
-
|
|
408
|
+
|
|
409
409
|
@objc(confirmApplePayPayment:resolver:rejecter:)
|
|
410
410
|
func confirmApplePayPayment(clientSecret: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
411
411
|
self.applePayCompletionRejecter = reject
|
|
412
412
|
self.confirmApplePayPaymentResolver = resolve
|
|
413
413
|
self.applePayCompletionCallback?(clientSecret, nil)
|
|
414
414
|
}
|
|
415
|
-
|
|
415
|
+
|
|
416
416
|
func applePayContext(_ context: STPApplePayContext, didCompleteWith status: STPPaymentStatus, error: Error?) {
|
|
417
417
|
switch status {
|
|
418
418
|
case .success:
|
|
@@ -442,14 +442,14 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
442
442
|
applePayRequestRejecter = nil
|
|
443
443
|
}
|
|
444
444
|
}
|
|
445
|
-
|
|
445
|
+
|
|
446
446
|
@objc(isApplePaySupported:rejecter:)
|
|
447
447
|
func isApplePaySupported(resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
448
448
|
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
449
449
|
let isSupported = StripeAPI.deviceSupportsApplePay()
|
|
450
450
|
resolve(isSupported)
|
|
451
451
|
}
|
|
452
|
-
|
|
452
|
+
|
|
453
453
|
@objc(handleURLCallback:resolver:rejecter:)
|
|
454
454
|
func handleURLCallback(url: String?, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
455
455
|
guard let url = url else {
|
|
@@ -466,7 +466,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
466
466
|
}
|
|
467
467
|
}
|
|
468
468
|
}
|
|
469
|
-
|
|
469
|
+
|
|
470
470
|
@objc(presentApplePay:resolver:rejecter:)
|
|
471
471
|
func presentApplePay(params: NSDictionary,
|
|
472
472
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
@@ -475,11 +475,11 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
475
475
|
reject(ErrorType.Failed, "You must provide merchantIdentifier", nil)
|
|
476
476
|
return
|
|
477
477
|
}
|
|
478
|
-
|
|
478
|
+
|
|
479
479
|
if (params["jcbEnabled"] as? Bool == true) {
|
|
480
480
|
StripeAPI.additionalEnabledApplePayNetworks = [.JCB]
|
|
481
481
|
}
|
|
482
|
-
|
|
482
|
+
|
|
483
483
|
guard let summaryItems = params["cartItems"] as? NSArray else {
|
|
484
484
|
reject(ErrorType.Failed, "You must provide the items for purchase", nil)
|
|
485
485
|
return
|
|
@@ -492,29 +492,29 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
492
492
|
reject(ErrorType.Failed, "You must provide the payment currency", nil)
|
|
493
493
|
return
|
|
494
494
|
}
|
|
495
|
-
|
|
495
|
+
|
|
496
496
|
self.applePayRequestResolver = resolve
|
|
497
497
|
self.applePayRequestRejecter = reject
|
|
498
|
-
|
|
498
|
+
|
|
499
499
|
let merchantIdentifier = self.merchantIdentifier ?? ""
|
|
500
500
|
let paymentRequest = StripeAPI.paymentRequest(withMerchantIdentifier: merchantIdentifier, country: country, currency: currency)
|
|
501
|
-
|
|
501
|
+
|
|
502
502
|
let requiredShippingAddressFields = params["requiredShippingAddressFields"] as? NSArray ?? NSArray()
|
|
503
503
|
let requiredBillingContactFields = params["requiredBillingContactFields"] as? NSArray ?? NSArray()
|
|
504
504
|
let shippingMethods = params["shippingMethods"] as? NSArray ?? NSArray()
|
|
505
|
-
|
|
505
|
+
|
|
506
506
|
paymentRequest.requiredShippingContactFields = Set(requiredShippingAddressFields.map {
|
|
507
507
|
Mappers.mapToPKContactField(field: $0 as! String)
|
|
508
508
|
})
|
|
509
|
-
|
|
509
|
+
|
|
510
510
|
paymentRequest.requiredBillingContactFields = Set(requiredBillingContactFields.map {
|
|
511
511
|
Mappers.mapToPKContactField(field: $0 as! String)
|
|
512
512
|
})
|
|
513
|
-
|
|
513
|
+
|
|
514
514
|
paymentRequest.shippingMethods = Mappers.mapToShippingMethods(shippingMethods: shippingMethods)
|
|
515
|
-
|
|
515
|
+
|
|
516
516
|
var paymentSummaryItems: [PKPaymentSummaryItem] = []
|
|
517
|
-
|
|
517
|
+
|
|
518
518
|
if let items = summaryItems as? [[String : Any]] {
|
|
519
519
|
for item in items {
|
|
520
520
|
let label = item["label"] as? String ?? ""
|
|
@@ -523,7 +523,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
523
523
|
paymentSummaryItems.append(PKPaymentSummaryItem(label: label, amount: amount, type: type))
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
|
-
|
|
526
|
+
|
|
527
527
|
paymentRequest.paymentSummaryItems = paymentSummaryItems
|
|
528
528
|
if let applePayContext = STPApplePayContext(paymentRequest: paymentRequest, delegate: self) {
|
|
529
529
|
DispatchQueue.main.async {
|
|
@@ -537,10 +537,10 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
537
537
|
func configure3dSecure(_ params: NSDictionary) {
|
|
538
538
|
let threeDSCustomizationSettings = STPPaymentHandler.shared().threeDSCustomizationSettings
|
|
539
539
|
let uiCustomization = Mappers.mapUICustomization(params)
|
|
540
|
-
|
|
540
|
+
|
|
541
541
|
threeDSCustomizationSettings.uiCustomization = uiCustomization
|
|
542
542
|
}
|
|
543
|
-
|
|
543
|
+
|
|
544
544
|
@objc(createPaymentMethod:options:resolver:rejecter:)
|
|
545
545
|
func createPaymentMethod(
|
|
546
546
|
params: NSDictionary,
|
|
@@ -553,7 +553,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
553
553
|
resolve(Errors.createError(ErrorType.Failed, "You must provide paymentMethodType"))
|
|
554
554
|
return
|
|
555
555
|
}
|
|
556
|
-
|
|
556
|
+
|
|
557
557
|
var paymentMethodParams: STPPaymentMethodParams?
|
|
558
558
|
let factory = PaymentMethodFactory.init(
|
|
559
559
|
paymentMethodData: params["paymentMethodData"] as? NSDictionary,
|
|
@@ -567,14 +567,14 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
567
567
|
resolve(Errors.createError(ErrorType.Failed, error.localizedDescription))
|
|
568
568
|
return
|
|
569
569
|
}
|
|
570
|
-
|
|
570
|
+
|
|
571
571
|
if let paymentMethodParams = paymentMethodParams {
|
|
572
572
|
STPAPIClient.shared.createPaymentMethod(with: paymentMethodParams) { paymentMethod, error in
|
|
573
573
|
if let createError = error {
|
|
574
574
|
resolve(Errors.createError(ErrorType.Failed, createError.localizedDescription))
|
|
575
575
|
return
|
|
576
576
|
}
|
|
577
|
-
|
|
577
|
+
|
|
578
578
|
if let paymentMethod = paymentMethod {
|
|
579
579
|
let method = Mappers.mapFromPaymentMethod(paymentMethod)
|
|
580
580
|
resolve(Mappers.createResult("paymentMethod", method))
|
|
@@ -584,7 +584,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
584
584
|
resolve(Errors.createError(ErrorType.Unknown, "Unhandled error occured"))
|
|
585
585
|
}
|
|
586
586
|
}
|
|
587
|
-
|
|
587
|
+
|
|
588
588
|
@objc(createToken:resolver:rejecter:)
|
|
589
589
|
func createToken(
|
|
590
590
|
params: NSDictionary,
|
|
@@ -595,18 +595,20 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
595
595
|
resolve(Errors.createError(ErrorType.Failed, "type parameter is required"))
|
|
596
596
|
return
|
|
597
597
|
}
|
|
598
|
-
|
|
598
|
+
|
|
599
599
|
// TODO: Consider moving this to its own class when more types are supported.
|
|
600
600
|
switch type {
|
|
601
601
|
case "BankAccount":
|
|
602
602
|
createTokenFromBankAccount(params: params, resolver: resolve, rejecter: reject)
|
|
603
603
|
case "Card":
|
|
604
604
|
createTokenFromCard(params: params, resolver: resolve, rejecter: reject)
|
|
605
|
+
case "Pii":
|
|
606
|
+
createTokenFromPii(params: params, resolver: resolve, rejecter: reject)
|
|
605
607
|
default:
|
|
606
608
|
resolve(Errors.createError(ErrorType.Failed, type + " type is not supported yet"))
|
|
607
609
|
}
|
|
608
610
|
}
|
|
609
|
-
|
|
611
|
+
|
|
610
612
|
func createTokenFromBankAccount(
|
|
611
613
|
params: NSDictionary,
|
|
612
614
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
@@ -626,8 +628,8 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
626
628
|
bankAccountParams.currency = currency
|
|
627
629
|
bankAccountParams.routingNumber = routingNumber
|
|
628
630
|
bankAccountParams.accountHolderType = Mappers.mapToBankAccountHolderType(accountHolderType)
|
|
629
|
-
|
|
630
|
-
|
|
631
|
+
|
|
632
|
+
|
|
631
633
|
STPAPIClient.shared.createToken(withBankAccount: bankAccountParams) { token, error in
|
|
632
634
|
if let token = token {
|
|
633
635
|
resolve(Mappers.createResult("token", Mappers.mapFromToken(token: token)))
|
|
@@ -636,7 +638,26 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
636
638
|
}
|
|
637
639
|
}
|
|
638
640
|
}
|
|
639
|
-
|
|
641
|
+
|
|
642
|
+
func createTokenFromPii(
|
|
643
|
+
params: NSDictionary,
|
|
644
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
645
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
646
|
+
) -> Void {
|
|
647
|
+
guard let personalId = params["personalId"] as? String else {
|
|
648
|
+
resolve(Errors.createError(ErrorType.Failed, "personalId parameter is required"))
|
|
649
|
+
return
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
STPAPIClient.shared.createToken(withPersonalIDNumber: personalId) { token, error in
|
|
653
|
+
if let token = token {
|
|
654
|
+
resolve(Mappers.createResult("token", Mappers.mapFromToken(token: token)))
|
|
655
|
+
} else {
|
|
656
|
+
resolve(Errors.createError(ErrorType.Failed, error as NSError?))
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
640
661
|
func createTokenFromCard(
|
|
641
662
|
params: NSDictionary,
|
|
642
663
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
@@ -646,7 +667,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
646
667
|
resolve(Errors.createError(ErrorType.Failed, "Card details not complete"))
|
|
647
668
|
return
|
|
648
669
|
}
|
|
649
|
-
|
|
670
|
+
|
|
650
671
|
let address = params["address"] as? NSDictionary
|
|
651
672
|
let cardSourceParams = STPCardParams()
|
|
652
673
|
cardSourceParams.number = cardParams.number
|
|
@@ -665,7 +686,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
665
686
|
}
|
|
666
687
|
}
|
|
667
688
|
}
|
|
668
|
-
|
|
689
|
+
|
|
669
690
|
@objc(handleNextAction:resolver:rejecter:)
|
|
670
691
|
func handleNextAction(
|
|
671
692
|
paymentIntentClientSecret: String,
|
|
@@ -696,7 +717,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
696
717
|
}
|
|
697
718
|
}
|
|
698
719
|
}
|
|
699
|
-
|
|
720
|
+
|
|
700
721
|
@objc(collectBankAccount:clientSecret:params:resolver:rejecter:)
|
|
701
722
|
func collectBankAccount(
|
|
702
723
|
isPaymentIntent: Bool,
|
|
@@ -711,22 +732,22 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
711
732
|
resolve(Errors.createError(ErrorType.Failed, "collectBankAccount currently only accepts the USBankAccount payment method type."))
|
|
712
733
|
return
|
|
713
734
|
}
|
|
714
|
-
|
|
735
|
+
|
|
715
736
|
guard let billingDetails = paymentMethodData?["billingDetails"] as? [String: Any?], let name = billingDetails["name"] as? String else {
|
|
716
737
|
resolve(Errors.createError(ErrorType.Failed, "You must provide a name when collecting US bank account details."))
|
|
717
738
|
return
|
|
718
739
|
}
|
|
719
|
-
|
|
740
|
+
|
|
720
741
|
if (name.isEmpty) {
|
|
721
742
|
resolve(Errors.createError(ErrorType.Failed, "You must provide a name when collecting US bank account details."))
|
|
722
743
|
return
|
|
723
744
|
}
|
|
724
|
-
|
|
745
|
+
|
|
725
746
|
let collectParams = STPCollectBankAccountParams.collectUSBankAccountParams(
|
|
726
747
|
with: name,
|
|
727
748
|
email: billingDetails["email"] as? String
|
|
728
749
|
)
|
|
729
|
-
|
|
750
|
+
|
|
730
751
|
if (isPaymentIntent) {
|
|
731
752
|
DispatchQueue.main.async {
|
|
732
753
|
STPBankAccountCollector().collectBankAccountForPayment(
|
|
@@ -738,7 +759,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
738
759
|
resolve(Errors.createError(ErrorType.Failed, error as NSError))
|
|
739
760
|
return
|
|
740
761
|
}
|
|
741
|
-
|
|
762
|
+
|
|
742
763
|
if let intent = intent {
|
|
743
764
|
if (intent.status == .requiresPaymentMethod) {
|
|
744
765
|
resolve(Errors.createError(ErrorType.Canceled, "Bank account collection was canceled."))
|
|
@@ -762,7 +783,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
762
783
|
resolve(Errors.createError(ErrorType.Failed, error as NSError))
|
|
763
784
|
return
|
|
764
785
|
}
|
|
765
|
-
|
|
786
|
+
|
|
766
787
|
if let intent = intent {
|
|
767
788
|
if (intent.status == .requiresPaymentMethod) {
|
|
768
789
|
resolve(Errors.createError(ErrorType.Canceled, "Bank account collection was canceled."))
|
|
@@ -788,14 +809,14 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
788
809
|
) -> Void {
|
|
789
810
|
self.confirmPaymentResolver = resolve
|
|
790
811
|
self.confirmPaymentClientSecret = paymentIntentClientSecret
|
|
791
|
-
|
|
812
|
+
|
|
792
813
|
let paymentMethodData = params["paymentMethodData"] as? NSDictionary
|
|
793
814
|
let type = Mappers.mapToPaymentMethodType(type: params["paymentMethodType"] as? String)
|
|
794
815
|
guard let paymentMethodType = type else {
|
|
795
816
|
resolve(Errors.createError(ErrorType.Failed, "You must provide paymentMethodType"))
|
|
796
817
|
return
|
|
797
818
|
}
|
|
798
|
-
|
|
819
|
+
|
|
799
820
|
if (paymentMethodType == .FPX) {
|
|
800
821
|
let testOfflineBank = paymentMethodData?["testOfflineBank"] as? Bool
|
|
801
822
|
if (testOfflineBank == false || testOfflineBank == nil) {
|
|
@@ -803,16 +824,16 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
803
824
|
return
|
|
804
825
|
}
|
|
805
826
|
}
|
|
806
|
-
|
|
827
|
+
|
|
807
828
|
let (error, paymentIntentParams) = createPaymentIntentParams(paymentIntentClientSecret: paymentIntentClientSecret, paymentMethodType: paymentMethodType, paymentMethodData: paymentMethodData, options: options)
|
|
808
|
-
|
|
829
|
+
|
|
809
830
|
if (error != nil) {
|
|
810
831
|
resolve(error)
|
|
811
832
|
} else {
|
|
812
833
|
STPPaymentHandler.shared().confirmPayment(paymentIntentParams, with: self, completion: onCompleteConfirmPayment)
|
|
813
834
|
}
|
|
814
835
|
}
|
|
815
|
-
|
|
836
|
+
|
|
816
837
|
func createPaymentIntentParams(
|
|
817
838
|
paymentIntentClientSecret: String,
|
|
818
839
|
paymentMethodType: STPPaymentMethodType,
|
|
@@ -821,7 +842,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
821
842
|
) -> (NSDictionary?, STPPaymentIntentParams) {
|
|
822
843
|
let factory = PaymentMethodFactory.init(paymentMethodData: paymentMethodData, options: options, cardFieldView: cardFieldView, cardFormView: cardFormView)
|
|
823
844
|
var err: NSDictionary? = nil
|
|
824
|
-
|
|
845
|
+
|
|
825
846
|
let paymentIntentParams: STPPaymentIntentParams = {
|
|
826
847
|
// If payment method data is not supplied, assume payment method was attached through via collectBankAccount
|
|
827
848
|
if (paymentMethodType == .USBankAccount && paymentMethodData == nil) {
|
|
@@ -829,7 +850,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
829
850
|
} else {
|
|
830
851
|
let paymentMethodId = paymentMethodData?["paymentMethodId"] as? String
|
|
831
852
|
let parameters = STPPaymentIntentParams(clientSecret: paymentIntentClientSecret)
|
|
832
|
-
|
|
853
|
+
|
|
833
854
|
if paymentMethodId != nil {
|
|
834
855
|
parameters.paymentMethodId = paymentMethodId
|
|
835
856
|
} else {
|
|
@@ -845,7 +866,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
845
866
|
return parameters
|
|
846
867
|
}
|
|
847
868
|
}()
|
|
848
|
-
|
|
869
|
+
|
|
849
870
|
if let setupFutureUsage = options["setupFutureUsage"] as? String {
|
|
850
871
|
paymentIntentParams.setupFutureUsage = Mappers.mapToPaymentIntentFutureUsage(usage: setupFutureUsage)
|
|
851
872
|
}
|
|
@@ -853,7 +874,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
853
874
|
paymentIntentParams.returnURL = Mappers.mapToReturnURL(urlScheme: urlScheme)
|
|
854
875
|
}
|
|
855
876
|
paymentIntentParams.shipping = Mappers.mapToShippingDetails(shippingDetails: paymentMethodData?["shippingDetails"] as? NSDictionary)
|
|
856
|
-
|
|
877
|
+
|
|
857
878
|
return (err, paymentIntentParams)
|
|
858
879
|
}
|
|
859
880
|
|
|
@@ -870,10 +891,10 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
870
891
|
} else {
|
|
871
892
|
resolve(Errors.createError(ErrorType.Unknown, error?.localizedDescription))
|
|
872
893
|
}
|
|
873
|
-
|
|
894
|
+
|
|
874
895
|
return
|
|
875
896
|
}
|
|
876
|
-
|
|
897
|
+
|
|
877
898
|
if let paymentIntent = paymentIntent {
|
|
878
899
|
resolve(Mappers.createResult("paymentIntent", Mappers.mapFromPaymentIntent(paymentIntent: paymentIntent)))
|
|
879
900
|
} else {
|
|
@@ -881,7 +902,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
881
902
|
}
|
|
882
903
|
}
|
|
883
904
|
}
|
|
884
|
-
|
|
905
|
+
|
|
885
906
|
@objc(retrieveSetupIntent:resolver:rejecter:)
|
|
886
907
|
func retrieveSetupIntent(
|
|
887
908
|
clientSecret: String,
|
|
@@ -895,10 +916,10 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
895
916
|
} else {
|
|
896
917
|
resolve(Errors.createError(ErrorType.Unknown, error?.localizedDescription))
|
|
897
918
|
}
|
|
898
|
-
|
|
919
|
+
|
|
899
920
|
return
|
|
900
921
|
}
|
|
901
|
-
|
|
922
|
+
|
|
902
923
|
if let setupIntent = setupIntent {
|
|
903
924
|
resolve(Mappers.createResult("setupIntent", Mappers.mapFromSetupIntent(setupIntent: setupIntent)))
|
|
904
925
|
} else {
|
|
@@ -906,7 +927,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
906
927
|
}
|
|
907
928
|
}
|
|
908
929
|
}
|
|
909
|
-
|
|
930
|
+
|
|
910
931
|
@objc(verifyMicrodeposits:clientSecret:params:resolver:rejecter:)
|
|
911
932
|
func verifyMicrodeposits(
|
|
912
933
|
isPaymentIntent: Bool,
|
|
@@ -917,12 +938,12 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
917
938
|
) -> Void {
|
|
918
939
|
let amounts = params["amounts"] as? NSArray
|
|
919
940
|
let descriptorCode = params["descriptorCode"] as? String
|
|
920
|
-
|
|
941
|
+
|
|
921
942
|
if (amounts != nil && descriptorCode != nil || amounts == nil && descriptorCode == nil) {
|
|
922
943
|
resolve(Errors.createError(ErrorType.Failed, "You must provide either amounts OR descriptorCode, not both."))
|
|
923
944
|
return
|
|
924
945
|
}
|
|
925
|
-
|
|
946
|
+
|
|
926
947
|
if let amounts = amounts {
|
|
927
948
|
if (amounts.count != 2) {
|
|
928
949
|
resolve(Errors.createError(ErrorType.Failed, "Expected 2 integers in the amounts array, but received " + String(amounts.count)))
|
|
@@ -958,7 +979,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
958
979
|
)
|
|
959
980
|
}
|
|
960
981
|
}
|
|
961
|
-
|
|
982
|
+
|
|
962
983
|
func onCompletePaymentVerification(intent: STPPaymentIntent?, error: Error?) {
|
|
963
984
|
if (error != nil) {
|
|
964
985
|
resolve(Errors.createError(ErrorType.Failed, error as NSError?))
|
|
@@ -975,6 +996,25 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
975
996
|
}
|
|
976
997
|
}
|
|
977
998
|
|
|
999
|
+
@objc(canAddCardToWallet:resolver:rejecter:)
|
|
1000
|
+
func canAddCardToWallet(
|
|
1001
|
+
params: NSDictionary,
|
|
1002
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1003
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1004
|
+
) -> Void {
|
|
1005
|
+
guard let last4 = params["cardLastFour"] as? String else {
|
|
1006
|
+
resolve(Errors.createError(ErrorType.Failed, "You must provide `cardLastFour`"))
|
|
1007
|
+
return
|
|
1008
|
+
}
|
|
1009
|
+
let (canAddCard, status) = PushProvisioningUtils.canAddCardToWallet(last4: last4,
|
|
1010
|
+
primaryAccountIdentifier: params["primaryAccountIdentifier"] as? String ?? "",
|
|
1011
|
+
testEnv: params["testEnv"] as? Bool ?? false)
|
|
1012
|
+
resolve([
|
|
1013
|
+
"canAddCard": canAddCard,
|
|
1014
|
+
"details": ["status": status?.rawValue],
|
|
1015
|
+
])
|
|
1016
|
+
}
|
|
1017
|
+
|
|
978
1018
|
@objc(isCardInWallet:resolver:rejecter:)
|
|
979
1019
|
func isCardInWallet(
|
|
980
1020
|
params: NSDictionary,
|
|
@@ -985,26 +1025,18 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
985
1025
|
resolve(Errors.createError(ErrorType.Failed, "You must provide `cardLastFour`"))
|
|
986
1026
|
return
|
|
987
1027
|
}
|
|
988
|
-
|
|
989
|
-
let existingPass: PKPass? = {
|
|
990
|
-
if #available(iOS 13.4, *) {
|
|
991
|
-
return PKPassLibrary().passes(of: PKPassType.secureElement).first(where: {$0.secureElementPass?.primaryAccountNumberSuffix == last4})
|
|
992
|
-
} else {
|
|
993
|
-
return PKPassLibrary().passes(of: PKPassType.payment).first(where: {$0.paymentPass?.primaryAccountNumberSuffix == last4})
|
|
994
|
-
}
|
|
995
|
-
}()
|
|
996
|
-
resolve(["isInWallet": existingPass != nil])
|
|
1028
|
+
resolve(["isInWallet": PushProvisioningUtils.passExistsWith(last4: last4)])
|
|
997
1029
|
}
|
|
998
|
-
|
|
1030
|
+
|
|
999
1031
|
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
|
|
1000
1032
|
confirmPaymentResolver?(Errors.createError(ErrorType.Canceled, "FPX Payment has been canceled"))
|
|
1001
1033
|
}
|
|
1002
|
-
|
|
1034
|
+
|
|
1003
1035
|
func payWithFPX(_ paymentIntentClientSecret: String) {
|
|
1004
1036
|
let vc = STPBankSelectionViewController.init(bankMethod: .FPX)
|
|
1005
1037
|
|
|
1006
1038
|
vc.delegate = self
|
|
1007
|
-
|
|
1039
|
+
|
|
1008
1040
|
DispatchQueue.main.async {
|
|
1009
1041
|
vc.presentationController?.delegate = self
|
|
1010
1042
|
|
|
@@ -1012,7 +1044,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
1012
1044
|
share?.window??.rootViewController?.present(vc, animated: true)
|
|
1013
1045
|
}
|
|
1014
1046
|
}
|
|
1015
|
-
|
|
1047
|
+
|
|
1016
1048
|
func bankSelectionViewController(_ bankViewController: STPBankSelectionViewController, didCreatePaymentMethodParams paymentMethodParams: STPPaymentMethodParams) {
|
|
1017
1049
|
guard let clientSecret = confirmPaymentClientSecret else {
|
|
1018
1050
|
confirmPaymentResolver?(Errors.createError(ErrorType.Failed, "Missing paymentIntentClientSecret"))
|
|
@@ -1020,7 +1052,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
1020
1052
|
}
|
|
1021
1053
|
let paymentIntentParams = STPPaymentIntentParams(clientSecret: clientSecret)
|
|
1022
1054
|
paymentIntentParams.paymentMethodParams = paymentMethodParams
|
|
1023
|
-
|
|
1055
|
+
|
|
1024
1056
|
if let urlScheme = urlScheme {
|
|
1025
1057
|
paymentIntentParams.returnURL = Mappers.mapToReturnURL(urlScheme: urlScheme)
|
|
1026
1058
|
}
|
|
@@ -1028,7 +1060,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
1028
1060
|
bankViewController.dismiss(animated: true)
|
|
1029
1061
|
paymentHandler.confirmPayment(paymentIntentParams, with: self, completion: onCompleteConfirmPayment)
|
|
1030
1062
|
}
|
|
1031
|
-
|
|
1063
|
+
|
|
1032
1064
|
func onCompleteConfirmPayment(status: STPPaymentHandlerActionStatus, paymentIntent: STPPaymentIntent?, error: NSError?) {
|
|
1033
1065
|
self.confirmPaymentClientSecret = nil
|
|
1034
1066
|
switch (status) {
|