Skip to content

Commit 46f359a

Browse files
add safety to verifyMicrodeposits method
1 parent 3cd0430 commit 46f359a

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt

+9-5
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
5757

5858
private val mActivityEventListener = object : BaseActivityEventListener() {
5959
override fun onActivityResult(activity: Activity, requestCode: Int, resultCode: Int, data: Intent?) {
60-
if (::stripe.isInitialized) {
60+
if (stripe != null) {
6161
paymentSheetFragment?.activity?.activityResultRegistry?.dispatchResult(requestCode, resultCode, data)
6262
googlePayFragment?.activity?.activityResultRegistry?.dispatchResult(requestCode, resultCode, data)
6363
try {
@@ -540,8 +540,8 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
540540
@SuppressWarnings("unused")
541541
fun retrievePaymentIntent(clientSecret: String, promise: Promise) {
542542
CoroutineScope(Dispatchers.IO).launch {
543-
stripe?.let {
544-
val paymentIntent = it.retrievePaymentIntentSynchronous(clientSecret)
543+
stripe?.let { stripe ->
544+
val paymentIntent = stripe.retrievePaymentIntentSynchronous(clientSecret)
545545
paymentIntent?.let {
546546
promise.resolve(createResult("paymentIntent", mapFromPaymentIntentResult(it)))
547547
} ?: run {
@@ -557,8 +557,8 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
557557
@SuppressWarnings("unused")
558558
fun retrieveSetupIntent(clientSecret: String, promise: Promise) {
559559
CoroutineScope(Dispatchers.IO).launch {
560-
stripe?.let {
561-
val setupIntent = it.retrieveSetupIntentSynchronous(clientSecret)
560+
stripe?.let { stripe ->
561+
val setupIntent = stripe.retrieveSetupIntentSynchronous(clientSecret)
562562
setupIntent?.let {
563563
promise.resolve(createResult("setupIntent", mapFromSetupIntentResult(it)))
564564
} ?: run {
@@ -699,6 +699,10 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
699699
@ReactMethod
700700
@SuppressWarnings("unused")
701701
fun verifyMicrodeposits(isPaymentIntent: Boolean, clientSecret: String, params: ReadableMap, promise: Promise) {
702+
val stripe = stripe ?: run {
703+
promise.resolve(MISSING_INIT_ERROR)
704+
return
705+
}
702706
val amounts = params.getArray("amounts")
703707
val descriptorCode = params.getString("descriptorCode")
704708

ios/StripeSdk.swift

+9-4
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,11 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
927927
resolver resolve: @escaping RCTPromiseResolveBlock,
928928
rejecter reject: @escaping RCTPromiseRejectBlock
929929
) -> Void {
930+
guard let apiClient = apiClient else {
931+
resolve(StripeSdk.MISSING_INIT_ERROR)
932+
return
933+
}
934+
930935
let amounts = params["amounts"] as? NSArray
931936
let descriptorCode = params["descriptorCode"] as? String
932937

@@ -941,14 +946,14 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
941946
return
942947
}
943948
if (isPaymentIntent) {
944-
STPAPIClient.shared.verifyPaymentIntentWithMicrodeposits(
949+
apiClient.verifyPaymentIntentWithMicrodeposits(
945950
clientSecret: clientSecret as String,
946951
firstAmount: amounts[0] as! Int,
947952
secondAmount: amounts[1] as! Int,
948953
completion: onCompletePaymentVerification
949954
)
950955
} else {
951-
STPAPIClient.shared.verifySetupIntentWithMicrodeposits(
956+
apiClient.verifySetupIntentWithMicrodeposits(
952957
clientSecret: clientSecret as String,
953958
firstAmount: amounts[0] as! Int,
954959
secondAmount: amounts[1] as! Int,
@@ -957,13 +962,13 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
957962
}
958963
} else if let descriptorCode = descriptorCode {
959964
if (isPaymentIntent) {
960-
STPAPIClient.shared.verifyPaymentIntentWithMicrodeposits(
965+
apiClient.verifyPaymentIntentWithMicrodeposits(
961966
clientSecret: clientSecret as String,
962967
descriptorCode: descriptorCode,
963968
completion: onCompletePaymentVerification
964969
)
965970
} else {
966-
STPAPIClient.shared.verifySetupIntentWithMicrodeposits(
971+
apiClient.verifySetupIntentWithMicrodeposits(
967972
clientSecret: clientSecret as String,
968973
descriptorCode: descriptorCode,
969974
completion: onCompleteSetupVerification

0 commit comments

Comments
 (0)