diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/InAppPaymentsRepository.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/InAppPaymentsRepository.kt index 77f2e3ccec..3805ad819c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/InAppPaymentsRepository.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/InAppPaymentsRepository.kt @@ -6,7 +6,6 @@ package org.thoughtcrime.securesms.components.settings.app.subscription import android.annotation.SuppressLint -import androidx.annotation.StringRes import androidx.annotation.WorkerThread import io.reactivex.rxjava3.core.BackpressureStrategy import io.reactivex.rxjava3.core.Completable @@ -25,7 +24,6 @@ import org.signal.libsignal.zkgroup.InvalidInputException import org.signal.libsignal.zkgroup.VerificationFailedException import org.signal.libsignal.zkgroup.receipts.ReceiptCredentialRequestContext import org.signal.libsignal.zkgroup.receipts.ReceiptSerial -import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.components.settings.app.subscription.DonationSerializationHelper.toFiatMoney import org.thoughtcrime.securesms.components.settings.app.subscription.donate.InAppPaymentError import org.thoughtcrime.securesms.components.settings.app.subscription.errors.DonationError @@ -67,15 +65,6 @@ object InAppPaymentsRepository { private val temporaryErrorProcessor = PublishProcessor.create>() - @get:StringRes - val InAppPaymentType.labelResource: Int get() { - return if (this == InAppPaymentType.RECURRING_BACKUP) { - R.string.InAppPaymentInProgressFragment__payment - } else { - R.string.InAppPaymentInProgressFragment__donation - } - } - /** * Wraps an in-app-payment update in a completable. */ diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/donate/paypal/PayPalPaymentInProgressFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/donate/paypal/PayPalPaymentInProgressFragment.kt index 48548eb5a1..a940449508 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/donate/paypal/PayPalPaymentInProgressFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/donate/paypal/PayPalPaymentInProgressFragment.kt @@ -20,9 +20,9 @@ import io.reactivex.rxjava3.schedulers.Schedulers import org.signal.core.util.concurrent.LifecycleDisposable import org.signal.core.util.getParcelableCompat import org.signal.core.util.logging.Log +import org.signal.donations.InAppPaymentType import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.components.ViewBinderDelegate -import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentsRepository.labelResource import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentsRepository.toErrorSource import org.thoughtcrime.securesms.components.settings.app.subscription.donate.InAppPaymentProcessorAction import org.thoughtcrime.securesms.components.settings.app.subscription.donate.InAppPaymentProcessorActionResult @@ -122,7 +122,11 @@ class PayPalPaymentInProgressFragment : DialogFragment(R.layout.donation_in_prog } private fun getProcessingStatus(): String { - return getString(R.string.InAppPaymentInProgressFragment__processing_s, getString(args.inAppPaymentType.labelResource)) + return if (args.inAppPaymentType == InAppPaymentType.RECURRING_BACKUP) { + getString(R.string.InAppPaymentInProgressFragment__processing_payment) + } else { + getString(R.string.InAppPaymentInProgressFragment__processing_donation) + } } private fun oneTimeConfirmationPipeline(createPaymentIntentResponse: PayPalCreatePaymentIntentResponse): Single { diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/donate/stripe/StripePaymentInProgressFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/donate/stripe/StripePaymentInProgressFragment.kt index 29a2c62265..cd9441f124 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/donate/stripe/StripePaymentInProgressFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/donate/stripe/StripePaymentInProgressFragment.kt @@ -19,12 +19,12 @@ import io.reactivex.rxjava3.schedulers.Schedulers import org.signal.core.util.concurrent.LifecycleDisposable import org.signal.core.util.getParcelableCompat import org.signal.core.util.logging.Log +import org.signal.donations.InAppPaymentType import org.signal.donations.StripeApi import org.signal.donations.StripeIntentAccessor import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.components.ViewBinderDelegate import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentComponent -import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentsRepository.labelResource import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentsRepository.requireSubscriberType import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentsRepository.toErrorSource import org.thoughtcrime.securesms.components.settings.app.subscription.donate.InAppPaymentProcessorAction @@ -127,9 +127,12 @@ class StripePaymentInProgressFragment : DialogFragment(R.layout.donation_in_prog } private fun getProcessingStatus(): String { - return getString(R.string.InAppPaymentInProgressFragment__processing_s, getString(args.inAppPaymentType.labelResource)) + return if (args.inAppPaymentType == InAppPaymentType.RECURRING_BACKUP) { + getString(R.string.InAppPaymentInProgressFragment__processing_payment) + } else { + getString(R.string.InAppPaymentInProgressFragment__processing_donation) + } } - private fun handleSecure3dsAction(secure3dsAction: StripeApi.Secure3DSAction, inAppPayment: InAppPaymentTable.InAppPayment): Single { return when (secure3dsAction) { is StripeApi.Secure3DSAction.NotNeeded -> { diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/errors/DonationErrorParams.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/errors/DonationErrorParams.kt index 98497fd5e9..bf3e43bbdc 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/errors/DonationErrorParams.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/errors/DonationErrorParams.kt @@ -18,6 +18,7 @@ class DonationErrorParams private constructor( val positiveAction: ErrorAction?, val negativeAction: ErrorAction? ) { + class ErrorAction( @StringRes val label: Int, val action: () -> V @@ -31,10 +32,10 @@ class DonationErrorParams private constructor( ): DonationErrorParams { return when (throwable) { is DonationError.GiftRecipientVerificationError -> getVerificationErrorParams(context, callback) - is DonationError.PaymentSetupError.StripeDeclinedError -> getStripeDeclinedErrorParams(context, throwable.method, throwable.declineCode, callback) - is DonationError.PaymentSetupError.StripeFailureCodeError -> getStripeFailureCodeErrorParams(context, throwable.method, throwable.failureCode, callback) - is DonationError.PaymentSetupError.PayPalDeclinedError -> getPayPalDeclinedErrorParams(context, throwable.code, callback) - is DonationError.PaymentSetupError -> getGenericPaymentSetupErrorParams(context, callback) + is DonationError.PaymentSetupError.StripeDeclinedError -> getStripeDeclinedErrorParams(context, throwable.method, throwable.declineCode, callback, throwable.source.toInAppPaymentType()) + is DonationError.PaymentSetupError.StripeFailureCodeError -> getStripeFailureCodeErrorParams(context, throwable.method, throwable.failureCode, throwable.source.toInAppPaymentType(), callback) + is DonationError.PaymentSetupError.PayPalDeclinedError -> getPayPalDeclinedErrorParams(context, throwable.code, callback, throwable.source.toInAppPaymentType()) + is DonationError.PaymentSetupError -> getGenericPaymentSetupErrorParams(context, callback, throwable.source.toInAppPaymentType()) is DonationError.BadgeRedemptionError.DonationPending -> getStillProcessingErrorParams(context, callback) is DonationError.BadgeRedemptionError.TimeoutWaitingForTokenError -> getStillProcessingErrorParams(context, callback) is DonationError.BadgeRedemptionError.FailedToValidateCredentialError -> getBadgeCredentialValidationErrorParams(context, callback) @@ -50,31 +51,37 @@ class DonationErrorParams private constructor( ): DonationErrorParams { return when (inAppPayment.data.error?.type) { InAppPaymentData.Error.Type.UNKNOWN -> getGenericRedemptionError(context, inAppPayment.type, callback) - InAppPaymentData.Error.Type.GOOGLE_PAY_REQUEST_TOKEN -> getGenericPaymentSetupErrorParams(context, callback) + InAppPaymentData.Error.Type.GOOGLE_PAY_REQUEST_TOKEN -> getGenericPaymentSetupErrorParams(context, callback, inAppPayment.type) InAppPaymentData.Error.Type.INVALID_GIFT_RECIPIENT -> getVerificationErrorParams(context, callback) - InAppPaymentData.Error.Type.ONE_TIME_AMOUNT_TOO_SMALL -> getGenericPaymentSetupErrorParams(context, callback) - InAppPaymentData.Error.Type.ONE_TIME_AMOUNT_TOO_LARGE -> getGenericPaymentSetupErrorParams(context, callback) - InAppPaymentData.Error.Type.INVALID_CURRENCY -> getGenericPaymentSetupErrorParams(context, callback) - InAppPaymentData.Error.Type.PAYMENT_SETUP -> getGenericPaymentSetupErrorParams(context, callback) - InAppPaymentData.Error.Type.STRIPE_CODED_ERROR -> getGenericPaymentSetupErrorParams(context, callback) + InAppPaymentData.Error.Type.ONE_TIME_AMOUNT_TOO_SMALL -> getGenericPaymentSetupErrorParams(context, callback, inAppPayment.type) + InAppPaymentData.Error.Type.ONE_TIME_AMOUNT_TOO_LARGE -> getGenericPaymentSetupErrorParams(context, callback, inAppPayment.type) + InAppPaymentData.Error.Type.INVALID_CURRENCY -> getGenericPaymentSetupErrorParams(context, callback, inAppPayment.type) + InAppPaymentData.Error.Type.PAYMENT_SETUP -> getGenericPaymentSetupErrorParams(context, callback, inAppPayment.type) + InAppPaymentData.Error.Type.STRIPE_CODED_ERROR -> getGenericPaymentSetupErrorParams(context, callback, inAppPayment.type) InAppPaymentData.Error.Type.STRIPE_DECLINED_ERROR -> getStripeDeclinedErrorParams( context = context, paymentSourceType = inAppPayment.data.paymentMethodType.toPaymentSourceType() as PaymentSourceType.Stripe, declineCode = StripeDeclineCode.getFromCode(inAppPayment.data.error.data_), - callback = callback + callback = callback, + inAppPaymentType = inAppPayment.type ) + InAppPaymentData.Error.Type.STRIPE_FAILURE -> getStripeFailureCodeErrorParams( context = context, paymentSourceType = inAppPayment.data.paymentMethodType.toPaymentSourceType() as PaymentSourceType.Stripe, failureCode = StripeFailureCode.getFromCode(inAppPayment.data.error.data_), + inAppPaymentType = inAppPayment.type, callback = callback ) - InAppPaymentData.Error.Type.PAYPAL_CODED_ERROR -> getGenericPaymentSetupErrorParams(context, callback) + + InAppPaymentData.Error.Type.PAYPAL_CODED_ERROR -> getGenericPaymentSetupErrorParams(context, callback, inAppPayment.type) InAppPaymentData.Error.Type.PAYPAL_DECLINED_ERROR -> getPayPalDeclinedErrorParams( context = context, payPalDeclineCode = PayPalDeclineCode.KnownCode.fromCode(inAppPayment.data.error.data_!!.toInt())!!, - callback = callback + callback = callback, + inAppPaymentType = inAppPayment.type ) + InAppPaymentData.Error.Type.PAYMENT_PROCESSING -> getGenericRedemptionError(context, inAppPayment.type, callback) InAppPaymentData.Error.Type.CREDENTIAL_VALIDATION -> getBadgeCredentialValidationErrorParams(context, callback) InAppPaymentData.Error.Type.REDEMPTION -> getGenericRedemptionError(context, inAppPayment.type, callback) @@ -112,11 +119,12 @@ class DonationErrorParams private constructor( private fun getPayPalDeclinedErrorParams( context: Context, payPalDeclineCode: PayPalDeclineCode.KnownCode, - callback: Callback + callback: Callback, + inAppPaymentType: InAppPaymentType ): DonationErrorParams { return when (payPalDeclineCode) { - PayPalDeclineCode.KnownCode.DECLINED -> getLearnMoreParams(context, callback, R.string.DeclineCode__try_another_payment_method_or_contact_your_bank_for_more_information_if_this_was_a_paypal) - else -> getLearnMoreParams(context, callback, R.string.DeclineCode__try_another_payment_method_or_contact_your_bank) + PayPalDeclineCode.KnownCode.DECLINED -> getLearnMoreParams(context, callback, inAppPaymentType, R.string.DeclineCode__try_another_payment_method_or_contact_your_bank_for_more_information_if_this_was_a_paypal) + else -> getLearnMoreParams(context, callback, inAppPaymentType, R.string.DeclineCode__try_another_payment_method_or_contact_your_bank) } } @@ -124,17 +132,18 @@ class DonationErrorParams private constructor( context: Context, paymentSourceType: PaymentSourceType.Stripe, declineCode: StripeDeclineCode, - callback: Callback + callback: Callback, + inAppPaymentType: InAppPaymentType ): DonationErrorParams { if (!paymentSourceType.hasDeclineCodeSupport()) { - return getGenericPaymentSetupErrorParams(context, callback) + return getGenericPaymentSetupErrorParams(context, callback, inAppPaymentType) } fun unexpectedDeclinedError(declineCode: StripeDeclineCode, paymentSourceType: PaymentSourceType.Stripe): Nothing { error("Unexpected declined error: $declineCode during $paymentSourceType processing.") } - val getStripeDeclineCodePositiveActionParams: (Context, Callback, Int) -> DonationErrorParams = when (paymentSourceType) { + val getStripeDeclineCodePositiveActionParams: (Context, Callback, InAppPaymentType, Int) -> DonationErrorParams = when (paymentSourceType) { PaymentSourceType.Stripe.CreditCard -> this::getTryCreditCardAgainParams PaymentSourceType.Stripe.GooglePay -> this::getGoToGooglePayParams else -> this::getLearnMoreParams @@ -145,6 +154,7 @@ class DonationErrorParams private constructor( StripeDeclineCode.Code.APPROVE_WITH_ID -> getStripeDeclineCodePositiveActionParams( context, callback, + inAppPaymentType, when (paymentSourceType) { PaymentSourceType.Stripe.CreditCard -> R.string.DeclineCode__verify_your_card_details_are_correct_and_try_again PaymentSourceType.Stripe.GooglePay -> R.string.DeclineCode__verify_your_payment_method_is_up_to_date_in_google_pay_and_try_again @@ -155,6 +165,7 @@ class DonationErrorParams private constructor( StripeDeclineCode.Code.CALL_ISSUER -> getStripeDeclineCodePositiveActionParams( context, callback, + inAppPaymentType, when (paymentSourceType) { PaymentSourceType.Stripe.CreditCard -> R.string.DeclineCode__verify_your_card_details_are_correct_and_try_again_if_the_problem_continues PaymentSourceType.Stripe.GooglePay -> R.string.DeclineCode__verify_your_payment_method_is_up_to_date_in_google_pay_and_try_again_if_the_problem @@ -162,10 +173,11 @@ class DonationErrorParams private constructor( } ) - StripeDeclineCode.Code.CARD_NOT_SUPPORTED -> getLearnMoreParams(context, callback, R.string.DeclineCode__your_card_does_not_support_this_type_of_purchase) + StripeDeclineCode.Code.CARD_NOT_SUPPORTED -> getLearnMoreParams(context, callback, inAppPaymentType, R.string.DeclineCode__your_card_does_not_support_this_type_of_purchase) StripeDeclineCode.Code.EXPIRED_CARD -> getStripeDeclineCodePositiveActionParams( context, callback, + inAppPaymentType, when (paymentSourceType) { PaymentSourceType.Stripe.CreditCard -> R.string.DeclineCode__your_card_has_expired_verify_your_card_details PaymentSourceType.Stripe.GooglePay -> R.string.DeclineCode__your_card_has_expired @@ -176,6 +188,7 @@ class DonationErrorParams private constructor( StripeDeclineCode.Code.INCORRECT_NUMBER -> getStripeDeclineCodePositiveActionParams( context, callback, + inAppPaymentType, when (paymentSourceType) { PaymentSourceType.Stripe.CreditCard -> R.string.DeclineCode__your_card_number_is_incorrect_verify_your_card_details PaymentSourceType.Stripe.GooglePay -> R.string.DeclineCode__your_card_number_is_incorrect @@ -186,6 +199,7 @@ class DonationErrorParams private constructor( StripeDeclineCode.Code.INCORRECT_CVC -> getStripeDeclineCodePositiveActionParams( context, callback, + inAppPaymentType, when (paymentSourceType) { PaymentSourceType.Stripe.CreditCard -> R.string.DeclineCode__your_cards_cvc_number_is_incorrect_verify_your_card_details PaymentSourceType.Stripe.GooglePay -> R.string.DeclineCode__your_cards_cvc_number_is_incorrect @@ -193,10 +207,11 @@ class DonationErrorParams private constructor( } ) - StripeDeclineCode.Code.INSUFFICIENT_FUNDS -> getLearnMoreParams(context, callback, R.string.DeclineCode__your_card_does_not_have_sufficient_funds) + StripeDeclineCode.Code.INSUFFICIENT_FUNDS -> getLearnMoreParams(context, callback, inAppPaymentType, R.string.DeclineCode__your_card_does_not_have_sufficient_funds) StripeDeclineCode.Code.INVALID_CVC -> getStripeDeclineCodePositiveActionParams( context, callback, + inAppPaymentType, when (paymentSourceType) { PaymentSourceType.Stripe.CreditCard -> R.string.DeclineCode__your_cards_cvc_number_is_incorrect_verify_your_card_details PaymentSourceType.Stripe.GooglePay -> R.string.DeclineCode__your_cards_cvc_number_is_incorrect @@ -207,6 +222,7 @@ class DonationErrorParams private constructor( StripeDeclineCode.Code.INVALID_EXPIRY_MONTH -> getStripeDeclineCodePositiveActionParams( context, callback, + inAppPaymentType, when (paymentSourceType) { PaymentSourceType.Stripe.CreditCard -> R.string.DeclineCode__the_expiration_month_on_your_card_is_incorrect PaymentSourceType.Stripe.GooglePay -> R.string.DeclineCode__the_expiration_month @@ -217,6 +233,7 @@ class DonationErrorParams private constructor( StripeDeclineCode.Code.INVALID_EXPIRY_YEAR -> getStripeDeclineCodePositiveActionParams( context, callback, + inAppPaymentType, when (paymentSourceType) { PaymentSourceType.Stripe.CreditCard -> R.string.DeclineCode__the_expiration_year_on_your_card_is_incorrect PaymentSourceType.Stripe.GooglePay -> R.string.DeclineCode__the_expiration_year @@ -227,6 +244,7 @@ class DonationErrorParams private constructor( StripeDeclineCode.Code.INVALID_NUMBER -> getStripeDeclineCodePositiveActionParams( context, callback, + inAppPaymentType, when (paymentSourceType) { PaymentSourceType.Stripe.CreditCard -> R.string.DeclineCode__your_card_number_is_incorrect_verify_your_card_details PaymentSourceType.Stripe.GooglePay -> R.string.DeclineCode__your_card_number_is_incorrect @@ -234,13 +252,13 @@ class DonationErrorParams private constructor( } ) - StripeDeclineCode.Code.ISSUER_NOT_AVAILABLE -> getLearnMoreParams(context, callback, R.string.DeclineCode__try_completing_the_payment_again) - StripeDeclineCode.Code.PROCESSING_ERROR -> getLearnMoreParams(context, callback, R.string.DeclineCode__try_again) - StripeDeclineCode.Code.REENTER_TRANSACTION -> getLearnMoreParams(context, callback, R.string.DeclineCode__try_again) - else -> getLearnMoreParams(context, callback, R.string.DeclineCode__try_another_payment_method_or_contact_your_bank) + StripeDeclineCode.Code.ISSUER_NOT_AVAILABLE -> getLearnMoreParams(context, callback, inAppPaymentType, R.string.DeclineCode__try_completing_the_payment_again) + StripeDeclineCode.Code.PROCESSING_ERROR -> getLearnMoreParams(context, callback, inAppPaymentType, R.string.DeclineCode__try_again) + StripeDeclineCode.Code.REENTER_TRANSACTION -> getLearnMoreParams(context, callback, inAppPaymentType, R.string.DeclineCode__try_again) + else -> getLearnMoreParams(context, callback, inAppPaymentType, R.string.DeclineCode__try_another_payment_method_or_contact_your_bank) } - else -> getLearnMoreParams(context, callback, R.string.DeclineCode__try_another_payment_method_or_contact_your_bank) + else -> getLearnMoreParams(context, callback, inAppPaymentType, R.string.DeclineCode__try_another_payment_method_or_contact_your_bank) } } @@ -248,33 +266,34 @@ class DonationErrorParams private constructor( context: Context, paymentSourceType: PaymentSourceType.Stripe, failureCode: StripeFailureCode, + inAppPaymentType: InAppPaymentType, callback: Callback ): DonationErrorParams { if (!paymentSourceType.hasFailureCodeSupport()) { - return getGenericPaymentSetupErrorParams(context, callback) + return getGenericPaymentSetupErrorParams(context, callback, inAppPaymentType) } return when (failureCode) { is StripeFailureCode.Known -> { val errorText = failureCode.mapToErrorStringResource() when (failureCode.code) { - StripeFailureCode.Code.REFER_TO_CUSTOMER -> getTryBankTransferAgainParams(context, callback, errorText) - StripeFailureCode.Code.INSUFFICIENT_FUNDS -> getLearnMoreParams(context, callback, errorText) - StripeFailureCode.Code.DEBIT_DISPUTED -> getLearnMoreParams(context, callback, errorText) - StripeFailureCode.Code.AUTHORIZATION_REVOKED -> getLearnMoreParams(context, callback, errorText) - StripeFailureCode.Code.DEBIT_NOT_AUTHORIZED -> getLearnMoreParams(context, callback, errorText) - StripeFailureCode.Code.ACCOUNT_CLOSED -> getLearnMoreParams(context, callback, errorText) - StripeFailureCode.Code.BANK_ACCOUNT_RESTRICTED -> getLearnMoreParams(context, callback, errorText) - StripeFailureCode.Code.DEBIT_AUTHORIZATION_NOT_MATCH -> getLearnMoreParams(context, callback, errorText) - StripeFailureCode.Code.RECIPIENT_DECEASED -> getLearnMoreParams(context, callback, errorText) - StripeFailureCode.Code.BRANCH_DOES_NOT_EXIST -> getTryBankTransferAgainParams(context, callback, errorText) - StripeFailureCode.Code.INCORRECT_ACCOUNT_HOLDER_NAME -> getTryBankTransferAgainParams(context, callback, errorText) - StripeFailureCode.Code.INVALID_ACCOUNT_NUMBER -> getTryBankTransferAgainParams(context, callback, errorText) - StripeFailureCode.Code.GENERIC_COULD_NOT_PROCESS -> getTryBankTransferAgainParams(context, callback, errorText) + StripeFailureCode.Code.REFER_TO_CUSTOMER -> getTryBankTransferAgainParams(context, callback, inAppPaymentType, errorText) + StripeFailureCode.Code.INSUFFICIENT_FUNDS -> getLearnMoreParams(context, callback, inAppPaymentType, errorText) + StripeFailureCode.Code.DEBIT_DISPUTED -> getLearnMoreParams(context, callback, inAppPaymentType, errorText) + StripeFailureCode.Code.AUTHORIZATION_REVOKED -> getLearnMoreParams(context, callback, inAppPaymentType, errorText) + StripeFailureCode.Code.DEBIT_NOT_AUTHORIZED -> getLearnMoreParams(context, callback, inAppPaymentType, errorText) + StripeFailureCode.Code.ACCOUNT_CLOSED -> getLearnMoreParams(context, callback, inAppPaymentType, errorText) + StripeFailureCode.Code.BANK_ACCOUNT_RESTRICTED -> getLearnMoreParams(context, callback, inAppPaymentType, errorText) + StripeFailureCode.Code.DEBIT_AUTHORIZATION_NOT_MATCH -> getLearnMoreParams(context, callback, inAppPaymentType, errorText) + StripeFailureCode.Code.RECIPIENT_DECEASED -> getLearnMoreParams(context, callback, inAppPaymentType, errorText) + StripeFailureCode.Code.BRANCH_DOES_NOT_EXIST -> getTryBankTransferAgainParams(context, callback, inAppPaymentType, errorText) + StripeFailureCode.Code.INCORRECT_ACCOUNT_HOLDER_NAME -> getTryBankTransferAgainParams(context, callback, inAppPaymentType, errorText) + StripeFailureCode.Code.INVALID_ACCOUNT_NUMBER -> getTryBankTransferAgainParams(context, callback, inAppPaymentType, errorText) + StripeFailureCode.Code.GENERIC_COULD_NOT_PROCESS -> getTryBankTransferAgainParams(context, callback, inAppPaymentType, errorText) } } - is StripeFailureCode.Unknown -> getGenericPaymentSetupErrorParams(context, callback) + is StripeFailureCode.Unknown -> getGenericPaymentSetupErrorParams(context, callback, inAppPaymentType) } } @@ -296,50 +315,68 @@ class DonationErrorParams private constructor( ) } - private fun getGenericPaymentSetupErrorParams(context: Context, callback: Callback): DonationErrorParams { + private fun getGenericPaymentSetupErrorParams(context: Context, callback: Callback, inAppPaymentType: InAppPaymentType): DonationErrorParams { return DonationErrorParams( - title = R.string.DonationsErrors__error_processing_payment, - message = R.string.DonationsErrors__your_payment, + title = getGenericErrorProcessingTitle(inAppPaymentType), + message = getPaymentSetupErrorMessage(inAppPaymentType), positiveAction = callback.onOk(context), negativeAction = null ) } - private fun getLearnMoreParams(context: Context, callback: Callback, message: Int): DonationErrorParams { + private fun getLearnMoreParams(context: Context, callback: Callback, inAppPaymentType: InAppPaymentType, message: Int): DonationErrorParams { return DonationErrorParams( - title = R.string.DonationsErrors__error_processing_payment, + title = getGenericErrorProcessingTitle(inAppPaymentType), message = message, positiveAction = callback.onOk(context), negativeAction = callback.onLearnMore(context) ) } - private fun getGoToGooglePayParams(context: Context, callback: Callback, message: Int): DonationErrorParams { + private fun getGoToGooglePayParams(context: Context, callback: Callback, inAppPaymentType: InAppPaymentType, message: Int): DonationErrorParams { return DonationErrorParams( - title = R.string.DonationsErrors__error_processing_payment, + title = getGenericErrorProcessingTitle(inAppPaymentType), message = message, positiveAction = callback.onGoToGooglePay(context), negativeAction = callback.onCancel(context) ) } - private fun getTryCreditCardAgainParams(context: Context, callback: Callback, message: Int): DonationErrorParams { + private fun getTryCreditCardAgainParams(context: Context, callback: Callback, inAppPaymentType: InAppPaymentType, message: Int): DonationErrorParams { return DonationErrorParams( - title = R.string.DonationsErrors__error_processing_payment, + title = getGenericErrorProcessingTitle(inAppPaymentType), message = message, positiveAction = callback.onTryCreditCardAgain(context), negativeAction = callback.onCancel(context) ) } - private fun getTryBankTransferAgainParams(context: Context, callback: Callback, message: Int): DonationErrorParams { + private fun getTryBankTransferAgainParams(context: Context, callback: Callback, inAppPaymentType: InAppPaymentType, message: Int): DonationErrorParams { return DonationErrorParams( - title = R.string.DonationsErrors__error_processing_payment, + title = getGenericErrorProcessingTitle(inAppPaymentType), message = message, positiveAction = callback.onTryBankTransferAgain(context), negativeAction = callback.onCancel(context) ) } + + @StringRes + private fun getGenericErrorProcessingTitle(inAppPaymentType: InAppPaymentType): Int { + return if (inAppPaymentType == InAppPaymentType.RECURRING_BACKUP) { + R.string.InAppPaymentErrors__error_processing_payment + } else { + R.string.DonationsErrors__error_processing_payment + } + } + + @StringRes + private fun getPaymentSetupErrorMessage(inAppPaymentType: InAppPaymentType): Int { + return if (inAppPaymentType == InAppPaymentType.RECURRING_BACKUP) { + R.string.InAppPaymentErrors__your_payment_couldnt_be_processed + } else { + R.string.DonationsErrors__your_payment + } + } } interface Callback { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9faab9dea8..2214777347 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -5473,12 +5473,14 @@ Get a %1$s badge - - donation - - payment - - Processing %1$s… + Processing donation… + Processing payment… + + + + Error processing payment + + Your payment couldn\'t be processed and you have not been charged. Please try again. Error processing donation