Take purchase token straight from payment result during linking to subscriber id.

This commit is contained in:
Alex Hart
2025-03-07 16:47:13 -04:00
committed by Greyson Parrelli
parent 1cc3e16d1a
commit 6d115a912d
4 changed files with 14 additions and 20 deletions

View File

@@ -218,10 +218,7 @@ class MessageBackupsFlowViewModel(
amount = paidFiat.toFiatValue(),
level = SubscriptionsConfiguration.BACKUPS_LEVEL.toLong(),
recipientId = Recipient.self().id.serialize(),
paymentMethodType = InAppPaymentData.PaymentMethodType.GOOGLE_PLAY_BILLING,
redemption = InAppPaymentData.RedemptionState(
stage = InAppPaymentData.RedemptionState.Stage.INIT
)
paymentMethodType = InAppPaymentData.PaymentMethodType.GOOGLE_PLAY_BILLING
)
)
@@ -261,11 +258,11 @@ class MessageBackupsFlowViewModel(
inAppPayment.copy(
state = InAppPaymentTable.State.PENDING,
subscriberId = InAppPaymentsRepository.requireSubscriber(InAppPaymentSubscriberRecord.Type.BACKUP).subscriberId,
data = inAppPayment.data.copy(
redemption = inAppPayment.data.redemption!!.copy(
googlePlayBillingPurchaseToken = result.purchaseToken
data = inAppPayment.data.newBuilder().redemption(
redemption = InAppPaymentData.RedemptionState(
stage = InAppPaymentData.RedemptionState.Stage.INIT
)
)
).build()
)
)

View File

@@ -13,7 +13,7 @@ import org.thoughtcrime.securesms.database.model.databaseprotos.InAppPaymentData
*/
class InAppPaymentError(
val inAppPaymentDataError: InAppPaymentData.Error
) : Exception() {
) : Exception(inAppPaymentDataError.toString()) {
companion object {
fun fromDonationError(donationError: DonationError): InAppPaymentError? {
val inAppPaymentDataError: InAppPaymentData.Error? = when (donationError) {

View File

@@ -92,12 +92,12 @@ class InAppPaymentPurchaseTokenJob private constructor(
return Result.failure()
}
val purchaseState: BillingPurchaseState = when (val purchase = AppDependencies.billingApi.queryPurchases()) {
is BillingPurchaseResult.Success -> purchase.purchaseState
else -> BillingPurchaseState.UNSPECIFIED
val purchase: BillingPurchaseResult = when (val purchase = AppDependencies.billingApi.queryPurchases()) {
is BillingPurchaseResult.Success -> purchase
else -> BillingPurchaseResult.None
}
if (purchaseState != BillingPurchaseState.PURCHASED) {
if (purchase !is BillingPurchaseResult.Success || purchase.purchaseState != BillingPurchaseState.PURCHASED) {
warning("Billing purchase not in the PURCHASED state. Retrying later.")
return Result.retry(defaultBackoff())
}
@@ -109,9 +109,12 @@ class InAppPaymentPurchaseTokenJob private constructor(
return Result.failure()
}
info("Attempting to link purchase token for purchase")
info("$purchase")
val response = AppDependencies.donationsService.linkGooglePlayBillingPurchaseTokenToSubscriberId(
inAppPayment.subscriberId!!,
inAppPayment.data.redemption!!.googlePlayBillingPurchaseToken!!,
purchase.purchaseToken,
InAppPaymentSubscriberRecord.Type.BACKUP.lock
)
@@ -158,11 +161,6 @@ class InAppPaymentPurchaseTokenJob private constructor(
throw IOException("InAppPayment has already started redemption.")
}
if (inAppPayment.data.redemption.googlePlayBillingPurchaseToken == null) {
warning("No purchase token for linking!")
throw IOException("InAppPayment does not have a purchase token!")
}
return inAppPayment
}

View File

@@ -377,7 +377,6 @@ message InAppPaymentData {
optional bool keepAlive = 3; // Only present for recurring donations, specifies this redemption started from a keep-alive
optional bytes receiptCredentialRequestContext = 4; // Reusable context for retrieving a presentation
optional bytes receiptCredentialPresentation = 5; // Redeemable presentation
optional string googlePlayBillingPurchaseToken = 6; // Only present for backups
}
message Error {