From be12a17ff76c563e882a9266bd9fd844c951474f Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Fri, 18 Nov 2022 13:22:30 -0400 Subject: [PATCH] Add handling for payment_intent with missing status. --- .../settings/app/subscription/StripeRepository.kt | 12 +++++++++--- .../org/signal/donations/json/StripePaymentIntent.kt | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/StripeRepository.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/StripeRepository.kt index 4d15c91549..c32c6345c8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/StripeRepository.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/StripeRepository.kt @@ -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 { return Single.fromCallable { when (stripeIntentAccessor.objectType) { StripeIntentAccessor.ObjectType.NONE -> StatusAndPaymentMethodId(StripeIntentStatus.SUCCEEDED, null) 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 { StatusAndPaymentMethodId(it.status, it.paymentMethod) diff --git a/donations/lib/src/main/java/org/signal/donations/json/StripePaymentIntent.kt b/donations/lib/src/main/java/org/signal/donations/json/StripePaymentIntent.kt index c7f2c426b8..a785a97419 100644 --- a/donations/lib/src/main/java/org/signal/donations/json/StripePaymentIntent.kt +++ b/donations/lib/src/main/java/org/signal/donations/json/StripePaymentIntent.kt @@ -13,6 +13,6 @@ import com.fasterxml.jackson.annotation.JsonProperty data class StripePaymentIntent @JsonCreator constructor( @JsonProperty("id") val id: String, @JsonProperty("client_secret") val clientSecret: String, - @JsonProperty("status") val status: StripeIntentStatus, + @JsonProperty("status") val status: StripeIntentStatus?, @JsonProperty("payment_method") val paymentMethod: String? ) \ No newline at end of file