mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-17 23:43:34 +01:00
Add proper retry for CC Fragment.
This commit is contained in:
committed by
jeffrey-signal
parent
b4ec935762
commit
c9e6204a8d
@@ -313,7 +313,7 @@ class InAppPaymentCheckoutDelegate(
|
||||
errorDialog = DonationErrorDialogs.show(
|
||||
fragment!!.requireContext(),
|
||||
throwable,
|
||||
DialogHandler()
|
||||
DialogHandler(inAppPayment)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -340,13 +340,13 @@ class InAppPaymentCheckoutDelegate(
|
||||
errorDialog = DonationErrorDialogs.show(
|
||||
fragment!!.requireContext(),
|
||||
inAppPayment,
|
||||
DialogHandler()
|
||||
DialogHandler(inAppPayment)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inner class DialogHandler : DonationErrorDialogs.DialogCallback() {
|
||||
private inner class DialogHandler(private val inAppPayment: InAppPaymentTable.InAppPayment) : DonationErrorDialogs.DialogCallback() {
|
||||
var tryAgain = false
|
||||
|
||||
override fun onTryCreditCardAgain(context: Context): DonationErrorParams.ErrorAction<Unit> {
|
||||
@@ -369,8 +369,18 @@ class InAppPaymentCheckoutDelegate(
|
||||
|
||||
override fun onDialogDismissed() {
|
||||
errorDialog = null
|
||||
if (!tryAgain) {
|
||||
tryAgain = false
|
||||
if (tryAgain) {
|
||||
Log.d(TAG, "Resetting InAppPayment[${inAppPayment.id}] to CREATED for retry.", true)
|
||||
InAppPaymentsRepository.updateInAppPayment(
|
||||
inAppPayment.copy(
|
||||
state = InAppPaymentTable.State.CREATED,
|
||||
data = inAppPayment.data.newBuilder()
|
||||
.error(null)
|
||||
.redemption(InAppPaymentData.RedemptionState(stage = InAppPaymentData.RedemptionState.Stage.INIT))
|
||||
.build()
|
||||
)
|
||||
).subscribe()
|
||||
} else {
|
||||
errorHandlerCallback?.exitCheckoutFlow()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.thoughtcrime.securesms.components.settings.app.subscription.donate.In
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.donate.InAppPaymentProcessorActionResult
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.donate.stripe.StripePaymentInProgressFragment
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.donate.stripe.StripePaymentInProgressViewModel
|
||||
import org.thoughtcrime.securesms.database.InAppPaymentTable
|
||||
import org.thoughtcrime.securesms.databinding.CreditCardFragmentBinding
|
||||
import org.thoughtcrime.securesms.payments.FiatMoneyUtil
|
||||
import org.thoughtcrime.securesms.util.ViewUtil
|
||||
@@ -37,7 +38,7 @@ import org.thoughtcrime.securesms.util.navigation.safeNavigate
|
||||
import org.thoughtcrime.securesms.util.viewModel
|
||||
import org.signal.core.ui.R as CoreUiR
|
||||
|
||||
class CreditCardFragment : Fragment(R.layout.credit_card_fragment) {
|
||||
class CreditCardFragment : Fragment(R.layout.credit_card_fragment), InAppPaymentCheckoutDelegate.ErrorHandlerCallback {
|
||||
|
||||
private val binding by ViewBinderDelegate(CreditCardFragmentBinding::bind)
|
||||
private val args: CreditCardFragmentArgs by navArgs()
|
||||
@@ -52,7 +53,7 @@ class CreditCardFragment : Fragment(R.layout.credit_card_fragment) {
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
TemporaryScreenshotSecurity.bindToViewLifecycleOwner(this)
|
||||
InAppPaymentCheckoutDelegate.ErrorHandler().attach(this, null, args.inAppPaymentId)
|
||||
InAppPaymentCheckoutDelegate.ErrorHandler().attach(this, this, args.inAppPaymentId)
|
||||
|
||||
setFragmentResultListener(StripePaymentInProgressFragment.REQUEST_KEY) { _, bundle ->
|
||||
val result: InAppPaymentProcessorActionResult = bundle.getParcelableCompat(StripePaymentInProgressFragment.REQUEST_KEY, InAppPaymentProcessorActionResult::class.java)!!
|
||||
@@ -222,6 +223,14 @@ class CreditCardFragment : Fragment(R.layout.credit_card_fragment) {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onUserLaunchedAnExternalApplication() = Unit
|
||||
|
||||
override fun navigateToDonationPending(inAppPayment: InAppPaymentTable.InAppPayment) = Unit
|
||||
|
||||
override fun exitCheckoutFlow() {
|
||||
findNavController().popBackStack()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val REQUEST_KEY = "card.result"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user