@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.
Files changed (72) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +3 -3
  3. package/android/gradle.properties +1 -1
  4. package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +46 -10
  5. package/android/src/main/java/com/reactnativestripesdk/CardFieldViewManager.kt +5 -0
  6. package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +8 -0
  7. package/android/src/main/java/com/reactnativestripesdk/CardFormViewManager.kt +6 -1
  8. package/android/src/main/java/com/reactnativestripesdk/Errors.kt +14 -1
  9. package/android/src/main/java/com/reactnativestripesdk/GooglePayFragment.kt +68 -52
  10. package/android/src/main/java/com/reactnativestripesdk/Mappers.kt +5 -7
  11. package/android/src/main/java/com/reactnativestripesdk/PaymentLauncherFragment.kt +127 -37
  12. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +173 -0
  13. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetFragment.kt +60 -36
  14. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +67 -177
  15. package/ios/CardFieldManager.m +1 -0
  16. package/ios/CardFieldView.swift +6 -0
  17. package/ios/Mappers.swift +8 -9
  18. package/ios/PaymentSheetAppearance.swift +209 -0
  19. package/ios/StripeSdk.swift +141 -116
  20. package/lib/commonjs/components/AddToWalletButton.js +1 -1
  21. package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
  22. package/lib/commonjs/components/ApplePayButton.js +1 -1
  23. package/lib/commonjs/components/ApplePayButton.js.map +1 -1
  24. package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
  25. package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
  26. package/lib/commonjs/components/CardField.js +1 -1
  27. package/lib/commonjs/components/CardField.js.map +1 -1
  28. package/lib/commonjs/components/CardForm.js +1 -1
  29. package/lib/commonjs/components/CardForm.js.map +1 -1
  30. package/lib/commonjs/components/GooglePayButton.js +1 -1
  31. package/lib/commonjs/components/GooglePayButton.js.map +1 -1
  32. package/lib/commonjs/components/StripeContainer.js +1 -1
  33. package/lib/commonjs/components/StripeContainer.js.map +1 -1
  34. package/lib/commonjs/functions.js.map +1 -1
  35. package/lib/commonjs/types/components/CardFieldInput.js.map +1 -1
  36. package/lib/commonjs/types/index.js.map +1 -1
  37. package/lib/module/components/AddToWalletButton.js +1 -1
  38. package/lib/module/components/AddToWalletButton.js.map +1 -1
  39. package/lib/module/components/ApplePayButton.js +1 -1
  40. package/lib/module/components/ApplePayButton.js.map +1 -1
  41. package/lib/module/components/AuBECSDebitForm.js +1 -1
  42. package/lib/module/components/AuBECSDebitForm.js.map +1 -1
  43. package/lib/module/components/CardField.js +1 -1
  44. package/lib/module/components/CardField.js.map +1 -1
  45. package/lib/module/components/CardForm.js +1 -1
  46. package/lib/module/components/CardForm.js.map +1 -1
  47. package/lib/module/components/GooglePayButton.js +1 -1
  48. package/lib/module/components/GooglePayButton.js.map +1 -1
  49. package/lib/module/components/StripeContainer.js +1 -1
  50. package/lib/module/components/StripeContainer.js.map +1 -1
  51. package/lib/module/functions.js.map +1 -1
  52. package/lib/module/types/components/CardFieldInput.js.map +1 -1
  53. package/lib/module/types/index.js.map +1 -1
  54. package/lib/typescript/example/src/screens/PaymentSheetAppearance.d.ts +3 -0
  55. package/lib/typescript/src/components/CardField.d.ts +3 -0
  56. package/lib/typescript/src/components/CardForm.d.ts +2 -0
  57. package/lib/typescript/src/types/PaymentSheet.d.ts +154 -1
  58. package/lib/typescript/src/types/Token.d.ts +9 -1
  59. package/lib/typescript/src/types/components/CardFieldInput.d.ts +1 -0
  60. package/lib/typescript/src/types/components/CardFormView.d.ts +6 -0
  61. package/lib/typescript/src/types/index.d.ts +1 -4
  62. package/package.json +1 -1
  63. package/src/components/CardField.tsx +5 -0
  64. package/src/components/CardForm.tsx +6 -0
  65. package/src/functions.ts +1 -1
  66. package/src/types/PaymentSheet.ts +159 -2
  67. package/src/types/Token.ts +13 -1
  68. package/src/types/components/CardFieldInput.ts +1 -0
  69. package/src/types/components/CardFormView.ts +7 -0
  70. package/src/types/index.ts +1 -5
  71. package/stripe-react-native.podspec +1 -1
  72. package/android/src/main/java/com/reactnativestripesdk/Constants.kt +0 -10
@@ -1,63 +1,50 @@
1
1
  package com.reactnativestripesdk
2
2
 
3
3
  import android.app.Activity
4
- import android.content.BroadcastReceiver
5
- import android.content.Context
6
4
  import android.content.Intent
7
- import android.content.IntentFilter
8
5
  import android.os.Parcelable
9
6
  import android.util.Log
10
7
  import androidx.appcompat.app.AppCompatActivity
11
- import androidx.localbroadcastmanager.content.LocalBroadcastManager
12
8
  import com.facebook.react.bridge.*
13
9
  import com.facebook.react.module.annotations.ReactModule
14
10
  import com.stripe.android.*
15
11
  import com.stripe.android.core.AppInfo
16
12
  import com.stripe.android.core.ApiVersion
17
- import com.stripe.android.googlepaylauncher.GooglePayLauncher
18
- import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncher
19
13
  import com.stripe.android.model.*
20
14
  import com.stripe.android.payments.bankaccount.CollectBankAccountConfiguration
21
- import com.stripe.android.paymentsheet.PaymentSheetResult
22
15
  import com.stripe.android.view.AddPaymentMethodActivityStarter
23
16
  import kotlinx.coroutines.CoroutineScope
24
17
  import kotlinx.coroutines.Dispatchers
25
18
  import kotlinx.coroutines.launch
26
19
 
27
20
  @ReactModule(name = StripeSdkModule.NAME)
28
- class StripeSdkModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
29
- var cardFieldView: CardFieldView? = null
30
- var cardFormView: CardFormView? = null
31
-
21
+ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
32
22
  override fun getName(): String {
33
23
  return "StripeSdk"
34
24
  }
35
- private lateinit var stripe: Stripe
36
25
 
37
- private lateinit var paymentLauncherFragment: PaymentLauncherFragment
26
+ var cardFieldView: CardFieldView? = null
27
+ var cardFormView: CardFormView? = null
38
28
 
29
+ private lateinit var stripe: Stripe
39
30
  private lateinit var publishableKey: String
40
31
  private var stripeAccountId: String? = null
32
+ private var urlScheme: String? = null
33
+
41
34
  private var paymentSheetFragment: PaymentSheetFragment? = null
35
+ private var googlePayFragment: GooglePayFragment? = null
36
+ private var paymentLauncherFragment: PaymentLauncherFragment? = null
42
37
 
43
- private var urlScheme: String? = null
44
38
  private var confirmPromise: Promise? = null
45
- private var confirmPaymentSheetPaymentPromise: Promise? = null
46
- private var presentPaymentSheetPromise: Promise? = null
47
- private var initPaymentSheetPromise: Promise? = null
48
39
  private var confirmPaymentClientSecret: String? = null
49
40
 
50
- private var googlePayFragment: GooglePayFragment? = null
51
- private var initGooglePayPromise: Promise? = null
52
- private var presentGooglePayPromise: Promise? = null
53
-
54
41
  private val mActivityEventListener = object : BaseActivityEventListener() {
55
42
  override fun onActivityResult(activity: Activity, requestCode: Int, resultCode: Int, data: Intent?) {
56
43
  if (::stripe.isInitialized) {
57
44
  // BEGIN - Necessary on older versions of React Native (~0.64 and below)
58
45
  paymentSheetFragment?.activity?.activityResultRegistry?.dispatchResult(requestCode, resultCode, data)
59
46
  googlePayFragment?.activity?.activityResultRegistry?.dispatchResult(requestCode, resultCode, data)
60
- paymentLauncherFragment.activity?.activityResultRegistry?.dispatchResult(requestCode, resultCode, data)
47
+ paymentLauncherFragment?.activity?.activityResultRegistry?.dispatchResult(requestCode, resultCode, data)
61
48
  // END
62
49
  try {
63
50
  val result = AddPaymentMethodActivityStarter.Result.fromIntent(data)
@@ -91,108 +78,6 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
91
78
  )
92
79
  }
93
80
 
94
- private val googlePayReceiver: BroadcastReceiver = object : BroadcastReceiver() {
95
- override fun onReceive(context: Context?, intent: Intent) {
96
- if (intent.action == ON_INIT_GOOGLE_PAY) {
97
- val isReady = intent.extras?.getBoolean("isReady") ?: false
98
- if (isReady) {
99
- initGooglePayPromise?.resolve(WritableNativeMap())
100
- } else {
101
- initGooglePayPromise?.resolve(
102
- createError(
103
- GooglePayErrorType.Failed.toString(),
104
- "Google Pay is not available on this device. You can use isGooglePaySupported to preemptively check for Google Pay support."
105
- )
106
- )
107
- }
108
- }
109
- if (intent.action == ON_GOOGLE_PAYMENT_METHOD_RESULT) {
110
- intent.extras?.getString("error")?.let {
111
- presentGooglePayPromise?.resolve(createError(GooglePayErrorType.Failed.toString(), it))
112
- return
113
- }
114
- when (val result = intent.extras?.getParcelable<GooglePayPaymentMethodLauncher.Result>("paymentResult")) {
115
- is GooglePayPaymentMethodLauncher.Result.Completed -> {
116
- presentGooglePayPromise?.resolve(createResult("paymentMethod", mapFromPaymentMethod(result.paymentMethod)))
117
- }
118
- GooglePayPaymentMethodLauncher.Result.Canceled -> {
119
- presentGooglePayPromise?.resolve(createError(GooglePayErrorType.Canceled.toString(), "Google Pay has been canceled"))
120
- }
121
- is GooglePayPaymentMethodLauncher.Result.Failed -> {
122
- presentGooglePayPromise?.resolve(createError(GooglePayErrorType.Failed.toString(), result.error))
123
- }
124
- }
125
- }
126
- if (intent.action == ON_GOOGLE_PAY_RESULT) {
127
- intent.extras?.getString("error")?.let {
128
- presentGooglePayPromise?.resolve(createError(GooglePayErrorType.Failed.toString(), it))
129
- return
130
- }
131
- when (val result = intent.extras?.getParcelable<GooglePayLauncher.Result>("paymentResult")) {
132
- GooglePayLauncher.Result.Completed -> {
133
- presentGooglePayPromise?.resolve(WritableNativeMap())
134
- }
135
- GooglePayLauncher.Result.Canceled -> {
136
- presentGooglePayPromise?.resolve(createError(GooglePayErrorType.Canceled.toString(), "Google Pay has been canceled"))
137
- }
138
- is GooglePayLauncher.Result.Failed -> {
139
- presentGooglePayPromise?.resolve(createError(GooglePayErrorType.Failed.toString(), result.error))
140
- }
141
- }
142
- }
143
- }
144
- }
145
-
146
- private val mPaymentSheetReceiver: BroadcastReceiver = object : BroadcastReceiver() {
147
- override fun onReceive(context: Context?, intent: Intent) {
148
- if (intent.action == ON_PAYMENT_RESULT_ACTION) {
149
- when (val result = intent.extras?.getParcelable<PaymentSheetResult>("paymentResult")) {
150
- is PaymentSheetResult.Canceled -> {
151
- val message = "The payment has been canceled"
152
- confirmPaymentSheetPaymentPromise?.resolve(createError(PaymentSheetErrorType.Canceled.toString(), message))
153
- presentPaymentSheetPromise?.resolve(createError(PaymentSheetErrorType.Canceled.toString(), message))
154
- }
155
- is PaymentSheetResult.Failed -> {
156
- confirmPaymentSheetPaymentPromise?.resolve(createError(PaymentSheetErrorType.Failed.toString(), result.error))
157
- presentPaymentSheetPromise?.resolve(createError(PaymentSheetErrorType.Failed.toString(), result.error))
158
- }
159
- is PaymentSheetResult.Completed -> {
160
- confirmPaymentSheetPaymentPromise?.resolve(WritableNativeMap())
161
- presentPaymentSheetPromise?.resolve(WritableNativeMap())
162
- }
163
- }
164
- } else if (intent.action == ON_PAYMENT_OPTION_ACTION) {
165
- val label = intent.extras?.getString("label")
166
- val image = intent.extras?.getString("image")
167
-
168
- if (label != null && image != null) {
169
- val option: WritableMap = WritableNativeMap()
170
- option.putString("label", label)
171
- option.putString("image", image)
172
- presentPaymentSheetPromise?.resolve(createResult("paymentOption", option))
173
- } else {
174
- presentPaymentSheetPromise?.resolve(WritableNativeMap())
175
- }
176
- presentPaymentSheetPromise = null
177
- }
178
- else if (intent.action == ON_INIT_PAYMENT_SHEET) {
179
- initPaymentSheetPromise?.resolve(WritableNativeMap())
180
- } else if (intent.action == ON_CONFIGURE_FLOW_CONTROLLER) {
181
- val label = intent.extras?.getString("label")
182
- val image = intent.extras?.getString("image")
183
-
184
- if (label != null && image != null) {
185
- val option: WritableMap = WritableNativeMap()
186
- option.putString("label", label)
187
- option.putString("image", image)
188
- initPaymentSheetPromise?.resolve(createResult("paymentOption", option))
189
- } else {
190
- initPaymentSheetPromise?.resolve(WritableNativeMap())
191
- }
192
- }
193
- }
194
- }
195
-
196
81
  override fun getConstants(): MutableMap<String, Any> =
197
82
  hashMapOf(
198
83
  "API_VERSIONS" to hashMapOf(
@@ -225,37 +110,13 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
225
110
  stripe = Stripe(reactApplicationContext, publishableKey, stripeAccountId)
226
111
 
227
112
  PaymentConfiguration.init(reactApplicationContext, publishableKey, stripeAccountId)
228
-
229
- paymentLauncherFragment = PaymentLauncherFragment(stripe, publishableKey, stripeAccountId)
230
- getCurrentActivityOrResolveWithError(promise)?.let {
231
- try {
232
- it.supportFragmentManager.beginTransaction()
233
- .add(paymentLauncherFragment, "payment_launcher_fragment")
234
- .commit()
235
- } catch (error: IllegalStateException) {
236
- promise.resolve(createError(ErrorType.Failed.toString(), error.message))
237
- }
238
-
239
- val localBroadcastManager = LocalBroadcastManager.getInstance(reactApplicationContext)
240
- localBroadcastManager.registerReceiver(mPaymentSheetReceiver, IntentFilter(ON_PAYMENT_RESULT_ACTION))
241
- localBroadcastManager.registerReceiver(mPaymentSheetReceiver, IntentFilter(ON_PAYMENT_OPTION_ACTION))
242
- localBroadcastManager.registerReceiver(mPaymentSheetReceiver, IntentFilter(ON_CONFIGURE_FLOW_CONTROLLER))
243
- localBroadcastManager.registerReceiver(mPaymentSheetReceiver, IntentFilter(ON_INIT_PAYMENT_SHEET))
244
-
245
- localBroadcastManager.registerReceiver(googlePayReceiver, IntentFilter(ON_INIT_GOOGLE_PAY))
246
- localBroadcastManager.registerReceiver(googlePayReceiver, IntentFilter(ON_GOOGLE_PAY_RESULT))
247
- localBroadcastManager.registerReceiver(googlePayReceiver, IntentFilter(ON_GOOGLE_PAYMENT_METHOD_RESULT))
248
-
249
- promise.resolve(null)
250
- }
113
+ promise.resolve(null)
251
114
  }
252
115
 
253
116
  @ReactMethod
254
117
  fun initPaymentSheet(params: ReadableMap, promise: Promise) {
255
118
  getCurrentActivityOrResolveWithError(promise)?.let { activity ->
256
- this.initPaymentSheetPromise = promise
257
-
258
- paymentSheetFragment = PaymentSheetFragment().also {
119
+ paymentSheetFragment = PaymentSheetFragment(reactApplicationContext, promise).also {
259
120
  val bundle = toBundleObject(params)
260
121
  it.arguments = bundle
261
122
  }
@@ -271,14 +132,12 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
271
132
 
272
133
  @ReactMethod
273
134
  fun presentPaymentSheet(promise: Promise) {
274
- this.presentPaymentSheetPromise = promise
275
- paymentSheetFragment?.present()
135
+ paymentSheetFragment?.present(promise)
276
136
  }
277
137
 
278
138
  @ReactMethod
279
139
  fun confirmPaymentSheetPayment(promise: Promise) {
280
- this.confirmPaymentSheetPaymentPromise = promise
281
- paymentSheetFragment?.confirmPayment()
140
+ paymentSheetFragment?.confirmPayment(promise)
282
141
  }
283
142
 
284
143
  private fun payWithFpx() {
@@ -295,13 +154,17 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
295
154
  when (result) {
296
155
  is AddPaymentMethodActivityStarter.Result.Success -> {
297
156
  if (confirmPaymentClientSecret != null && confirmPromise != null) {
298
- paymentLauncherFragment.confirm(
157
+ paymentLauncherFragment = PaymentLauncherFragment.forPayment(
158
+ context = reactApplicationContext,
159
+ stripe,
160
+ publishableKey,
161
+ stripeAccountId,
162
+ confirmPromise!!,
163
+ confirmPaymentClientSecret!!,
299
164
  ConfirmPaymentIntentParams.createWithPaymentMethodId(
300
165
  result.paymentMethod.id!!,
301
166
  confirmPaymentClientSecret!!
302
- ),
303
- confirmPaymentClientSecret!!,
304
- confirmPromise!!
167
+ )
305
168
  )
306
169
  } else {
307
170
  Log.e("StripeReactNative", "FPX payment failed. Promise and/or client secret is not set.")
@@ -359,12 +222,30 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
359
222
  "Card" -> {
360
223
  createTokenFromCard(params, promise)
361
224
  }
225
+ "Pii" -> {
226
+ createTokenFromPii(params, promise)
227
+ }
362
228
  else -> {
363
229
  promise.resolve(createError(CreateTokenErrorType.Failed.toString(), "$type type is not supported yet"))
364
230
  }
365
231
  }
366
232
  }
367
233
 
234
+ private fun createTokenFromPii(params: ReadableMap, promise: Promise) {
235
+ getValOr(params, "personalId", null)?.let {
236
+ CoroutineScope(Dispatchers.IO).launch {
237
+ runCatching {
238
+ val token = stripe.createPiiToken(it, null, stripeAccountId)
239
+ promise.resolve(createResult("token", mapFromToken(token)))
240
+ }.onFailure {
241
+ promise.resolve(createError(CreateTokenErrorType.Failed.toString(), it.message))
242
+ }
243
+ }
244
+ } ?: run {
245
+ promise.resolve(createError(CreateTokenErrorType.Failed.toString(), "personalId parameter is required"))
246
+ }
247
+ }
248
+
368
249
  private fun createTokenFromBankAccount(params: ReadableMap, promise: Promise) {
369
250
  val accountHolderName = getValOr(params, "accountHolderName", null)
370
251
  val accountHolderType = getValOr(params, "accountHolderType", null)
@@ -445,9 +326,13 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
445
326
 
446
327
  @ReactMethod
447
328
  fun handleNextAction(paymentIntentClientSecret: String, promise: Promise) {
448
- paymentLauncherFragment.handleNextActionForPaymentIntent(
449
- paymentIntentClientSecret,
450
- promise
329
+ paymentLauncherFragment = PaymentLauncherFragment.forNextAction(
330
+ context = reactApplicationContext,
331
+ stripe,
332
+ publishableKey,
333
+ stripeAccountId,
334
+ promise,
335
+ paymentIntentClientSecret
451
336
  )
452
337
  }
453
338
 
@@ -505,10 +390,14 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
505
390
  confirmParams.returnUrl = mapToReturnURL(urlScheme)
506
391
  }
507
392
  confirmParams.shipping = mapToShippingDetails(getMapOrNull(paymentMethodData, "shippingDetails"))
508
- paymentLauncherFragment.confirm(
509
- confirmParams,
393
+ paymentLauncherFragment = PaymentLauncherFragment.forPayment(
394
+ context = reactApplicationContext,
395
+ stripe,
396
+ publishableKey,
397
+ stripeAccountId,
398
+ promise,
510
399
  paymentIntentClientSecret,
511
- promise
400
+ confirmParams
512
401
  )
513
402
  } catch (error: PaymentMethodCreateParamsException) {
514
403
  promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), error))
@@ -553,10 +442,14 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
553
442
  urlScheme?.let {
554
443
  confirmParams.returnUrl = mapToReturnURL(urlScheme)
555
444
  }
556
- paymentLauncherFragment.confirm(
557
- confirmParams,
445
+ paymentLauncherFragment = PaymentLauncherFragment.forSetup(
446
+ context = reactApplicationContext,
447
+ stripe,
448
+ publishableKey,
449
+ stripeAccountId,
450
+ promise,
558
451
  setupIntentClientSecret,
559
- promise
452
+ confirmParams
560
453
  )
561
454
  } catch (error: PaymentMethodCreateParamsException) {
562
455
  promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), error))
@@ -566,7 +459,7 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
566
459
  @ReactMethod
567
460
  fun isGooglePaySupported(params: ReadableMap?, promise: Promise) {
568
461
  val fragment = GooglePayPaymentMethodLauncherFragment(
569
- reactContext,
462
+ reactApplicationContext,
570
463
  getBooleanOrFalse(params, "testEnv"),
571
464
  getBooleanOrFalse(params, "existingPaymentMethodRequired"),
572
465
  promise
@@ -585,14 +478,12 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
585
478
 
586
479
  @ReactMethod
587
480
  fun initGooglePay(params: ReadableMap, promise: Promise) {
588
- googlePayFragment = GooglePayFragment().also {
481
+ googlePayFragment = GooglePayFragment(promise).also {
589
482
  val bundle = toBundleObject(params)
590
483
  it.arguments = bundle
591
484
  }
592
485
 
593
486
  getCurrentActivityOrResolveWithError(promise)?.let {
594
- initGooglePayPromise = promise
595
-
596
487
  try {
597
488
  it.supportFragmentManager.beginTransaction()
598
489
  .add(googlePayFragment!!, "google_pay_launch_fragment")
@@ -609,15 +500,15 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
609
500
  promise.resolve(createError(GooglePayErrorType.Failed.toString(), "you must provide clientSecret"))
610
501
  return
611
502
  }
612
- presentGooglePayPromise = promise
503
+
613
504
  if (getBooleanOrFalse(params, "forSetupIntent")) {
614
505
  val currencyCode = getValOr(params, "currencyCode") ?: run {
615
506
  promise.resolve(createError(GooglePayErrorType.Failed.toString(), "you must provide currencyCode"))
616
507
  return
617
508
  }
618
- googlePayFragment?.presentForSetupIntent(clientSecret, currencyCode)
509
+ googlePayFragment?.presentForSetupIntent(clientSecret, currencyCode, promise)
619
510
  } else {
620
- googlePayFragment?.presentForPaymentIntent(clientSecret)
511
+ googlePayFragment?.presentForPaymentIntent(clientSecret, promise)
621
512
  }
622
513
  }
623
514
 
@@ -631,8 +522,7 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
631
522
  promise.resolve(createError(GooglePayErrorType.Failed.toString(), "you must provide amount"))
632
523
  return
633
524
  }
634
- presentGooglePayPromise = promise
635
- googlePayFragment?.createPaymentMethod(currencyCode, amount)
525
+ googlePayFragment?.createPaymentMethod(currencyCode, amount, promise)
636
526
  }
637
527
 
638
528
  @ReactMethod
@@ -669,7 +559,7 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
669
559
  )
670
560
 
671
561
  val fragment = CollectBankAccountLauncherFragment(
672
- reactContext,
562
+ reactApplicationContext,
673
563
  publishableKey,
674
564
  clientSecret,
675
565
  isPaymentIntent,
@@ -4,6 +4,7 @@
4
4
 
5
5
  @interface RCT_EXTERN_MODULE(CardFieldManager, RCTViewManager)
6
6
  RCT_EXPORT_VIEW_PROPERTY(postalCodeEnabled, BOOL)
7
+ RCT_EXPORT_VIEW_PROPERTY(countryCode, NSString)
7
8
  RCT_EXPORT_VIEW_PROPERTY(onCardChange, RCTDirectEventBlock)
8
9
  RCT_EXPORT_VIEW_PROPERTY(onFocusChange, RCTDirectEventBlock)
9
10
  RCT_EXPORT_VIEW_PROPERTY(cardStyle, NSDictionary)
@@ -18,6 +18,12 @@ class CardFieldView: UIView, STPPaymentCardTextFieldDelegate {
18
18
  }
19
19
  }
20
20
 
21
+ @objc var countryCode: String? {
22
+ didSet {
23
+ cardField.countryCode = countryCode
24
+ }
25
+ }
26
+
21
27
  @objc var placeholders: NSDictionary = NSDictionary() {
22
28
  didSet {
23
29
  if let numberPlaceholder = placeholders["number"] as? String {
package/ios/Mappers.swift CHANGED
@@ -157,7 +157,6 @@ class Mappers {
157
157
  "card": mapFromCard(token.card) ?? NSNull(),
158
158
  "livemode": token.livemode,
159
159
  "type": mapFromTokenType(token.type) ?? NSNull(),
160
-
161
160
  ]
162
161
 
163
162
  return tokenMap
@@ -498,7 +497,7 @@ class Mappers {
498
497
  billing.name = RCTConvert.nsString(billingDetails["name"])
499
498
 
500
499
  let address = STPPaymentMethodAddress()
501
-
500
+
502
501
  if let addressMap = billingDetails["address"] as? NSDictionary {
503
502
  address.city = RCTConvert.nsString(addressMap["city"])
504
503
  address.postalCode = RCTConvert.nsString(addressMap["postalCode"])
@@ -507,7 +506,7 @@ class Mappers {
507
506
  address.line2 = RCTConvert.nsString(addressMap["line2"])
508
507
  address.state = RCTConvert.nsString(addressMap["state"])
509
508
  }
510
-
509
+
511
510
  billing.address = address
512
511
 
513
512
  return billing
@@ -517,7 +516,7 @@ class Mappers {
517
516
  guard let shippingDetails = shippingDetails else {
518
517
  return nil
519
518
  }
520
-
519
+
521
520
  let shippingAddress = STPPaymentIntentShippingDetailsAddressParams(line1: "")
522
521
 
523
522
  if let addressMap = shippingDetails["address"] as? NSDictionary {
@@ -528,7 +527,7 @@ class Mappers {
528
527
  shippingAddress.line2 = addressMap["line2"] as? String
529
528
  shippingAddress.state = addressMap["state"] as? String
530
529
  }
531
-
530
+
532
531
  let shipping = STPPaymentIntentShippingDetailsParams(address: shippingAddress, name: shippingDetails["name"] as? String ?? "")
533
532
 
534
533
  return shipping
@@ -568,7 +567,7 @@ class Mappers {
568
567
  }
569
568
  return nil
570
569
  }
571
-
570
+
572
571
  class func mapToCardBrand(_ brand: String?) -> STPCardBrand {
573
572
  if let brand = brand {
574
573
  switch brand {
@@ -722,7 +721,7 @@ class Mappers {
722
721
  if let lastSetupError = setupIntent.lastSetupError {
723
722
  let setupError: NSMutableDictionary = [
724
723
  "code": lastSetupError.code ?? NSNull(),
725
- "message": lastSetupError.description,
724
+ "message": lastSetupError.message ?? NSNull(),
726
725
  "type": mapFromSetupIntentLastPaymentErrorType(lastSetupError.type) ?? NSNull(),
727
726
  "declineCode": lastSetupError.declineCode ?? NSNull(),
728
727
  "paymentMethod": mapFromPaymentMethod(lastSetupError.paymentMethod) ?? NSNull()
@@ -962,7 +961,7 @@ class Mappers {
962
961
  }
963
962
  return "Unknown"
964
963
  }
965
-
964
+
966
965
  class func mapToUSBankAccountHolderType(type: String?) -> STPPaymentMethodUSBankAccountHolderType {
967
966
  switch type {
968
967
  case "Company": return STPPaymentMethodUSBankAccountHolderType.company
@@ -981,7 +980,7 @@ class Mappers {
981
980
  }
982
981
  return "Unknown"
983
982
  }
984
-
983
+
985
984
  class func mapToUSBankAccountType(type: String?) -> STPPaymentMethodUSBankAccountType {
986
985
  switch type {
987
986
  case "Savings": return STPPaymentMethodUSBankAccountType.savings