kopia lustrzana https://github.com/ryukoposting/Signal-Android
Better logging; add payment setup failure params.
rodzic
889e17e4d5
commit
e4f4682357
|
@ -24,6 +24,12 @@ class DonationErrorParams<V> private constructor(
|
||||||
): DonationErrorParams<V> {
|
): DonationErrorParams<V> {
|
||||||
return when (throwable) {
|
return when (throwable) {
|
||||||
is DonationError.PaymentSetupError.DeclinedError -> getDeclinedErrorParams(context, throwable, callback)
|
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(
|
is DonationError.BadgeRedemptionError.TimeoutWaitingForTokenError -> DonationErrorParams(
|
||||||
title = R.string.DonationsErrors__still_processing,
|
title = R.string.DonationsErrors__still_processing,
|
||||||
message = R.string.DonationsErrors__your_payment_is_still,
|
message = R.string.DonationsErrors__your_payment_is_still,
|
||||||
|
|
|
@ -9,6 +9,7 @@ import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import okio.ByteString
|
import okio.ByteString
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
import org.signal.core.util.logging.Log
|
||||||
import org.signal.core.util.money.FiatMoney
|
import org.signal.core.util.money.FiatMoney
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
@ -20,6 +21,10 @@ class StripeApi(
|
||||||
private val okHttpClient: OkHttpClient
|
private val okHttpClient: OkHttpClient
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val TAG = Log.tag(StripeApi::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
sealed class CreatePaymentIntentResult {
|
sealed class CreatePaymentIntentResult {
|
||||||
data class AmountIsTooSmall(val amount: FiatMoney) : CreatePaymentIntentResult()
|
data class AmountIsTooSmall(val amount: FiatMoney) : CreatePaymentIntentResult()
|
||||||
data class AmountIsTooLarge(val amount: FiatMoney) : CreatePaymentIntentResult()
|
data class AmountIsTooLarge(val amount: FiatMoney) : CreatePaymentIntentResult()
|
||||||
|
@ -73,12 +78,6 @@ class StripeApi(
|
||||||
"payment_method" to paymentMethodId
|
"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)
|
postForm("payment_intents/${paymentIntent.id}/confirm", parameters)
|
||||||
}.subscribeOn(Schedulers.io())
|
}.subscribeOn(Schedulers.io())
|
||||||
|
|
||||||
|
@ -101,12 +100,6 @@ class StripeApi(
|
||||||
"type" to "card",
|
"type" to "card",
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO Donation receipts
|
|
||||||
// val email = paymentSource.email()
|
|
||||||
// if (email != null) {
|
|
||||||
// parameters["billing_details[email]"] = email
|
|
||||||
// }
|
|
||||||
|
|
||||||
return postForm("payment_methods", parameters)
|
return postForm("payment_methods", parameters)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,24 +131,33 @@ class StripeApi(
|
||||||
|
|
||||||
private fun parseErrorCode(body: String?): String? {
|
private fun parseErrorCode(body: String?): String? {
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
|
Log.d(TAG, "parseErrorCode: No body.", true)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
JSONObject(body).getJSONObject("error").getString("code")
|
JSONObject(body).getJSONObject("error").getString("code")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
Log.d(TAG, "parseErrorCode: Failed to parse error.", e, true)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseDeclineCode(body: String?): StripeDeclineCode? {
|
private fun parseDeclineCode(body: String?): StripeDeclineCode? {
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
|
Log.d(TAG, "parseDeclineCode: No body.", true)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return try {
|
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) {
|
} catch (e: Exception) {
|
||||||
|
Log.d(TAG, "parseDeclineCode: Failed to parse decline code.", e, true)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue