Skip to content

Commit

Permalink
add safety to verifyMicrodeposits method
Browse files Browse the repository at this point in the history
  • Loading branch information
charliecruzan-stripe committed Apr 18, 2022
1 parent 3cd0430 commit 46f359a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ

private val mActivityEventListener = object : BaseActivityEventListener() {
override fun onActivityResult(activity: Activity, requestCode: Int, resultCode: Int, data: Intent?) {
if (::stripe.isInitialized) {
if (stripe != null) {
paymentSheetFragment?.activity?.activityResultRegistry?.dispatchResult(requestCode, resultCode, data)
googlePayFragment?.activity?.activityResultRegistry?.dispatchResult(requestCode, resultCode, data)
try {
Expand Down Expand Up @@ -540,8 +540,8 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
@SuppressWarnings("unused")
fun retrievePaymentIntent(clientSecret: String, promise: Promise) {
CoroutineScope(Dispatchers.IO).launch {
stripe?.let {
val paymentIntent = it.retrievePaymentIntentSynchronous(clientSecret)
stripe?.let { stripe ->
val paymentIntent = stripe.retrievePaymentIntentSynchronous(clientSecret)
paymentIntent?.let {
promise.resolve(createResult("paymentIntent", mapFromPaymentIntentResult(it)))
} ?: run {
Expand All @@ -557,8 +557,8 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
@SuppressWarnings("unused")
fun retrieveSetupIntent(clientSecret: String, promise: Promise) {
CoroutineScope(Dispatchers.IO).launch {
stripe?.let {
val setupIntent = it.retrieveSetupIntentSynchronous(clientSecret)
stripe?.let { stripe ->
val setupIntent = stripe.retrieveSetupIntentSynchronous(clientSecret)
setupIntent?.let {
promise.resolve(createResult("setupIntent", mapFromSetupIntentResult(it)))
} ?: run {
Expand Down Expand Up @@ -699,6 +699,10 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
@ReactMethod
@SuppressWarnings("unused")
fun verifyMicrodeposits(isPaymentIntent: Boolean, clientSecret: String, params: ReadableMap, promise: Promise) {
val stripe = stripe ?: run {
promise.resolve(MISSING_INIT_ERROR)
return
}
val amounts = params.getArray("amounts")
val descriptorCode = params.getString("descriptorCode")

Expand Down
13 changes: 9 additions & 4 deletions ios/StripeSdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,11 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock
) -> Void {
guard let apiClient = apiClient else {
resolve(StripeSdk.MISSING_INIT_ERROR)
return
}

let amounts = params["amounts"] as? NSArray
let descriptorCode = params["descriptorCode"] as? String

Expand All @@ -941,14 +946,14 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
return
}
if (isPaymentIntent) {
STPAPIClient.shared.verifyPaymentIntentWithMicrodeposits(
apiClient.verifyPaymentIntentWithMicrodeposits(
clientSecret: clientSecret as String,
firstAmount: amounts[0] as! Int,
secondAmount: amounts[1] as! Int,
completion: onCompletePaymentVerification
)
} else {
STPAPIClient.shared.verifySetupIntentWithMicrodeposits(
apiClient.verifySetupIntentWithMicrodeposits(
clientSecret: clientSecret as String,
firstAmount: amounts[0] as! Int,
secondAmount: amounts[1] as! Int,
Expand All @@ -957,13 +962,13 @@ class StripeSdk: RCTEventEmitter, STPApplePayContextDelegate, STPBankSelectionVi
}
} else if let descriptorCode = descriptorCode {
if (isPaymentIntent) {
STPAPIClient.shared.verifyPaymentIntentWithMicrodeposits(
apiClient.verifyPaymentIntentWithMicrodeposits(
clientSecret: clientSecret as String,
descriptorCode: descriptorCode,
completion: onCompletePaymentVerification
)
} else {
STPAPIClient.shared.verifySetupIntentWithMicrodeposits(
apiClient.verifySetupIntentWithMicrodeposits(
clientSecret: clientSecret as String,
descriptorCode: descriptorCode,
completion: onCompleteSetupVerification
Expand Down

0 comments on commit 46f359a

Please sign in to comment.