@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
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
//
|
|
2
|
+
// PaymentSheetAppearance.swift
|
|
3
|
+
// stripe-react-native
|
|
4
|
+
//
|
|
5
|
+
// Created by Charles Cruzan on 5/11/22.
|
|
6
|
+
//
|
|
7
|
+
import Stripe
|
|
8
|
+
|
|
9
|
+
extension StripeSdk {
|
|
10
|
+
func buildPaymentSheetAppearance(userParams: NSDictionary) throws -> PaymentSheet.Appearance {
|
|
11
|
+
var appearance = PaymentSheet.Appearance()
|
|
12
|
+
|
|
13
|
+
if let fontParams = userParams[PaymentSheetAppearanceKeys.FONT] as? NSDictionary {
|
|
14
|
+
appearance.font = try buildFont(params: fontParams)
|
|
15
|
+
}
|
|
16
|
+
if let colorParams = userParams[PaymentSheetAppearanceKeys.COLORS] as? NSDictionary {
|
|
17
|
+
appearance.colors = try buildColors(params: colorParams)
|
|
18
|
+
}
|
|
19
|
+
if let shapeParams = userParams[PaymentSheetAppearanceKeys.SHAPES] as? NSDictionary {
|
|
20
|
+
appearance.cornerRadius = shapeParams[PaymentSheetAppearanceKeys.BORDER_RADIUS] as? CGFloat ?? PaymentSheet.Appearance.default.cornerRadius
|
|
21
|
+
appearance.borderWidth = shapeParams[PaymentSheetAppearanceKeys.BORDER_WIDTH] as? CGFloat ?? PaymentSheet.Appearance.default.borderWidth
|
|
22
|
+
if let shadowParams = shapeParams[PaymentSheetAppearanceKeys.SHADOW] as? NSDictionary {
|
|
23
|
+
appearance.shadow = try buildShadow(params: shadowParams)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if let primaryButtonParams = userParams[PaymentSheetAppearanceKeys.PRIMARY_BUTTON] as? NSDictionary {
|
|
27
|
+
appearance.primaryButton = try buildPrimaryButton(params: primaryButtonParams)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return appearance
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private func buildFont(params: NSDictionary) throws -> Stripe.PaymentSheet.Appearance.Font {
|
|
34
|
+
var font = Stripe.PaymentSheet.Appearance.Font()
|
|
35
|
+
if let fontName = params[PaymentSheetAppearanceKeys.FAMILY] as? String {
|
|
36
|
+
guard let customFont = UIFont(name: fontName, size: UIFont.systemFontSize) else {
|
|
37
|
+
throw PaymentSheetAppearanceError.missingFont(fontName)
|
|
38
|
+
}
|
|
39
|
+
font.base = customFont
|
|
40
|
+
}
|
|
41
|
+
font.sizeScaleFactor = params[PaymentSheetAppearanceKeys.SCALE] as? CGFloat ?? PaymentSheet.Appearance.default.font.sizeScaleFactor
|
|
42
|
+
return font
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private func buildColors(params: NSDictionary) throws -> Stripe.PaymentSheet.Appearance.Colors {
|
|
46
|
+
var colors = Stripe.PaymentSheet.Appearance.Colors()
|
|
47
|
+
|
|
48
|
+
if (params.object(forKey: PaymentSheetAppearanceKeys.LIGHT) != nil && params.object(forKey: PaymentSheetAppearanceKeys.DARK) == nil ||
|
|
49
|
+
params.object(forKey: PaymentSheetAppearanceKeys.DARK) != nil && params.object(forKey: PaymentSheetAppearanceKeys.LIGHT) == nil) {
|
|
50
|
+
throw PaymentSheetAppearanceError.missingAppearanceMode
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let lightModeParams = params[PaymentSheetAppearanceKeys.LIGHT] as? NSDictionary ?? params
|
|
54
|
+
let darkModeParams = params[PaymentSheetAppearanceKeys.DARK] as? NSDictionary ?? params
|
|
55
|
+
|
|
56
|
+
colors.primary = try StripeSdk.buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.PRIMARY, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.primary
|
|
57
|
+
colors.background = try StripeSdk.buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.BACKGROUND, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.background
|
|
58
|
+
colors.componentBackground = try StripeSdk.buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.COMPONENT_BACKGROUND, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.componentBackground
|
|
59
|
+
colors.componentBorder = try StripeSdk.buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.COMPONENT_BORDER, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.componentBorder
|
|
60
|
+
colors.componentDivider = try StripeSdk.buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.COMPONENT_DIVIDER, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.componentDivider
|
|
61
|
+
colors.text = try StripeSdk.buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.PRIMARY_TEXT, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.text
|
|
62
|
+
colors.textSecondary = try StripeSdk.buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.SECONDARY_TEXT, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.textSecondary
|
|
63
|
+
colors.componentText = try StripeSdk.buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.COMPONENT_TEXT, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.componentText
|
|
64
|
+
colors.componentPlaceholderText = try StripeSdk.buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.PLACEHOLDER_TEXT, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.componentPlaceholderText
|
|
65
|
+
colors.icon = try StripeSdk.buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.ICON, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.icon
|
|
66
|
+
colors.danger = try StripeSdk.buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.ERROR, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.colors.danger
|
|
67
|
+
|
|
68
|
+
return colors
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private func buildShadow(params: NSDictionary) throws -> PaymentSheet.Appearance.Shadow {
|
|
72
|
+
var shadow = PaymentSheet.Appearance.Shadow()
|
|
73
|
+
|
|
74
|
+
if let color = try StripeSdk.buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.SHADOW_COLOR, lightParams: params, darkParams: params) {
|
|
75
|
+
shadow.color = color
|
|
76
|
+
}
|
|
77
|
+
if let opacity = params[PaymentSheetAppearanceKeys.OPACITY] as? CGFloat {
|
|
78
|
+
shadow.opacity = opacity
|
|
79
|
+
}
|
|
80
|
+
if let radius = params[PaymentSheetAppearanceKeys.BLUR_RADIUS] as? CGFloat {
|
|
81
|
+
shadow.radius = radius
|
|
82
|
+
}
|
|
83
|
+
if let offsetParams = params[PaymentSheetAppearanceKeys.OFFSET] as? NSDictionary {
|
|
84
|
+
if let x = offsetParams[PaymentSheetAppearanceKeys.X] as? CGFloat, let y = offsetParams[PaymentSheetAppearanceKeys.Y] as? CGFloat {
|
|
85
|
+
shadow.offset = CGSize(width: x, height:-y)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return shadow
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private func buildPrimaryButton(params: NSDictionary) throws -> PaymentSheet.Appearance.PrimaryButton {
|
|
93
|
+
var primaryButton = PaymentSheet.Appearance.PrimaryButton()
|
|
94
|
+
|
|
95
|
+
if let fontName = (params[PaymentSheetAppearanceKeys.FONT] as? NSDictionary)?[PaymentSheetAppearanceKeys.FAMILY] as? String {
|
|
96
|
+
guard let customFont = UIFont(name: fontName, size: UIFont.systemFontSize) else {
|
|
97
|
+
throw PaymentSheetAppearanceError.missingFont(fontName)
|
|
98
|
+
}
|
|
99
|
+
primaryButton.font = customFont
|
|
100
|
+
}
|
|
101
|
+
if let shapeParams = params[PaymentSheetAppearanceKeys.SHAPES] as? NSDictionary {
|
|
102
|
+
if let borderRadius = shapeParams[PaymentSheetAppearanceKeys.BORDER_RADIUS] as? CGFloat {
|
|
103
|
+
primaryButton.cornerRadius = borderRadius
|
|
104
|
+
}
|
|
105
|
+
if let borderWidth = shapeParams[PaymentSheetAppearanceKeys.BORDER_WIDTH] as? CGFloat {
|
|
106
|
+
primaryButton.borderWidth = borderWidth
|
|
107
|
+
}
|
|
108
|
+
if let shadowParams = shapeParams[PaymentSheetAppearanceKeys.SHADOW] as? NSDictionary {
|
|
109
|
+
primaryButton.shadow = try buildShadow(params: shadowParams)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if let colorParams = params[PaymentSheetAppearanceKeys.COLORS] as? NSDictionary {
|
|
113
|
+
if (colorParams.object(forKey: PaymentSheetAppearanceKeys.LIGHT) != nil && colorParams.object(forKey: PaymentSheetAppearanceKeys.DARK) == nil ||
|
|
114
|
+
colorParams.object(forKey: PaymentSheetAppearanceKeys.DARK) != nil && colorParams.object(forKey: PaymentSheetAppearanceKeys.LIGHT) == nil) {
|
|
115
|
+
throw PaymentSheetAppearanceError.missingAppearanceMode
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
let lightModeParams = colorParams[PaymentSheetAppearanceKeys.LIGHT] as? NSDictionary ?? colorParams
|
|
119
|
+
let darkModeParams = colorParams[PaymentSheetAppearanceKeys.DARK] as? NSDictionary ?? colorParams
|
|
120
|
+
|
|
121
|
+
primaryButton.backgroundColor = try StripeSdk.buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.BACKGROUND, lightParams: lightModeParams, darkParams: darkModeParams)
|
|
122
|
+
primaryButton.textColor = try StripeSdk.buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.TEXT, lightParams: lightModeParams, darkParams: darkModeParams)
|
|
123
|
+
primaryButton.borderColor = try StripeSdk.buildUserInterfaceStyleAwareColor(key: PaymentSheetAppearanceKeys.BORDER, lightParams: lightModeParams, darkParams: darkModeParams) ?? PaymentSheet.Appearance.default.primaryButton.borderColor
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return primaryButton
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private static func buildUserInterfaceStyleAwareColor(key: String, lightParams: NSDictionary, darkParams: NSDictionary) throws -> UIColor? {
|
|
130
|
+
guard let lightHexString = lightParams[key] as? String, let darkHexString = darkParams[key] as? String else {
|
|
131
|
+
return nil
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
let darkCount = darkHexString.trimmingCharacters(in: CharacterSet.alphanumerics.inverted).count
|
|
135
|
+
let lightCount = lightHexString.trimmingCharacters(in: CharacterSet.alphanumerics.inverted).count
|
|
136
|
+
if (lightCount != 6 && lightCount != 8) {
|
|
137
|
+
throw PaymentSheetAppearanceError.unexpectedHexStringLength(lightHexString)
|
|
138
|
+
} else if (darkCount != 6 && darkCount != 8) {
|
|
139
|
+
throw PaymentSheetAppearanceError.unexpectedHexStringLength(darkHexString)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let lightColor = UIColor(hexString: lightHexString)
|
|
143
|
+
let darkColor = UIColor(hexString: darkHexString)
|
|
144
|
+
|
|
145
|
+
if #available(iOS 13.0, *) {
|
|
146
|
+
return UIColor.init { traits in
|
|
147
|
+
return traits.userInterfaceStyle == .dark ? darkColor : lightColor
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
return lightColor
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
enum PaymentSheetAppearanceError : Error {
|
|
156
|
+
case missingFont(String)
|
|
157
|
+
case missingAppearanceMode
|
|
158
|
+
case unexpectedHexStringLength(String)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
extension PaymentSheetAppearanceError: LocalizedError {
|
|
162
|
+
public var errorDescription: String? {
|
|
163
|
+
switch self {
|
|
164
|
+
case .missingFont(let fontFamily):
|
|
165
|
+
return NSLocalizedString("Failed to set Payment Sheet appearance. Unable to find font: \(fontFamily)", comment: "Failed to set font")
|
|
166
|
+
case .missingAppearanceMode:
|
|
167
|
+
return NSLocalizedString("Failed to set Payment Sheet appearance. When providing 'colors.light' or 'colors.dark', you must provide both.", comment: "Failed to set colors")
|
|
168
|
+
case .unexpectedHexStringLength(let hexString):
|
|
169
|
+
return NSLocalizedString("Failed to set Payment Sheet appearance. Expected hex string of length 6 or 8, but received: \(hexString)", comment: "Failed to set color")
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private struct PaymentSheetAppearanceKeys {
|
|
175
|
+
static let COLORS = "colors"
|
|
176
|
+
static let LIGHT = "light"
|
|
177
|
+
static let DARK = "dark"
|
|
178
|
+
static let PRIMARY = "primary"
|
|
179
|
+
static let BACKGROUND = "background"
|
|
180
|
+
static let COMPONENT_BACKGROUND = "componentBackground"
|
|
181
|
+
static let COMPONENT_BORDER = "componentBorder"
|
|
182
|
+
static let COMPONENT_DIVIDER = "componentDivider"
|
|
183
|
+
static let COMPONENT_TEXT = "componentText"
|
|
184
|
+
static let PRIMARY_TEXT = "primaryText"
|
|
185
|
+
static let SECONDARY_TEXT = "secondaryText"
|
|
186
|
+
static let PLACEHOLDER_TEXT = "placeholderText"
|
|
187
|
+
static let ICON = "icon"
|
|
188
|
+
static let ERROR = "error"
|
|
189
|
+
|
|
190
|
+
static let FONT = "font"
|
|
191
|
+
static let FAMILY = "family"
|
|
192
|
+
static let SCALE = "scale"
|
|
193
|
+
|
|
194
|
+
static let SHAPES = "shapes"
|
|
195
|
+
static let BORDER_RADIUS = "borderRadius"
|
|
196
|
+
static let BORDER_WIDTH = "borderWidth"
|
|
197
|
+
|
|
198
|
+
static let SHADOW = "shadow"
|
|
199
|
+
static let SHADOW_COLOR = "color"
|
|
200
|
+
static let OPACITY = "opacity"
|
|
201
|
+
static let OFFSET = "offset"
|
|
202
|
+
static let BLUR_RADIUS = "blurRadius"
|
|
203
|
+
static let X = "x"
|
|
204
|
+
static let Y = "y"
|
|
205
|
+
|
|
206
|
+
static let PRIMARY_BUTTON = "primaryButton"
|
|
207
|
+
static let TEXT = "text"
|
|
208
|
+
static let BORDER = "border"
|
|
209
|
+
}
|