Add handling for payment_intent with missing status.
This commit is contained in:
parent
0c615e2fc2
commit
be12a17ff7
2 changed files with 10 additions and 4 deletions
|
@ -174,14 +174,20 @@ class StripeRepository(activity: Activity) : StripeApi.PaymentIntentFetcher, Str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to get the status and payment id from the intent.
|
/**
|
||||||
|
* Note: There seem to be times when PaymentIntent does not return a status. In these cases, we assume
|
||||||
|
* that we are successful and proceed as normal. If the payment didn't actually succeed, then we
|
||||||
|
* expect an error later in the chain to inform us of this.
|
||||||
|
*/
|
||||||
fun getStatusAndPaymentMethodId(stripeIntentAccessor: StripeIntentAccessor): Single<StatusAndPaymentMethodId> {
|
fun getStatusAndPaymentMethodId(stripeIntentAccessor: StripeIntentAccessor): Single<StatusAndPaymentMethodId> {
|
||||||
return Single.fromCallable {
|
return Single.fromCallable {
|
||||||
when (stripeIntentAccessor.objectType) {
|
when (stripeIntentAccessor.objectType) {
|
||||||
StripeIntentAccessor.ObjectType.NONE -> StatusAndPaymentMethodId(StripeIntentStatus.SUCCEEDED, null)
|
StripeIntentAccessor.ObjectType.NONE -> StatusAndPaymentMethodId(StripeIntentStatus.SUCCEEDED, null)
|
||||||
StripeIntentAccessor.ObjectType.PAYMENT_INTENT -> stripeApi.getPaymentIntent(stripeIntentAccessor).let {
|
StripeIntentAccessor.ObjectType.PAYMENT_INTENT -> stripeApi.getPaymentIntent(stripeIntentAccessor).let {
|
||||||
StatusAndPaymentMethodId(it.status, it.paymentMethod)
|
if (it.status == null) {
|
||||||
|
Log.d(TAG, "Returned payment intent had a null status.", true)
|
||||||
|
}
|
||||||
|
StatusAndPaymentMethodId(it.status ?: StripeIntentStatus.SUCCEEDED, it.paymentMethod)
|
||||||
}
|
}
|
||||||
StripeIntentAccessor.ObjectType.SETUP_INTENT -> stripeApi.getSetupIntent(stripeIntentAccessor).let {
|
StripeIntentAccessor.ObjectType.SETUP_INTENT -> stripeApi.getSetupIntent(stripeIntentAccessor).let {
|
||||||
StatusAndPaymentMethodId(it.status, it.paymentMethod)
|
StatusAndPaymentMethodId(it.status, it.paymentMethod)
|
||||||
|
|
|
@ -13,6 +13,6 @@ import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
data class StripePaymentIntent @JsonCreator constructor(
|
data class StripePaymentIntent @JsonCreator constructor(
|
||||||
@JsonProperty("id") val id: String,
|
@JsonProperty("id") val id: String,
|
||||||
@JsonProperty("client_secret") val clientSecret: String,
|
@JsonProperty("client_secret") val clientSecret: String,
|
||||||
@JsonProperty("status") val status: StripeIntentStatus,
|
@JsonProperty("status") val status: StripeIntentStatus?,
|
||||||
@JsonProperty("payment_method") val paymentMethod: String?
|
@JsonProperty("payment_method") val paymentMethod: String?
|
||||||
)
|
)
|
Loading…
Add table
Reference in a new issue