@stripe/stripe-react-native 0.10.0 → 0.13.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 +42 -0
- package/README.md +3 -3
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +46 -10
- 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 +6 -1
- package/android/src/main/java/com/reactnativestripesdk/Errors.kt +14 -1
- package/android/src/main/java/com/reactnativestripesdk/GooglePayFragment.kt +68 -52
- package/android/src/main/java/com/reactnativestripesdk/Mappers.kt +5 -7
- package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherFragment.kt +127 -37
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +173 -0
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +60 -36
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +67 -177
- package/ios/CardFieldManager.m +1 -0
- package/ios/CardFieldView.swift +6 -0
- package/ios/Mappers.swift +8 -9
- package/ios/PaymentSheetAppearance.swift +209 -0
- package/ios/StripeSdk.swift +141 -116
- 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.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/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.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/example/src/screens/PaymentSheetAppearance.d.ts +3 -0
- package/lib/typescript/src/components/CardField.d.ts +3 -0
- package/lib/typescript/src/components/CardForm.d.ts +2 -0
- package/lib/typescript/src/types/PaymentSheet.d.ts +154 -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 +1 -4
- package/package.json +1 -1
- package/src/components/CardField.tsx +5 -0
- package/src/components/CardForm.tsx +6 -0
- package/src/functions.ts +1 -1
- package/src/types/PaymentSheet.ts +159 -2
- 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 +1 -5
- package/stripe-react-native.podspec +1 -1
- package/android/src/main/java/com/reactnativestripesdk/Constants.kt +0 -10
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,16 @@ 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
|
+
if let appearanceParams = params["appearance"] as? NSDictionary {
|
|
80
|
+
do {
|
|
81
|
+
configuration.appearance = try buildPaymentSheetAppearance(userParams: appearanceParams)
|
|
82
|
+
} catch {
|
|
83
|
+
resolve(Errors.createError(ErrorType.Failed, error.localizedDescription))
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
79
88
|
if params["applePay"] as? Bool == true {
|
|
80
89
|
if let merchantIdentifier = self.merchantIdentifier, let merchantCountryCode = params["merchantCountryCode"] as? String {
|
|
81
90
|
configuration.applePay = .init(merchantId: merchantIdentifier,
|
|
@@ -85,29 +94,24 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
85
94
|
return
|
|
86
95
|
}
|
|
87
96
|
}
|
|
88
|
-
|
|
97
|
+
|
|
89
98
|
if let merchantDisplayName = params["merchantDisplayName"] as? String {
|
|
90
99
|
configuration.merchantDisplayName = merchantDisplayName
|
|
91
100
|
}
|
|
92
|
-
|
|
101
|
+
|
|
93
102
|
if let returnURL = params["returnURL"] as? String {
|
|
94
103
|
configuration.returnURL = returnURL
|
|
95
104
|
}
|
|
96
|
-
|
|
97
|
-
if let buttonColorHexStr = params["primaryButtonColor"] as? String {
|
|
98
|
-
let primaryButtonColor = UIColor(hexString: buttonColorHexStr)
|
|
99
|
-
configuration.primaryButtonColor = primaryButtonColor
|
|
100
|
-
}
|
|
101
|
-
|
|
105
|
+
|
|
102
106
|
if let allowsDelayedPaymentMethods = params["allowsDelayedPaymentMethods"] as? Bool {
|
|
103
107
|
configuration.allowsDelayedPaymentMethods = allowsDelayedPaymentMethods
|
|
104
108
|
}
|
|
105
|
-
|
|
109
|
+
|
|
106
110
|
if let defaultBillingDetails = params["defaultBillingDetails"] as? [String: Any?] {
|
|
107
111
|
configuration.defaultBillingDetails.name = defaultBillingDetails["name"] as? String
|
|
108
112
|
configuration.defaultBillingDetails.email = defaultBillingDetails["email"] as? String
|
|
109
113
|
configuration.defaultBillingDetails.phone = defaultBillingDetails["phone"] as? String
|
|
110
|
-
|
|
114
|
+
|
|
111
115
|
if let address = defaultBillingDetails["address"] as? [String: String] {
|
|
112
116
|
configuration.defaultBillingDetails.address = .init(city: address["city"],
|
|
113
117
|
country: address["country"],
|
|
@@ -116,9 +120,9 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
116
120
|
postalCode: address["postalCode"],
|
|
117
121
|
state: address["state"])
|
|
118
122
|
}
|
|
119
|
-
|
|
123
|
+
|
|
120
124
|
}
|
|
121
|
-
|
|
125
|
+
|
|
122
126
|
if let customerId = params["customerId"] as? String {
|
|
123
127
|
if let customerEphemeralKeySecret = params["customerEphemeralKeySecret"] as? String {
|
|
124
128
|
if (!Errors.isEKClientSecretValid(clientSecret: customerEphemeralKeySecret)) {
|
|
@@ -128,13 +132,13 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
128
132
|
configuration.customer = .init(id: customerId, ephemeralKeySecret: customerEphemeralKeySecret)
|
|
129
133
|
}
|
|
130
134
|
}
|
|
131
|
-
|
|
135
|
+
|
|
132
136
|
if #available(iOS 13.0, *) {
|
|
133
137
|
if let style = params["style"] as? String {
|
|
134
138
|
configuration.style = Mappers.mapToUserInterfaceStyle(style)
|
|
135
139
|
}
|
|
136
140
|
}
|
|
137
|
-
|
|
141
|
+
|
|
138
142
|
func handlePaymentSheetFlowControllerResult(result: Result<PaymentSheet.FlowController, Error>, stripeSdk: StripeSdk?) {
|
|
139
143
|
switch result {
|
|
140
144
|
case .failure(let error):
|
|
@@ -152,13 +156,13 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
152
156
|
}
|
|
153
157
|
}
|
|
154
158
|
}
|
|
155
|
-
|
|
159
|
+
|
|
156
160
|
if let paymentIntentClientSecret = params["paymentIntentClientSecret"] as? String {
|
|
157
161
|
if (!Errors.isPIClientSecretValid(clientSecret: paymentIntentClientSecret)) {
|
|
158
162
|
resolve(Errors.createError(ErrorType.Failed, "`secret` format does not match expected client secret formatting."))
|
|
159
163
|
return
|
|
160
164
|
}
|
|
161
|
-
|
|
165
|
+
|
|
162
166
|
if params["customFlow"] as? Bool == true {
|
|
163
167
|
PaymentSheet.FlowController.create(paymentIntentClientSecret: paymentIntentClientSecret,
|
|
164
168
|
configuration: configuration) { [weak self] result in
|
|
@@ -173,7 +177,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
173
177
|
resolve(Errors.createError(ErrorType.Failed, "`secret` format does not match expected client secret formatting."))
|
|
174
178
|
return
|
|
175
179
|
}
|
|
176
|
-
|
|
180
|
+
|
|
177
181
|
if params["customFlow"] as? Bool == true {
|
|
178
182
|
PaymentSheet.FlowController.create(setupIntentClientSecret: setupIntentClientSecret,
|
|
179
183
|
configuration: configuration) { [weak self] result in
|
|
@@ -186,7 +190,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
186
190
|
} else {
|
|
187
191
|
resolve(Errors.createError(ErrorType.Failed, "You must provide either paymentIntentClientSecret or setupIntentClientSecret"))
|
|
188
192
|
}
|
|
189
|
-
|
|
193
|
+
|
|
190
194
|
}
|
|
191
195
|
|
|
192
196
|
@objc(confirmPaymentSheetPayment:rejecter:)
|
|
@@ -200,22 +204,22 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
200
204
|
resolve([])
|
|
201
205
|
self.paymentSheetFlowController = nil
|
|
202
206
|
case .canceled:
|
|
203
|
-
resolve(Errors.createError(ErrorType.Canceled, "The payment has been canceled"))
|
|
207
|
+
resolve(Errors.createError(ErrorType.Canceled, "The payment flow has been canceled"))
|
|
204
208
|
case .failed(let error):
|
|
205
209
|
resolve(Errors.createError(ErrorType.Failed, error.localizedDescription))
|
|
206
210
|
}
|
|
207
|
-
|
|
211
|
+
|
|
208
212
|
}
|
|
209
213
|
} else {
|
|
210
214
|
resolve(Errors.createError(ErrorType.Failed, "No payment sheet has been initialized yet"))
|
|
211
215
|
}
|
|
212
216
|
}
|
|
213
217
|
}
|
|
214
|
-
|
|
218
|
+
|
|
215
219
|
@objc(presentPaymentSheet:rejecter:)
|
|
216
220
|
func presentPaymentSheet(resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
217
221
|
rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
218
|
-
|
|
222
|
+
|
|
219
223
|
DispatchQueue.main.async {
|
|
220
224
|
if let paymentSheetFlowController = self.paymentSheetFlowController {
|
|
221
225
|
paymentSheetFlowController.presentPaymentOptions(from:
|
|
@@ -228,7 +232,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
228
232
|
]
|
|
229
233
|
resolve(Mappers.createResult("paymentOption", option))
|
|
230
234
|
} else {
|
|
231
|
-
resolve(
|
|
235
|
+
resolve(Errors.createError(ErrorType.Canceled, "The payment option selection flow has been canceled"))
|
|
232
236
|
}
|
|
233
237
|
}
|
|
234
238
|
} else if let paymentSheet = self.paymentSheet {
|
|
@@ -250,14 +254,14 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
250
254
|
}
|
|
251
255
|
}
|
|
252
256
|
}
|
|
253
|
-
|
|
257
|
+
|
|
254
258
|
@objc(createTokenForCVCUpdate:resolver:rejecter:)
|
|
255
259
|
func createTokenForCVCUpdate(cvc: String?, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
256
260
|
guard let cvc = cvc else {
|
|
257
261
|
resolve(Errors.createError(ErrorType.Failed, "You must provide CVC"))
|
|
258
262
|
return;
|
|
259
263
|
}
|
|
260
|
-
|
|
264
|
+
|
|
261
265
|
STPAPIClient.shared.createToken(forCVCUpdate: cvc) { (token, error) in
|
|
262
266
|
if error != nil || token == nil {
|
|
263
267
|
resolve(Errors.createError(ErrorType.Failed, error?.localizedDescription ?? ""))
|
|
@@ -267,7 +271,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
267
271
|
}
|
|
268
272
|
}
|
|
269
273
|
}
|
|
270
|
-
|
|
274
|
+
|
|
271
275
|
@objc(confirmSetupIntent:data:options:resolver:rejecter:)
|
|
272
276
|
func confirmSetupIntent (setupIntentClientSecret: String, params: NSDictionary,
|
|
273
277
|
options: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
@@ -278,11 +282,11 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
278
282
|
resolve(Errors.createError(ErrorType.Failed, "You must provide paymentMethodType."))
|
|
279
283
|
return
|
|
280
284
|
}
|
|
281
|
-
|
|
285
|
+
|
|
282
286
|
if (paymentMethodType == .payPal) {
|
|
283
287
|
resolve(Errors.createError(ErrorType.Failed, "PayPal is not yet supported through SetupIntents."))
|
|
284
288
|
}
|
|
285
|
-
|
|
289
|
+
|
|
286
290
|
var err: NSDictionary? = nil
|
|
287
291
|
let setupIntentParams: STPSetupIntentConfirmParams = {
|
|
288
292
|
// If payment method data is not supplied, assume payment method was attached through via collectBankAccount
|
|
@@ -297,20 +301,20 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
297
301
|
} catch {
|
|
298
302
|
err = Errors.createError(ErrorType.Failed, error as NSError?)
|
|
299
303
|
}
|
|
300
|
-
|
|
304
|
+
|
|
301
305
|
return parameters
|
|
302
306
|
}
|
|
303
307
|
}()
|
|
304
|
-
|
|
308
|
+
|
|
305
309
|
if (err != nil) {
|
|
306
310
|
resolve(err)
|
|
307
311
|
return
|
|
308
312
|
}
|
|
309
|
-
|
|
313
|
+
|
|
310
314
|
if let urlScheme = urlScheme {
|
|
311
315
|
setupIntentParams.returnURL = Mappers.mapToReturnURL(urlScheme: urlScheme)
|
|
312
316
|
}
|
|
313
|
-
|
|
317
|
+
|
|
314
318
|
let paymentHandler = STPPaymentHandler.shared()
|
|
315
319
|
paymentHandler.confirmSetupIntent(setupIntentParams, with: self) { status, setupIntent, error in
|
|
316
320
|
switch (status) {
|
|
@@ -333,7 +337,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
333
337
|
}
|
|
334
338
|
}
|
|
335
339
|
}
|
|
336
|
-
|
|
340
|
+
|
|
337
341
|
@objc(updateApplePaySummaryItems:errorAddressFields:resolver:rejecter:)
|
|
338
342
|
func updateApplePaySummaryItems(summaryItems: NSArray, errorAddressFields: [NSDictionary], resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
339
343
|
if (shippingMethodUpdateHandler == nil && shippingContactUpdateHandler == nil) {
|
|
@@ -363,7 +367,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
363
367
|
self.shippingContactUpdateHandler = nil
|
|
364
368
|
resolve([])
|
|
365
369
|
}
|
|
366
|
-
|
|
370
|
+
|
|
367
371
|
@objc(openApplePaySetup:rejecter:)
|
|
368
372
|
func openApplePaySetup(resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
369
373
|
let library = PKPassLibrary.init()
|
|
@@ -374,21 +378,21 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
374
378
|
resolve(Errors.createError(ErrorType.Failed, "Cannot open payment setup"))
|
|
375
379
|
}
|
|
376
380
|
}
|
|
377
|
-
|
|
378
|
-
|
|
381
|
+
|
|
382
|
+
|
|
379
383
|
func applePayContext(_ context: STPApplePayContext, didSelect shippingMethod: PKShippingMethod, handler: @escaping (PKPaymentRequestShippingMethodUpdate) -> Void) {
|
|
380
384
|
self.shippingMethodUpdateHandler = handler
|
|
381
385
|
sendEvent(withName: "onDidSetShippingMethod", body: ["shippingMethod": Mappers.mapFromShippingMethod(shippingMethod: shippingMethod)])
|
|
382
386
|
}
|
|
383
|
-
|
|
387
|
+
|
|
384
388
|
func applePayContext(_ context: STPApplePayContext, didSelectShippingContact contact: PKContact, handler: @escaping (PKPaymentRequestShippingContactUpdate) -> Void) {
|
|
385
389
|
self.shippingContactUpdateHandler = handler
|
|
386
390
|
sendEvent(withName: "onDidSetShippingContact", body: ["shippingContact": Mappers.mapFromShippingContact(shippingContact: contact)])
|
|
387
391
|
}
|
|
388
|
-
|
|
392
|
+
|
|
389
393
|
func applePayContext(_ context: STPApplePayContext, didCreatePaymentMethod paymentMethod: STPPaymentMethod, paymentInformation: PKPayment, completion: @escaping STPIntentClientSecretCompletionBlock) {
|
|
390
394
|
self.applePayCompletionCallback = completion
|
|
391
|
-
|
|
395
|
+
|
|
392
396
|
let address = paymentMethod.billingDetails?.address?.line1?.split(whereSeparator: \.isNewline)
|
|
393
397
|
if (address?.indices.contains(0) == true) {
|
|
394
398
|
paymentMethod.billingDetails?.address?.line1 = String(address?[0] ?? "")
|
|
@@ -396,19 +400,19 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
396
400
|
if (address?.indices.contains(1) == true) {
|
|
397
401
|
paymentMethod.billingDetails?.address?.line2 = String(address?[1] ?? "")
|
|
398
402
|
}
|
|
399
|
-
|
|
403
|
+
|
|
400
404
|
let method = Mappers.mapFromPaymentMethod(paymentMethod)
|
|
401
405
|
self.applePayRequestResolver?(Mappers.createResult("paymentMethod", method))
|
|
402
406
|
self.applePayRequestRejecter = nil
|
|
403
407
|
}
|
|
404
|
-
|
|
408
|
+
|
|
405
409
|
@objc(confirmApplePayPayment:resolver:rejecter:)
|
|
406
410
|
func confirmApplePayPayment(clientSecret: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
407
411
|
self.applePayCompletionRejecter = reject
|
|
408
412
|
self.confirmApplePayPaymentResolver = resolve
|
|
409
413
|
self.applePayCompletionCallback?(clientSecret, nil)
|
|
410
414
|
}
|
|
411
|
-
|
|
415
|
+
|
|
412
416
|
func applePayContext(_ context: STPApplePayContext, didCompleteWith status: STPPaymentStatus, error: Error?) {
|
|
413
417
|
switch status {
|
|
414
418
|
case .success:
|
|
@@ -438,14 +442,14 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
438
442
|
applePayRequestRejecter = nil
|
|
439
443
|
}
|
|
440
444
|
}
|
|
441
|
-
|
|
445
|
+
|
|
442
446
|
@objc(isApplePaySupported:rejecter:)
|
|
443
447
|
func isApplePaySupported(resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
444
448
|
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
445
449
|
let isSupported = StripeAPI.deviceSupportsApplePay()
|
|
446
450
|
resolve(isSupported)
|
|
447
451
|
}
|
|
448
|
-
|
|
452
|
+
|
|
449
453
|
@objc(handleURLCallback:resolver:rejecter:)
|
|
450
454
|
func handleURLCallback(url: String?, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
451
455
|
guard let url = url else {
|
|
@@ -462,7 +466,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
462
466
|
}
|
|
463
467
|
}
|
|
464
468
|
}
|
|
465
|
-
|
|
469
|
+
|
|
466
470
|
@objc(presentApplePay:resolver:rejecter:)
|
|
467
471
|
func presentApplePay(params: NSDictionary,
|
|
468
472
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
@@ -471,11 +475,11 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
471
475
|
reject(ErrorType.Failed, "You must provide merchantIdentifier", nil)
|
|
472
476
|
return
|
|
473
477
|
}
|
|
474
|
-
|
|
478
|
+
|
|
475
479
|
if (params["jcbEnabled"] as? Bool == true) {
|
|
476
480
|
StripeAPI.additionalEnabledApplePayNetworks = [.JCB]
|
|
477
481
|
}
|
|
478
|
-
|
|
482
|
+
|
|
479
483
|
guard let summaryItems = params["cartItems"] as? NSArray else {
|
|
480
484
|
reject(ErrorType.Failed, "You must provide the items for purchase", nil)
|
|
481
485
|
return
|
|
@@ -488,29 +492,29 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
488
492
|
reject(ErrorType.Failed, "You must provide the payment currency", nil)
|
|
489
493
|
return
|
|
490
494
|
}
|
|
491
|
-
|
|
495
|
+
|
|
492
496
|
self.applePayRequestResolver = resolve
|
|
493
497
|
self.applePayRequestRejecter = reject
|
|
494
|
-
|
|
498
|
+
|
|
495
499
|
let merchantIdentifier = self.merchantIdentifier ?? ""
|
|
496
500
|
let paymentRequest = StripeAPI.paymentRequest(withMerchantIdentifier: merchantIdentifier, country: country, currency: currency)
|
|
497
|
-
|
|
501
|
+
|
|
498
502
|
let requiredShippingAddressFields = params["requiredShippingAddressFields"] as? NSArray ?? NSArray()
|
|
499
503
|
let requiredBillingContactFields = params["requiredBillingContactFields"] as? NSArray ?? NSArray()
|
|
500
504
|
let shippingMethods = params["shippingMethods"] as? NSArray ?? NSArray()
|
|
501
|
-
|
|
505
|
+
|
|
502
506
|
paymentRequest.requiredShippingContactFields = Set(requiredShippingAddressFields.map {
|
|
503
507
|
Mappers.mapToPKContactField(field: $0 as! String)
|
|
504
508
|
})
|
|
505
|
-
|
|
509
|
+
|
|
506
510
|
paymentRequest.requiredBillingContactFields = Set(requiredBillingContactFields.map {
|
|
507
511
|
Mappers.mapToPKContactField(field: $0 as! String)
|
|
508
512
|
})
|
|
509
|
-
|
|
513
|
+
|
|
510
514
|
paymentRequest.shippingMethods = Mappers.mapToShippingMethods(shippingMethods: shippingMethods)
|
|
511
|
-
|
|
515
|
+
|
|
512
516
|
var paymentSummaryItems: [PKPaymentSummaryItem] = []
|
|
513
|
-
|
|
517
|
+
|
|
514
518
|
if let items = summaryItems as? [[String : Any]] {
|
|
515
519
|
for item in items {
|
|
516
520
|
let label = item["label"] as? String ?? ""
|
|
@@ -519,7 +523,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
519
523
|
paymentSummaryItems.append(PKPaymentSummaryItem(label: label, amount: amount, type: type))
|
|
520
524
|
}
|
|
521
525
|
}
|
|
522
|
-
|
|
526
|
+
|
|
523
527
|
paymentRequest.paymentSummaryItems = paymentSummaryItems
|
|
524
528
|
if let applePayContext = STPApplePayContext(paymentRequest: paymentRequest, delegate: self) {
|
|
525
529
|
DispatchQueue.main.async {
|
|
@@ -533,10 +537,10 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
533
537
|
func configure3dSecure(_ params: NSDictionary) {
|
|
534
538
|
let threeDSCustomizationSettings = STPPaymentHandler.shared().threeDSCustomizationSettings
|
|
535
539
|
let uiCustomization = Mappers.mapUICustomization(params)
|
|
536
|
-
|
|
540
|
+
|
|
537
541
|
threeDSCustomizationSettings.uiCustomization = uiCustomization
|
|
538
542
|
}
|
|
539
|
-
|
|
543
|
+
|
|
540
544
|
@objc(createPaymentMethod:options:resolver:rejecter:)
|
|
541
545
|
func createPaymentMethod(
|
|
542
546
|
params: NSDictionary,
|
|
@@ -549,7 +553,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
549
553
|
resolve(Errors.createError(ErrorType.Failed, "You must provide paymentMethodType"))
|
|
550
554
|
return
|
|
551
555
|
}
|
|
552
|
-
|
|
556
|
+
|
|
553
557
|
var paymentMethodParams: STPPaymentMethodParams?
|
|
554
558
|
let factory = PaymentMethodFactory.init(
|
|
555
559
|
paymentMethodData: params["paymentMethodData"] as? NSDictionary,
|
|
@@ -563,14 +567,14 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
563
567
|
resolve(Errors.createError(ErrorType.Failed, error.localizedDescription))
|
|
564
568
|
return
|
|
565
569
|
}
|
|
566
|
-
|
|
570
|
+
|
|
567
571
|
if let paymentMethodParams = paymentMethodParams {
|
|
568
572
|
STPAPIClient.shared.createPaymentMethod(with: paymentMethodParams) { paymentMethod, error in
|
|
569
573
|
if let createError = error {
|
|
570
574
|
resolve(Errors.createError(ErrorType.Failed, createError.localizedDescription))
|
|
571
575
|
return
|
|
572
576
|
}
|
|
573
|
-
|
|
577
|
+
|
|
574
578
|
if let paymentMethod = paymentMethod {
|
|
575
579
|
let method = Mappers.mapFromPaymentMethod(paymentMethod)
|
|
576
580
|
resolve(Mappers.createResult("paymentMethod", method))
|
|
@@ -580,7 +584,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
580
584
|
resolve(Errors.createError(ErrorType.Unknown, "Unhandled error occured"))
|
|
581
585
|
}
|
|
582
586
|
}
|
|
583
|
-
|
|
587
|
+
|
|
584
588
|
@objc(createToken:resolver:rejecter:)
|
|
585
589
|
func createToken(
|
|
586
590
|
params: NSDictionary,
|
|
@@ -591,18 +595,20 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
591
595
|
resolve(Errors.createError(ErrorType.Failed, "type parameter is required"))
|
|
592
596
|
return
|
|
593
597
|
}
|
|
594
|
-
|
|
598
|
+
|
|
595
599
|
// TODO: Consider moving this to its own class when more types are supported.
|
|
596
600
|
switch type {
|
|
597
601
|
case "BankAccount":
|
|
598
602
|
createTokenFromBankAccount(params: params, resolver: resolve, rejecter: reject)
|
|
599
603
|
case "Card":
|
|
600
604
|
createTokenFromCard(params: params, resolver: resolve, rejecter: reject)
|
|
605
|
+
case "Pii":
|
|
606
|
+
createTokenFromPii(params: params, resolver: resolve, rejecter: reject)
|
|
601
607
|
default:
|
|
602
608
|
resolve(Errors.createError(ErrorType.Failed, type + " type is not supported yet"))
|
|
603
609
|
}
|
|
604
610
|
}
|
|
605
|
-
|
|
611
|
+
|
|
606
612
|
func createTokenFromBankAccount(
|
|
607
613
|
params: NSDictionary,
|
|
608
614
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
@@ -622,8 +628,8 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
622
628
|
bankAccountParams.currency = currency
|
|
623
629
|
bankAccountParams.routingNumber = routingNumber
|
|
624
630
|
bankAccountParams.accountHolderType = Mappers.mapToBankAccountHolderType(accountHolderType)
|
|
625
|
-
|
|
626
|
-
|
|
631
|
+
|
|
632
|
+
|
|
627
633
|
STPAPIClient.shared.createToken(withBankAccount: bankAccountParams) { token, error in
|
|
628
634
|
if let token = token {
|
|
629
635
|
resolve(Mappers.createResult("token", Mappers.mapFromToken(token: token)))
|
|
@@ -632,7 +638,26 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
632
638
|
}
|
|
633
639
|
}
|
|
634
640
|
}
|
|
635
|
-
|
|
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
|
+
|
|
636
661
|
func createTokenFromCard(
|
|
637
662
|
params: NSDictionary,
|
|
638
663
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
@@ -642,7 +667,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
642
667
|
resolve(Errors.createError(ErrorType.Failed, "Card details not complete"))
|
|
643
668
|
return
|
|
644
669
|
}
|
|
645
|
-
|
|
670
|
+
|
|
646
671
|
let address = params["address"] as? NSDictionary
|
|
647
672
|
let cardSourceParams = STPCardParams()
|
|
648
673
|
cardSourceParams.number = cardParams.number
|
|
@@ -661,7 +686,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
661
686
|
}
|
|
662
687
|
}
|
|
663
688
|
}
|
|
664
|
-
|
|
689
|
+
|
|
665
690
|
@objc(handleNextAction:resolver:rejecter:)
|
|
666
691
|
func handleNextAction(
|
|
667
692
|
paymentIntentClientSecret: String,
|
|
@@ -692,7 +717,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
692
717
|
}
|
|
693
718
|
}
|
|
694
719
|
}
|
|
695
|
-
|
|
720
|
+
|
|
696
721
|
@objc(collectBankAccount:clientSecret:params:resolver:rejecter:)
|
|
697
722
|
func collectBankAccount(
|
|
698
723
|
isPaymentIntent: Bool,
|
|
@@ -707,22 +732,22 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
707
732
|
resolve(Errors.createError(ErrorType.Failed, "collectBankAccount currently only accepts the USBankAccount payment method type."))
|
|
708
733
|
return
|
|
709
734
|
}
|
|
710
|
-
|
|
735
|
+
|
|
711
736
|
guard let billingDetails = paymentMethodData?["billingDetails"] as? [String: Any?], let name = billingDetails["name"] as? String else {
|
|
712
737
|
resolve(Errors.createError(ErrorType.Failed, "You must provide a name when collecting US bank account details."))
|
|
713
738
|
return
|
|
714
739
|
}
|
|
715
|
-
|
|
740
|
+
|
|
716
741
|
if (name.isEmpty) {
|
|
717
742
|
resolve(Errors.createError(ErrorType.Failed, "You must provide a name when collecting US bank account details."))
|
|
718
743
|
return
|
|
719
744
|
}
|
|
720
|
-
|
|
745
|
+
|
|
721
746
|
let collectParams = STPCollectBankAccountParams.collectUSBankAccountParams(
|
|
722
747
|
with: name,
|
|
723
748
|
email: billingDetails["email"] as? String
|
|
724
749
|
)
|
|
725
|
-
|
|
750
|
+
|
|
726
751
|
if (isPaymentIntent) {
|
|
727
752
|
DispatchQueue.main.async {
|
|
728
753
|
STPBankAccountCollector().collectBankAccountForPayment(
|
|
@@ -734,7 +759,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
734
759
|
resolve(Errors.createError(ErrorType.Failed, error as NSError))
|
|
735
760
|
return
|
|
736
761
|
}
|
|
737
|
-
|
|
762
|
+
|
|
738
763
|
if let intent = intent {
|
|
739
764
|
if (intent.status == .requiresPaymentMethod) {
|
|
740
765
|
resolve(Errors.createError(ErrorType.Canceled, "Bank account collection was canceled."))
|
|
@@ -758,7 +783,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
758
783
|
resolve(Errors.createError(ErrorType.Failed, error as NSError))
|
|
759
784
|
return
|
|
760
785
|
}
|
|
761
|
-
|
|
786
|
+
|
|
762
787
|
if let intent = intent {
|
|
763
788
|
if (intent.status == .requiresPaymentMethod) {
|
|
764
789
|
resolve(Errors.createError(ErrorType.Canceled, "Bank account collection was canceled."))
|
|
@@ -784,14 +809,14 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
784
809
|
) -> Void {
|
|
785
810
|
self.confirmPaymentResolver = resolve
|
|
786
811
|
self.confirmPaymentClientSecret = paymentIntentClientSecret
|
|
787
|
-
|
|
812
|
+
|
|
788
813
|
let paymentMethodData = params["paymentMethodData"] as? NSDictionary
|
|
789
814
|
let type = Mappers.mapToPaymentMethodType(type: params["paymentMethodType"] as? String)
|
|
790
815
|
guard let paymentMethodType = type else {
|
|
791
816
|
resolve(Errors.createError(ErrorType.Failed, "You must provide paymentMethodType"))
|
|
792
817
|
return
|
|
793
818
|
}
|
|
794
|
-
|
|
819
|
+
|
|
795
820
|
if (paymentMethodType == .FPX) {
|
|
796
821
|
let testOfflineBank = paymentMethodData?["testOfflineBank"] as? Bool
|
|
797
822
|
if (testOfflineBank == false || testOfflineBank == nil) {
|
|
@@ -799,16 +824,16 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
799
824
|
return
|
|
800
825
|
}
|
|
801
826
|
}
|
|
802
|
-
|
|
827
|
+
|
|
803
828
|
let (error, paymentIntentParams) = createPaymentIntentParams(paymentIntentClientSecret: paymentIntentClientSecret, paymentMethodType: paymentMethodType, paymentMethodData: paymentMethodData, options: options)
|
|
804
|
-
|
|
829
|
+
|
|
805
830
|
if (error != nil) {
|
|
806
831
|
resolve(error)
|
|
807
832
|
} else {
|
|
808
833
|
STPPaymentHandler.shared().confirmPayment(paymentIntentParams, with: self, completion: onCompleteConfirmPayment)
|
|
809
834
|
}
|
|
810
835
|
}
|
|
811
|
-
|
|
836
|
+
|
|
812
837
|
func createPaymentIntentParams(
|
|
813
838
|
paymentIntentClientSecret: String,
|
|
814
839
|
paymentMethodType: STPPaymentMethodType,
|
|
@@ -817,7 +842,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
817
842
|
) -> (NSDictionary?, STPPaymentIntentParams) {
|
|
818
843
|
let factory = PaymentMethodFactory.init(paymentMethodData: paymentMethodData, options: options, cardFieldView: cardFieldView, cardFormView: cardFormView)
|
|
819
844
|
var err: NSDictionary? = nil
|
|
820
|
-
|
|
845
|
+
|
|
821
846
|
let paymentIntentParams: STPPaymentIntentParams = {
|
|
822
847
|
// If payment method data is not supplied, assume payment method was attached through via collectBankAccount
|
|
823
848
|
if (paymentMethodType == .USBankAccount && paymentMethodData == nil) {
|
|
@@ -825,7 +850,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
825
850
|
} else {
|
|
826
851
|
let paymentMethodId = paymentMethodData?["paymentMethodId"] as? String
|
|
827
852
|
let parameters = STPPaymentIntentParams(clientSecret: paymentIntentClientSecret)
|
|
828
|
-
|
|
853
|
+
|
|
829
854
|
if paymentMethodId != nil {
|
|
830
855
|
parameters.paymentMethodId = paymentMethodId
|
|
831
856
|
} else {
|
|
@@ -841,7 +866,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
841
866
|
return parameters
|
|
842
867
|
}
|
|
843
868
|
}()
|
|
844
|
-
|
|
869
|
+
|
|
845
870
|
if let setupFutureUsage = options["setupFutureUsage"] as? String {
|
|
846
871
|
paymentIntentParams.setupFutureUsage = Mappers.mapToPaymentIntentFutureUsage(usage: setupFutureUsage)
|
|
847
872
|
}
|
|
@@ -849,7 +874,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
849
874
|
paymentIntentParams.returnURL = Mappers.mapToReturnURL(urlScheme: urlScheme)
|
|
850
875
|
}
|
|
851
876
|
paymentIntentParams.shipping = Mappers.mapToShippingDetails(shippingDetails: paymentMethodData?["shippingDetails"] as? NSDictionary)
|
|
852
|
-
|
|
877
|
+
|
|
853
878
|
return (err, paymentIntentParams)
|
|
854
879
|
}
|
|
855
880
|
|
|
@@ -866,10 +891,10 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
866
891
|
} else {
|
|
867
892
|
resolve(Errors.createError(ErrorType.Unknown, error?.localizedDescription))
|
|
868
893
|
}
|
|
869
|
-
|
|
894
|
+
|
|
870
895
|
return
|
|
871
896
|
}
|
|
872
|
-
|
|
897
|
+
|
|
873
898
|
if let paymentIntent = paymentIntent {
|
|
874
899
|
resolve(Mappers.createResult("paymentIntent", Mappers.mapFromPaymentIntent(paymentIntent: paymentIntent)))
|
|
875
900
|
} else {
|
|
@@ -877,7 +902,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
877
902
|
}
|
|
878
903
|
}
|
|
879
904
|
}
|
|
880
|
-
|
|
905
|
+
|
|
881
906
|
@objc(retrieveSetupIntent:resolver:rejecter:)
|
|
882
907
|
func retrieveSetupIntent(
|
|
883
908
|
clientSecret: String,
|
|
@@ -891,10 +916,10 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
891
916
|
} else {
|
|
892
917
|
resolve(Errors.createError(ErrorType.Unknown, error?.localizedDescription))
|
|
893
918
|
}
|
|
894
|
-
|
|
919
|
+
|
|
895
920
|
return
|
|
896
921
|
}
|
|
897
|
-
|
|
922
|
+
|
|
898
923
|
if let setupIntent = setupIntent {
|
|
899
924
|
resolve(Mappers.createResult("setupIntent", Mappers.mapFromSetupIntent(setupIntent: setupIntent)))
|
|
900
925
|
} else {
|
|
@@ -902,7 +927,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
902
927
|
}
|
|
903
928
|
}
|
|
904
929
|
}
|
|
905
|
-
|
|
930
|
+
|
|
906
931
|
@objc(verifyMicrodeposits:clientSecret:params:resolver:rejecter:)
|
|
907
932
|
func verifyMicrodeposits(
|
|
908
933
|
isPaymentIntent: Bool,
|
|
@@ -913,12 +938,12 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
913
938
|
) -> Void {
|
|
914
939
|
let amounts = params["amounts"] as? NSArray
|
|
915
940
|
let descriptorCode = params["descriptorCode"] as? String
|
|
916
|
-
|
|
941
|
+
|
|
917
942
|
if (amounts != nil && descriptorCode != nil || amounts == nil && descriptorCode == nil) {
|
|
918
943
|
resolve(Errors.createError(ErrorType.Failed, "You must provide either amounts OR descriptorCode, not both."))
|
|
919
944
|
return
|
|
920
945
|
}
|
|
921
|
-
|
|
946
|
+
|
|
922
947
|
if let amounts = amounts {
|
|
923
948
|
if (amounts.count != 2) {
|
|
924
949
|
resolve(Errors.createError(ErrorType.Failed, "Expected 2 integers in the amounts array, but received " + String(amounts.count)))
|
|
@@ -954,7 +979,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
954
979
|
)
|
|
955
980
|
}
|
|
956
981
|
}
|
|
957
|
-
|
|
982
|
+
|
|
958
983
|
func onCompletePaymentVerification(intent: STPPaymentIntent?, error: Error?) {
|
|
959
984
|
if (error != nil) {
|
|
960
985
|
resolve(Errors.createError(ErrorType.Failed, error as NSError?))
|
|
@@ -970,7 +995,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
970
995
|
}
|
|
971
996
|
}
|
|
972
997
|
}
|
|
973
|
-
|
|
998
|
+
|
|
974
999
|
@objc(isCardInWallet:resolver:rejecter:)
|
|
975
1000
|
func isCardInWallet(
|
|
976
1001
|
params: NSDictionary,
|
|
@@ -981,7 +1006,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
981
1006
|
resolve(Errors.createError(ErrorType.Failed, "You must provide `cardLastFour`"))
|
|
982
1007
|
return
|
|
983
1008
|
}
|
|
984
|
-
|
|
1009
|
+
|
|
985
1010
|
let existingPass: PKPass? = {
|
|
986
1011
|
if #available(iOS 13.4, *) {
|
|
987
1012
|
return PKPassLibrary().passes(of: PKPassType.secureElement).first(where: {$0.secureElementPass?.primaryAccountNumberSuffix == last4})
|
|
@@ -991,16 +1016,16 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
991
1016
|
}()
|
|
992
1017
|
resolve(["isInWallet": existingPass != nil])
|
|
993
1018
|
}
|
|
994
|
-
|
|
1019
|
+
|
|
995
1020
|
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
|
|
996
1021
|
confirmPaymentResolver?(Errors.createError(ErrorType.Canceled, "FPX Payment has been canceled"))
|
|
997
1022
|
}
|
|
998
|
-
|
|
1023
|
+
|
|
999
1024
|
func payWithFPX(_ paymentIntentClientSecret: String) {
|
|
1000
1025
|
let vc = STPBankSelectionViewController.init(bankMethod: .FPX)
|
|
1001
1026
|
|
|
1002
1027
|
vc.delegate = self
|
|
1003
|
-
|
|
1028
|
+
|
|
1004
1029
|
DispatchQueue.main.async {
|
|
1005
1030
|
vc.presentationController?.delegate = self
|
|
1006
1031
|
|
|
@@ -1008,7 +1033,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
1008
1033
|
share?.window??.rootViewController?.present(vc, animated: true)
|
|
1009
1034
|
}
|
|
1010
1035
|
}
|
|
1011
|
-
|
|
1036
|
+
|
|
1012
1037
|
func bankSelectionViewController(_ bankViewController: STPBankSelectionViewController, didCreatePaymentMethodParams paymentMethodParams: STPPaymentMethodParams) {
|
|
1013
1038
|
guard let clientSecret = confirmPaymentClientSecret else {
|
|
1014
1039
|
confirmPaymentResolver?(Errors.createError(ErrorType.Failed, "Missing paymentIntentClientSecret"))
|
|
@@ -1016,7 +1041,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
1016
1041
|
}
|
|
1017
1042
|
let paymentIntentParams = STPPaymentIntentParams(clientSecret: clientSecret)
|
|
1018
1043
|
paymentIntentParams.paymentMethodParams = paymentMethodParams
|
|
1019
|
-
|
|
1044
|
+
|
|
1020
1045
|
if let urlScheme = urlScheme {
|
|
1021
1046
|
paymentIntentParams.returnURL = Mappers.mapToReturnURL(urlScheme: urlScheme)
|
|
1022
1047
|
}
|
|
@@ -1024,7 +1049,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
1024
1049
|
bankViewController.dismiss(animated: true)
|
|
1025
1050
|
paymentHandler.confirmPayment(paymentIntentParams, with: self, completion: onCompleteConfirmPayment)
|
|
1026
1051
|
}
|
|
1027
|
-
|
|
1052
|
+
|
|
1028
1053
|
func onCompleteConfirmPayment(status: STPPaymentHandlerActionStatus, paymentIntent: STPPaymentIntent?, error: NSError?) {
|
|
1029
1054
|
self.confirmPaymentClientSecret = nil
|
|
1030
1055
|
switch (status) {
|