Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle null client_secret in result Intent #2989

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ internal class StripePaymentController internal constructor(
return
}

val clientSecret = getClientSecret(data)
if (clientSecret.isNullOrBlank()) {
callback.onError(IllegalArgumentException(CLIENT_SECRET_INTENT_ERROR))
return
}

val shouldCancelSource = result.shouldCancelSource
val sourceId = result.sourceId.orEmpty()
@StripeIntentResult.Outcome val flowOutcome = result.flowOutcome
Expand All @@ -274,7 +280,7 @@ internal class StripePaymentController internal constructor(
)

stripeRepository.retrieveIntent(
getClientSecret(data),
clientSecret,
requestOptions,
expandFields = EXPAND_PAYMENT_METHOD,
callback = createPaymentIntentCallback(
Expand Down Expand Up @@ -307,6 +313,12 @@ internal class StripePaymentController internal constructor(
return
}

val clientSecret = getClientSecret(data)
if (clientSecret.isNullOrBlank()) {
callback.onError(IllegalArgumentException(CLIENT_SECRET_INTENT_ERROR))
return
}

val shouldCancelSource = result.shouldCancelSource
val sourceId = result.sourceId.orEmpty()
@StripeIntentResult.Outcome val flowOutcome = result.flowOutcome
Expand All @@ -317,7 +329,7 @@ internal class StripePaymentController internal constructor(
)

stripeRepository.retrieveIntent(
getClientSecret(data),
clientSecret,
requestOptions,
expandFields = EXPAND_PAYMENT_METHOD,
callback = createSetupIntentCallback(
Expand Down Expand Up @@ -1231,13 +1243,15 @@ internal class StripePaymentController internal constructor(
}

@JvmSynthetic
internal fun getClientSecret(data: Intent): String {
return requireNotNull(PaymentController.Result.fromIntent(data)?.clientSecret)
internal fun getClientSecret(data: Intent): String? {
return PaymentController.Result.fromIntent(data)?.clientSecret
}

private val EXPAND_PAYMENT_METHOD = listOf("payment_method")
internal val CHALLENGE_DELAY = TimeUnit.SECONDS.toMillis(2L)

private const val REQUIRED_ERROR = "API request returned an invalid response."

private const val CLIENT_SECRET_INTENT_ERROR = "Invalid client_secret value in result Intent."
}
}