@stripe/stripe-react-native 0.55.0 → 0.56.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 (135) hide show
  1. package/android/.idea/AndroidProjectSystem.xml +6 -0
  2. package/android/.idea/caches/deviceStreaming.xml +703 -0
  3. package/android/.idea/compiler.xml +6 -0
  4. package/android/.idea/gradle.xml +18 -0
  5. package/android/.idea/migrations.xml +10 -0
  6. package/android/.idea/misc.xml +10 -0
  7. package/android/.idea/runConfigurations.xml +17 -0
  8. package/android/.idea/vcs.xml +6 -0
  9. package/android/gradle.properties +1 -1
  10. package/android/local.properties +8 -0
  11. package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementView.kt +120 -57
  12. package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +5 -0
  13. package/android/src/main/java/com/reactnativestripesdk/EventEmitterCompat.kt +12 -0
  14. package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherFragment.kt +1 -0
  15. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +54 -8
  16. package/android/src/main/java/com/reactnativestripesdk/StripeAbstractComposeView.kt +3 -2
  17. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +64 -0
  18. package/android/src/main/java/com/reactnativestripesdk/customersheet/CustomerSheetFragment.kt +72 -34
  19. package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerSessionProvider.kt +37 -0
  20. package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +84 -1
  21. package/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerDelegate.java +12 -0
  22. package/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerInterface.java +4 -0
  23. package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +12 -64
  24. package/ios/ApplePayButtonManager.m +1 -1
  25. package/ios/ApplePayButtonView.swift +2 -2
  26. package/ios/Mappers.swift +111 -18
  27. package/ios/NewArch/ApplePayButtonComponentView.mm +1 -1
  28. package/ios/OldArch/StripeSdkEventEmitterCompat.h +3 -0
  29. package/ios/OldArch/StripeSdkEventEmitterCompat.m +18 -0
  30. package/ios/StripeSdk.mm +21 -0
  31. package/ios/StripeSdkEmitter.swift +3 -0
  32. package/ios/StripeSdkImpl+CustomerSheet.swift +70 -19
  33. package/ios/StripeSdkImpl+Embedded.swift +26 -4
  34. package/ios/StripeSdkImpl+PaymentSheet.swift +46 -15
  35. package/ios/StripeSdkImpl.swift +21 -2
  36. package/lib/commonjs/components/AddToWalletButton.js +1 -1
  37. package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
  38. package/lib/commonjs/components/AddressSheet.js +1 -1
  39. package/lib/commonjs/components/AddressSheet.js.map +1 -1
  40. package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
  41. package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
  42. package/lib/commonjs/components/CardField.js +1 -1
  43. package/lib/commonjs/components/CardField.js.map +1 -1
  44. package/lib/commonjs/components/CardForm.js +1 -1
  45. package/lib/commonjs/components/CardForm.js.map +1 -1
  46. package/lib/commonjs/components/CustomerSheet.js +1 -1
  47. package/lib/commonjs/components/CustomerSheet.js.map +1 -1
  48. package/lib/commonjs/components/PlatformPayButton.js +1 -1
  49. package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
  50. package/lib/commonjs/components/StripeContainer.js +1 -1
  51. package/lib/commonjs/components/StripeContainer.js.map +1 -1
  52. package/lib/commonjs/events.js.map +1 -1
  53. package/lib/commonjs/functions.js +1 -1
  54. package/lib/commonjs/functions.js.map +1 -1
  55. package/lib/commonjs/index.js +1 -1
  56. package/lib/commonjs/index.js.map +1 -1
  57. package/lib/commonjs/specs/NativeApplePayButton.js +1 -1
  58. package/lib/commonjs/specs/NativeApplePayButton.js.map +1 -1
  59. package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
  60. package/lib/commonjs/types/ConfirmationToken.js +2 -0
  61. package/lib/commonjs/types/ConfirmationToken.js.map +1 -0
  62. package/lib/commonjs/types/EmbeddedPaymentElement.js +1 -1
  63. package/lib/commonjs/types/EmbeddedPaymentElement.js.map +1 -1
  64. package/lib/commonjs/types/PaymentSheet.js.map +1 -1
  65. package/lib/commonjs/types/index.js +1 -1
  66. package/lib/commonjs/types/index.js.map +1 -1
  67. package/lib/module/components/AddToWalletButton.js +1 -1
  68. package/lib/module/components/AddToWalletButton.js.map +1 -1
  69. package/lib/module/components/AddressSheet.js +1 -1
  70. package/lib/module/components/AddressSheet.js.map +1 -1
  71. package/lib/module/components/AuBECSDebitForm.js +1 -1
  72. package/lib/module/components/AuBECSDebitForm.js.map +1 -1
  73. package/lib/module/components/CardField.js +1 -1
  74. package/lib/module/components/CardField.js.map +1 -1
  75. package/lib/module/components/CardForm.js +1 -1
  76. package/lib/module/components/CardForm.js.map +1 -1
  77. package/lib/module/components/CustomerSheet.js +1 -1
  78. package/lib/module/components/CustomerSheet.js.map +1 -1
  79. package/lib/module/components/PlatformPayButton.js +1 -1
  80. package/lib/module/components/PlatformPayButton.js.map +1 -1
  81. package/lib/module/components/StripeContainer.js +1 -1
  82. package/lib/module/components/StripeContainer.js.map +1 -1
  83. package/lib/module/events.js.map +1 -1
  84. package/lib/module/functions.js +1 -1
  85. package/lib/module/functions.js.map +1 -1
  86. package/lib/module/index.js +1 -1
  87. package/lib/module/index.js.map +1 -1
  88. package/lib/module/specs/NativeApplePayButton.js +1 -1
  89. package/lib/module/specs/NativeApplePayButton.js.map +1 -1
  90. package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
  91. package/lib/module/types/ConfirmationToken.js +2 -0
  92. package/lib/module/types/ConfirmationToken.js.map +1 -0
  93. package/lib/module/types/EmbeddedPaymentElement.js +1 -1
  94. package/lib/module/types/EmbeddedPaymentElement.js.map +1 -1
  95. package/lib/module/types/PaymentSheet.js.map +1 -1
  96. package/lib/module/types/index.js +1 -1
  97. package/lib/module/types/index.js.map +1 -1
  98. package/lib/typescript/src/components/CustomerSheet.d.ts +1 -1
  99. package/lib/typescript/src/components/CustomerSheet.d.ts.map +1 -1
  100. package/lib/typescript/src/events.d.ts +6 -0
  101. package/lib/typescript/src/events.d.ts.map +1 -1
  102. package/lib/typescript/src/functions.d.ts.map +1 -1
  103. package/lib/typescript/src/index.d.ts +1 -0
  104. package/lib/typescript/src/index.d.ts.map +1 -1
  105. package/lib/typescript/src/specs/NativeApplePayButton.d.ts +1 -1
  106. package/lib/typescript/src/specs/NativeApplePayButton.d.ts.map +1 -1
  107. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +4 -1
  108. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
  109. package/lib/typescript/src/types/ConfirmationToken.d.ts +56 -0
  110. package/lib/typescript/src/types/ConfirmationToken.d.ts.map +1 -0
  111. package/lib/typescript/src/types/CustomerSheet.d.ts +70 -12
  112. package/lib/typescript/src/types/CustomerSheet.d.ts.map +1 -1
  113. package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts +2 -4
  114. package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts.map +1 -1
  115. package/lib/typescript/src/types/PaymentSheet.d.ts +26 -4
  116. package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -1
  117. package/lib/typescript/src/types/index.d.ts +2 -1
  118. package/lib/typescript/src/types/index.d.ts.map +1 -1
  119. package/package.json +1 -1
  120. package/src/components/CustomerSheet.tsx +65 -9
  121. package/src/components/PlatformPayButton.tsx +1 -1
  122. package/src/events.ts +6 -0
  123. package/src/functions.ts +16 -0
  124. package/src/index.tsx +1 -0
  125. package/src/specs/NativeApplePayButton.ts +1 -1
  126. package/src/specs/NativeStripeSdkModule.ts +10 -0
  127. package/src/types/ConfirmationToken.ts +73 -0
  128. package/src/types/CustomerSheet.ts +80 -12
  129. package/src/types/EmbeddedPaymentElement.tsx +23 -4
  130. package/src/types/PaymentSheet.ts +31 -12
  131. package/src/types/index.ts +2 -0
  132. package/stripe-react-native.podspec +1 -1
  133. package/ios/StripeSdk.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  134. package/ios/StripeSdk.xcodeproj/project.xcworkspace/xcuserdata/wooj.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  135. package/ios/StripeSdk.xcodeproj/xcuserdata/wooj.xcuserdatad/xcschemes/xcschememanagement.plist +0 -19
@@ -13,6 +13,7 @@ import com.facebook.react.bridge.ReactApplicationContext
13
13
  import com.facebook.react.bridge.WritableMap
14
14
  import com.facebook.react.bridge.WritableNativeMap
15
15
  import com.reactnativestripesdk.ReactNativeCustomerAdapter
16
+ import com.reactnativestripesdk.ReactNativeCustomerSessionProvider
16
17
  import com.reactnativestripesdk.buildPaymentSheetAppearance
17
18
  import com.reactnativestripesdk.getBase64FromBitmap
18
19
  import com.reactnativestripesdk.getBitmapFromDrawable
@@ -34,15 +35,17 @@ import com.stripe.android.customersheet.CustomerSheet
34
35
  import com.stripe.android.customersheet.CustomerSheetResult
35
36
  import com.stripe.android.customersheet.PaymentOptionSelection
36
37
  import com.stripe.android.model.PaymentMethod
38
+ import com.stripe.android.paymentsheet.ExperimentalCustomerSessionApi
37
39
  import com.stripe.android.paymentsheet.PaymentSheet
38
40
  import kotlinx.coroutines.CoroutineScope
39
41
  import kotlinx.coroutines.Dispatchers
40
42
  import kotlinx.coroutines.launch
41
43
 
42
- @OptIn(ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class)
44
+ @OptIn(ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class, ExperimentalCustomerSessionApi::class)
43
45
  class CustomerSheetFragment : StripeFragment() {
44
46
  private var customerSheet: CustomerSheet? = null
45
47
  internal var customerAdapter: ReactNativeCustomerAdapter? = null
48
+ internal var customerSessionProvider: ReactNativeCustomerSessionProvider? = null
46
49
  internal var context: ReactApplicationContext? = null
47
50
  internal var initPromise: Promise? = null
48
51
  private var presentPromise: Promise? = null
@@ -73,28 +76,9 @@ class CustomerSheetFragment : StripeFragment() {
73
76
  val googlePayEnabled = arguments?.getBoolean("googlePayEnabled") ?: false
74
77
  val billingDetailsBundle = arguments?.getBundle("defaultBillingDetails")
75
78
  val billingConfigParams = arguments?.getBundle("billingDetailsCollectionConfiguration")
76
- val setupIntentClientSecret = arguments?.getString("setupIntentClientSecret")
77
- val customerId = arguments?.getString("customerId")
78
- val customerEphemeralKeySecret = arguments?.getString("customerEphemeralKeySecret")
79
- val customerAdapterOverrideParams = arguments?.getBundle("customerAdapter")
80
79
  val allowsRemovalOfLastSavedPaymentMethod =
81
80
  arguments?.getBoolean("allowsRemovalOfLastSavedPaymentMethod", true) ?: true
82
81
  val paymentMethodOrder = arguments?.getStringArrayList("paymentMethodOrder")
83
- if (customerId == null) {
84
- initPromise.resolve(
85
- createError(ErrorType.Failed.toString(), "You must provide a value for `customerId`"),
86
- )
87
- return
88
- }
89
- if (customerEphemeralKeySecret == null) {
90
- initPromise.resolve(
91
- createError(
92
- ErrorType.Failed.toString(),
93
- "You must provide a value for `customerEphemeralKeySecret`",
94
- ),
95
- )
96
- return
97
- }
98
82
 
99
83
  val appearance =
100
84
  try {
@@ -125,21 +109,62 @@ class CustomerSheetFragment : StripeFragment() {
125
109
  )
126
110
  }
127
111
 
128
- val customerAdapter =
129
- createCustomerAdapter(
130
- context,
131
- customerId,
132
- customerEphemeralKeySecret,
133
- setupIntentClientSecret,
134
- customerAdapterOverrideParams,
135
- ).also { this.customerAdapter = it }
136
-
137
- customerSheet =
138
- CustomerSheet.create(
139
- fragment = this,
140
- customerAdapter = customerAdapter,
141
- callback = ::handleResult,
112
+ val customerEphemeralKeySecret = arguments?.getString("customerEphemeralKeySecret")
113
+ val intentConfiguration = createIntentConfiguration(arguments?.getBundle("intentConfiguration"))
114
+ if (customerEphemeralKeySecret == null && intentConfiguration == null) {
115
+ initPromise.resolve(
116
+ createError(
117
+ ErrorType.Failed.toString(),
118
+ "You must provide either `customerEphemeralKeySecret` or `intentConfiguration`",
119
+ ),
142
120
  )
121
+ return
122
+ } else if (customerEphemeralKeySecret == null) {
123
+ val customerSessionProvider =
124
+ ReactNativeCustomerSessionProvider(
125
+ context = context,
126
+ intentConfiguration = intentConfiguration!!,
127
+ ).also { this.customerSessionProvider = it }
128
+
129
+ customerSheet =
130
+ CustomerSheet.create(
131
+ fragment = this,
132
+ customerSessionProvider = customerSessionProvider,
133
+ callback = ::handleResult,
134
+ )
135
+ } else if (intentConfiguration == null) {
136
+ val customerId = arguments?.getString("customerId")
137
+ if (customerId == null) {
138
+ initPromise.resolve(
139
+ createError(ErrorType.Failed.toString(), "When using `customerEphemeralKeySecret` you must provide a value for `customerId`"),
140
+ )
141
+ return
142
+ }
143
+ val setupIntentClientSecret = arguments?.getString("setupIntentClientSecret")
144
+ val customerAdapterOverrideParams = arguments?.getBundle("customerAdapter")
145
+ val customerAdapter =
146
+ createCustomerAdapter(
147
+ context,
148
+ customerId!!,
149
+ customerEphemeralKeySecret,
150
+ setupIntentClientSecret,
151
+ customerAdapterOverrideParams,
152
+ ).also { this.customerAdapter = it }
153
+
154
+ customerSheet =
155
+ CustomerSheet.create(
156
+ fragment = this,
157
+ customerAdapter = customerAdapter,
158
+ callback = ::handleResult,
159
+ )
160
+ } else {
161
+ initPromise.resolve(
162
+ createError(
163
+ ErrorType.Failed.toString(),
164
+ "You must provide either `customerEphemeralKeySecret` or `intentConfiguration`, but not both",
165
+ ),
166
+ )
167
+ }
143
168
 
144
169
  customerSheet?.configure(configuration.build())
145
170
 
@@ -389,6 +414,19 @@ class CustomerSheetFragment : StripeFragment() {
389
414
  return paymentOptionResult
390
415
  }
391
416
 
417
+ internal fun createIntentConfiguration(intentConfigurationBundle: Bundle?): CustomerSheet.IntentConfiguration? =
418
+ intentConfigurationBundle?.let { bundle ->
419
+ val onBehalfOf = bundle?.getString("onBehalfOf")
420
+ CustomerSheet.IntentConfiguration
421
+ .Builder()
422
+ .paymentMethodTypes(bundle?.getStringArrayList("paymentMethodTypes") ?: emptyList())
423
+ .apply {
424
+ if (onBehalfOf != null) {
425
+ this.onBehalfOf(onBehalfOf!!)
426
+ }
427
+ }.build()
428
+ }
429
+
392
430
  private fun buildResult(
393
431
  label: String,
394
432
  drawable: Drawable,
@@ -0,0 +1,37 @@
1
+ package com.reactnativestripesdk
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.stripe.android.customersheet.CustomerSheet
5
+ import com.stripe.android.paymentsheet.ExperimentalCustomerSessionApi
6
+ import kotlinx.coroutines.CompletableDeferred
7
+
8
+ @OptIn(ExperimentalCustomerSessionApi::class)
9
+ class ReactNativeCustomerSessionProvider(
10
+ val context: ReactApplicationContext,
11
+ val intentConfiguration: CustomerSheet.IntentConfiguration,
12
+ ) : CustomerSheet.CustomerSessionProvider() {
13
+ private val stripeSdkModule = context.getNativeModule(StripeSdkModule::class.java)
14
+
15
+ internal var provideSetupIntentClientSecretCallback: CompletableDeferred<String>? = null
16
+ internal var providesCustomerSessionClientSecretCallback: CompletableDeferred<CustomerSheet.CustomerSessionClientSecret>? = null
17
+
18
+ override suspend fun intentConfiguration(): Result<CustomerSheet.IntentConfiguration> = Result.success(intentConfiguration)
19
+
20
+ override suspend fun provideSetupIntentClientSecret(customerId: String): Result<String> {
21
+ CompletableDeferred<String>().also {
22
+ provideSetupIntentClientSecretCallback = it
23
+ stripeSdkModule?.eventEmitter?.emitOnCustomerSessionProviderSetupIntentClientSecret()
24
+ val resultFromJavascript = it.await()
25
+ return Result.success(resultFromJavascript)
26
+ }
27
+ }
28
+
29
+ override suspend fun providesCustomerSessionClientSecret(): Result<CustomerSheet.CustomerSessionClientSecret> {
30
+ CompletableDeferred<CustomerSheet.CustomerSessionClientSecret>().also {
31
+ providesCustomerSessionClientSecretCallback = it
32
+ stripeSdkModule?.eventEmitter?.emitOnCustomerSessionProviderCustomerSessionClientSecret()
33
+ val resultFromJavascript = it.await()
34
+ return Result.success(resultFromJavascript)
35
+ }
36
+ }
37
+ }
@@ -18,6 +18,7 @@ import com.stripe.android.model.BankAccountTokenParams
18
18
  import com.stripe.android.model.Card
19
19
  import com.stripe.android.model.CardBrand
20
20
  import com.stripe.android.model.ConfirmPaymentIntentParams
21
+ import com.stripe.android.model.ConfirmationToken
21
22
  import com.stripe.android.model.GooglePayResult
22
23
  import com.stripe.android.model.MicrodepositType
23
24
  import com.stripe.android.model.PaymentIntent
@@ -152,6 +153,7 @@ internal fun mapPaymentMethodType(type: PaymentMethod.Type?): String =
152
153
  PaymentMethod.Type.Affirm -> "Affirm"
153
154
  PaymentMethod.Type.CashAppPay -> "CashApp"
154
155
  PaymentMethod.Type.RevolutPay -> "RevolutPay"
156
+ PaymentMethod.Type.Link -> "Link"
155
157
  else -> "Unknown"
156
158
  }
157
159
 
@@ -183,6 +185,7 @@ internal fun mapToPaymentMethodType(type: String?): PaymentMethod.Type? =
183
185
  "Affirm" -> PaymentMethod.Type.Affirm
184
186
  "CashApp" -> PaymentMethod.Type.CashAppPay
185
187
  "RevolutPay" -> PaymentMethod.Type.RevolutPay
188
+ "Link" -> PaymentMethod.Type.Link
186
189
  else -> null
187
190
  }
188
191
 
@@ -561,6 +564,7 @@ internal fun mapNextAction(
561
564
  NextActionType.UseStripeSdk,
562
565
  NextActionType.UpiAwaitNotification,
563
566
  NextActionType.DisplayPayNowDetails,
567
+ NextActionType.DisplayPromptPayDetails,
564
568
  null,
565
569
  -> {
566
570
  return null
@@ -1028,7 +1032,16 @@ internal fun mapToPreferredNetworks(networksAsInts: ArrayList<Int>?): List<CardB
1028
1032
  internal fun mapFromFinancialConnectionsEvent(event: FinancialConnectionsEvent): WritableMap =
1029
1033
  Arguments.createMap().apply {
1030
1034
  putString("name", event.name.value)
1031
- putMap("metadata", event.metadata.toMap().toReadableMap())
1035
+
1036
+ // We require keys to use pascal case, but the original map uses snake case.
1037
+ val tweakedMap =
1038
+ buildMap {
1039
+ put("institutionName", event.metadata.institutionName)
1040
+ put("manualEntry", event.metadata.manualEntry)
1041
+ put("errorCode", event.metadata.errorCode)
1042
+ }
1043
+
1044
+ putMap("metadata", tweakedMap.toReadableMap())
1032
1045
  }
1033
1046
 
1034
1047
  private fun List<Any?>.toWritableArray(): WritableArray {
@@ -1118,3 +1131,73 @@ internal fun mapFromCustomPaymentMethod(
1118
1131
  )
1119
1132
  putMap("billingDetails", mapFromBillingDetails(billingDetails))
1120
1133
  }
1134
+
1135
+ @SuppressLint("RestrictedApi")
1136
+ internal fun mapFromConfirmationToken(confirmationToken: ConfirmationToken): WritableMap {
1137
+ val token: WritableMap = WritableNativeMap()
1138
+
1139
+ token.putString("id", confirmationToken.id)
1140
+ token.putDouble("created", confirmationToken.created.toDouble())
1141
+ token.putDouble("expiresAt", confirmationToken.expiresAt?.toDouble() ?: 0.0)
1142
+ token.putBoolean("liveMode", confirmationToken.liveMode)
1143
+ token.putString("paymentIntentId", confirmationToken.paymentIntentId)
1144
+ token.putString("setupIntentId", confirmationToken.setupIntentId)
1145
+ token.putString("returnURL", confirmationToken.returnUrl)
1146
+ token.putString("setupFutureUsage", mapFromSetupFutureUsage(confirmationToken.setupFutureUsage))
1147
+
1148
+ // PaymentMethodPreview
1149
+ confirmationToken.paymentMethodPreview?.let { preview ->
1150
+ val paymentMethodPreview = WritableNativeMap()
1151
+ paymentMethodPreview.putString("type", mapPaymentMethodType(preview.type))
1152
+ paymentMethodPreview.putMap("billingDetails", mapFromBillingDetails(preview.billingDetails))
1153
+ paymentMethodPreview.putString("allowRedisplay", mapFromAllowRedisplay(preview.allowRedisplay))
1154
+ paymentMethodPreview.putString("customerId", preview.customerId)
1155
+ token.putMap("paymentMethodPreview", paymentMethodPreview)
1156
+ } ?: run {
1157
+ token.putNull("paymentMethodPreview")
1158
+ }
1159
+
1160
+ // Shipping details
1161
+ confirmationToken.shipping?.let { shippingDetails ->
1162
+ val shipping = WritableNativeMap()
1163
+ shipping.putString("name", shippingDetails.name)
1164
+ shipping.putString("phone", shippingDetails.phone)
1165
+
1166
+ shippingDetails.address?.let { address ->
1167
+ val addressMap = WritableNativeMap()
1168
+ addressMap.putString("city", address.city)
1169
+ addressMap.putString("country", address.country)
1170
+ addressMap.putString("line1", address.line1)
1171
+ addressMap.putString("line2", address.line2)
1172
+ addressMap.putString("postalCode", address.postalCode)
1173
+ addressMap.putString("state", address.state)
1174
+ shipping.putMap("address", addressMap)
1175
+ } ?: run {
1176
+ shipping.putMap("address", WritableNativeMap())
1177
+ }
1178
+
1179
+ token.putMap("shipping", shipping)
1180
+ } ?: run {
1181
+ token.putNull("shipping")
1182
+ }
1183
+
1184
+ return token
1185
+ }
1186
+
1187
+ @SuppressLint("RestrictedApi")
1188
+ private fun mapFromSetupFutureUsage(setupFutureUsage: ConfirmPaymentIntentParams.SetupFutureUsage?): String? =
1189
+ when (setupFutureUsage) {
1190
+ ConfirmPaymentIntentParams.SetupFutureUsage.OnSession -> "on_session"
1191
+ ConfirmPaymentIntentParams.SetupFutureUsage.OffSession -> "off_session"
1192
+ ConfirmPaymentIntentParams.SetupFutureUsage.Blank -> ""
1193
+ ConfirmPaymentIntentParams.SetupFutureUsage.None -> "none"
1194
+ null -> null
1195
+ }
1196
+
1197
+ private fun mapFromAllowRedisplay(allowRedisplay: PaymentMethod.AllowRedisplay?): String? =
1198
+ when (allowRedisplay) {
1199
+ PaymentMethod.AllowRedisplay.ALWAYS -> "always"
1200
+ PaymentMethod.AllowRedisplay.LIMITED -> "limited"
1201
+ PaymentMethod.AllowRedisplay.UNSPECIFIED -> "unspecified"
1202
+ null -> null
1203
+ }
@@ -34,6 +34,18 @@ public class ApplePayButtonManagerDelegate<T extends View, U extends BaseViewMan
34
34
  case "borderRadius":
35
35
  mViewManager.setBorderRadius(view, value == null ? 4 : ((Double) value).intValue());
36
36
  break;
37
+ case "hasShippingMethodCallback":
38
+ mViewManager.setHasShippingMethodCallback(view, value == null ? false : (boolean) value);
39
+ break;
40
+ case "hasShippingContactCallback":
41
+ mViewManager.setHasShippingContactCallback(view, value == null ? false : (boolean) value);
42
+ break;
43
+ case "hasCouponCodeCallback":
44
+ mViewManager.setHasCouponCodeCallback(view, value == null ? false : (boolean) value);
45
+ break;
46
+ case "hasOrderTrackingCallback":
47
+ mViewManager.setHasOrderTrackingCallback(view, value == null ? false : (boolean) value);
48
+ break;
37
49
  default:
38
50
  super.setProperty(view, propName, value);
39
51
  }
@@ -16,4 +16,8 @@ public interface ApplePayButtonManagerInterface<T extends View> {
16
16
  void setType(T view, int value);
17
17
  void setButtonStyle(T view, int value);
18
18
  void setBorderRadius(T view, int value);
19
+ void setHasShippingMethodCallback(T view, boolean value);
20
+ void setHasShippingContactCallback(T view, boolean value);
21
+ void setHasCouponCodeCallback(T view, boolean value);
22
+ void setHasOrderTrackingCallback(T view, boolean value);
19
23
  }
@@ -54,70 +54,6 @@ public abstract class NativeStripeSdkModuleSpec extends ReactContextBaseJavaModu
54
54
  invoke(eventName, null);
55
55
  }
56
56
 
57
- protected final void emitOnConfirmHandlerCallback(ReadableMap value) {
58
- invoke("onConfirmHandlerCallback", value);
59
- }
60
-
61
- protected final void emitOnFinancialConnectionsEvent(ReadableMap value) {
62
- invoke("onFinancialConnectionsEvent", value);
63
- }
64
-
65
- protected final void emitOnOrderTrackingCallback() {
66
- invoke("onOrderTrackingCallback");
67
- }
68
-
69
- protected final void emitOnCustomerAdapterFetchPaymentMethodsCallback() {
70
- invoke("onCustomerAdapterFetchPaymentMethodsCallback");
71
- }
72
-
73
- protected final void emitOnCustomerAdapterAttachPaymentMethodCallback(ReadableMap value) {
74
- invoke("onCustomerAdapterAttachPaymentMethodCallback", value);
75
- }
76
-
77
- protected final void emitOnCustomerAdapterDetachPaymentMethodCallback(ReadableMap value) {
78
- invoke("onCustomerAdapterDetachPaymentMethodCallback", value);
79
- }
80
-
81
- protected final void emitOnCustomerAdapterSetSelectedPaymentOptionCallback(ReadableMap value) {
82
- invoke("onCustomerAdapterSetSelectedPaymentOptionCallback", value);
83
- }
84
-
85
- protected final void emitOnCustomerAdapterFetchSelectedPaymentOptionCallback() {
86
- invoke("onCustomerAdapterFetchSelectedPaymentOptionCallback");
87
- }
88
-
89
- protected final void emitOnCustomerAdapterSetupIntentClientSecretForCustomerAttachCallback() {
90
- invoke("onCustomerAdapterSetupIntentClientSecretForCustomerAttachCallback");
91
- }
92
-
93
- protected final void emitEmbeddedPaymentElementDidUpdateHeight(ReadableMap value) {
94
- invoke("embeddedPaymentElementDidUpdateHeight", value);
95
- }
96
-
97
- protected final void emitEmbeddedPaymentElementWillPresent() {
98
- invoke("embeddedPaymentElementWillPresent");
99
- }
100
-
101
- protected final void emitEmbeddedPaymentElementDidUpdatePaymentOption(ReadableMap value) {
102
- invoke("embeddedPaymentElementDidUpdatePaymentOption", value);
103
- }
104
-
105
- protected final void emitEmbeddedPaymentElementFormSheetConfirmComplete(ReadableMap value) {
106
- invoke("embeddedPaymentElementFormSheetConfirmComplete", value);
107
- }
108
-
109
- protected final void emitEmbeddedPaymentElementRowSelectionImmediateAction() {
110
- invoke("embeddedPaymentElementRowSelectionImmediateAction");
111
- }
112
-
113
- protected final void emitEmbeddedPaymentElementLoadingFailed(ReadableMap value) {
114
- invoke("embeddedPaymentElementLoadingFailed", value);
115
- }
116
-
117
- protected final void emitOnCustomPaymentMethodConfirmHandlerCallback(ReadableMap value) {
118
- invoke("onCustomPaymentMethodConfirmHandlerCallback", value);
119
- }
120
-
121
57
  @ReactMethod
122
58
  @DoNotStrip
123
59
  public abstract void initialise(ReadableMap params, Promise promise);
@@ -158,6 +94,10 @@ public abstract class NativeStripeSdkModuleSpec extends ReactContextBaseJavaModu
158
94
  @DoNotStrip
159
95
  public abstract void intentCreationCallback(ReadableMap result, Promise promise);
160
96
 
97
+ @ReactMethod
98
+ @DoNotStrip
99
+ public abstract void confirmationTokenCreationCallback(ReadableMap result, Promise promise);
100
+
161
101
  @ReactMethod
162
102
  @DoNotStrip
163
103
  public abstract void customPaymentMethodResultCallback(ReadableMap result, Promise promise);
@@ -300,6 +240,14 @@ public abstract class NativeStripeSdkModuleSpec extends ReactContextBaseJavaModu
300
240
  @DoNotStrip
301
241
  public abstract void customerAdapterSetupIntentClientSecretForCustomerAttachCallback(String clientSecret, Promise promise);
302
242
 
243
+ @ReactMethod
244
+ @DoNotStrip
245
+ public abstract void clientSecretProviderSetupIntentClientSecretCallback(String setupIntentClientSecret, Promise promise);
246
+
247
+ @ReactMethod
248
+ @DoNotStrip
249
+ public abstract void clientSecretProviderCustomerSessionClientSecretCallback(ReadableMap customerSessionClientSecret, Promise promise);
250
+
303
251
  @ReactMethod
304
252
  @DoNotStrip
305
253
  public abstract void createEmbeddedPaymentElement(ReadableMap intentConfig, ReadableMap configuration, Promise promise);
@@ -5,7 +5,7 @@
5
5
  @interface RCT_EXTERN_MODULE(ApplePayButtonManager, RCTViewManager)
6
6
  RCT_EXPORT_VIEW_PROPERTY(type, NSNumber)
7
7
  RCT_EXPORT_VIEW_PROPERTY(buttonStyle, NSNumber)
8
- RCT_EXPORT_VIEW_PROPERTY(borderRadius, NSNumber)
8
+ RCT_EXPORT_VIEW_PROPERTY(buttonBorderRadius, NSNumber)
9
9
  RCT_EXPORT_VIEW_PROPERTY(disabled, BOOL)
10
10
  RCT_EXPORT_VIEW_PROPERTY(onShippingMethodSelectedAction, RCTDirectEventBlock)
11
11
  RCT_EXPORT_VIEW_PROPERTY(onShippingContactSelectedAction, RCTDirectEventBlock)
@@ -18,7 +18,7 @@ public class ApplePayButtonView: UIView {
18
18
 
19
19
  @objc public var type: NSNumber?
20
20
  @objc public var buttonStyle: NSNumber?
21
- @objc public var borderRadius: NSNumber?
21
+ @objc public var buttonBorderRadius: NSNumber?
22
22
  @objc public var disabled = false
23
23
 
24
24
  @objc func handleApplePayButtonTapped() {
@@ -37,7 +37,7 @@ public class ApplePayButtonView: UIView {
37
37
  let paymentButtonStyle = PKPaymentButtonStyle(rawValue: self.buttonStyle as? Int ?? 2) ?? .black
38
38
  self.applePayButton = PKPaymentButton(paymentButtonType: paymentButtonType, paymentButtonStyle: paymentButtonStyle)
39
39
  if #available(iOS 12.0, *) {
40
- self.applePayButton?.cornerRadius = self.borderRadius as? CGFloat ?? 4.0
40
+ self.applePayButton?.cornerRadius = self.buttonBorderRadius as? CGFloat ?? 4.0
41
41
  }
42
42
 
43
43
  if let applePayButton = self.applePayButton {
package/ios/Mappers.swift CHANGED
@@ -1,5 +1,7 @@
1
1
  import Stripe
2
2
  import StripePaymentSheet
3
+ @_spi(ConfirmationTokensPublicPreview) import StripePayments
4
+ import Contacts
3
5
 
4
6
  class Mappers {
5
7
  class func createResult(_ key: String, _ value: NSDictionary?, additionalFields: [String: Any]? = nil) -> NSDictionary {
@@ -298,6 +300,7 @@ class Mappers {
298
300
  case STPPaymentMethodType.affirm: return "Affirm"
299
301
  case STPPaymentMethodType.cashApp: return "CashApp"
300
302
  case STPPaymentMethodType.revolutPay: return "RevolutPay"
303
+ case STPPaymentMethodType.link: return "Link"
301
304
  case STPPaymentMethodType.unknown: return "Unknown"
302
305
  default: return "Unknown"
303
306
  }
@@ -331,6 +334,7 @@ class Mappers {
331
334
  case "Affirm": return STPPaymentMethodType.affirm
332
335
  case "CashApp": return STPPaymentMethodType.cashApp
333
336
  case "RevolutPay": return STPPaymentMethodType.revolutPay
337
+ case "Link": return STPPaymentMethodType.link
334
338
  default: return STPPaymentMethodType.unknown
335
339
  }
336
340
  }
@@ -557,18 +561,31 @@ class Mappers {
557
561
  }
558
562
 
559
563
  class func mapFromBillingDetails(billingDetails: STPPaymentMethodBillingDetails?) -> NSDictionary {
564
+ let email: Any = billingDetails?.email ?? NSNull()
565
+ let phone: Any = billingDetails?.phone ?? NSNull()
566
+ let name: Any = billingDetails?.name ?? NSNull()
567
+
568
+ let addressCity: Any = billingDetails?.address?.city ?? NSNull()
569
+ let addressPostalCode: Any = billingDetails?.address?.postalCode ?? NSNull()
570
+ let addressCountry: Any = billingDetails?.address?.country ?? NSNull()
571
+ let addressLine1: Any = billingDetails?.address?.line1 ?? NSNull()
572
+ let addressLine2: Any = billingDetails?.address?.line2 ?? NSNull()
573
+ let addressState: Any = billingDetails?.address?.state ?? NSNull()
574
+
575
+ let address: NSDictionary = [
576
+ "city": addressCity,
577
+ "postalCode": addressPostalCode,
578
+ "country": addressCountry,
579
+ "line1": addressLine1,
580
+ "line2": addressLine2,
581
+ "state": addressState,
582
+ ]
583
+
560
584
  let billing: NSDictionary = [
561
- "email": billingDetails?.email ?? NSNull(),
562
- "phone": billingDetails?.phone ?? NSNull(),
563
- "name": billingDetails?.name ?? NSNull(),
564
- "address": [
565
- "city": billingDetails?.address?.city,
566
- "postalCode": billingDetails?.address?.postalCode,
567
- "country": billingDetails?.address?.country,
568
- "line1": billingDetails?.address?.line1,
569
- "line2": billingDetails?.address?.line2,
570
- "state": billingDetails?.address?.state,
571
- ],
585
+ "email": email,
586
+ "phone": phone,
587
+ "name": name,
588
+ "address": address,
572
589
  ]
573
590
 
574
591
  return billing
@@ -679,6 +696,89 @@ class Mappers {
679
696
  return method
680
697
  }
681
698
 
699
+ class func mapFromConfirmationToken(_ confirmationToken: STPConfirmationToken?) -> NSDictionary? {
700
+ guard let confirmationToken = confirmationToken else {
701
+ return nil
702
+ }
703
+
704
+ var paymentMethodPreview: NSDictionary? = nil
705
+ if let preview = confirmationToken.paymentMethodPreview {
706
+ paymentMethodPreview = [
707
+ "type": Mappers.mapPaymentMethodType(type: preview.type),
708
+ "billingDetails": Mappers.mapFromBillingDetails(billingDetails: preview.billingDetails),
709
+ "allowRedisplay": mapFromAllowRedisplay(allowRedisplay: preview.allowRedisplay) ?? NSNull(),
710
+ "customerId": preview.customerId ?? NSNull(),
711
+ "allResponseFields": preview.allResponseFields
712
+ ]
713
+ }
714
+
715
+ var shipping: NSDictionary? = nil
716
+ if let shippingDetails = confirmationToken.shipping {
717
+ var addressDetails: NSDictionary = [:]
718
+ if let address = shippingDetails.address {
719
+ addressDetails = [
720
+ "city": address.city ?? NSNull(),
721
+ "state": address.state ?? NSNull(),
722
+ "country": address.country ?? NSNull(),
723
+ "line1": address.line1 ?? NSNull(),
724
+ "line2": address.line2 ?? NSNull(),
725
+ "postalCode": address.postalCode ?? NSNull(),
726
+ ]
727
+ }
728
+ shipping = [
729
+ "address": addressDetails,
730
+ "name": shippingDetails.name ?? NSNull(),
731
+ "phone": shippingDetails.phone ?? NSNull()
732
+ ]
733
+ }
734
+
735
+ let token: NSDictionary = [
736
+ "id": confirmationToken.stripeId,
737
+ "created": convertDateToUnixTimestampSeconds(date: confirmationToken.created) ?? NSNull(),
738
+ "expiresAt": convertDateToUnixTimestampSeconds(date: confirmationToken.expiresAt) ?? NSNull(),
739
+ "liveMode": confirmationToken.liveMode,
740
+ "paymentIntentId": confirmationToken.paymentIntentId ?? NSNull(),
741
+ "setupIntentId": confirmationToken.setupIntentId ?? NSNull(),
742
+ "returnURL": confirmationToken.returnURL ?? NSNull(),
743
+ "setupFutureUsage": mapFromSetupFutureUsage(setupFutureUsage: confirmationToken.setupFutureUsage) ?? NSNull(),
744
+ "paymentMethodPreview": paymentMethodPreview ?? NSNull(),
745
+ "shipping": shipping ?? NSNull(),
746
+ "allResponseFields": confirmationToken.allResponseFields
747
+ ]
748
+ return token
749
+ }
750
+
751
+ class func mapFromAllowRedisplay(allowRedisplay: STPPaymentMethodAllowRedisplay?) -> String? {
752
+ guard let allowRedisplay = allowRedisplay else {
753
+ return nil
754
+ }
755
+ switch allowRedisplay {
756
+ case .always: return "always"
757
+ case .limited: return "limited"
758
+ case .unspecified: return "unspecified"
759
+ @unknown default: return "unspecified"
760
+ }
761
+ }
762
+
763
+ class func mapFromSetupFutureUsage(setupFutureUsage: STPPaymentIntentSetupFutureUsage?) -> String? {
764
+ guard let setupFutureUsage = setupFutureUsage else {
765
+ return nil
766
+ }
767
+ switch setupFutureUsage {
768
+ case .offSession: return "OffSession"
769
+ case .onSession: return "OnSession"
770
+ case .none: return "None"
771
+ default: return nil
772
+ }
773
+ }
774
+
775
+ class func convertDateToUnixTimestampSeconds(date: Date?) -> NSNumber? {
776
+ guard let date = date else {
777
+ return nil
778
+ }
779
+ return NSNumber(value: date.timeIntervalSince1970)
780
+ }
781
+
682
782
  class func mapIntentStatus(status: STPSetupIntentStatus?) -> String {
683
783
  if let status = status {
684
784
  switch status {
@@ -961,13 +1061,6 @@ class Mappers {
961
1061
  return nil
962
1062
  }
963
1063
 
964
- class func convertDateToUnixTimestampSeconds(date: Date?) -> String? {
965
- if let date = date {
966
- let value = date.timeIntervalSince1970
967
- return String(format: "%.0f", value)
968
- }
969
- return nil
970
- }
971
1064
 
972
1065
  class func mapFromCardValidationState(state: STPCardValidationState?) -> String {
973
1066
  if let state = state {
@@ -96,7 +96,7 @@ using namespace facebook::react;
96
96
  _view.type = @(newViewProps.type);
97
97
  _view.buttonStyle = @(newViewProps.buttonStyle);
98
98
  _view.disabled = newViewProps.disabled;
99
- _view.borderRadius = @(newViewProps.borderRadius);
99
+ _view.buttonBorderRadius = @(newViewProps.buttonBorderRadius);
100
100
 
101
101
  // Set the boolean flags from props
102
102
  _view.hasShippingMethodCallback = newViewProps.hasShippingMethodCallback;
@@ -5,6 +5,7 @@
5
5
 
6
6
  @interface StripeSdkEventEmitterCompat : RCTEventEmitter
7
7
  - (void)emitOnConfirmHandlerCallback:(NSDictionary *)value;
8
+ - (void)emitOnConfirmationTokenHandlerCallback:(NSDictionary *)value;
8
9
  - (void)emitOnFinancialConnectionsEvent:(NSDictionary *)value;
9
10
  - (void)emitOnOrderTrackingCallback;
10
11
  - (void)emitOnCustomerAdapterFetchPaymentMethodsCallback;
@@ -13,6 +14,8 @@
13
14
  - (void)emitOnCustomerAdapterSetSelectedPaymentOptionCallback:(NSDictionary *)value;
14
15
  - (void)emitOnCustomerAdapterFetchSelectedPaymentOptionCallback;
15
16
  - (void)emitOnCustomerAdapterSetupIntentClientSecretForCustomerAttachCallback;
17
+ - (void)emitOnCustomerSessionProviderSetupIntentClientSecret;
18
+ - (void)emitOnCustomerSessionProviderCustomerSessionClientSecret;
16
19
  - (void)emitEmbeddedPaymentElementDidUpdateHeight:(NSDictionary *)value;
17
20
  - (void)emitEmbeddedPaymentElementWillPresent;
18
21
  - (void)emitEmbeddedPaymentElementDidUpdatePaymentOption:(NSDictionary *)value;