@stripe/stripe-react-native 0.65.1 → 0.67.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.
Files changed (107) hide show
  1. package/android/detekt/detekt-baseline.xml +0 -10
  2. package/android/gradle.properties +1 -1
  3. package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +51 -57
  4. package/android/src/main/java/com/reactnativestripesdk/CurrencySelectorElementEvent.kt +26 -0
  5. package/android/src/main/java/com/reactnativestripesdk/CurrencySelectorElementView.kt +129 -16
  6. package/android/src/main/java/com/reactnativestripesdk/CurrencySelectorElementViewManager.kt +17 -0
  7. package/android/src/main/java/com/reactnativestripesdk/EventEmitterCompat.kt +4 -0
  8. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetManager.kt +8 -19
  9. package/android/src/main/java/com/reactnativestripesdk/StripeAbstractComposeView.kt +1 -0
  10. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +89 -31
  11. package/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt +1 -0
  12. package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetManager.kt +2 -16
  13. package/android/src/main/java/com/reactnativestripesdk/utils/CheckoutMappers.kt +59 -33
  14. package/android/src/main/java/com/reactnativestripesdk/utils/DefaultActivityLifecycleCallbacks.kt +41 -0
  15. package/android/src/main/java/com/reactnativestripesdk/utils/Errors.kt +11 -6
  16. package/android/src/oldarch/java/com/reactnativestripesdk/NativeOnrampSdkModuleSpec.java +17 -3
  17. package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +2 -2
  18. package/android/src/onramp/java/com/reactnativestripesdk/OnrampErrors.kt +145 -0
  19. package/android/src/onramp/java/com/reactnativestripesdk/OnrampMappers.kt +125 -0
  20. package/android/src/onramp/java/com/reactnativestripesdk/OnrampSdkModule.kt +144 -22
  21. package/android/src/test/java/com/reactnativestripesdk/DrawableLoadingTest.kt +6 -2
  22. package/android/src/test/java/com/reactnativestripesdk/OnrampErrorsTest.kt +168 -0
  23. package/android/src/test/java/com/reactnativestripesdk/mappers/OnrampMappersTest.kt +107 -0
  24. package/android/src/test/java/com/reactnativestripesdk/utils/CheckoutMappersTest.kt +39 -30
  25. package/android/src/test/java/com/reactnativestripesdk/utils/CheckoutTestFixtures.java +8 -0
  26. package/ios/CurrencySelectorElementManager.m +7 -0
  27. package/ios/CurrencySelectorElementView.swift +142 -7
  28. package/ios/EmbeddedPaymentElementView.swift +1 -1
  29. package/ios/Mappers+Checkout.swift +251 -107
  30. package/ios/Mappers.swift +97 -7
  31. package/ios/NewArch/StripeCurrencySelectorElementComponentView.mm +14 -0
  32. package/ios/OldArch/StripeSdkEventEmitterCompat.h +1 -0
  33. package/ios/OldArch/StripeSdkEventEmitterCompat.m +6 -0
  34. package/ios/OnrampErrors.swift +132 -0
  35. package/ios/PaymentOptionDisplayData+ReactNative.swift +1 -1
  36. package/ios/PaymentSheetAppearance.swift +1 -1
  37. package/ios/StripeOnrampSdk.mm +19 -0
  38. package/ios/StripeSdk.mm +14 -14
  39. package/ios/StripeSdkEmitter.swift +1 -0
  40. package/ios/StripeSdkImpl+Checkout.swift +66 -31
  41. package/ios/StripeSdkImpl+CustomerSheet.swift +1 -1
  42. package/ios/StripeSdkImpl+Embedded.swift +1 -1
  43. package/ios/StripeSdkImpl+PaymentSheet.swift +1 -1
  44. package/ios/StripeSdkImpl.swift +116 -24
  45. package/lib/commonjs/components/PaymentMethodMessagingElement.js +1 -1
  46. package/lib/commonjs/components/PaymentMethodMessagingElement.js.map +1 -1
  47. package/lib/commonjs/components/StripeProvider.js +1 -1
  48. package/lib/commonjs/components/StripeProvider.js.map +1 -1
  49. package/lib/commonjs/hooks/useCheckout.js +1 -1
  50. package/lib/commonjs/hooks/useCheckout.js.map +1 -1
  51. package/lib/commonjs/hooks/useOnramp.js +1 -1
  52. package/lib/commonjs/hooks/useOnramp.js.map +1 -1
  53. package/lib/commonjs/internal/stripeConfig.js +2 -0
  54. package/lib/commonjs/internal/stripeConfig.js.map +1 -0
  55. package/lib/commonjs/specs/NativeOnrampSdkModule.js.map +1 -1
  56. package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
  57. package/lib/commonjs/types/Errors.js +1 -1
  58. package/lib/commonjs/types/Errors.js.map +1 -1
  59. package/lib/commonjs/types/Onramp.js +1 -1
  60. package/lib/commonjs/types/Onramp.js.map +1 -1
  61. package/lib/module/components/PaymentMethodMessagingElement.js +1 -1
  62. package/lib/module/components/PaymentMethodMessagingElement.js.map +1 -1
  63. package/lib/module/components/StripeProvider.js +1 -1
  64. package/lib/module/components/StripeProvider.js.map +1 -1
  65. package/lib/module/hooks/useCheckout.js +1 -1
  66. package/lib/module/hooks/useCheckout.js.map +1 -1
  67. package/lib/module/hooks/useOnramp.js +1 -1
  68. package/lib/module/hooks/useOnramp.js.map +1 -1
  69. package/lib/module/internal/stripeConfig.js +2 -0
  70. package/lib/module/internal/stripeConfig.js.map +1 -0
  71. package/lib/module/specs/NativeOnrampSdkModule.js.map +1 -1
  72. package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
  73. package/lib/module/types/Errors.js +1 -1
  74. package/lib/module/types/Errors.js.map +1 -1
  75. package/lib/module/types/Onramp.js +1 -1
  76. package/lib/module/types/Onramp.js.map +1 -1
  77. package/lib/typescript/src/components/PaymentMethodMessagingElement.d.ts +1 -1
  78. package/lib/typescript/src/components/PaymentMethodMessagingElement.d.ts.map +1 -1
  79. package/lib/typescript/src/components/StripeProvider.d.ts.map +1 -1
  80. package/lib/typescript/src/hooks/useCheckout.d.ts.map +1 -1
  81. package/lib/typescript/src/hooks/useOnramp.d.ts +32 -10
  82. package/lib/typescript/src/hooks/useOnramp.d.ts.map +1 -1
  83. package/lib/typescript/src/internal/stripeConfig.d.ts +3 -0
  84. package/lib/typescript/src/internal/stripeConfig.d.ts.map +1 -0
  85. package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts +3 -0
  86. package/lib/typescript/src/specs/NativeOnrampSdkModule.d.ts.map +1 -1
  87. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +2 -2
  88. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
  89. package/lib/typescript/src/types/Checkout.d.ts +266 -92
  90. package/lib/typescript/src/types/Checkout.d.ts.map +1 -1
  91. package/lib/typescript/src/types/Errors.d.ts +0 -5
  92. package/lib/typescript/src/types/Errors.d.ts.map +1 -1
  93. package/lib/typescript/src/types/Onramp.d.ts +168 -9
  94. package/lib/typescript/src/types/Onramp.d.ts.map +1 -1
  95. package/package.json +3 -2
  96. package/src/components/PaymentMethodMessagingElement.tsx +54 -52
  97. package/src/components/StripeProvider.tsx +2 -0
  98. package/src/hooks/useCheckout.tsx +20 -13
  99. package/src/hooks/useOnramp.tsx +139 -12
  100. package/src/internal/stripeConfig.ts +9 -0
  101. package/src/specs/NativeOnrampSdkModule.ts +5 -0
  102. package/src/specs/NativeStripeSdkModule.ts +6 -5
  103. package/src/types/Checkout.ts +289 -93
  104. package/src/types/Errors.ts +0 -6
  105. package/src/types/Onramp.ts +192 -9
  106. package/stripe-react-native.podspec +3 -3
  107. package/ios/CurrencySelectorElementManager.swift +0 -12
@@ -6,7 +6,7 @@
6
6
  //
7
7
 
8
8
  import Foundation
9
- @_spi(EmbeddedPaymentElementPrivateBeta) import StripePaymentSheet
9
+ import StripePaymentSheet
10
10
  import UIKit
11
11
 
12
12
  @objc(EmbeddedPaymentElementView)
@@ -6,188 +6,332 @@
6
6
  //
7
7
 
8
8
  import Foundation
9
- @_spi(CheckoutSessionsPreview) import StripePaymentSheet
9
+ @_spi(ReactNativeSDK) import StripePaymentSheet
10
10
 
11
11
  extension Mappers {
12
+
13
+ // MARK: - State & Session
14
+
12
15
  class func mapFromCheckoutState(_ state: Checkout.State) -> NSDictionary {
13
- return [
16
+ [
14
17
  "status": state.isLoading ? "loading" : "loaded",
15
18
  "session": mapFromCheckoutSession(state.session),
16
19
  ]
17
20
  }
18
21
 
19
- class func mapFromCheckoutSession(_ session: any Checkout.Session) -> NSDictionary {
22
+ class func mapFromCheckoutSession(_ session: Checkout.Session) -> NSDictionary {
20
23
  let result = NSMutableDictionary()
21
24
  result["id"] = session.id
22
- result["paymentStatus"] = mapFromCheckoutPaymentStatus(session.paymentStatus)
23
25
  result["livemode"] = session.livemode
24
- result["lineItems"] = session.lineItems.map(mapFromCheckoutLineItem)
25
- result["shippingOptions"] = session.shippingOptions.map(mapFromCheckoutShippingOption)
26
- result["discounts"] = session.discounts.map(mapFromCheckoutDiscount)
27
-
28
- if let status = mapFromCheckoutStatus(session.status) {
29
- result["status"] = status
26
+ result["lineItems"] = session.lineItems.map(mapFromLineItem)
27
+ result["shippingOptions"] = session.shippingOptions.map(mapFromShippingOption)
28
+ result["discountAmounts"] = session.discountAmounts.map(mapFromDiscountAmount)
29
+ result["currencyOptions"] = session.currencyOptions.map(mapFromCurrencyOption)
30
+ result["tax"] = mapFromTax(session.tax)
31
+
32
+ if let businessName = session.businessName {
33
+ result["businessName"] = businessName
30
34
  }
31
-
32
35
  if let currency = session.currency {
33
36
  result["currency"] = currency
34
37
  }
35
-
36
- if let totals = session.totals {
37
- result["totals"] = mapFromCheckoutTotals(totals)
38
+ if let email = session.email {
39
+ result["email"] = email
38
40
  }
39
-
40
- if let customerId = session.customerId {
41
- result["customerId"] = customerId
41
+ if let minorUnitsAmountDivisor = session.minorUnitsAmountDivisor {
42
+ result["minorUnitsAmountDivisor"] = minorUnitsAmountDivisor
42
43
  }
43
-
44
- if let customerEmail = session.customerEmail {
45
- result["customerEmail"] = customerEmail
44
+ if let status = session.status {
45
+ result["status"] = mapFromStatus(status)
46
+ }
47
+ if let total = session.total {
48
+ result["total"] = mapFromTotal(total)
49
+ }
50
+ if let shipping = session.shipping {
51
+ result["shipping"] = mapFromSelectedShipping(shipping)
46
52
  }
47
-
48
53
  if let billingAddress = session.billingAddress {
49
- result["billingAddress"] = mapFromCheckoutAddressUpdate(billingAddress)
54
+ result["billingAddress"] = mapFromContactAddress(billingAddress)
50
55
  }
51
-
52
56
  if let shippingAddress = session.shippingAddress {
53
- result["shippingAddress"] = mapFromCheckoutAddressUpdate(shippingAddress)
57
+ result["shippingAddress"] = mapFromContactAddress(shippingAddress)
54
58
  }
55
59
 
56
60
  return result
57
61
  }
58
62
 
59
- class func mapFromCheckoutAddressUpdate(_ addressUpdate: Checkout.AddressUpdate) -> NSDictionary {
63
+ // MARK: - Amount
64
+
65
+ class func mapFromAmount(_ amount: Checkout.Amount) -> NSDictionary {
66
+ [
67
+ "amount": amount.amount,
68
+ "minorUnitsAmount": amount.minorUnitsAmount,
69
+ ]
70
+ }
71
+
72
+ class func mapFromDecimalAmount(_ decimalAmount: Checkout.DecimalAmount) -> NSDictionary {
73
+ [
74
+ "amount": decimalAmount.amount,
75
+ "minorUnitsAmount": NSDecimalNumber(decimal: decimalAmount.minorUnitsAmount).doubleValue,
76
+ ]
77
+ }
78
+
79
+ // MARK: - Status
80
+
81
+ class func mapFromStatus(_ status: Checkout.Status) -> NSDictionary {
60
82
  let result = NSMutableDictionary()
61
- result["address"] = mapFromCheckoutAddress(addressUpdate.address)
83
+ result["type"] = mapFromStatusType(status.type)
62
84
 
63
- if let name = addressUpdate.name {
64
- result["name"] = name
85
+ if let paymentStatus = status.paymentStatus {
86
+ result["paymentStatus"] = mapFromPaymentStatus(paymentStatus)
65
87
  }
66
88
 
67
- if let phone = addressUpdate.phone {
68
- result["phone"] = phone
89
+ return result
90
+ }
91
+
92
+ private class func mapFromStatusType(_ type: Checkout.StatusType) -> String {
93
+ switch type {
94
+ case .open: return "open"
95
+ case .complete: return "complete"
96
+ case .expired: return "expired"
97
+ case .unknown: return "unknown"
98
+ @unknown default: return "unknown"
69
99
  }
100
+ }
70
101
 
71
- return result
102
+ private class func mapFromPaymentStatus(_ paymentStatus: Checkout.PaymentStatus) -> String {
103
+ switch paymentStatus {
104
+ case .paid: return "paid"
105
+ case .unpaid: return "unpaid"
106
+ case .noPaymentRequired: return "noPaymentRequired"
107
+ case .unknown: return "unknown"
108
+ @unknown default: return "unknown"
109
+ }
72
110
  }
73
111
 
74
- private class func mapFromCheckoutAddress(_ address: Checkout.Address) -> NSDictionary {
112
+ // MARK: - Total
113
+
114
+ class func mapFromTotal(_ total: Checkout.Total) -> NSDictionary {
115
+ [
116
+ "subtotal": mapFromAmount(total.subtotal),
117
+ "taxExclusive": mapFromAmount(total.taxExclusive),
118
+ "taxInclusive": mapFromAmount(total.taxInclusive),
119
+ "shippingRate": mapFromAmount(total.shippingRate),
120
+ "discount": mapFromAmount(total.discount),
121
+ "total": mapFromAmount(total.total),
122
+ "appliedBalance": mapFromAmount(total.appliedBalance),
123
+ "balanceAppliedToNextInvoice": total.balanceAppliedToNextInvoice,
124
+ ]
125
+ }
126
+
127
+ // MARK: - Tax
128
+
129
+ class func mapFromTax(_ tax: Checkout.Tax) -> NSDictionary {
75
130
  let result = NSMutableDictionary()
76
- result["country"] = address.country
131
+ result["status"] = mapFromTaxStatus(tax.status)
77
132
 
78
- if let line1 = address.line1 {
79
- result["line1"] = line1
133
+ if let taxAmounts = tax.taxAmounts {
134
+ result["taxAmounts"] = taxAmounts.map(mapFromTaxAmount)
80
135
  }
81
136
 
82
- if let line2 = address.line2 {
83
- result["line2"] = line2
137
+ return result
138
+ }
139
+
140
+ private class func mapFromTaxStatus(_ status: Checkout.TaxStatus) -> String {
141
+ switch status {
142
+ case .ready: return "ready"
143
+ case .requiresShippingAddress: return "requiresShippingAddress"
144
+ case .requiresBillingAddress: return "requiresBillingAddress"
145
+ case .unknown: return "unknown"
146
+ @unknown default: return "unknown"
84
147
  }
148
+ }
85
149
 
86
- if let city = address.city {
87
- result["city"] = city
150
+ private class func mapFromTaxAmount(_ taxAmount: Checkout.TaxAmount) -> NSDictionary {
151
+ [
152
+ "amount": mapFromAmount(taxAmount.amount),
153
+ "inclusive": taxAmount.inclusive,
154
+ "displayName": taxAmount.displayName,
155
+ ]
156
+ }
157
+
158
+ // MARK: - Line Items
159
+
160
+ class func mapFromLineItem(_ lineItem: Checkout.LineItem) -> NSDictionary {
161
+ let result = NSMutableDictionary()
162
+ result["id"] = lineItem.id
163
+ result["name"] = lineItem.name
164
+ result["images"] = lineItem.images
165
+ result["quantity"] = lineItem.quantity
166
+ result["discountAmounts"] = lineItem.discountAmounts.map(mapFromDiscountAmount)
167
+ result["taxAmounts"] = lineItem.taxAmounts.map(mapFromTaxAmount)
168
+
169
+ if let description = lineItem.description {
170
+ result["description"] = description
171
+ }
172
+ if let unitAmount = lineItem.unitAmount {
173
+ result["unitAmount"] = mapFromAmount(unitAmount)
174
+ }
175
+ if let unitAmountDecimal = lineItem.unitAmountDecimal {
176
+ result["unitAmountDecimal"] = mapFromDecimalAmount(unitAmountDecimal)
177
+ }
178
+ if let subtotal = lineItem.subtotal {
179
+ result["subtotal"] = mapFromAmount(subtotal)
180
+ }
181
+ if let discount = lineItem.discount {
182
+ result["discount"] = mapFromAmount(discount)
183
+ }
184
+ if let taxExclusive = lineItem.taxExclusive {
185
+ result["taxExclusive"] = mapFromAmount(taxExclusive)
186
+ }
187
+ if let taxInclusive = lineItem.taxInclusive {
188
+ result["taxInclusive"] = mapFromAmount(taxInclusive)
189
+ }
190
+ if let total = lineItem.total {
191
+ result["total"] = mapFromAmount(total)
192
+ }
193
+ if let adjustableQuantity = lineItem.adjustableQuantity {
194
+ result["adjustableQuantity"] = mapFromAdjustableQuantity(adjustableQuantity)
88
195
  }
89
196
 
90
- if let state = address.state {
91
- result["state"] = state
197
+ return result
198
+ }
199
+
200
+ private class func mapFromAdjustableQuantity(_ adjustableQuantity: Checkout.AdjustableQuantity) -> NSDictionary {
201
+ [
202
+ "minimum": adjustableQuantity.minimum,
203
+ "maximum": adjustableQuantity.maximum,
204
+ ]
205
+ }
206
+
207
+ // MARK: - Shipping
208
+
209
+ class func mapFromShippingOption(_ shippingOption: Checkout.ShippingOption) -> NSDictionary {
210
+ let result = NSMutableDictionary()
211
+ result["id"] = shippingOption.id
212
+ result["amount"] = mapFromAmount(shippingOption.amount)
213
+ result["currency"] = shippingOption.currency
214
+
215
+ if let displayName = shippingOption.displayName {
216
+ result["displayName"] = displayName
217
+ }
218
+ if let deliveryEstimate = shippingOption.deliveryEstimate {
219
+ result["deliveryEstimate"] = mapFromDeliveryEstimate(deliveryEstimate)
92
220
  }
93
221
 
94
- if let postalCode = address.postalCode {
95
- result["postalCode"] = postalCode
222
+ return result
223
+ }
224
+
225
+ private class func mapFromDeliveryEstimate(_ estimate: Checkout.DeliveryEstimate) -> NSDictionary {
226
+ let result = NSMutableDictionary()
227
+
228
+ if let minimum = estimate.minimum {
229
+ result["minimum"] = mapFromDeliveryEstimateBound(minimum)
230
+ }
231
+ if let maximum = estimate.maximum {
232
+ result["maximum"] = mapFromDeliveryEstimateBound(maximum)
96
233
  }
97
234
 
98
235
  return result
99
236
  }
100
237
 
101
- private class func mapFromCheckoutTotals(_ totals: Checkout.Totals) -> NSDictionary {
102
- return [
103
- "subtotal": totals.subtotal,
104
- "total": totals.total,
105
- "due": totals.due,
106
- "discount": totals.discount,
107
- "shipping": totals.shipping,
108
- "tax": totals.tax,
238
+ private class func mapFromDeliveryEstimateBound(_ bound: Checkout.DeliveryEstimate.Bound) -> NSDictionary {
239
+ [
240
+ "unit": mapFromDeliveryEstimateUnit(bound.unit),
241
+ "value": bound.value,
109
242
  ]
110
243
  }
111
244
 
112
- private class func mapFromCheckoutLineItem(_ lineItem: Checkout.LineItem) -> NSDictionary {
113
- return [
114
- "id": lineItem.id,
115
- "name": lineItem.name,
116
- "quantity": lineItem.quantity,
117
- "unitAmount": lineItem.unitAmount,
118
- "currency": lineItem.currency,
119
- ]
245
+ private class func mapFromDeliveryEstimateUnit(_ unit: Checkout.DeliveryEstimate.Bound.Unit) -> String {
246
+ switch unit {
247
+ case .hour: return "hour"
248
+ case .day: return "day"
249
+ case .businessDay: return "businessDay"
250
+ case .week: return "week"
251
+ case .month: return "month"
252
+ case .unknown: return "unknown"
253
+ @unknown default: return "unknown"
254
+ }
120
255
  }
121
256
 
122
- private class func mapFromCheckoutShippingOption(_ shippingOption: Checkout.ShippingOption) -> NSDictionary {
123
- return [
124
- "id": shippingOption.id,
125
- "displayName": shippingOption.displayName,
126
- "amount": shippingOption.amount,
127
- "currency": shippingOption.currency,
257
+ class func mapFromSelectedShipping(_ selectedShipping: Checkout.SelectedShipping) -> NSDictionary {
258
+ [
259
+ "shippingOption": mapFromShippingOption(selectedShipping.shippingOption),
260
+ "taxAmounts": selectedShipping.taxAmounts.map(mapFromTaxAmount),
128
261
  ]
129
262
  }
130
263
 
131
- private class func mapFromCheckoutDiscount(_ discount: Checkout.Discount) -> NSDictionary {
264
+ // MARK: - Discounts
265
+
266
+ class func mapFromDiscountAmount(_ discountAmount: Checkout.DiscountAmount) -> NSDictionary {
132
267
  let result = NSMutableDictionary()
133
- result["coupon"] = mapFromCheckoutCoupon(discount.coupon)
134
- result["amount"] = discount.amount
268
+ result["amount"] = mapFromAmount(discountAmount.amount)
269
+ result["displayName"] = discountAmount.displayName
135
270
 
136
- if let promotionCode = discount.promotionCode {
271
+ if let promotionCode = discountAmount.promotionCode {
137
272
  result["promotionCode"] = promotionCode
138
273
  }
139
274
 
140
275
  return result
141
276
  }
142
277
 
143
- private class func mapFromCheckoutCoupon(_ coupon: Checkout.Coupon) -> NSDictionary {
278
+ // MARK: - Currency Options
279
+
280
+ class func mapFromCurrencyOption(_ currencyOption: Checkout.CurrencyOption) -> NSDictionary {
144
281
  let result = NSMutableDictionary()
145
- result["id"] = coupon.id
282
+ result["amount"] = mapFromAmount(currencyOption.amount)
283
+ result["currency"] = currencyOption.currency
146
284
 
147
- if let name = coupon.name {
148
- result["name"] = name
285
+ if let currencyConversion = currencyOption.currencyConversion {
286
+ result["currencyConversion"] = mapFromCurrencyConversion(currencyConversion)
149
287
  }
150
288
 
151
- if let percentOff = coupon.percentOff {
152
- result["percentOff"] = percentOff
153
- }
289
+ return result
290
+ }
291
+
292
+ private class func mapFromCurrencyConversion(_ conversion: Checkout.CurrencyConversion) -> NSDictionary {
293
+ [
294
+ "fxRate": conversion.fxRate,
295
+ "sourceCurrency": conversion.sourceCurrency,
296
+ ]
297
+ }
298
+
299
+ // MARK: - Address
300
+
301
+ class func mapFromContactAddress(_ contactAddress: Checkout.ContactAddress) -> NSDictionary {
302
+ let result = NSMutableDictionary()
303
+ result["address"] = mapFromCheckoutAddress(contactAddress.address)
154
304
 
155
- if let amountOff = coupon.amountOff {
156
- result["amountOff"] = amountOff
305
+ if let name = contactAddress.name {
306
+ result["name"] = name
307
+ }
308
+ if let phone = contactAddress.phone {
309
+ result["phone"] = phone
157
310
  }
158
311
 
159
312
  return result
160
313
  }
161
314
 
162
- private class func mapFromCheckoutStatus(_ status: Checkout.Status?) -> String? {
163
- switch status {
164
- case .open:
165
- return "open"
166
- case .complete:
167
- return "complete"
168
- case .expired:
169
- return "expired"
170
- case .unknown:
171
- return "unknown"
172
- case nil:
173
- return nil
174
- @unknown default:
175
- return "unknown"
176
- }
177
- }
178
-
179
- private class func mapFromCheckoutPaymentStatus(_ paymentStatus: Checkout.PaymentStatus) -> String {
180
- switch paymentStatus {
181
- case .paid:
182
- return "paid"
183
- case .unpaid:
184
- return "unpaid"
185
- case .noPaymentRequired:
186
- return "noPaymentRequired"
187
- case .unknown:
188
- return "unknown"
189
- @unknown default:
190
- return "unknown"
315
+ private class func mapFromCheckoutAddress(_ address: Checkout.Address) -> NSDictionary {
316
+ let result = NSMutableDictionary()
317
+ result["country"] = address.country
318
+
319
+ if let line1 = address.line1 {
320
+ result["line1"] = line1
191
321
  }
322
+ if let line2 = address.line2 {
323
+ result["line2"] = line2
324
+ }
325
+ if let city = address.city {
326
+ result["city"] = city
327
+ }
328
+ if let state = address.state {
329
+ result["state"] = state
330
+ }
331
+ if let postalCode = address.postalCode {
332
+ result["postalCode"] = postalCode
333
+ }
334
+
335
+ return result
192
336
  }
193
337
  }
package/ios/Mappers.swift CHANGED
@@ -3,7 +3,7 @@ import Stripe
3
3
  @_spi(ConfirmationTokensPublicPreview) import StripePayments
4
4
  #if canImport(StripeCryptoOnramp)
5
5
  @_spi(CryptoOnrampAlpha) import StripeCryptoOnramp
6
- @_spi(STP) import StripePaymentSheet
6
+ @_spi(CryptoOnrampAlpha) import StripePaymentSheet
7
7
  #else
8
8
  import StripePaymentSheet
9
9
  #endif
@@ -1225,11 +1225,11 @@ class Mappers {
1225
1225
  nil
1226
1226
  }
1227
1227
 
1228
- let primaryButtonConfiguration: LinkAppearance.PrimaryButtonConfiguration? =
1229
- if let primaryButton = params["primaryButton"] as? [String: CGFloat],
1230
- let cornerRadius = primaryButton["cornerRadius"],
1231
- let height = primaryButton["height"] {
1232
- .init(cornerRadius: cornerRadius, height: height)
1228
+ let primaryButtonConfiguration: LinkAppearance.PrimaryButtonConfiguration? = if let primaryButton = params["primaryButton"] as? [String: CGFloat] {
1229
+ .init(
1230
+ cornerRadius: primaryButton["cornerRadius"],
1231
+ height: primaryButton["height"]
1232
+ )
1233
1233
  } else {
1234
1234
  nil
1235
1235
  }
@@ -1262,13 +1262,20 @@ class Mappers {
1262
1262
  class func mapToKycInfo(_ params: [String: Any]) throws -> KycInfo {
1263
1263
  let address = try mapOptionalKycAddress(params["address"])
1264
1264
  let dateOfBirth = try mapOptionalDateOfBirth(params["dateOfBirth"])
1265
+ let nationalities = try mapOptionalNormalizedStringArray(
1266
+ params["nationalities"],
1267
+ field: "nationalities"
1268
+ )
1265
1269
 
1266
1270
  return KycInfo(
1267
1271
  firstName: normalizedString(params["firstName"]),
1268
1272
  lastName: normalizedString(params["lastName"]),
1269
1273
  idNumber: normalizedString(params["idNumber"]),
1270
1274
  address: address,
1271
- dateOfBirth: dateOfBirth
1275
+ dateOfBirth: dateOfBirth,
1276
+ birthCountry: normalizedString(params["birthCountry"]),
1277
+ birthCity: normalizedString(params["birthCity"]),
1278
+ nationalities: nationalities
1272
1279
  )
1273
1280
  }
1274
1281
 
@@ -1295,6 +1302,18 @@ class Mappers {
1295
1302
  result["dateOfBirth"] = mapFromDateOfBirth(dateOfBirth)
1296
1303
  }
1297
1304
 
1305
+ if let birthCountry = kycInfo.birthCountry {
1306
+ result["birthCountry"] = birthCountry
1307
+ }
1308
+
1309
+ if let birthCity = kycInfo.birthCity {
1310
+ result["birthCity"] = birthCity
1311
+ }
1312
+
1313
+ if let nationalities = kycInfo.nationalities {
1314
+ result["nationalities"] = nationalities
1315
+ }
1316
+
1298
1317
  return result
1299
1318
  }
1300
1319
 
@@ -1336,6 +1355,50 @@ class Mappers {
1336
1355
  ]
1337
1356
  }
1338
1357
 
1358
+ class func mapToComplianceIdentifier(_ params: [String: Any]) throws -> ComplianceIdentifier {
1359
+ guard let type = normalizedString(params["type"]) else {
1360
+ throw ComplianceIdentifierError.invalidField("type")
1361
+ }
1362
+
1363
+ guard let value = normalizedString(params["value"]) else {
1364
+ throw ComplianceIdentifierError.invalidField("value")
1365
+ }
1366
+
1367
+ return ComplianceIdentifier(type: ComplianceIdentifierType(rawValue: type), value: value)
1368
+ }
1369
+
1370
+ class func mapFromComplianceIdentifierRequirements(_ requirements: ComplianceIdentifierRequirements) -> [String: Any] {
1371
+ [
1372
+ "identifiers": requirements.identifiers.map(mapFromComplianceIdentifierRequirement),
1373
+ "alternatives": requirements.alternatives.map(mapFromComplianceIdentifierAlternativeGroup),
1374
+ "carfTinRequired": requirements.carfTinRequired,
1375
+ ]
1376
+ }
1377
+
1378
+ class func mapFromSubmitIdentifiersResult(_ result: SubmitIdentifiersResult) -> [String: Any] {
1379
+ [
1380
+ "completed": result.completed,
1381
+ "identifiers": result.identifiers.map(mapFromComplianceIdentifierRequirement),
1382
+ "alternatives": result.alternatives.map(mapFromComplianceIdentifierAlternativeGroup),
1383
+ "carfTinRequired": result.carfTinRequired,
1384
+ "invalidIdentifiers": result.invalidIdentifiers.map(\.rawValue),
1385
+ ]
1386
+ }
1387
+
1388
+ private class func mapFromComplianceIdentifierRequirement(_ requirement: ComplianceIdentifierRequirement) -> [String: String] {
1389
+ [
1390
+ "type": requirement.type.rawValue,
1391
+ "regulation": requirement.regulation.rawValue,
1392
+ ]
1393
+ }
1394
+
1395
+ private class func mapFromComplianceIdentifierAlternativeGroup(_ group: ComplianceIdentifierAlternativeGroup) -> [String: [String]] {
1396
+ [
1397
+ "originalMissingIdentifiers": group.originalMissingIdentifiers.map(\.rawValue),
1398
+ "alternativeMissingIdentifiers": group.alternativeMissingIdentifiers.map(\.rawValue),
1399
+ ]
1400
+ }
1401
+
1339
1402
  private class func mapOptionalKycAddress(_ value: Any?) throws -> Address? {
1340
1403
  guard let value else {
1341
1404
  return nil
@@ -1380,6 +1443,29 @@ class Mappers {
1380
1443
  return nil
1381
1444
  }
1382
1445
 
1446
+ private class func mapOptionalNormalizedStringArray(
1447
+ _ value: Any?,
1448
+ field: String
1449
+ ) throws -> [String]? {
1450
+ guard let value else {
1451
+ return nil
1452
+ }
1453
+
1454
+ guard let values = value as? [Any] else {
1455
+ throw KycInfoError.invalidField(field)
1456
+ }
1457
+
1458
+ let normalizedValues = try values.map { value in
1459
+ guard let normalizedValue = normalizedString(value) else {
1460
+ throw KycInfoError.invalidField(field)
1461
+ }
1462
+
1463
+ return normalizedValue
1464
+ }
1465
+
1466
+ return normalizedValues.isEmpty ? nil : normalizedValues
1467
+ }
1468
+
1383
1469
  private class func normalizedString(_ value: Any?) -> String? {
1384
1470
  guard let stringValue = value as? String else {
1385
1471
  return nil
@@ -1415,5 +1501,9 @@ class Mappers {
1415
1501
  enum KycInfoError: Swift.Error {
1416
1502
  case invalidField(String)
1417
1503
  }
1504
+
1505
+ enum ComplianceIdentifierError: Swift.Error {
1506
+ case invalidField(String)
1507
+ }
1418
1508
  #endif
1419
1509
  }
@@ -41,6 +41,20 @@ using namespace facebook::react;
41
41
  {
42
42
  _view = [[StripeCurrencySelectorElementContainerView alloc] initWithFrame:self.frame];
43
43
  self.contentView = _view;
44
+
45
+ __weak __typeof(self) weakSelf = self;
46
+
47
+ _view.onHeightChange = ^(NSDictionary *event) {
48
+ __typeof(self) strongSelf = weakSelf;
49
+ if (!strongSelf || !strongSelf->_eventEmitter) {
50
+ return;
51
+ }
52
+ StripeCurrencySelectorElementEventEmitter::OnHeightChange emitterEvent = {
53
+ .height = [(NSNumber *)event[@"height"] doubleValue],
54
+ };
55
+ std::static_pointer_cast<const StripeCurrencySelectorElementEventEmitter>(strongSelf->_eventEmitter)
56
+ ->onHeightChange(std::move(emitterEvent));
57
+ };
44
58
  }
45
59
 
46
60
  - (void)updateProps:(const facebook::react::Props::Shared &)props
@@ -26,5 +26,6 @@
26
26
  - (void)emitOnCheckoutClientSecretRequested:(NSDictionary *)value;
27
27
  - (void)emitPaymentMethodMessagingElementDidUpdateHeight:(NSDictionary *)value;
28
28
  - (void)emitPaymentMethodMessagingElementConfigureResult:(NSDictionary *)value;
29
+ - (void)emitCheckoutSessionDidChangeState:(NSDictionary *)value;
29
30
  @end
30
31
 
@@ -27,6 +27,7 @@
27
27
  @"onCheckoutClientSecretRequested",
28
28
  @"paymentMethodMessagingElementDidUpdateHeight",
29
29
  @"paymentMethodMessagingElementConfigureResult",
30
+ @"checkoutSessionDidChangeState",
30
31
  ];
31
32
  }
32
33
 
@@ -140,4 +141,9 @@
140
141
  [self sendEventWithName:@"paymentMethodMessagingElementConfigureResult" body:value];
141
142
  }
142
143
 
144
+ - (void)emitCheckoutSessionDidChangeState:(NSDictionary *)value
145
+ {
146
+ [self sendEventWithName:@"checkoutSessionDidChangeState" body:value];
147
+ }
148
+
143
149
  @end