Skip to content

Commit 01bcc3a

Browse files
add safety to verifyMicrodeposits method
1 parent 0e1ac56 commit 01bcc3a

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(private val reactContext: ReactApplicationContext) : React
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 {
@@ -530,8 +530,8 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
530530
@ReactMethod
531531
fun retrievePaymentIntent(clientSecret: String, promise: Promise) {
532532
CoroutineScope(Dispatchers.IO).launch {
533-
stripe?.let {
534-
val paymentIntent = it.retrievePaymentIntentSynchronous(clientSecret)
533+
stripe?.let { stripe ->
534+
val paymentIntent = stripe.retrievePaymentIntentSynchronous(clientSecret)
535535
paymentIntent?.let {
536536
promise.resolve(createResult("paymentIntent", mapFromPaymentIntentResult(it)))
537537
} ?: run {
@@ -546,8 +546,8 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
546546
@ReactMethod
547547
fun retrieveSetupIntent(clientSecret: String, promise: Promise) {
548548
CoroutineScope(Dispatchers.IO).launch {
549-
stripe?.let {
550-
val setupIntent = it.retrieveSetupIntentSynchronous(clientSecret)
549+
stripe?.let { stripe ->
550+
val setupIntent = stripe.retrieveSetupIntentSynchronous(clientSecret)
551551
setupIntent?.let {
552552
promise.resolve(createResult("setupIntent", mapFromSetupIntentResult(it)))
553553
} ?: run {
@@ -686,6 +686,10 @@ class StripeSdkModule(private val reactContext: ReactApplicationContext) : React
686686

687687
@ReactMethod
688688
fun verifyMicrodeposits(isPaymentIntent: Boolean, clientSecret: String, params: ReadableMap, promise: Promise) {
689+
val stripe = stripe ?: run {
690+
promise.resolve(MISSING_INIT_ERROR)
691+
return
692+
}
689693
val amounts = params.getArray("amounts")
690694
val descriptorCode = params.getString("descriptorCode")
691695

ios/StripeSdk.swift

+9-4
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,11 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
936936
resolver resolve: @escaping RCTPromiseResolveBlock,
937937
rejecter reject: @escaping RCTPromiseRejectBlock
938938
) -> Void {
939+
guard let apiClient = apiClient else {
940+
resolve(StripeSdk.MISSING_INIT_ERROR)
941+
return
942+
}
943+
939944
let amounts = params["amounts"] as? NSArray
940945
let descriptorCode = params["descriptorCode"] as? String
941946

@@ -950,14 +955,14 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
950955
return
951956
}
952957
if (isPaymentIntent) {
953-
STPAPIClient.shared.verifyPaymentIntentWithMicrodeposits(
958+
apiClient.verifyPaymentIntentWithMicrodeposits(
954959
clientSecret: clientSecret as String,
955960
firstAmount: amounts[0] as! Int,
956961
secondAmount: amounts[1] as! Int,
957962
completion: onCompletePaymentVerification
958963
)
959964
} else {
960-
STPAPIClient.shared.verifySetupIntentWithMicrodeposits(
965+
apiClient.verifySetupIntentWithMicrodeposits(
961966
clientSecret: clientSecret as String,
962967
firstAmount: amounts[0] as! Int,
963968
secondAmount: amounts[1] as! Int,
@@ -966,13 +971,13 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
966971
}
967972
} else if let descriptorCode = descriptorCode {
968973
if (isPaymentIntent) {
969-
STPAPIClient.shared.verifyPaymentIntentWithMicrodeposits(
974+
apiClient.verifyPaymentIntentWithMicrodeposits(
970975
clientSecret: clientSecret as String,
971976
descriptorCode: descriptorCode,
972977
completion: onCompletePaymentVerification
973978
)
974979
} else {
975-
STPAPIClient.shared.verifySetupIntentWithMicrodeposits(
980+
apiClient.verifySetupIntentWithMicrodeposits(
976981
clientSecret: clientSecret as String,
977982
descriptorCode: descriptorCode,
978983
completion: onCompleteSetupVerification

0 commit comments

Comments
 (0)