@stripe/stripe-react-native 0.20.0 → 0.21.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 +13 -0
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/reactnativestripesdk/CollectBankAccountLauncherFragment.kt +1 -1
- package/android/src/main/java/com/reactnativestripesdk/FinancialConnectionsSheetFragment.kt +4 -1
- package/android/src/main/java/com/reactnativestripesdk/GooglePayFragment.kt +1 -1
- package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherFragment.kt +1 -1
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +10 -9
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +8 -3
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +20 -14
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +3 -1
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherFragment.kt +111 -0
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetEvent.kt +28 -0
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +178 -0
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetViewManager.kt +67 -0
- package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +1 -1
- package/ios/AddressSheet/AddressSheetUtils.swift +98 -0
- package/ios/AddressSheet/AddressSheetView.swift +131 -0
- package/ios/AddressSheet/AddressSheetViewManager.m +25 -0
- package/ios/AddressSheet/AddressSheetViewManager.swift +19 -0
- package/ios/PaymentSheetAppearance.swift +24 -23
- package/ios/{pushprovisioning → PushProvisioning}/AddToWalletButtonManager.m +0 -0
- package/ios/{pushprovisioning → PushProvisioning}/AddToWalletButtonManager.swift +0 -0
- package/ios/{pushprovisioning → PushProvisioning}/AddToWalletButtonView.swift +0 -0
- package/ios/{pushprovisioning → PushProvisioning}/PushProvisioningUtils.swift +0 -0
- package/ios/StripeSdk.swift +7 -1
- package/ios/Tests/AddressSheetUtilsTests.swift +279 -0
- package/lib/commonjs/components/AddressSheet.js +2 -0
- package/lib/commonjs/components/AddressSheet.js.map +1 -0
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/index.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/index.js +1 -1
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/module/components/AddressSheet.js +2 -0
- package/lib/module/components/AddressSheet.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.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/index.js +1 -1
- package/lib/module/types/index.js.map +1 -1
- package/lib/typescript/src/components/AddressSheet.d.ts +53 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/types/Common.d.ts +12 -0
- package/lib/typescript/src/types/Errors.d.ts +4 -0
- package/lib/typescript/src/types/PaymentSheet.d.ts +7 -1
- package/lib/typescript/src/types/index.d.ts +3 -6
- package/package.json +1 -1
- package/src/components/AddressSheet.tsx +82 -0
- package/src/index.tsx +4 -1
- package/src/types/Common.ts +13 -0
- package/src/types/Errors.ts +5 -0
- package/src/types/PaymentSheet.ts +7 -1
- package/src/types/index.ts +5 -10
- package/stripe-react-native.podspec +1 -1
package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetViewManager.kt
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
package com.reactnativestripesdk.addresssheet
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableArray
|
|
4
|
+
import com.facebook.react.bridge.ReadableMap
|
|
5
|
+
import com.facebook.react.common.MapBuilder
|
|
6
|
+
import com.facebook.react.uimanager.SimpleViewManager
|
|
7
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
8
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
9
|
+
|
|
10
|
+
class AddressSheetViewManager : SimpleViewManager<AddressSheetView>() {
|
|
11
|
+
override fun getName() = "AddressSheetView"
|
|
12
|
+
|
|
13
|
+
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
|
|
14
|
+
return MapBuilder.of(
|
|
15
|
+
AddressSheetEvent.ON_SUBMIT, MapBuilder.of("registrationName", "onSubmitAction"),
|
|
16
|
+
AddressSheetEvent.ON_ERROR, MapBuilder.of("registrationName", "onErrorAction"))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@ReactProp(name = "visible")
|
|
20
|
+
fun setVisible(view: AddressSheetView, visibility: Boolean) {
|
|
21
|
+
view.setVisible(visibility)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@ReactProp(name = "appearance")
|
|
25
|
+
fun setAppearance(view: AddressSheetView, appearance: ReadableMap) {
|
|
26
|
+
view.setAppearance(appearance)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@ReactProp(name = "defaultValues")
|
|
30
|
+
fun setDefaultValues(view: AddressSheetView, defaults: ReadableMap) {
|
|
31
|
+
view.setDefaultValues(defaults)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@ReactProp(name = "additionalFields")
|
|
35
|
+
fun setAdditionalFields(view: AddressSheetView, fields: ReadableMap) {
|
|
36
|
+
view.setAdditionalFields(fields)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@ReactProp(name = "allowedCountries")
|
|
40
|
+
fun setAllowedCountries(view: AddressSheetView, countries: ReadableArray) {
|
|
41
|
+
view.setAllowedCountries(countries.toArrayList().filterIsInstance<String>())
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@ReactProp(name = "autocompleteCountries")
|
|
45
|
+
fun setAutocompleteCountries(view: AddressSheetView, countries: ReadableArray) {
|
|
46
|
+
view.setAutocompleteCountries(countries.toArrayList().filterIsInstance<String>())
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@ReactProp(name = "primaryButtonTitle")
|
|
50
|
+
fun setPrimaryButtonTitle(view: AddressSheetView, title: String) {
|
|
51
|
+
view.setPrimaryButtonTitle(title)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@ReactProp(name = "sheetTitle")
|
|
55
|
+
fun setSheetTitle(view: AddressSheetView, title: String) {
|
|
56
|
+
view.setSheetTitle(title)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@ReactProp(name = "googlePlacesApiKey")
|
|
60
|
+
fun setGooglePlacesApiKey(view: AddressSheetView, key: String) {
|
|
61
|
+
view.setGooglePlacesApiKey(key)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
override fun createViewInstance(reactContext: ThemedReactContext): AddressSheetView {
|
|
65
|
+
return AddressSheetView(reactContext)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -487,7 +487,7 @@ internal fun mapNextAction(type: NextActionType?, data: NextActionData?): Writab
|
|
|
487
487
|
NextActionType.AlipayRedirect -> { // TODO: Can't access, private
|
|
488
488
|
return null
|
|
489
489
|
}
|
|
490
|
-
NextActionType.BlikAuthorize, NextActionType.UseStripeSdk, null -> {
|
|
490
|
+
NextActionType.BlikAuthorize, NextActionType.UseStripeSdk, NextActionType.UpiAwaitNotification, null -> {
|
|
491
491
|
return null
|
|
492
492
|
}
|
|
493
493
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AddressSheetUtils.swift
|
|
3
|
+
// stripe-react-native
|
|
4
|
+
//
|
|
5
|
+
// Created by Charles Cruzan on 10/12/22.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import StripePaymentSheet
|
|
10
|
+
|
|
11
|
+
class AddressSheetUtils {
|
|
12
|
+
internal class func buildDefaultValues(params: NSDictionary?) -> AddressViewController.Configuration.DefaultAddressDetails {
|
|
13
|
+
guard let params = params else {
|
|
14
|
+
return AddressViewController.Configuration.DefaultAddressDetails()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return AddressViewController.Configuration.DefaultAddressDetails(
|
|
18
|
+
address: buildAddress(params: params["address"] as? NSDictionary),
|
|
19
|
+
name: params["name"] as? String,
|
|
20
|
+
phone: params["phone"] as? String,
|
|
21
|
+
isCheckboxSelected: params["isCheckboxSelected"] as? Bool
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
internal class func buildAddressDetails(params: NSDictionary?) -> AddressViewController.AddressDetails {
|
|
26
|
+
guard let params = params else { return AddressViewController.AddressDetails(address: buildAddress(params: nil)) }
|
|
27
|
+
return AddressViewController.AddressDetails(
|
|
28
|
+
address: buildAddress(params: params["address"] as? NSDictionary),
|
|
29
|
+
name: params["name"] as? String,
|
|
30
|
+
phone: params["phone"] as? String,
|
|
31
|
+
isCheckboxSelected: params["isCheckboxSelected"] as? Bool)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
internal class func buildAddress(params: NSDictionary?) -> PaymentSheet.Address {
|
|
35
|
+
guard let params = params else { return PaymentSheet.Address() }
|
|
36
|
+
return PaymentSheet.Address(
|
|
37
|
+
city: params["city"] as? String,
|
|
38
|
+
country: params["country"] as? String,
|
|
39
|
+
line1: params["line1"] as? String,
|
|
40
|
+
line2: params["line2"] as? String,
|
|
41
|
+
postalCode: params["postalCode"] as? String,
|
|
42
|
+
state: params["state"] as? String
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
internal class func buildAddress(params: NSDictionary?) -> AddressViewController.AddressDetails.Address {
|
|
47
|
+
guard let params = params else { return AddressViewController.AddressDetails.Address(country: "", line1: "") }
|
|
48
|
+
return AddressViewController.AddressDetails.Address(
|
|
49
|
+
city: params["city"] as? String,
|
|
50
|
+
country: params["country"] as? String ?? "",
|
|
51
|
+
line1: params["line1"] as? String ?? "",
|
|
52
|
+
line2: params["line2"] as? String,
|
|
53
|
+
postalCode: params["postalCode"] as? String,
|
|
54
|
+
state: params["state"] as? String
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
internal class func buildAdditionalFieldsConfiguration(params: NSDictionary?) -> AddressViewController.Configuration.AdditionalFields {
|
|
59
|
+
guard let params = params else {
|
|
60
|
+
return AddressViewController.Configuration.AdditionalFields(phone: .hidden, checkboxLabel: nil)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return AddressViewController.Configuration.AdditionalFields(
|
|
64
|
+
phone: getFieldConfiguration(input: params["phoneNumber"] as? String, default: .hidden),
|
|
65
|
+
checkboxLabel: params["checkboxLabel"] as? String
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
internal class func getFieldConfiguration(input: String?, default: AddressViewController.Configuration.AdditionalFields.FieldConfiguration) -> AddressViewController.Configuration.AdditionalFields.FieldConfiguration {
|
|
70
|
+
switch (input) {
|
|
71
|
+
case "optional":
|
|
72
|
+
return .optional
|
|
73
|
+
case "required":
|
|
74
|
+
return .required
|
|
75
|
+
case "hidden":
|
|
76
|
+
return .hidden
|
|
77
|
+
default:
|
|
78
|
+
return `default`
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
internal class func buildResult(address: AddressViewController.AddressDetails) -> [AnyHashable : Any] {
|
|
83
|
+
return [
|
|
84
|
+
"name": address.name ?? NSNull(),
|
|
85
|
+
"address": [
|
|
86
|
+
"country": address.address.country,
|
|
87
|
+
"state": address.address.state,
|
|
88
|
+
"line1": address.address.line1,
|
|
89
|
+
"line2": address.address.line2,
|
|
90
|
+
"postalCode": address.address.postalCode,
|
|
91
|
+
"city": address.address.city,
|
|
92
|
+
],
|
|
93
|
+
"phone": address.phone ?? NSNull(),
|
|
94
|
+
"isCheckboxSelected": address.isCheckboxSelected ?? NSNull(),
|
|
95
|
+
] as [AnyHashable : Any]
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AddressSheetView.swift
|
|
3
|
+
// stripe-react-native
|
|
4
|
+
//
|
|
5
|
+
// Created by Charles Cruzan on 10/11/22.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import StripePaymentSheet
|
|
10
|
+
|
|
11
|
+
@objc(AddressSheetView)
|
|
12
|
+
class AddressSheetView: UIView {
|
|
13
|
+
@objc var visible = false
|
|
14
|
+
@objc var presentationStyle: String = "popover"
|
|
15
|
+
@objc var animationStyle: String = ""
|
|
16
|
+
@objc var appearance: NSDictionary? = nil
|
|
17
|
+
@objc var defaultValues: NSDictionary? = nil
|
|
18
|
+
@objc var additionalFields: NSDictionary? = nil
|
|
19
|
+
@objc var allowedCountries: [String] = []
|
|
20
|
+
@objc var autocompleteCountries: [String] = []
|
|
21
|
+
@objc var primaryButtonTitle: String? = nil
|
|
22
|
+
@objc var sheetTitle: String? = nil
|
|
23
|
+
@objc var onSubmitAction: RCTDirectEventBlock?
|
|
24
|
+
@objc var onErrorAction: RCTDirectEventBlock?
|
|
25
|
+
|
|
26
|
+
private var wasVisible = false
|
|
27
|
+
private var addressViewController: AddressViewController? = nil
|
|
28
|
+
internal var addressDetails: AddressViewController.AddressDetails? = nil
|
|
29
|
+
|
|
30
|
+
override init(frame: CGRect) {
|
|
31
|
+
super.init(frame: frame)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
required init?(coder: NSCoder) {
|
|
35
|
+
fatalError("init(coder:) has not been implemented")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
override func didSetProps(_ changedProps: [String]!) {
|
|
39
|
+
if (visible && !wasVisible) {
|
|
40
|
+
presentAddressSheet()
|
|
41
|
+
wasVisible = true
|
|
42
|
+
} else if (!visible && wasVisible) {
|
|
43
|
+
addressViewController?.dismiss(animated: true)
|
|
44
|
+
wasVisible = false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private func presentAddressSheet() {
|
|
49
|
+
if (STPAPIClient.shared.publishableKey == nil) {
|
|
50
|
+
onErrorAction!(
|
|
51
|
+
Errors.createError(ErrorType.Failed, "No publishable key set. Stripe has not been initialized. Initialize Stripe in your app with the StripeProvider component or the initStripe method.") as? [AnyHashable : Any]
|
|
52
|
+
)
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
var config: AddressViewController.Configuration
|
|
56
|
+
do {
|
|
57
|
+
config = try buildAddressSheetConfiguration()
|
|
58
|
+
} catch {
|
|
59
|
+
onErrorAction!(
|
|
60
|
+
Errors.createError(ErrorType.Failed, error.localizedDescription) as? [AnyHashable : Any]
|
|
61
|
+
)
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
self.addressViewController = AddressViewController(
|
|
66
|
+
configuration: config,
|
|
67
|
+
delegate: self
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
let navigationController = UINavigationController(rootViewController: addressViewController!)
|
|
71
|
+
navigationController.modalPresentationStyle = getModalPresentationStyle()
|
|
72
|
+
navigationController.modalTransitionStyle = getModalTransitionStyle()
|
|
73
|
+
let vc = findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController())
|
|
74
|
+
vc.present(navigationController, animated: true)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private func buildAddressSheetConfiguration() throws -> AddressViewController.Configuration {
|
|
78
|
+
let appearanceConfiguration = try PaymentSheetAppearance.buildAppearanceFromParams(userParams: appearance)
|
|
79
|
+
|
|
80
|
+
return AddressViewController.Configuration(
|
|
81
|
+
defaultValues: AddressSheetUtils.buildDefaultValues(params: defaultValues),
|
|
82
|
+
additionalFields: AddressSheetUtils.buildAdditionalFieldsConfiguration(params: additionalFields),
|
|
83
|
+
allowedCountries: allowedCountries,
|
|
84
|
+
appearance: appearanceConfiguration,
|
|
85
|
+
buttonTitle: primaryButtonTitle,
|
|
86
|
+
title: sheetTitle
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private func getModalPresentationStyle() -> UIModalPresentationStyle {
|
|
91
|
+
switch (presentationStyle) {
|
|
92
|
+
case "fullscreen":
|
|
93
|
+
return .fullScreen
|
|
94
|
+
case "popover":
|
|
95
|
+
fallthrough
|
|
96
|
+
default:
|
|
97
|
+
return .popover
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private func getModalTransitionStyle() -> UIModalTransitionStyle {
|
|
102
|
+
switch (animationStyle) {
|
|
103
|
+
case "flip":
|
|
104
|
+
return .flipHorizontal
|
|
105
|
+
case "curl":
|
|
106
|
+
return .partialCurl
|
|
107
|
+
case "dissolve":
|
|
108
|
+
return .crossDissolve
|
|
109
|
+
case "slide":
|
|
110
|
+
fallthrough
|
|
111
|
+
default:
|
|
112
|
+
return .coverVertical
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
extension AddressSheetView: AddressViewControllerDelegate {
|
|
118
|
+
func addressViewControllerDidFinish(_ addressViewController: AddressViewController, with address: AddressViewController.AddressDetails?) {
|
|
119
|
+
guard let address = address else {
|
|
120
|
+
onErrorAction!(
|
|
121
|
+
Errors.createError(
|
|
122
|
+
ErrorType.Canceled,
|
|
123
|
+
"The flow has been canceled."
|
|
124
|
+
) as? [AnyHashable : Any]
|
|
125
|
+
)
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
self.addressDetails = address
|
|
129
|
+
onSubmitAction!(AddressSheetUtils.buildResult(address: address))
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AddressSheetViewManager.m
|
|
3
|
+
// stripe-react-native
|
|
4
|
+
//
|
|
5
|
+
// Created by Charles Cruzan on 10/11/22.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
#import <React/RCTBridgeModule.h>
|
|
10
|
+
#import <React/RCTViewManager.h>
|
|
11
|
+
|
|
12
|
+
@interface RCT_EXTERN_MODULE(AddressSheetViewManager, RCTViewManager)
|
|
13
|
+
RCT_EXPORT_VIEW_PROPERTY(visible, BOOL)
|
|
14
|
+
RCT_EXPORT_VIEW_PROPERTY(presentationStyle, NSString)
|
|
15
|
+
RCT_EXPORT_VIEW_PROPERTY(animationStyle, NSString)
|
|
16
|
+
RCT_EXPORT_VIEW_PROPERTY(appearance, NSDictionary)
|
|
17
|
+
RCT_EXPORT_VIEW_PROPERTY(defaultValues, NSDictionary)
|
|
18
|
+
RCT_EXPORT_VIEW_PROPERTY(additionalFields, NSDictionary)
|
|
19
|
+
RCT_EXPORT_VIEW_PROPERTY(allowedCountries, NSArray)
|
|
20
|
+
RCT_EXPORT_VIEW_PROPERTY(autocompleteCountries, NSArray)
|
|
21
|
+
RCT_EXPORT_VIEW_PROPERTY(primaryButtonTitle, NSString)
|
|
22
|
+
RCT_EXPORT_VIEW_PROPERTY(sheetTitle, NSString)
|
|
23
|
+
RCT_EXPORT_VIEW_PROPERTY(onSubmitAction, RCTDirectEventBlock)
|
|
24
|
+
RCT_EXPORT_VIEW_PROPERTY(onErrorAction, RCTDirectEventBlock)
|
|
25
|
+
@end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AddressSheetViewManager.swift
|
|
3
|
+
// stripe-react-native
|
|
4
|
+
//
|
|
5
|
+
// Created by Charles Cruzan on 10/11/22.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
@objc(AddressSheetViewManager)
|
|
11
|
+
class AddressSheetViewManager : RCTViewManager {
|
|
12
|
+
override func view() -> UIView! {
|
|
13
|
+
return AddressSheetView()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
override class func requiresMainQueueSetup() -> Bool {
|
|
17
|
+
return true
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
//
|
|
7
7
|
import StripePaymentSheet
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
func
|
|
9
|
+
internal class PaymentSheetAppearance {
|
|
10
|
+
class func buildAppearanceFromParams(userParams: NSDictionary?) throws -> PaymentSheet.Appearance {
|
|
11
11
|
var appearance = PaymentSheet.Appearance()
|
|
12
|
+
guard let userParams = userParams else { return appearance }
|
|
12
13
|
|
|
13
14
|
if let fontParams = userParams[PaymentSheetAppearanceKeys.FONT] as? NSDictionary {
|
|
14
15
|
appearance.font = try buildFont(params: fontParams)
|
|
@@ -30,7 +31,7 @@ extension StripeSdk {
|
|
|
30
31
|
return appearance
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
private func buildFont(params: NSDictionary) throws -> PaymentSheet.Appearance.Font {
|
|
34
|
+
private class func buildFont(params: NSDictionary) throws -> PaymentSheet.Appearance.Font {
|
|
34
35
|
var font = PaymentSheet.Appearance.Font()
|
|
35
36
|
if let fontName = params[PaymentSheetAppearanceKeys.FAMILY] as? String {
|
|
36
37
|
guard let customFont = UIFont(name: fontName, size: UIFont.systemFontSize) else {
|
|
@@ -41,8 +42,8 @@ extension StripeSdk {
|
|
|
41
42
|
font.sizeScaleFactor = params[PaymentSheetAppearanceKeys.SCALE] as? CGFloat ?? PaymentSheet.Appearance.default.font.sizeScaleFactor
|
|
42
43
|
return font
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
private func buildColors(params: NSDictionary) throws -> PaymentSheet.Appearance.Colors {
|
|
45
|
+
|
|
46
|
+
private class func buildColors(params: NSDictionary) throws -> PaymentSheet.Appearance.Colors {
|
|
46
47
|
var colors = PaymentSheet.Appearance.Colors()
|
|
47
48
|
|
|
48
49
|
if (params.object(forKey: PaymentSheetAppearanceKeys.LIGHT) != nil && params.object(forKey: PaymentSheetAppearanceKeys.DARK) == nil ||
|
|
@@ -53,25 +54,25 @@ extension StripeSdk {
|
|
|
53
54
|
let lightModeParams = params[PaymentSheetAppearanceKeys.LIGHT] as? NSDictionary ?? params
|
|
54
55
|
let darkModeParams = params[PaymentSheetAppearanceKeys.DARK] as? NSDictionary ?? params
|
|
55
56
|
|
|
56
|
-
colors.primary = try
|
|
57
|
-
colors.background = try
|
|
58
|
-
colors.componentBackground = try
|
|
59
|
-
colors.componentBorder = try
|
|
60
|
-
colors.componentDivider = try
|
|
61
|
-
colors.text = try
|
|
62
|
-
colors.textSecondary = try
|
|
63
|
-
colors.componentText = try
|
|
64
|
-
colors.componentPlaceholderText = try
|
|
65
|
-
colors.icon = try
|
|
66
|
-
colors.danger = try
|
|
57
|
+
colors.primary = try buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.PRIMARY, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.primary
|
|
58
|
+
colors.background = try buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.BACKGROUND, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.background
|
|
59
|
+
colors.componentBackground = try buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.COMPONENT_BACKGROUND, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.componentBackground
|
|
60
|
+
colors.componentBorder = try buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.COMPONENT_BORDER, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.componentBorder
|
|
61
|
+
colors.componentDivider = try buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.COMPONENT_DIVIDER, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.componentDivider
|
|
62
|
+
colors.text = try buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.PRIMARY_TEXT, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.text
|
|
63
|
+
colors.textSecondary = try buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.SECONDARY_TEXT, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.textSecondary
|
|
64
|
+
colors.componentText = try buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.COMPONENT_TEXT, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.componentText
|
|
65
|
+
colors.componentPlaceholderText = try buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.PLACEHOLDER_TEXT, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.componentPlaceholderText
|
|
66
|
+
colors.icon = try buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.ICON, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.icon
|
|
67
|
+
colors.danger = try buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.ERROR, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.danger
|
|
67
68
|
|
|
68
69
|
return colors
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
private func buildShadow(params: NSDictionary) throws -> PaymentSheet.Appearance.Shadow {
|
|
72
|
+
private class func buildShadow(params: NSDictionary) throws -> PaymentSheet.Appearance.Shadow {
|
|
72
73
|
var shadow = PaymentSheet.Appearance.Shadow()
|
|
73
74
|
|
|
74
|
-
if let color = try
|
|
75
|
+
if let color = try buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.SHADOW_COLOR, lightParams: params, darkParams: params) {
|
|
75
76
|
shadow.color = color
|
|
76
77
|
}
|
|
77
78
|
if let opacity = params[PaymentSheetAppearanceKeys.OPACITY] as? CGFloat {
|
|
@@ -89,7 +90,7 @@ extension StripeSdk {
|
|
|
89
90
|
return shadow
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
private func buildPrimaryButton(params: NSDictionary) throws -> PaymentSheet.Appearance.PrimaryButton {
|
|
93
|
+
private class func buildPrimaryButton(params: NSDictionary) throws -> PaymentSheet.Appearance.PrimaryButton {
|
|
93
94
|
var primaryButton = PaymentSheet.Appearance.PrimaryButton()
|
|
94
95
|
|
|
95
96
|
if let fontName = (params[PaymentSheetAppearanceKeys.FONT] as? NSDictionary)?[PaymentSheetAppearanceKeys.FAMILY] as? String {
|
|
@@ -118,15 +119,15 @@ extension StripeSdk {
|
|
|
118
119
|
let lightModeParams = colorParams[PaymentSheetAppearanceKeys.LIGHT] as? NSDictionary ?? colorParams
|
|
119
120
|
let darkModeParams = colorParams[PaymentSheetAppearanceKeys.DARK] as? NSDictionary ?? colorParams
|
|
120
121
|
|
|
121
|
-
primaryButton.backgroundColor = try
|
|
122
|
-
primaryButton.textColor = try
|
|
123
|
-
primaryButton.borderColor = try
|
|
122
|
+
primaryButton.backgroundColor = try buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.BACKGROUND, lightParams: lightModeParams, darkParams: darkModeParams)
|
|
123
|
+
primaryButton.textColor = try buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.TEXT, lightParams: lightModeParams, darkParams: darkModeParams)
|
|
124
|
+
primaryButton.borderColor = try buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.BORDER, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.primaryButton.borderColor
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
return primaryButton
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
private
|
|
130
|
+
private class func buildUserInterfaceStyleAwareColor(key: String, lightParams: NSDictionary, darkParams: NSDictionary) throws -> UIColor? {
|
|
130
131
|
guard let lightHexString = lightParams[key] as? String, let darkHexString = darkParams[key] as? String else {
|
|
131
132
|
return nil
|
|
132
133
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/ios/StripeSdk.swift
CHANGED
|
@@ -83,7 +83,7 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
83
83
|
|
|
84
84
|
if let appearanceParams = params["appearance"] as? NSDictionary {
|
|
85
85
|
do {
|
|
86
|
-
configuration.appearance = try
|
|
86
|
+
configuration.appearance = try PaymentSheetAppearance.buildAppearanceFromParams(userParams: appearanceParams)
|
|
87
87
|
} catch {
|
|
88
88
|
resolve(Errors.createError(ErrorType.Failed, error.localizedDescription))
|
|
89
89
|
return
|
|
@@ -130,6 +130,12 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
}
|
|
133
|
+
|
|
134
|
+
if let defaultShippingDetails = params["defaultShippingDetails"] as? NSDictionary {
|
|
135
|
+
configuration.shippingDetails = {
|
|
136
|
+
return AddressSheetUtils.buildAddressDetails(params: defaultShippingDetails)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
133
139
|
|
|
134
140
|
if let customerId = params["customerId"] as? String {
|
|
135
141
|
if let customerEphemeralKeySecret = params["customerEphemeralKeySecret"] as? String {
|