Add generic payment in progress strings.

This commit is contained in:
Alex Hart
2024-07-22 11:10:05 -03:00
committed by Nicholas Tinsley
parent 853c934a5a
commit cc806a2f79
6 changed files with 38 additions and 7 deletions

View File

@@ -6,6 +6,7 @@
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
@@ -24,6 +25,7 @@ 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
@@ -65,6 +67,15 @@ object InAppPaymentsRepository {
private val temporaryErrorProcessor = PublishProcessor.create<Pair<InAppPaymentTable.InAppPaymentId, Throwable>>()
@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.
*/

View File

@@ -22,6 +22,7 @@ import org.signal.core.util.getParcelableCompat
import org.signal.core.util.logging.Log
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
@@ -82,8 +83,8 @@ class PayPalPaymentInProgressFragment : DialogFragment(R.layout.donation_in_prog
private fun presentUiState(stage: InAppPaymentProcessorStage) {
when (stage) {
InAppPaymentProcessorStage.INIT -> binding.progressCardStatus.setText(R.string.SubscribeFragment__processing_payment)
InAppPaymentProcessorStage.PAYMENT_PIPELINE -> binding.progressCardStatus.setText(R.string.SubscribeFragment__processing_payment)
InAppPaymentProcessorStage.INIT -> binding.progressCardStatus.text = getProcessingStatus()
InAppPaymentProcessorStage.PAYMENT_PIPELINE -> binding.progressCardStatus.text = getProcessingStatus()
InAppPaymentProcessorStage.FAILED -> {
viewModel.onEndAction()
findNavController().popBackStack()
@@ -120,6 +121,10 @@ class PayPalPaymentInProgressFragment : DialogFragment(R.layout.donation_in_prog
}
}
private fun getProcessingStatus(): String {
return getString(R.string.InAppPaymentInProgressFragment__processing_s, getString(args.inAppPaymentType.labelResource))
}
private fun oneTimeConfirmationPipeline(createPaymentIntentResponse: PayPalCreatePaymentIntentResponse): Single<PayPalConfirmationResult> {
return routeToOneTimeConfirmation(createPaymentIntentResponse)
}

View File

@@ -24,6 +24,7 @@ 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
@@ -68,9 +69,11 @@ class StripePaymentInProgressFragment : DialogFragment(R.layout.donation_in_prog
InAppPaymentProcessorAction.PROCESS_NEW_IN_APP_PAYMENT -> {
viewModel.processNewDonation(args.inAppPayment!!, this::handleSecure3dsAction)
}
InAppPaymentProcessorAction.UPDATE_SUBSCRIPTION -> {
viewModel.updateSubscription(args.inAppPayment!!)
}
InAppPaymentProcessorAction.CANCEL_SUBSCRIPTION -> {
viewModel.cancelSubscription(args.inAppPaymentType.requireSubscriberType())
}
@@ -85,8 +88,8 @@ class StripePaymentInProgressFragment : DialogFragment(R.layout.donation_in_prog
private fun presentUiState(stage: InAppPaymentProcessorStage) {
when (stage) {
InAppPaymentProcessorStage.INIT -> binding.progressCardStatus.setText(R.string.SubscribeFragment__processing_payment)
InAppPaymentProcessorStage.PAYMENT_PIPELINE -> binding.progressCardStatus.setText(R.string.SubscribeFragment__processing_payment)
InAppPaymentProcessorStage.INIT -> binding.progressCardStatus.text = getProcessingStatus()
InAppPaymentProcessorStage.PAYMENT_PIPELINE -> binding.progressCardStatus.text = getProcessingStatus()
InAppPaymentProcessorStage.FAILED -> {
viewModel.onEndAction()
findNavController().popBackStack()
@@ -102,6 +105,7 @@ class StripePaymentInProgressFragment : DialogFragment(R.layout.donation_in_prog
)
)
}
InAppPaymentProcessorStage.COMPLETE -> {
viewModel.onEndAction()
findNavController().popBackStack()
@@ -117,16 +121,22 @@ class StripePaymentInProgressFragment : DialogFragment(R.layout.donation_in_prog
)
)
}
InAppPaymentProcessorStage.CANCELLING -> binding.progressCardStatus.setText(R.string.StripePaymentInProgressFragment__cancelling)
}
}
private fun getProcessingStatus(): String {
return getString(R.string.InAppPaymentInProgressFragment__processing_s, getString(args.inAppPaymentType.labelResource))
}
private fun handleSecure3dsAction(secure3dsAction: StripeApi.Secure3DSAction, inAppPayment: InAppPaymentTable.InAppPayment): Single<StripeIntentAccessor> {
return when (secure3dsAction) {
is StripeApi.Secure3DSAction.NotNeeded -> {
Log.d(TAG, "No 3DS action required.")
Single.just(StripeIntentAccessor.NO_ACTION_REQUIRED)
}
is StripeApi.Secure3DSAction.ConfirmRequired -> {
Log.d(TAG, "3DS action required. Displaying dialog...")
Single.create { emitter ->