@stripe/stripe-react-native 0.23.3 → 0.24.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 +34 -10
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +72 -16
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +19 -2
- package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +1 -1
- package/ios/ApplePayButtonManager.m +1 -0
- package/ios/ApplePayButtonView.swift +2 -0
- package/ios/ApplePayUtils.swift +116 -15
- package/ios/ApplePayViewController.swift +13 -0
- package/ios/Errors.swift +1 -0
- package/ios/StripeSdk+PaymentSheet.swift +166 -0
- package/ios/StripeSdk-Bridging-Header.h +1 -0
- package/ios/StripeSdk.m +17 -1
- package/ios/StripeSdk.swift +67 -134
- package/lib/commonjs/NativeStripeSdk.js.map +1 -1
- package/lib/commonjs/components/PlatformPayButton.js +1 -1
- package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
- package/lib/commonjs/functions.js +1 -1
- package/lib/commonjs/functions.js.map +1 -1
- package/lib/commonjs/hooks/usePaymentSheet.js +1 -1
- package/lib/commonjs/hooks/usePaymentSheet.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/Errors.js +1 -1
- package/lib/commonjs/types/Errors.js.map +1 -1
- package/lib/commonjs/types/PaymentSheet.js.map +1 -1
- package/lib/commonjs/types/PlatformPay.js +1 -1
- package/lib/commonjs/types/PlatformPay.js.map +1 -1
- package/lib/commonjs/types/components/ApplePayButtonComponent.js.map +1 -1
- package/lib/module/NativeStripeSdk.js.map +1 -1
- package/lib/module/components/PlatformPayButton.js +1 -1
- package/lib/module/components/PlatformPayButton.js.map +1 -1
- package/lib/module/functions.js +1 -1
- package/lib/module/functions.js.map +1 -1
- package/lib/module/hooks/usePaymentSheet.js +1 -1
- package/lib/module/hooks/usePaymentSheet.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/Errors.js +1 -1
- package/lib/module/types/Errors.js.map +1 -1
- package/lib/module/types/PaymentSheet.js.map +1 -1
- package/lib/module/types/PlatformPay.js +1 -1
- package/lib/module/types/PlatformPay.js.map +1 -1
- package/lib/module/types/components/ApplePayButtonComponent.js.map +1 -1
- package/lib/typescript/src/NativeStripeSdk.d.ts +3 -1
- package/lib/typescript/src/components/PlatformPayButton.d.ts +6 -1
- package/lib/typescript/src/functions.d.ts +1 -1
- package/lib/typescript/src/hooks/usePaymentSheet.d.ts +1 -1
- package/lib/typescript/src/hooks/useStripe.d.ts +1 -1
- package/lib/typescript/src/types/Errors.d.ts +2 -1
- package/lib/typescript/src/types/PaymentSheet.d.ts +17 -1
- package/lib/typescript/src/types/PlatformPay.d.ts +64 -1
- package/lib/typescript/src/types/components/ApplePayButtonComponent.d.ts +1 -0
- package/package.json +1 -1
- package/src/NativeStripeSdk.tsx +13 -1
- package/src/components/PlatformPayButton.tsx +31 -3
- package/src/functions.ts +34 -21
- package/src/hooks/usePaymentSheet.tsx +2 -2
- package/src/hooks/useStripe.tsx +8 -4
- package/src/types/Errors.ts +1 -0
- package/src/types/PaymentSheet.ts +33 -3
- package/src/types/PlatformPay.ts +72 -1
- package/src/types/components/ApplePayButtonComponent.ts +1 -0
- package/stripe-react-native.podspec +1 -1
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
//
|
|
2
|
+
// StripeSdk+PaymentSheet.swift
|
|
3
|
+
// stripe-react-native
|
|
4
|
+
//
|
|
5
|
+
// Created by Charles Cruzan on 1/6/23.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import StripePaymentSheet
|
|
10
|
+
|
|
11
|
+
extension StripeSdk {
|
|
12
|
+
internal func buildPaymentSheetConfiguration(params: NSDictionary, orderTrackingCallback: RCTResponseSenderBlock? = nil) -> (error: NSDictionary?, configuration: PaymentSheet.Configuration?) {
|
|
13
|
+
var configuration = PaymentSheet.Configuration()
|
|
14
|
+
|
|
15
|
+
configuration.primaryButtonLabel = params["primaryButtonLabel"] as? String
|
|
16
|
+
|
|
17
|
+
if let appearanceParams = params["appearance"] as? NSDictionary {
|
|
18
|
+
do {
|
|
19
|
+
configuration.appearance = try PaymentSheetAppearance.buildAppearanceFromParams(userParams: appearanceParams)
|
|
20
|
+
} catch {
|
|
21
|
+
return(error: Errors.createError(ErrorType.Failed, error.localizedDescription), configuration: nil)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if let applePayParams = params["applePay"] as? NSDictionary {
|
|
26
|
+
do {
|
|
27
|
+
configuration.applePay = try ApplePayUtils.buildPaymentSheetApplePayConfig(
|
|
28
|
+
merchantIdentifier: self.merchantIdentifier,
|
|
29
|
+
merchantCountryCode: applePayParams["merchantCountryCode"] as? String,
|
|
30
|
+
paymentSummaryItems: applePayParams["cartItems"] as? [[String : Any]],
|
|
31
|
+
buttonType: applePayParams["buttonType"] as? NSNumber,
|
|
32
|
+
customHandlers: buildCustomerHandlersForPaymentSheet(applePayParams: applePayParams, orderTrackingCallback: orderTrackingCallback)
|
|
33
|
+
)
|
|
34
|
+
} catch {
|
|
35
|
+
return(error: Errors.createError(ErrorType.Failed, error.localizedDescription), configuration: nil)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if let merchantDisplayName = params["merchantDisplayName"] as? String {
|
|
40
|
+
configuration.merchantDisplayName = merchantDisplayName
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if let returnURL = params["returnURL"] as? String {
|
|
44
|
+
configuration.returnURL = returnURL
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if let allowsDelayedPaymentMethods = params["allowsDelayedPaymentMethods"] as? Bool {
|
|
48
|
+
configuration.allowsDelayedPaymentMethods = allowsDelayedPaymentMethods
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if let defaultBillingDetails = params["defaultBillingDetails"] as? [String: Any?] {
|
|
52
|
+
configuration.defaultBillingDetails.name = defaultBillingDetails["name"] as? String
|
|
53
|
+
configuration.defaultBillingDetails.email = defaultBillingDetails["email"] as? String
|
|
54
|
+
configuration.defaultBillingDetails.phone = defaultBillingDetails["phone"] as? String
|
|
55
|
+
|
|
56
|
+
if let address = defaultBillingDetails["address"] as? [String: String] {
|
|
57
|
+
configuration.defaultBillingDetails.address = .init(city: address["city"],
|
|
58
|
+
country: address["country"],
|
|
59
|
+
line1: address["line1"],
|
|
60
|
+
line2: address["line2"],
|
|
61
|
+
postalCode: address["postalCode"],
|
|
62
|
+
state: address["state"])
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if let defaultShippingDetails = params["defaultShippingDetails"] as? NSDictionary {
|
|
68
|
+
configuration.shippingDetails = {
|
|
69
|
+
return AddressSheetUtils.buildAddressDetails(params: defaultShippingDetails)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if #available(iOS 13.0, *) {
|
|
74
|
+
if let style = params["style"] as? String {
|
|
75
|
+
configuration.style = Mappers.mapToUserInterfaceStyle(style)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if let customerId = params["customerId"] as? String {
|
|
80
|
+
if let customerEphemeralKeySecret = params["customerEphemeralKeySecret"] as? String {
|
|
81
|
+
if (!Errors.isEKClientSecretValid(clientSecret: customerEphemeralKeySecret)) {
|
|
82
|
+
return(error: Errors.createError(ErrorType.Failed, "`customerEphemeralKeySecret` format does not match expected client secret formatting."), configuration: nil)
|
|
83
|
+
}
|
|
84
|
+
configuration.customer = .init(id: customerId, ephemeralKeySecret: customerEphemeralKeySecret)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return (nil, configuration)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
internal func preparePaymentSheetInstance(params: NSDictionary, configuration: PaymentSheet.Configuration, resolve: @escaping RCTPromiseResolveBlock) {
|
|
92
|
+
|
|
93
|
+
func handlePaymentSheetFlowControllerResult(result: Result<PaymentSheet.FlowController, Error>, stripeSdk: StripeSdk?) {
|
|
94
|
+
switch result {
|
|
95
|
+
case .failure(let error):
|
|
96
|
+
resolve(Errors.createError(ErrorType.Failed, error as NSError))
|
|
97
|
+
case .success(let paymentSheetFlowController):
|
|
98
|
+
self.paymentSheetFlowController = paymentSheetFlowController
|
|
99
|
+
var result: NSDictionary? = nil
|
|
100
|
+
if let paymentOption = stripeSdk?.paymentSheetFlowController?.paymentOption {
|
|
101
|
+
result = [
|
|
102
|
+
"label": paymentOption.label,
|
|
103
|
+
"image": paymentOption.image.pngData()?.base64EncodedString() ?? ""
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
resolve(Mappers.createResult("paymentOption", result))
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if let paymentIntentClientSecret = params["paymentIntentClientSecret"] as? String {
|
|
111
|
+
if (!Errors.isPIClientSecretValid(clientSecret: paymentIntentClientSecret)) {
|
|
112
|
+
resolve(Errors.createError(ErrorType.Failed, "`secret` format does not match expected client secret formatting."))
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if params["customFlow"] as? Bool == true {
|
|
117
|
+
PaymentSheet.FlowController.create(paymentIntentClientSecret: paymentIntentClientSecret,
|
|
118
|
+
configuration: configuration) { [weak self] result in
|
|
119
|
+
handlePaymentSheetFlowControllerResult(result: result, stripeSdk: self)
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
self.paymentSheet = PaymentSheet(paymentIntentClientSecret: paymentIntentClientSecret, configuration: configuration)
|
|
123
|
+
resolve([])
|
|
124
|
+
}
|
|
125
|
+
} else if let setupIntentClientSecret = params["setupIntentClientSecret"] as? String {
|
|
126
|
+
if (!Errors.isSetiClientSecretValid(clientSecret: setupIntentClientSecret)) {
|
|
127
|
+
resolve(Errors.createError(ErrorType.Failed, "`secret` format does not match expected client secret formatting."))
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if params["customFlow"] as? Bool == true {
|
|
132
|
+
PaymentSheet.FlowController.create(setupIntentClientSecret: setupIntentClientSecret,
|
|
133
|
+
configuration: configuration) { [weak self] result in
|
|
134
|
+
handlePaymentSheetFlowControllerResult(result: result, stripeSdk: self)
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
self.paymentSheet = PaymentSheet(setupIntentClientSecret: setupIntentClientSecret, configuration: configuration)
|
|
138
|
+
resolve([])
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
resolve(Errors.createError(ErrorType.Failed, "You must provide either paymentIntentClientSecret or setupIntentClientSecret"))
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private func buildCustomerHandlersForPaymentSheet(applePayParams: NSDictionary, orderTrackingCallback: RCTResponseSenderBlock?) -> PaymentSheet.ApplePayConfiguration.Handlers? {
|
|
146
|
+
if (applePayParams["request"] == nil && orderTrackingCallback == nil) {
|
|
147
|
+
return nil
|
|
148
|
+
}
|
|
149
|
+
return PaymentSheet.ApplePayConfiguration.Handlers(paymentRequestHandler: { request in
|
|
150
|
+
do {
|
|
151
|
+
try request.configureRequestType(requestParams: applePayParams)
|
|
152
|
+
} catch {
|
|
153
|
+
// At this point, we can't resolve a promise with an error object, so our best option is to create a redbox error
|
|
154
|
+
RCTMakeAndLogError(error.localizedDescription, nil, nil)
|
|
155
|
+
}
|
|
156
|
+
return request
|
|
157
|
+
}, authorizationResultHandler: { result, completion in
|
|
158
|
+
if let orderTrackingCallback = orderTrackingCallback {
|
|
159
|
+
self.orderTrackingHandler = (result, completion)
|
|
160
|
+
orderTrackingCallback(nil)
|
|
161
|
+
} else {
|
|
162
|
+
completion(result)
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
}
|
package/ios/StripeSdk.m
CHANGED
|
@@ -113,7 +113,15 @@ RCT_EXTERN_METHOD(
|
|
|
113
113
|
)
|
|
114
114
|
|
|
115
115
|
RCT_EXTERN_METHOD(
|
|
116
|
-
|
|
116
|
+
initPaymentSheetWithOrderTracking:(NSDictionary *)params
|
|
117
|
+
callback:(RCTResponseSenderBlock)orderTrackingCallback
|
|
118
|
+
resolver: (RCTPromiseResolveBlock)resolve
|
|
119
|
+
rejecter: (RCTPromiseRejectBlock)reject
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
RCT_EXTERN_METHOD(
|
|
123
|
+
presentPaymentSheet:(NSDictionary *)options
|
|
124
|
+
resolver: (RCTPromiseResolveBlock)resolve
|
|
117
125
|
rejecter: (RCTPromiseRejectBlock)reject
|
|
118
126
|
)
|
|
119
127
|
|
|
@@ -177,4 +185,12 @@ RCT_EXTERN_METHOD(
|
|
|
177
185
|
resolver: (RCTPromiseResolveBlock)resolve
|
|
178
186
|
rejecter: (RCTPromiseRejectBlock)reject
|
|
179
187
|
)
|
|
188
|
+
RCT_EXTERN_METHOD(
|
|
189
|
+
configureOrderTracking:(NSString *)orderTypeIdentifier
|
|
190
|
+
orderIdentifier:(NSString *)orderIdentifier
|
|
191
|
+
webServiceUrl:(NSString *)webServiceUrl
|
|
192
|
+
authenticationToken:(NSString *)authenticationToken
|
|
193
|
+
resolver: (RCTPromiseResolveBlock)resolve
|
|
194
|
+
rejecter: (RCTPromiseRejectBlock)reject
|
|
195
|
+
)
|
|
180
196
|
@end
|
package/ios/StripeSdk.swift
CHANGED
|
@@ -10,8 +10,8 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
|
|
|
10
10
|
|
|
11
11
|
var merchantIdentifier: String? = nil
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
internal var paymentSheet: PaymentSheet?
|
|
14
|
+
internal var paymentSheetFlowController: PaymentSheet.FlowController?
|
|
15
15
|
|
|
16
16
|
var urlScheme: String? = nil
|
|
17
17
|
|
|
@@ -42,9 +42,11 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
|
|
|
42
42
|
set { _couponCodeUpdateCompletion = newValue }
|
|
43
43
|
}
|
|
44
44
|
private var _couponCodeUpdateCompletion: Any? = nil
|
|
45
|
+
var orderTrackingHandler: (result: PKPaymentAuthorizationResult, handler: ((PKPaymentAuthorizationResult) -> Void))? = nil
|
|
45
46
|
var shippingMethodUpdateJSCallback: RCTDirectEventBlock? = nil
|
|
46
47
|
var shippingContactUpdateJSCallback: RCTDirectEventBlock? = nil
|
|
47
48
|
var couponCodeEnteredJSCallback: RCTDirectEventBlock? = nil
|
|
49
|
+
var platformPayOrderTrackingJSCallback: RCTDirectEventBlock? = nil
|
|
48
50
|
var applePaySummaryItems: [PKPaymentSummaryItem] = []
|
|
49
51
|
var applePayShippingMethods: [PKShippingMethod] = []
|
|
50
52
|
var applePayShippingAddressErrors: [Error]? = nil
|
|
@@ -59,7 +61,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
override func supportedEvents() -> [String]! {
|
|
62
|
-
return ["onDidSetShippingMethod", "onDidSetShippingContact"]
|
|
64
|
+
return ["onDidSetShippingMethod", "onDidSetShippingContact", "onDidSetCouponCode"]
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
@objc override static func requiresMainQueueSetup() -> Bool {
|
|
@@ -107,134 +109,27 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
|
|
|
107
109
|
@objc(initPaymentSheet:resolver:rejecter:)
|
|
108
110
|
func initPaymentSheet(params: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
109
111
|
rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
110
|
-
var configuration = PaymentSheet.Configuration()
|
|
111
112
|
self.paymentSheetFlowController = nil
|
|
112
113
|
|
|
113
|
-
configuration
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
configuration.appearance = try PaymentSheetAppearance.buildAppearanceFromParams(userParams: appearanceParams)
|
|
118
|
-
} catch {
|
|
119
|
-
resolve(Errors.createError(ErrorType.Failed, error.localizedDescription))
|
|
120
|
-
return
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if let applePayParams = params["applePay"] as? NSDictionary {
|
|
125
|
-
do {
|
|
126
|
-
configuration.applePay = try ApplePayUtils.buildPaymentSheetApplePayConfig(
|
|
127
|
-
merchantIdentifier: self.merchantIdentifier,
|
|
128
|
-
merchantCountryCode: applePayParams["merchantCountryCode"] as? String,
|
|
129
|
-
paymentSummaryItems: applePayParams["paymentSummaryItems"] as? [[String : Any]]
|
|
130
|
-
)
|
|
131
|
-
} catch {
|
|
132
|
-
resolve(Errors.createError(ErrorType.Failed, error.localizedDescription))
|
|
133
|
-
return
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if let merchantDisplayName = params["merchantDisplayName"] as? String {
|
|
138
|
-
configuration.merchantDisplayName = merchantDisplayName
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if let returnURL = params["returnURL"] as? String {
|
|
142
|
-
configuration.returnURL = returnURL
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if let allowsDelayedPaymentMethods = params["allowsDelayedPaymentMethods"] as? Bool {
|
|
146
|
-
configuration.allowsDelayedPaymentMethods = allowsDelayedPaymentMethods
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if let defaultBillingDetails = params["defaultBillingDetails"] as? [String: Any?] {
|
|
150
|
-
configuration.defaultBillingDetails.name = defaultBillingDetails["name"] as? String
|
|
151
|
-
configuration.defaultBillingDetails.email = defaultBillingDetails["email"] as? String
|
|
152
|
-
configuration.defaultBillingDetails.phone = defaultBillingDetails["phone"] as? String
|
|
153
|
-
|
|
154
|
-
if let address = defaultBillingDetails["address"] as? [String: String] {
|
|
155
|
-
configuration.defaultBillingDetails.address = .init(city: address["city"],
|
|
156
|
-
country: address["country"],
|
|
157
|
-
line1: address["line1"],
|
|
158
|
-
line2: address["line2"],
|
|
159
|
-
postalCode: address["postalCode"],
|
|
160
|
-
state: address["state"])
|
|
161
|
-
}
|
|
162
|
-
|
|
114
|
+
let (error, configuration) = buildPaymentSheetConfiguration(params: params)
|
|
115
|
+
guard let configuration = configuration else {
|
|
116
|
+
resolve(error)
|
|
117
|
+
return
|
|
163
118
|
}
|
|
164
119
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return
|
|
176
|
-
}
|
|
177
|
-
configuration.customer = .init(id: customerId, ephemeralKeySecret: customerEphemeralKeySecret)
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if #available(iOS 13.0, *) {
|
|
182
|
-
if let style = params["style"] as? String {
|
|
183
|
-
configuration.style = Mappers.mapToUserInterfaceStyle(style)
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
func handlePaymentSheetFlowControllerResult(result: Result<PaymentSheet.FlowController, Error>, stripeSdk: StripeSdk?) {
|
|
188
|
-
switch result {
|
|
189
|
-
case .failure(let error):
|
|
190
|
-
resolve(Errors.createError(ErrorType.Failed, error as NSError))
|
|
191
|
-
case .success(let paymentSheetFlowController):
|
|
192
|
-
self.paymentSheetFlowController = paymentSheetFlowController
|
|
193
|
-
var result: NSDictionary? = nil
|
|
194
|
-
if let paymentOption = stripeSdk?.paymentSheetFlowController?.paymentOption {
|
|
195
|
-
result = [
|
|
196
|
-
"label": paymentOption.label,
|
|
197
|
-
"image": paymentOption.image.pngData()?.base64EncodedString() ?? ""
|
|
198
|
-
]
|
|
199
|
-
}
|
|
200
|
-
resolve(Mappers.createResult("paymentOption", result))
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if let paymentIntentClientSecret = params["paymentIntentClientSecret"] as? String {
|
|
205
|
-
if (!Errors.isPIClientSecretValid(clientSecret: paymentIntentClientSecret)) {
|
|
206
|
-
resolve(Errors.createError(ErrorType.Failed, "`secret` format does not match expected client secret formatting."))
|
|
207
|
-
return
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if params["customFlow"] as? Bool == true {
|
|
211
|
-
PaymentSheet.FlowController.create(paymentIntentClientSecret: paymentIntentClientSecret,
|
|
212
|
-
configuration: configuration) { [weak self] result in
|
|
213
|
-
handlePaymentSheetFlowControllerResult(result: result, stripeSdk: self)
|
|
214
|
-
}
|
|
215
|
-
} else {
|
|
216
|
-
self.paymentSheet = PaymentSheet(paymentIntentClientSecret: paymentIntentClientSecret, configuration: configuration)
|
|
217
|
-
resolve([])
|
|
218
|
-
}
|
|
219
|
-
} else if let setupIntentClientSecret = params["setupIntentClientSecret"] as? String {
|
|
220
|
-
if (!Errors.isSetiClientSecretValid(clientSecret: setupIntentClientSecret)) {
|
|
221
|
-
resolve(Errors.createError(ErrorType.Failed, "`secret` format does not match expected client secret formatting."))
|
|
222
|
-
return
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if params["customFlow"] as? Bool == true {
|
|
226
|
-
PaymentSheet.FlowController.create(setupIntentClientSecret: setupIntentClientSecret,
|
|
227
|
-
configuration: configuration) { [weak self] result in
|
|
228
|
-
handlePaymentSheetFlowControllerResult(result: result, stripeSdk: self)
|
|
229
|
-
}
|
|
230
|
-
} else {
|
|
231
|
-
self.paymentSheet = PaymentSheet(setupIntentClientSecret: setupIntentClientSecret, configuration: configuration)
|
|
232
|
-
resolve([])
|
|
233
|
-
}
|
|
234
|
-
} else {
|
|
235
|
-
resolve(Errors.createError(ErrorType.Failed, "You must provide either paymentIntentClientSecret or setupIntentClientSecret"))
|
|
120
|
+
preparePaymentSheetInstance(params: params, configuration: configuration, resolve: resolve)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@objc(initPaymentSheetWithOrderTracking:callback:resolver:rejecter:)
|
|
124
|
+
func initPaymentSheetWithOrderTracking(params: NSDictionary, callback orderTrackingCallback: @escaping RCTResponseSenderBlock, resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
125
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
126
|
+
let (error, configuration) = buildPaymentSheetConfiguration(params: params, orderTrackingCallback: orderTrackingCallback)
|
|
127
|
+
guard let configuration = configuration else {
|
|
128
|
+
resolve(error)
|
|
129
|
+
return
|
|
236
130
|
}
|
|
237
|
-
|
|
131
|
+
|
|
132
|
+
preparePaymentSheetInstance(params: params, configuration: configuration, resolve: resolve)
|
|
238
133
|
}
|
|
239
134
|
|
|
240
135
|
@objc(confirmPaymentSheetPayment:rejecter:)
|
|
@@ -267,15 +162,26 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
|
|
|
267
162
|
resolve(nil)
|
|
268
163
|
}
|
|
269
164
|
|
|
270
|
-
@objc(presentPaymentSheet:rejecter:)
|
|
271
|
-
func presentPaymentSheet(
|
|
165
|
+
@objc(presentPaymentSheet:resolver:rejecter:)
|
|
166
|
+
func presentPaymentSheet(options: NSDictionary,
|
|
167
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
272
168
|
rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
|
|
273
|
-
|
|
169
|
+
var paymentSheetViewController: UIViewController?
|
|
170
|
+
|
|
171
|
+
if let timeout = options["timeout"] as? Double {
|
|
172
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + timeout/1000) {
|
|
173
|
+
if let paymentSheetViewController = paymentSheetViewController {
|
|
174
|
+
paymentSheetViewController.dismiss(animated: true)
|
|
175
|
+
resolve(Errors.createError(ErrorType.Timeout, "The payment has timed out."))
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
274
179
|
DispatchQueue.main.async {
|
|
180
|
+
paymentSheetViewController = UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()
|
|
275
181
|
if let paymentSheetFlowController = self.paymentSheetFlowController {
|
|
276
|
-
paymentSheetFlowController.presentPaymentOptions(from:
|
|
277
|
-
findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController())
|
|
182
|
+
paymentSheetFlowController.presentPaymentOptions(from: findViewControllerPresenter(from: paymentSheetViewController!)
|
|
278
183
|
) {
|
|
184
|
+
paymentSheetViewController = nil
|
|
279
185
|
if let paymentOption = self.paymentSheetFlowController?.paymentOption {
|
|
280
186
|
let option: NSDictionary = [
|
|
281
187
|
"label": paymentOption.label,
|
|
@@ -287,9 +193,9 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
|
|
|
287
193
|
}
|
|
288
194
|
}
|
|
289
195
|
} else if let paymentSheet = self.paymentSheet {
|
|
290
|
-
paymentSheet.present(from:
|
|
291
|
-
findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController())
|
|
196
|
+
paymentSheet.present(from: findViewControllerPresenter(from: paymentSheetViewController!)
|
|
292
197
|
) { paymentResult in
|
|
198
|
+
paymentSheetViewController = nil
|
|
293
199
|
switch paymentResult {
|
|
294
200
|
case .completed:
|
|
295
201
|
resolve([])
|
|
@@ -301,7 +207,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
|
|
|
301
207
|
}
|
|
302
208
|
}
|
|
303
209
|
} else {
|
|
304
|
-
resolve(Errors.createError(ErrorType.Failed, "No payment sheet has been initialized yet"))
|
|
210
|
+
resolve(Errors.createError(ErrorType.Failed, "No payment sheet has been initialized yet. You must call `initPaymentSheet` before `presentPaymentSheet`."))
|
|
305
211
|
}
|
|
306
212
|
}
|
|
307
213
|
}
|
|
@@ -603,6 +509,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
|
|
|
603
509
|
self.applePayShippingMethods = paymentRequest.shippingMethods ?? []
|
|
604
510
|
self.applePayShippingAddressErrors = nil
|
|
605
511
|
self.applePayCouponCodeErrors = nil
|
|
512
|
+
self.orderTrackingHandler = nil
|
|
606
513
|
self.confirmApplePayResolver = resolve
|
|
607
514
|
if (isPaymentIntent) {
|
|
608
515
|
self.confirmApplePayPaymentClientSecret = clientSecret
|
|
@@ -1182,6 +1089,32 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
|
|
|
1182
1089
|
}
|
|
1183
1090
|
FinancialConnections.present(withClientSecret: clientSecret, returnURL: returnURL, resolve: resolve)
|
|
1184
1091
|
}
|
|
1092
|
+
|
|
1093
|
+
@objc(configureOrderTracking:orderIdentifier:webServiceUrl:authenticationToken:resolver:rejecter:)
|
|
1094
|
+
func configureOrderTracking(
|
|
1095
|
+
orderTypeIdentifier: String,
|
|
1096
|
+
orderIdentifier: String,
|
|
1097
|
+
webServiceUrl: String,
|
|
1098
|
+
authenticationToken: String,
|
|
1099
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
1100
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
1101
|
+
) {
|
|
1102
|
+
#if compiler(>=5.7)
|
|
1103
|
+
if #available(iOS 16.0, *) {
|
|
1104
|
+
if let orderTrackingHandler = self.orderTrackingHandler {
|
|
1105
|
+
if let url = URL(string: webServiceUrl) {
|
|
1106
|
+
orderTrackingHandler.result.orderDetails = PKPaymentOrderDetails(
|
|
1107
|
+
orderTypeIdentifier: orderTypeIdentifier,
|
|
1108
|
+
orderIdentifier: orderIdentifier,
|
|
1109
|
+
webServiceURL: url,
|
|
1110
|
+
authenticationToken: authenticationToken)
|
|
1111
|
+
}
|
|
1112
|
+
orderTrackingHandler.handler(orderTrackingHandler.result)
|
|
1113
|
+
self.orderTrackingHandler = nil
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
#endif
|
|
1117
|
+
}
|
|
1185
1118
|
|
|
1186
1119
|
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
|
|
1187
1120
|
confirmPaymentResolver?(Errors.createError(ErrorType.Canceled, "FPX Payment has been canceled"))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["StripeSdk","NativeModules"],"sources":["NativeStripeSdk.tsx"],"sourcesContent":["import { NativeModules } from 'react-native';\nimport type {\n PaymentMethod,\n PaymentIntent,\n ApplePay,\n PlatformPay,\n PaymentSheet,\n SetupIntent,\n InitialiseParams,\n CreatePaymentMethodResult,\n RetrievePaymentIntentResult,\n RetrieveSetupIntentResult,\n ConfirmPaymentResult,\n HandleNextActionResult,\n ConfirmSetupIntentResult,\n CreateTokenForCVCUpdateResult,\n InitPaymentSheetResult,\n PresentPaymentSheetResult,\n ConfirmPaymentSheetPaymentResult,\n ApplePayResult,\n CreateTokenResult,\n GooglePayInitResult,\n PayWithGooglePayResult,\n CreateGooglePayPaymentMethodResult,\n GooglePay,\n OpenApplePaySetupResult,\n Token,\n VerifyMicrodepositsParams,\n IsCardInWalletResult,\n CanAddCardToWalletParams,\n CanAddCardToWalletResult,\n FinancialConnections,\n} from './types';\n\ntype NativeStripeSdkType = {\n initialise(params: InitialiseParams): Promise<void>;\n createPaymentMethod(\n params: PaymentMethod.CreateParams,\n options: PaymentMethod.CreateOptions\n ): Promise<CreatePaymentMethodResult>;\n handleNextAction(\n paymentIntentClientSecret: string,\n returnURL?: string | null\n ): Promise<HandleNextActionResult>;\n confirmPayment(\n paymentIntentClientSecret: string,\n params?: PaymentIntent.ConfirmParams,\n options?: PaymentIntent.ConfirmOptions\n ): Promise<ConfirmPaymentResult>;\n isApplePaySupported(): Promise<boolean>;\n presentApplePay(params: ApplePay.PresentParams): Promise<ApplePayResult>;\n confirmApplePayPayment(clientSecret: string): Promise<void>;\n updateApplePaySummaryItems(\n summaryItems: ApplePay.CartSummaryItem[],\n errorAddressFields: Array<{\n field: ApplePay.AddressFields;\n message?: string;\n }>\n ): Promise<void>;\n confirmSetupIntent(\n paymentIntentClientSecret: string,\n params: SetupIntent.ConfirmParams,\n options: SetupIntent.ConfirmOptions\n ): Promise<ConfirmSetupIntentResult>;\n retrievePaymentIntent(\n clientSecret: string\n ): Promise<RetrievePaymentIntentResult>;\n retrieveSetupIntent(clientSecret: string): Promise<RetrieveSetupIntentResult>;\n initPaymentSheet(\n params: PaymentSheet.SetupParams\n ): Promise<InitPaymentSheetResult>;\n presentPaymentSheet(): Promise<PresentPaymentSheetResult>;\n confirmPaymentSheetPayment(): Promise<ConfirmPaymentSheetPaymentResult>;\n createTokenForCVCUpdate(cvc: string): Promise<CreateTokenForCVCUpdateResult>;\n handleURLCallback(url: string): Promise<boolean>;\n createToken(params: Token.CreateParams): Promise<CreateTokenResult>;\n isGooglePaySupported(params: GooglePay.IsSupportedParams): Promise<boolean>;\n initGooglePay(params: GooglePay.InitParams): Promise<GooglePayInitResult>;\n presentGooglePay(\n params: GooglePay.PresentParams\n ): Promise<PayWithGooglePayResult>;\n createGooglePayPaymentMethod(\n params: GooglePay.CreatePaymentMethodParams\n ): Promise<CreateGooglePayPaymentMethodResult>;\n openApplePaySetup(): Promise<OpenApplePaySetupResult>;\n verifyMicrodeposits(\n isPaymentIntent: boolean,\n clientSecret: string,\n params: VerifyMicrodepositsParams\n ): Promise<ConfirmSetupIntentResult | ConfirmPaymentResult>;\n collectBankAccount(\n isPaymentIntent: boolean,\n clientSecret: string,\n params: PaymentMethod.CollectBankAccountParams\n ): Promise<ConfirmSetupIntentResult | ConfirmPaymentResult>;\n getConstants(): { API_VERSIONS: { CORE: string; ISSUING: string } };\n canAddCardToWallet(\n params: CanAddCardToWalletParams\n ): Promise<CanAddCardToWalletResult>;\n isCardInWallet(params: {\n cardLastFour: string;\n }): Promise<IsCardInWalletResult>;\n collectBankAccountToken(\n clientSecret: string\n ): Promise<FinancialConnections.TokenResult>;\n collectFinancialConnectionsAccounts(\n clientSecret: string\n ): Promise<FinancialConnections.SessionResult>;\n resetPaymentSheetCustomer(): Promise<null>;\n isPlatformPaySupported(params: {\n googlePay?: GooglePay.IsSupportedParams;\n }): Promise<boolean>;\n createPlatformPayPaymentMethod(\n params: PlatformPay.PaymentMethodParams,\n usesDeprecatedTokenFlow: boolean\n ): Promise<PlatformPay.PaymentMethodResult | PlatformPay.TokenResult>;\n dismissPlatformPay(): Promise<boolean>;\n updatePlatformPaySheet(\n summaryItems: Array<ApplePay.CartSummaryItem>,\n shippingMethods: Array<ApplePay.ShippingMethod>,\n errors: Array<PlatformPay.ApplePaySheetError>\n ): Promise<void>;\n confirmPlatformPay(\n clientSecret: string,\n params: PlatformPay.ConfirmParams,\n isPaymentIntent: boolean\n ): Promise<\n PlatformPay.ConfirmPaymentResult | PlatformPay.ConfirmSetupIntentResult\n >;\n};\n\nconst { StripeSdk } = NativeModules;\n\nexport default StripeSdk as NativeStripeSdkType;\n"],"mappings":"gFAAA,
|
|
1
|
+
{"version":3,"names":["StripeSdk","NativeModules"],"sources":["NativeStripeSdk.tsx"],"sourcesContent":["import { NativeModules } from 'react-native';\nimport type {\n PaymentMethod,\n PaymentIntent,\n ApplePay,\n PlatformPay,\n PaymentSheet,\n SetupIntent,\n InitialiseParams,\n CreatePaymentMethodResult,\n RetrievePaymentIntentResult,\n RetrieveSetupIntentResult,\n ConfirmPaymentResult,\n HandleNextActionResult,\n ConfirmSetupIntentResult,\n CreateTokenForCVCUpdateResult,\n InitPaymentSheetResult,\n PresentPaymentSheetResult,\n ConfirmPaymentSheetPaymentResult,\n ApplePayResult,\n CreateTokenResult,\n GooglePayInitResult,\n PayWithGooglePayResult,\n CreateGooglePayPaymentMethodResult,\n GooglePay,\n OpenApplePaySetupResult,\n Token,\n VerifyMicrodepositsParams,\n IsCardInWalletResult,\n CanAddCardToWalletParams,\n CanAddCardToWalletResult,\n FinancialConnections,\n} from './types';\n\ntype NativeStripeSdkType = {\n initialise(params: InitialiseParams): Promise<void>;\n createPaymentMethod(\n params: PaymentMethod.CreateParams,\n options: PaymentMethod.CreateOptions\n ): Promise<CreatePaymentMethodResult>;\n handleNextAction(\n paymentIntentClientSecret: string,\n returnURL?: string | null\n ): Promise<HandleNextActionResult>;\n confirmPayment(\n paymentIntentClientSecret: string,\n params?: PaymentIntent.ConfirmParams,\n options?: PaymentIntent.ConfirmOptions\n ): Promise<ConfirmPaymentResult>;\n isApplePaySupported(): Promise<boolean>;\n presentApplePay(params: ApplePay.PresentParams): Promise<ApplePayResult>;\n confirmApplePayPayment(clientSecret: string): Promise<void>;\n updateApplePaySummaryItems(\n summaryItems: ApplePay.CartSummaryItem[],\n errorAddressFields: Array<{\n field: ApplePay.AddressFields;\n message?: string;\n }>\n ): Promise<void>;\n confirmSetupIntent(\n paymentIntentClientSecret: string,\n params: SetupIntent.ConfirmParams,\n options: SetupIntent.ConfirmOptions\n ): Promise<ConfirmSetupIntentResult>;\n retrievePaymentIntent(\n clientSecret: string\n ): Promise<RetrievePaymentIntentResult>;\n retrieveSetupIntent(clientSecret: string): Promise<RetrieveSetupIntentResult>;\n initPaymentSheet(\n params: PaymentSheet.SetupParams\n ): Promise<InitPaymentSheetResult>;\n initPaymentSheetWithOrderTracking(\n params: PaymentSheet.SetupParams,\n callback?: () => void\n ): Promise<InitPaymentSheetResult>;\n presentPaymentSheet(\n options: PaymentSheet.PresentOptions\n ): Promise<PresentPaymentSheetResult>;\n confirmPaymentSheetPayment(): Promise<ConfirmPaymentSheetPaymentResult>;\n createTokenForCVCUpdate(cvc: string): Promise<CreateTokenForCVCUpdateResult>;\n handleURLCallback(url: string): Promise<boolean>;\n createToken(params: Token.CreateParams): Promise<CreateTokenResult>;\n isGooglePaySupported(params: GooglePay.IsSupportedParams): Promise<boolean>;\n initGooglePay(params: GooglePay.InitParams): Promise<GooglePayInitResult>;\n presentGooglePay(\n params: GooglePay.PresentParams\n ): Promise<PayWithGooglePayResult>;\n createGooglePayPaymentMethod(\n params: GooglePay.CreatePaymentMethodParams\n ): Promise<CreateGooglePayPaymentMethodResult>;\n openApplePaySetup(): Promise<OpenApplePaySetupResult>;\n verifyMicrodeposits(\n isPaymentIntent: boolean,\n clientSecret: string,\n params: VerifyMicrodepositsParams\n ): Promise<ConfirmSetupIntentResult | ConfirmPaymentResult>;\n collectBankAccount(\n isPaymentIntent: boolean,\n clientSecret: string,\n params: PaymentMethod.CollectBankAccountParams\n ): Promise<ConfirmSetupIntentResult | ConfirmPaymentResult>;\n getConstants(): { API_VERSIONS: { CORE: string; ISSUING: string } };\n canAddCardToWallet(\n params: CanAddCardToWalletParams\n ): Promise<CanAddCardToWalletResult>;\n isCardInWallet(params: {\n cardLastFour: string;\n }): Promise<IsCardInWalletResult>;\n collectBankAccountToken(\n clientSecret: string\n ): Promise<FinancialConnections.TokenResult>;\n collectFinancialConnectionsAccounts(\n clientSecret: string\n ): Promise<FinancialConnections.SessionResult>;\n resetPaymentSheetCustomer(): Promise<null>;\n isPlatformPaySupported(params: {\n googlePay?: GooglePay.IsSupportedParams;\n }): Promise<boolean>;\n createPlatformPayPaymentMethod(\n params: PlatformPay.PaymentMethodParams,\n usesDeprecatedTokenFlow: boolean\n ): Promise<PlatformPay.PaymentMethodResult | PlatformPay.TokenResult>;\n dismissPlatformPay(): Promise<boolean>;\n updatePlatformPaySheet(\n summaryItems: Array<ApplePay.CartSummaryItem>,\n shippingMethods: Array<ApplePay.ShippingMethod>,\n errors: Array<PlatformPay.ApplePaySheetError>\n ): Promise<void>;\n confirmPlatformPay(\n clientSecret: string,\n params: PlatformPay.ConfirmParams,\n isPaymentIntent: boolean\n ): Promise<\n PlatformPay.ConfirmPaymentResult | PlatformPay.ConfirmSetupIntentResult\n >;\n configureOrderTracking(\n orderTypeIdentifier: string,\n orderIdentifier: string,\n webServiceUrl: string,\n authenticationToken: string\n ): Promise<void>;\n};\n\nconst { StripeSdk } = NativeModules;\n\nexport default StripeSdk as NativeStripeSdkType;\n"],"mappings":"gFAAA,yCA+IA,GAAQA,UAAS,CAAKC,0BAAa,CAA3BD,SAAS,CAAmB,aAErBA,SAAS"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.PlatformPayButton=PlatformPayButton;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));var _objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));var _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _PlatformPay=require("../types/PlatformPay");var _GooglePayButtonNative=_interopRequireDefault(require("./GooglePayButtonNative"));var _ApplePayButtonNative=_interopRequireDefault(require("./ApplePayButtonNative"));var _jsxFileName="/Users/charliecruzan/stripe/stripe-react-native/src/components/PlatformPayButton.tsx";var _excluded=["type","appearance","onPress","disabled","borderRadius","onShippingMethodSelected","onShippingContactSelected","onCouponCodeEntered"];function PlatformPayButton(_ref){var _ref$type=_ref.type,type=_ref$type===void 0?_PlatformPay.ButtonType.Default:_ref$type,_ref$appearance=_ref.appearance,appearance=_ref$appearance===void 0?_PlatformPay.ButtonStyle.Automatic:_ref$appearance,onPress=_ref.onPress,disabled=_ref.disabled,borderRadius=_ref.borderRadius,onShippingMethodSelected=_ref.onShippingMethodSelected,onShippingContactSelected=_ref.onShippingContactSelected,onCouponCodeEntered=_ref.onCouponCodeEntered,props=(0,_objectWithoutProperties2.default)(_ref,_excluded);var shippingMethodCallback=onShippingMethodSelected?function(value){onShippingMethodSelected&&onShippingMethodSelected(value.nativeEvent);}:undefined;var shippingContactCallback=onShippingContactSelected?function(value){onShippingContactSelected(value.nativeEvent);}:undefined;var couponCodeCallback=onCouponCodeEntered?function(value){onCouponCodeEntered&&onCouponCodeEntered(value.nativeEvent);}:undefined;return _react.default.createElement(_reactNative.TouchableOpacity,{disabled:disabled,activeOpacity:disabled?0.3:1,onPress:onPress,style:disabled?styles.disabled:styles.notDisabled,__self:this,__source:{fileName:_jsxFileName,lineNumber:
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.PlatformPayButton=PlatformPayButton;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));var _objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));var _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _NativeStripeSdk=_interopRequireDefault(require("../NativeStripeSdk"));var _PlatformPay=require("../types/PlatformPay");var _GooglePayButtonNative=_interopRequireDefault(require("./GooglePayButtonNative"));var _ApplePayButtonNative=_interopRequireDefault(require("./ApplePayButtonNative"));var _jsxFileName="/Users/charliecruzan/stripe/stripe-react-native/src/components/PlatformPayButton.tsx";var _excluded=["type","appearance","onPress","disabled","borderRadius","onShippingMethodSelected","onShippingContactSelected","onCouponCodeEntered","setOrderTracking","style"];function PlatformPayButton(_ref){var _ref$type=_ref.type,type=_ref$type===void 0?_PlatformPay.ButtonType.Default:_ref$type,_ref$appearance=_ref.appearance,appearance=_ref$appearance===void 0?_PlatformPay.ButtonStyle.Automatic:_ref$appearance,onPress=_ref.onPress,disabled=_ref.disabled,borderRadius=_ref.borderRadius,onShippingMethodSelected=_ref.onShippingMethodSelected,onShippingContactSelected=_ref.onShippingContactSelected,onCouponCodeEntered=_ref.onCouponCodeEntered,setOrderTracking=_ref.setOrderTracking,style=_ref.style,props=(0,_objectWithoutProperties2.default)(_ref,_excluded);var shippingMethodCallback=onShippingMethodSelected?function(value){onShippingMethodSelected&&onShippingMethodSelected(value.nativeEvent);}:undefined;var shippingContactCallback=onShippingContactSelected?function(value){onShippingContactSelected(value.nativeEvent);}:undefined;var couponCodeCallback=onCouponCodeEntered?function(value){onCouponCodeEntered&&onCouponCodeEntered(value.nativeEvent);}:undefined;var orderTrackingCallback=setOrderTracking?function(){setOrderTracking(_NativeStripeSdk.default.configureOrderTracking);}:undefined;return _react.default.createElement(_reactNative.TouchableOpacity,{disabled:disabled,activeOpacity:disabled?0.3:1,onPress:onPress,style:[disabled?styles.disabled:styles.notDisabled,style],__self:this,__source:{fileName:_jsxFileName,lineNumber:144,columnNumber:5}},_reactNative.Platform.OS==='ios'?_react.default.createElement(_ApplePayButtonNative.default,(0,_extends2.default)({type:type,buttonStyle:appearance,borderRadius:borderRadius,disabled:disabled,onShippingMethodSelectedAction:shippingMethodCallback,onShippingContactSelectedAction:shippingContactCallback,onCouponCodeEnteredAction:couponCodeCallback,onOrderTrackingAction:orderTrackingCallback,style:styles.nativeButtonStyle},props,{__self:this,__source:{fileName:_jsxFileName,lineNumber:151,columnNumber:9}})):_react.default.createElement(_GooglePayButtonNative.default,(0,_extends2.default)({type:type,style:styles.nativeButtonStyle},props,{__self:this,__source:{fileName:_jsxFileName,lineNumber:164,columnNumber:9}})));}var styles=_reactNative.StyleSheet.create({disabled:{flex:0,opacity:0.4},notDisabled:{flex:0},nativeButtonStyle:{flex:1}});
|
|
2
2
|
//# sourceMappingURL=PlatformPayButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PlatformPayButton","type","ButtonType","Default","appearance","ButtonStyle","Automatic","onPress","disabled","borderRadius","onShippingMethodSelected","onShippingContactSelected","onCouponCodeEntered","props","shippingMethodCallback","value","nativeEvent","undefined","shippingContactCallback","couponCodeCallback","styles","notDisabled","Platform","OS","StyleSheet","create","flex","opacity"],"sources":["PlatformPayButton.tsx"],"sourcesContent":["import React from 'react';\nimport {\n AccessibilityProps,\n StyleProp,\n ViewStyle,\n TouchableOpacity,\n StyleSheet,\n Platform,\n NativeSyntheticEvent,\n} from 'react-native';\nimport {\n ButtonType,\n ButtonStyle,\n ShippingMethod,\n ShippingContact,\n} from '../types/PlatformPay';\nimport GooglePayButtonNative from './GooglePayButtonNative';\nimport ApplePayButtonNative from './ApplePayButtonNative';\n\n/**\n * PlatformPayButton Component Props\n */\nexport interface Props extends AccessibilityProps {\n /** Sets the text displayed by the button. */\n type?: ButtonType;\n /** iOS only. Sets the coloring of the button. */\n appearance?: ButtonStyle;\n /** iOS only. Sets the border radius of the button. */\n borderRadius?: number;\n /** Function called whenever the button is pressed. */\n onPress(): void;\n /** Set to `true` to disable the button from being pressed & apply a slight opacity to indicate that it is unpressable. Defaults to false. */\n disabled?: boolean;\n /**\n * This callback is triggered whenever the user selects a shipping method in the Apple Pay sheet.\n * It receives one parameter: an `event` object with a `shippingMethod` field. You MUST\n * update the Apple Pay sheet in your callback using the updatePlatformPaySheet function, otherwise the\n * Apple Pay sheet will hang and the payment flow will automatically cancel.\n */\n onShippingMethodSelected?: (event: {\n shippingMethod: ShippingMethod;\n }) => void;\n /**\n * This callback is triggered whenever the user selects a shipping contact in the Apple Pay sheet.\n * It receives one parameter: an `event` object with a `shippingContact` field. You MUST\n * update the Apple Pay sheet in your callback using the updatePlatformPaySheet function, otherwise the\n * Apple Pay sheet will hang and the payment flow will automatically cancel.\n */\n onShippingContactSelected?: (event: {\n shippingContact: ShippingContact;\n }) => void;\n /**\n * This callback is triggered whenever the user inputs a coupon code in the Apple Pay sheet.\n * It receives one parameter: an `event` object with a `couponCode` field. You MUST\n * update the Apple Pay sheet in your callback using the updatePlatformPaySheet function, otherwise the\n * Apple Pay sheet will hang and the payment flow will automatically cancel.\n */\n onCouponCodeEntered?: (event: { couponCode: string }) => void;\n testID?: string;\n style?: StyleProp<ViewStyle>;\n}\n\n/**\n * PlatformPayButton Component. Display the platform-specific native wallet pay button: Apple Pay on iOS, and Google Pay on Android.\n *\n * @example\n * ```ts\n * <PlatformPayButton\n * onPress={pay}\n * type={PlatformPay.ButtonType.Subscribe}\n * appearance={PlatformPay.ButtonStyle.WhiteOutline}\n * borderRadius={4}\n * disabled={!isApplePaySupported}\n * style={styles.payButton}\n * />\n * ```\n * @param __namedParameters Props\n * @returns JSX.Element\n * @category ReactComponents\n */\nexport function PlatformPayButton({\n type = ButtonType.Default,\n appearance = ButtonStyle.Automatic,\n onPress,\n disabled,\n borderRadius,\n onShippingMethodSelected,\n onShippingContactSelected,\n onCouponCodeEntered,\n ...props\n}: Props) {\n const shippingMethodCallback = onShippingMethodSelected\n ? (\n value: NativeSyntheticEvent<{\n shippingMethod: ShippingMethod;\n }>\n ) => {\n onShippingMethodSelected && onShippingMethodSelected(value.nativeEvent);\n }\n : undefined;\n\n const shippingContactCallback = onShippingContactSelected\n ? (\n value: NativeSyntheticEvent<{\n shippingContact: ShippingContact;\n }>\n ) => {\n onShippingContactSelected(value.nativeEvent);\n }\n : undefined;\n\n const couponCodeCallback = onCouponCodeEntered\n ? (\n value: NativeSyntheticEvent<{\n couponCode: string;\n }>\n ) => {\n onCouponCodeEntered && onCouponCodeEntered(value.nativeEvent);\n }\n : undefined;\n\n return (\n <TouchableOpacity\n disabled={disabled}\n activeOpacity={disabled ? 0.3 : 1}\n onPress={onPress}\n style={disabled ? styles.disabled : styles.notDisabled}\n >\n {Platform.OS === 'ios' ? (\n <ApplePayButtonNative\n type={type}\n buttonStyle={appearance}\n borderRadius={borderRadius}\n disabled={disabled}\n onShippingMethodSelectedAction={shippingMethodCallback}\n onShippingContactSelectedAction={shippingContactCallback}\n onCouponCodeEnteredAction={couponCodeCallback}\n {...props}\n />\n ) : (\n <GooglePayButtonNative
|
|
1
|
+
{"version":3,"names":["PlatformPayButton","type","ButtonType","Default","appearance","ButtonStyle","Automatic","onPress","disabled","borderRadius","onShippingMethodSelected","onShippingContactSelected","onCouponCodeEntered","setOrderTracking","style","props","shippingMethodCallback","value","nativeEvent","undefined","shippingContactCallback","couponCodeCallback","orderTrackingCallback","NativeStripeSdk","configureOrderTracking","styles","notDisabled","Platform","OS","nativeButtonStyle","StyleSheet","create","flex","opacity"],"sources":["PlatformPayButton.tsx"],"sourcesContent":["import React from 'react';\nimport {\n AccessibilityProps,\n StyleProp,\n ViewStyle,\n TouchableOpacity,\n StyleSheet,\n Platform,\n NativeSyntheticEvent,\n} from 'react-native';\nimport NativeStripeSdk from '../NativeStripeSdk';\nimport {\n ButtonType,\n ButtonStyle,\n ShippingMethod,\n ShippingContact,\n} from '../types/PlatformPay';\nimport GooglePayButtonNative from './GooglePayButtonNative';\nimport ApplePayButtonNative from './ApplePayButtonNative';\n\n/**\n * PlatformPayButton Component Props\n */\nexport interface Props extends AccessibilityProps {\n /** Sets the text displayed by the button. */\n type?: ButtonType;\n /** iOS only. Sets the coloring of the button. */\n appearance?: ButtonStyle;\n /** iOS only. Sets the border radius of the button. */\n borderRadius?: number;\n /** Function called whenever the button is pressed. */\n onPress(): void;\n /** Set to `true` to disable the button from being pressed & apply a slight opacity to indicate that it is unpressable. Defaults to false. */\n disabled?: boolean;\n /**\n * This callback is triggered whenever the user selects a shipping method in the Apple Pay sheet.\n * It receives one parameter: an `event` object with a `shippingMethod` field. You MUST\n * update the Apple Pay sheet in your callback using the updatePlatformPaySheet function, otherwise the\n * Apple Pay sheet will hang and the payment flow will automatically cancel.\n */\n onShippingMethodSelected?: (event: {\n shippingMethod: ShippingMethod;\n }) => void;\n /**\n * This callback is triggered whenever the user selects a shipping contact in the Apple Pay sheet.\n * It receives one parameter: an `event` object with a `shippingContact` field. You MUST\n * update the Apple Pay sheet in your callback using the updatePlatformPaySheet function, otherwise the\n * Apple Pay sheet will hang and the payment flow will automatically cancel.\n */\n onShippingContactSelected?: (event: {\n shippingContact: ShippingContact;\n }) => void;\n /**\n * This callback is triggered whenever the user inputs a coupon code in the Apple Pay sheet.\n * It receives one parameter: an `event` object with a `couponCode` field. You MUST\n * update the Apple Pay sheet in your callback using the updatePlatformPaySheet function, otherwise the\n * Apple Pay sheet will hang and the payment flow will automatically cancel.\n */\n onCouponCodeEntered?: (event: { couponCode: string }) => void;\n /** Callback function for setting the order details (retrieved from your server) to give users the\n * ability to track and manage their purchases in Wallet. Stripe calls your implementation after the\n * payment is complete, but before iOS dismisses the Apple Pay sheet. You must call the `completion`\n * function, or else the Apple Pay sheet will hang.*/\n setOrderTracking?: (\n completion: (\n orderIdentifier: string,\n orderTypeIdentifier: string,\n authenticationToken: string,\n webServiceUrl: string\n ) => void\n ) => void;\n testID?: string;\n style?: StyleProp<ViewStyle>;\n}\n\n/**\n * PlatformPayButton Component. Display the platform-specific native wallet pay button: Apple Pay on iOS, and Google Pay on Android.\n *\n * @example\n * ```ts\n * <PlatformPayButton\n * onPress={pay}\n * type={PlatformPay.ButtonType.Subscribe}\n * appearance={PlatformPay.ButtonStyle.WhiteOutline}\n * borderRadius={4}\n * disabled={!isApplePaySupported}\n * style={styles.payButton}\n * />\n * ```\n * @param __namedParameters Props\n * @returns JSX.Element\n * @category ReactComponents\n */\nexport function PlatformPayButton({\n type = ButtonType.Default,\n appearance = ButtonStyle.Automatic,\n onPress,\n disabled,\n borderRadius,\n onShippingMethodSelected,\n onShippingContactSelected,\n onCouponCodeEntered,\n setOrderTracking,\n style,\n ...props\n}: Props) {\n const shippingMethodCallback = onShippingMethodSelected\n ? (\n value: NativeSyntheticEvent<{\n shippingMethod: ShippingMethod;\n }>\n ) => {\n onShippingMethodSelected && onShippingMethodSelected(value.nativeEvent);\n }\n : undefined;\n\n const shippingContactCallback = onShippingContactSelected\n ? (\n value: NativeSyntheticEvent<{\n shippingContact: ShippingContact;\n }>\n ) => {\n onShippingContactSelected(value.nativeEvent);\n }\n : undefined;\n\n const couponCodeCallback = onCouponCodeEntered\n ? (\n value: NativeSyntheticEvent<{\n couponCode: string;\n }>\n ) => {\n onCouponCodeEntered && onCouponCodeEntered(value.nativeEvent);\n }\n : undefined;\n\n const orderTrackingCallback = setOrderTracking\n ? () => {\n setOrderTracking(NativeStripeSdk.configureOrderTracking);\n }\n : undefined;\n\n return (\n <TouchableOpacity\n disabled={disabled}\n activeOpacity={disabled ? 0.3 : 1}\n onPress={onPress}\n style={[disabled ? styles.disabled : styles.notDisabled, style]}\n >\n {Platform.OS === 'ios' ? (\n <ApplePayButtonNative\n type={type}\n buttonStyle={appearance}\n borderRadius={borderRadius}\n disabled={disabled}\n onShippingMethodSelectedAction={shippingMethodCallback}\n onShippingContactSelectedAction={shippingContactCallback}\n onCouponCodeEnteredAction={couponCodeCallback}\n onOrderTrackingAction={orderTrackingCallback}\n style={styles.nativeButtonStyle}\n {...props}\n />\n ) : (\n <GooglePayButtonNative\n type={type}\n style={styles.nativeButtonStyle}\n {...props}\n />\n )}\n </TouchableOpacity>\n );\n}\n\nconst styles = StyleSheet.create({\n disabled: {\n flex: 0,\n opacity: 0.4,\n },\n notDisabled: {\n flex: 0,\n },\n nativeButtonStyle: { flex: 1 },\n});\n"],"mappings":"wXAAA,oDACA,yCASA,2EACA,iDAMA,sFACA,oFAA0D,wRA2EnD,QAASA,kBAAiB,MAYvB,oBAXRC,IAAI,CAAJA,IAAI,oBAAGC,uBAAU,CAACC,OAAO,gCACzBC,UAAU,CAAVA,UAAU,0BAAGC,wBAAW,CAACC,SAAS,iBAClCC,OAAO,MAAPA,OAAO,CACPC,QAAQ,MAARA,QAAQ,CACRC,YAAY,MAAZA,YAAY,CACZC,wBAAwB,MAAxBA,wBAAwB,CACxBC,yBAAyB,MAAzBA,yBAAyB,CACzBC,mBAAmB,MAAnBA,mBAAmB,CACnBC,gBAAgB,MAAhBA,gBAAgB,CAChBC,KAAK,MAALA,KAAK,CACFC,KAAK,uDAER,GAAMC,uBAAsB,CAAGN,wBAAwB,CACnD,SACEO,KAEE,CACC,CACHP,wBAAwB,EAAIA,wBAAwB,CAACO,KAAK,CAACC,WAAW,CAAC,CACzE,CAAC,CACDC,SAAS,CAEb,GAAMC,wBAAuB,CAAGT,yBAAyB,CACrD,SACEM,KAEE,CACC,CACHN,yBAAyB,CAACM,KAAK,CAACC,WAAW,CAAC,CAC9C,CAAC,CACDC,SAAS,CAEb,GAAME,mBAAkB,CAAGT,mBAAmB,CAC1C,SACEK,KAEE,CACC,CACHL,mBAAmB,EAAIA,mBAAmB,CAACK,KAAK,CAACC,WAAW,CAAC,CAC/D,CAAC,CACDC,SAAS,CAEb,GAAMG,sBAAqB,CAAGT,gBAAgB,CAC1C,UAAM,CACJA,gBAAgB,CAACU,wBAAe,CAACC,sBAAsB,CAAC,CAC1D,CAAC,CACDL,SAAS,CAEb,MACE,8BAAC,6BAAgB,EACf,QAAQ,CAAEX,QAAS,CACnB,aAAa,CAAEA,QAAQ,CAAG,GAAG,CAAG,CAAE,CAClC,OAAO,CAAED,OAAQ,CACjB,KAAK,CAAE,CAACC,QAAQ,CAAGiB,MAAM,CAACjB,QAAQ,CAAGiB,MAAM,CAACC,WAAW,CAAEZ,KAAK,CAAE,6EAE/Da,qBAAQ,CAACC,EAAE,GAAK,KAAK,CACpB,6BAAC,6BAAoB,wBACnB,IAAI,CAAE3B,IAAK,CACX,WAAW,CAAEG,UAAW,CACxB,YAAY,CAAEK,YAAa,CAC3B,QAAQ,CAAED,QAAS,CACnB,8BAA8B,CAAEQ,sBAAuB,CACvD,+BAA+B,CAAEI,uBAAwB,CACzD,yBAAyB,CAAEC,kBAAmB,CAC9C,qBAAqB,CAAEC,qBAAsB,CAC7C,KAAK,CAAEG,MAAM,CAACI,iBAAkB,EAC5Bd,KAAK,+EACT,CAEF,6BAAC,8BAAqB,wBACpB,IAAI,CAAEd,IAAK,CACX,KAAK,CAAEwB,MAAM,CAACI,iBAAkB,EAC5Bd,KAAK,+EAEZ,CACgB,CAEvB,CAEA,GAAMU,OAAM,CAAGK,uBAAU,CAACC,MAAM,CAAC,CAC/BvB,QAAQ,CAAE,CACRwB,IAAI,CAAE,CAAC,CACPC,OAAO,CAAE,GACX,CAAC,CACDP,WAAW,CAAE,CACXM,IAAI,CAAE,CACR,CAAC,CACDH,iBAAiB,CAAE,CAAEG,IAAI,CAAE,CAAE,CAC/B,CAAC,CAAC"}
|