Rename DonationErrorSource value to ONE_TIME and document.

This commit is contained in:
Alex Hart
2023-10-16 15:14:00 -03:00
committed by Cody Henthorne
parent 073e138ab2
commit 940e67b1ca
11 changed files with 40 additions and 15 deletions

View File

@@ -40,7 +40,7 @@ class OneTimeDonationRepository(private val donationsService: DonationsService)
Single.error(throwable)
} else {
val recipient = Recipient.resolved(badgeRecipient)
val errorSource = if (recipient.isSelf) DonationErrorSource.BOOST else DonationErrorSource.GIFT
val errorSource = if (recipient.isSelf) DonationErrorSource.ONE_TIME else DonationErrorSource.GIFT
Single.error(DonationError.getPaymentSetupError(errorSource, throwable, paymentSourceType))
}
}
@@ -115,7 +115,7 @@ class OneTimeDonationRepository(private val donationsService: DonationsService)
): Completable {
val isLongRunning = paymentSourceType == PaymentSourceType.Stripe.SEPADebit
val isBoost = gatewayRequest.recipientId == Recipient.self().id
val donationErrorSource: DonationErrorSource = if (isBoost) DonationErrorSource.BOOST else DonationErrorSource.GIFT
val donationErrorSource: DonationErrorSource = if (isBoost) DonationErrorSource.ONE_TIME else DonationErrorSource.GIFT
val waitOnRedemption = Completable.create {
val donationReceiptRecord = if (isBoost) {

View File

@@ -101,7 +101,7 @@ class StripeRepository(activity: Activity) : StripeApi.PaymentIntentFetcher, Str
}
.flatMap { result ->
val recipient = Recipient.resolved(badgeRecipient)
val errorSource = if (recipient.isSelf) DonationErrorSource.BOOST else DonationErrorSource.GIFT
val errorSource = if (recipient.isSelf) DonationErrorSource.ONE_TIME else DonationErrorSource.GIFT
Log.d(TAG, "Created payment intent for $price.", true)
when (result) {
@@ -131,7 +131,7 @@ class StripeRepository(activity: Activity) : StripeApi.PaymentIntentFetcher, Str
badgeRecipient: RecipientId
): Single<StripeApi.Secure3DSAction> {
val isBoost = badgeRecipient == Recipient.self().id
val donationErrorSource: DonationErrorSource = if (isBoost) DonationErrorSource.BOOST else DonationErrorSource.GIFT
val donationErrorSource: DonationErrorSource = if (isBoost) DonationErrorSource.ONE_TIME else DonationErrorSource.GIFT
Log.d(TAG, "Confirming payment intent...", true)
return stripeApi.confirmPaymentIntent(paymentSource, paymentIntent)

View File

@@ -106,7 +106,7 @@ class DonateToSignalFragment :
}
override fun bindAdapter(adapter: MappingAdapter) {
donationCheckoutDelegate = DonationCheckoutDelegate(this, this, viewModel.uiSessionKey, DonationErrorSource.BOOST, DonationErrorSource.SUBSCRIPTION)
donationCheckoutDelegate = DonationCheckoutDelegate(this, this, viewModel.uiSessionKey, DonationErrorSource.ONE_TIME, DonationErrorSource.SUBSCRIPTION)
val recyclerView = this.recyclerView!!
recyclerView.overScrollMode = RecyclerView.OVER_SCROLL_IF_CONTENT_SCROLLS

View File

@@ -12,7 +12,7 @@ enum class DonateToSignalType(val requestCode: Short) : Parcelable {
fun toErrorSource(): DonationErrorSource {
return when (this) {
ONE_TIME -> DonationErrorSource.BOOST
ONE_TIME -> DonationErrorSource.ONE_TIME
MONTHLY -> DonationErrorSource.SUBSCRIPTION
GIFT -> DonationErrorSource.GIFT
}

View File

@@ -200,7 +200,7 @@ class DonationCheckoutDelegate(
val error = DonationError.getGooglePayRequestTokenError(
source = when (request.donateToSignalType) {
DonateToSignalType.MONTHLY -> DonationErrorSource.SUBSCRIPTION
DonateToSignalType.ONE_TIME -> DonationErrorSource.BOOST
DonateToSignalType.ONE_TIME -> DonationErrorSource.ONE_TIME
DonateToSignalType.GIFT -> DonationErrorSource.GIFT
},
throwable = googlePayException

View File

@@ -50,7 +50,7 @@ class CreditCardFragment : Fragment(R.layout.credit_card_fragment) {
TemporaryScreenshotSecurity.bindToViewLifecycleOwner(this)
val errorSource: DonationErrorSource = when (args.request.donateToSignalType) {
DonateToSignalType.ONE_TIME -> DonationErrorSource.BOOST
DonateToSignalType.ONE_TIME -> DonationErrorSource.ONE_TIME
DonateToSignalType.MONTHLY -> DonationErrorSource.SUBSCRIPTION
DonateToSignalType.GIFT -> DonationErrorSource.GIFT
}

View File

@@ -73,7 +73,7 @@ class StripePaymentInProgressViewModel(
Log.d(TAG, "Proceeding with donation...", true)
val errorSource = when (request.donateToSignalType) {
DonateToSignalType.ONE_TIME -> DonationErrorSource.BOOST
DonateToSignalType.ONE_TIME -> DonationErrorSource.ONE_TIME
DonateToSignalType.MONTHLY -> DonationErrorSource.SUBSCRIPTION
DonateToSignalType.GIFT -> DonationErrorSource.GIFT
}

View File

@@ -92,7 +92,7 @@ class BankTransferDetailsFragment : ComposeFragment(), DonationCheckoutDelegate.
TemporaryScreenshotSecurity.bindToViewLifecycleOwner(this)
val errorSource: DonationErrorSource = when (args.request.donateToSignalType) {
DonateToSignalType.ONE_TIME -> DonationErrorSource.BOOST
DonateToSignalType.ONE_TIME -> DonationErrorSource.ONE_TIME
DonateToSignalType.MONTHLY -> DonationErrorSource.SUBSCRIPTION
DonateToSignalType.GIFT -> DonationErrorSource.GIFT
}

View File

@@ -1,11 +1,36 @@
package org.thoughtcrime.securesms.components.settings.app.subscription.errors
/**
* Descriptor of where an error originated from.
*/
enum class DonationErrorSource(private val code: String) {
BOOST("boost"),
/**
* Refers to a one-time donation where the user paying receives a badge immediately.
*/
ONE_TIME("boost"),
/**
* Refers to a recurring monthly donation where the user paying receives a badge immediately
* and upon each renewal period.
*/
SUBSCRIPTION("subscription"),
/**
* Refers to a one-time donation where the user pays to send a badge to another individual.
*/
GIFT("gift"),
/**
* Refers to when the individual who received a gift token is redeeming it for a badge.
*/
GIFT_REDEMPTION("gift-redemption"),
/**
* Refers to the monthly keep-alive job for an active monthly subscriber, which is started in
* the background as needed.
*/
KEEP_ALIVE("keep-alive"),
UNKNOWN("unknown");
fun serialize(): String = code

View File

@@ -65,7 +65,7 @@ public class BoostReceiptRequestResponseJob extends BaseJob {
private final boolean isLongRunningDonationPaymentType;
private static String resolveQueue(DonationErrorSource donationErrorSource, boolean isLongRunning) {
String baseQueue = donationErrorSource == DonationErrorSource.BOOST ? BOOST_QUEUE : GIFT_QUEUE;
String baseQueue = donationErrorSource == DonationErrorSource.ONE_TIME ? BOOST_QUEUE : GIFT_QUEUE;
return isLongRunning ? baseQueue + LONG_RUNNING_SUFFIX : baseQueue;
}
@@ -97,7 +97,7 @@ public class BoostReceiptRequestResponseJob extends BaseJob {
long uiSessionKey,
boolean isLongRunning)
{
BoostReceiptRequestResponseJob requestReceiptJob = createJob(paymentIntentId, DonationErrorSource.BOOST, Long.parseLong(SubscriptionLevels.BOOST_LEVEL), donationProcessor, uiSessionKey, isLongRunning);
BoostReceiptRequestResponseJob requestReceiptJob = createJob(paymentIntentId, DonationErrorSource.ONE_TIME, Long.parseLong(SubscriptionLevels.BOOST_LEVEL), donationProcessor, uiSessionKey, isLongRunning);
DonationReceiptRedemptionJob redeemReceiptJob = DonationReceiptRedemptionJob.createJobForBoost(uiSessionKey, isLongRunning);
RefreshOwnProfileJob refreshOwnProfileJob = RefreshOwnProfileJob.forBoost();
MultiDeviceProfileContentUpdateJob multiDeviceProfileContentUpdateJob = new MultiDeviceProfileContentUpdateJob();
@@ -319,7 +319,7 @@ public class BoostReceiptRequestResponseJob extends BaseJob {
JsonJobData data = JsonJobData.deserialize(serializedData);
String paymentIntentId = data.getString(DATA_PAYMENT_INTENT_ID);
DonationErrorSource donationErrorSource = DonationErrorSource.deserialize(data.getStringOrDefault(DATA_ERROR_SOURCE, DonationErrorSource.BOOST.serialize()));
DonationErrorSource donationErrorSource = DonationErrorSource.deserialize(data.getStringOrDefault(DATA_ERROR_SOURCE, DonationErrorSource.ONE_TIME.serialize()));
long badgeLevel = data.getLongOrDefault(DATA_BADGE_LEVEL, Long.parseLong(SubscriptionLevels.BOOST_LEVEL));
String rawDonationProcessor = data.getStringOrDefault(DATA_DONATION_PROCESSOR, DonationProcessor.STRIPE.getCode());
DonationProcessor donationProcessor = DonationProcessor.fromCode(rawDonationProcessor);

View File

@@ -78,7 +78,7 @@ public class DonationReceiptRedemptionJob extends BaseJob {
return new DonationReceiptRedemptionJob(
NO_ID,
false,
DonationErrorSource.BOOST,
DonationErrorSource.ONE_TIME,
uiSessionKey,
isLongRunningDonationPaymentType,
new Job.Parameters