Better logging; add payment setup failure params.

This commit is contained in:
Alex Hart 2022-02-11 14:41:58 -04:00
parent 889e17e4d5
commit e4f4682357
2 changed files with 21 additions and 13 deletions

View file

@ -24,6 +24,12 @@ class DonationErrorParams<V> private constructor(
): DonationErrorParams<V> {
return when (throwable) {
is DonationError.PaymentSetupError.DeclinedError -> getDeclinedErrorParams(context, throwable, callback)
is DonationError.PaymentSetupError -> DonationErrorParams(
title = R.string.DonationsErrors__error_processing_payment,
message = R.string.DonationsErrors__your_payment,
positiveAction = callback.onOk(context),
negativeAction = null
)
is DonationError.BadgeRedemptionError.TimeoutWaitingForTokenError -> DonationErrorParams(
title = R.string.DonationsErrors__still_processing,
message = R.string.DonationsErrors__your_payment_is_still,

View file

@ -9,6 +9,7 @@ import okhttp3.Request
import okhttp3.Response
import okio.ByteString
import org.json.JSONObject
import org.signal.core.util.logging.Log
import org.signal.core.util.money.FiatMoney
import java.math.BigDecimal
import java.util.Locale
@ -20,6 +21,10 @@ class StripeApi(
private val okHttpClient: OkHttpClient
) {
companion object {
private val TAG = Log.tag(StripeApi::class.java)
}
sealed class CreatePaymentIntentResult {
data class AmountIsTooSmall(val amount: FiatMoney) : CreatePaymentIntentResult()
data class AmountIsTooLarge(val amount: FiatMoney) : CreatePaymentIntentResult()
@ -73,12 +78,6 @@ class StripeApi(
"payment_method" to paymentMethodId
)
// TODO Donation receipts
// val email = paymentSource.email()
// if (email != null) {
// parameters["receipt_email"] = email
// }
postForm("payment_intents/${paymentIntent.id}/confirm", parameters)
}.subscribeOn(Schedulers.io())
@ -101,12 +100,6 @@ class StripeApi(
"type" to "card",
)
// TODO Donation receipts
// val email = paymentSource.email()
// if (email != null) {
// parameters["billing_details[email]"] = email
// }
return postForm("payment_methods", parameters)
}
@ -138,24 +131,33 @@ class StripeApi(
private fun parseErrorCode(body: String?): String? {
if (body == null) {
Log.d(TAG, "parseErrorCode: No body.", true)
return null
}
return try {
JSONObject(body).getJSONObject("error").getString("code")
} catch (e: Exception) {
Log.d(TAG, "parseErrorCode: Failed to parse error.", e, true)
null
}
}
private fun parseDeclineCode(body: String?): StripeDeclineCode? {
if (body == null) {
Log.d(TAG, "parseDeclineCode: No body.", true)
return null
}
return try {
StripeDeclineCode.getFromCode(JSONObject(body).getJSONObject("error").getString("decline_code"))
val jsonBody = JSONObject(body)
Log.d(TAG, "parseDeclineCode: Parsed body with keys: ${jsonBody.keys().asSequence().joinToString(", ")}")
val jsonError = jsonBody.getJSONObject("error")
Log.d(TAG, "parseDeclineCode: Parsed error with keys: ${jsonError.keys().asSequence().joinToString(", ")}")
StripeDeclineCode.getFromCode(jsonError.getString("decline_code"))
} catch (e: Exception) {
Log.d(TAG, "parseDeclineCode: Failed to parse decline code.", e, true)
null
}
}