Fix retry issue with payment processing.

This commit is contained in:
Alex Hart
2021-11-01 09:42:50 -03:00
committed by Greyson Parrelli
parent cf9b91ebd4
commit b0788f7307
7 changed files with 51 additions and 42 deletions

View File

@@ -6,6 +6,7 @@ import com.google.android.gms.wallet.PaymentData
import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.schedulers.Schedulers
import org.signal.core.util.logging.Log
import org.signal.core.util.money.FiatMoney
import org.signal.donations.GooglePayApi
import org.signal.donations.GooglePayPaymentSource
@@ -15,6 +16,7 @@ import org.thoughtcrime.securesms.jobs.BoostReceiptRequestResponseJob
import org.thoughtcrime.securesms.jobs.SubscriptionReceiptRequestResponseJob
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.storage.StorageSyncHelper
import org.thoughtcrime.securesms.subscription.LevelUpdate
import org.thoughtcrime.securesms.subscription.LevelUpdateOperation
import org.thoughtcrime.securesms.subscription.Subscriber
import org.thoughtcrime.securesms.util.Environment
@@ -142,7 +144,8 @@ class DonationPaymentRepository(activity: Activity) : StripeApi.PaymentIntentFet
levelUpdateOperation.idempotencyKey.serialize()
).flatMap(ServiceResponse<EmptyResponse>::flattenResult).ignoreElement().andThen {
SignalStore.donationsValues().clearUserManuallyCancelled()
SignalStore.donationsValues().clearLevelOperation(levelUpdateOperation)
SignalStore.donationsValues().clearLevelOperation()
LevelUpdate.updateProcessingState(false)
it.onComplete()
}.andThen {
val jobId = SubscriptionReceiptRequestResponseJob.enqueueSubscriptionContinuation()
@@ -164,6 +167,8 @@ class DonationPaymentRepository(activity: Activity) : StripeApi.PaymentIntentFet
it.onError(DonationExceptions.TimedOutWaitingForTokenRedemption)
}
}
}.doOnError {
LevelUpdate.updateProcessingState(false)
}.subscribeOn(Schedulers.io())
}
@@ -176,8 +181,10 @@ class DonationPaymentRepository(activity: Activity) : StripeApi.PaymentIntentFet
)
SignalStore.donationsValues().setLevelOperation(newOperation)
LevelUpdate.updateProcessingState(true)
newOperation
} else {
LevelUpdate.updateProcessingState(true)
levelUpdateOperation
}
}
@@ -206,4 +213,8 @@ class DonationPaymentRepository(activity: Activity) : StripeApi.PaymentIntentFet
ApplicationDependencies.getDonationsService().setDefaultPaymentMethodId(it.subscriberId, paymentMethodId)
}.flatMap(ServiceResponse<EmptyResponse>::flattenResult).ignoreElement()
}
companion object {
private val TAG = Log.tag(DonationPaymentRepository::class.java)
}
}

View File

@@ -193,6 +193,7 @@ class BoostFragment : DSLSettingsBottomSheetFragment(
dialog.dismiss()
findNavController().popBackStack()
}
.show()
} else {
Log.w(TAG, "Error occurred while processing payment", throwable)
MaterialAlertDialogBuilder(requireContext())
@@ -202,6 +203,7 @@ class BoostFragment : DSLSettingsBottomSheetFragment(
dialog.dismiss()
findNavController().popBackStack()
}
.show()
}
}
@@ -214,6 +216,7 @@ class BoostFragment : DSLSettingsBottomSheetFragment(
dialog.dismiss()
findNavController().popBackStack()
}
.show()
}
private fun startAnimationAboveSelectedBoost(view: View) {

View File

@@ -14,9 +14,8 @@ import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.components.settings.app.subscription.SubscriptionsRepository
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.subscription.LevelUpdateOperation
import org.thoughtcrime.securesms.subscription.LevelUpdate
import org.thoughtcrime.securesms.util.livedata.Store
import org.whispersystems.libsignal.util.guava.Optional
import org.whispersystems.signalservice.api.subscriptions.ActiveSubscription
class ManageDonationsViewModel(
@@ -43,11 +42,11 @@ class ManageDonationsViewModel(
fun refresh() {
disposables.clear()
val levelUpdateOperationEdges: Observable<Optional<LevelUpdateOperation>> = SignalStore.donationsValues().levelUpdateOperationObservable.distinctUntilChanged()
val levelUpdateOperationEdges: Observable<Boolean> = LevelUpdate.isProcessing.distinctUntilChanged()
val activeSubscription: Single<ActiveSubscription> = subscriptionsRepository.getActiveSubscription()
disposables += levelUpdateOperationEdges.flatMapSingle { optionalKey ->
if (optionalKey.isPresent) {
disposables += levelUpdateOperationEdges.flatMapSingle { isProcessing ->
if (isProcessing) {
Single.just(ManageDonationsState.TransactionState.InTransaction)
} else {
activeSubscription.map { ManageDonationsState.TransactionState.NotInTransaction(it) }

View File

@@ -241,6 +241,7 @@ class SubscribeFragment : DSLSettingsFragment(
requireActivity().finish()
requireActivity().startActivity(AppSettingsActivity.subscriptions(requireContext()))
}
.show()
} else {
Log.w(TAG, "Error occurred while processing payment", throwable)
MaterialAlertDialogBuilder(requireContext())
@@ -249,6 +250,7 @@ class SubscribeFragment : DSLSettingsFragment(
.setPositiveButton(android.R.string.ok) { dialog, _ ->
dialog.dismiss()
}
.show()
}
}
@@ -281,6 +283,7 @@ class SubscribeFragment : DSLSettingsFragment(
dialog.dismiss()
findNavController().popBackStack()
}
.show()
}
companion object {

View File

@@ -19,6 +19,7 @@ import org.thoughtcrime.securesms.components.settings.app.subscription.DonationP
import org.thoughtcrime.securesms.components.settings.app.subscription.SubscriptionsRepository
import org.thoughtcrime.securesms.components.settings.app.subscription.models.CurrencySelection
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.subscription.LevelUpdate
import org.thoughtcrime.securesms.subscription.Subscription
import org.thoughtcrime.securesms.util.livedata.Store
import org.whispersystems.signalservice.api.subscriptions.ActiveSubscription
@@ -51,10 +52,10 @@ class SubscribeViewModel(
val allSubscriptions: Observable<List<Subscription>> = currency.switchMapSingle { subscriptionsRepository.getSubscriptions(it) }
refreshActiveSubscription()
disposables += SignalStore.donationsValues().levelUpdateOperationObservable.subscribeBy {
disposables += LevelUpdate.isProcessing.subscribeBy {
store.update { state ->
state.copy(
hasInProgressSubscriptionTransaction = it.isPresent
hasInProgressSubscriptionTransaction = it
)
}
}
@@ -113,6 +114,7 @@ class SubscribeViewModel(
onComplete = {
eventPublisher.onNext(DonationEvent.SubscriptionCancelled)
SignalStore.donationsValues().setLastEndOfPeriod(0L)
SignalStore.donationsValues().clearLevelOperation()
SignalStore.donationsValues().markUserManuallyCancelled()
refreshActiveSubscription()
store.update { it.copy(stage = SubscribeState.Stage.READY) }