mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 12:38:33 +00:00
Self-heal payment state transfer if onAdded fails to update as expected.
This commit is contained in:
committed by
Greyson Parrelli
parent
f9902bda67
commit
dce3dca9cc
@@ -99,6 +99,7 @@ class InAppPaymentOneTimeContextJob private constructor(
|
|||||||
|
|
||||||
override fun onAdded() {
|
override fun onAdded() {
|
||||||
val inAppPayment = SignalDatabase.inAppPayments.getById(inAppPaymentId)
|
val inAppPayment = SignalDatabase.inAppPayments.getById(inAppPaymentId)
|
||||||
|
info("Added context job for payment with state ${inAppPayment?.state}")
|
||||||
if (inAppPayment?.state == InAppPaymentTable.State.CREATED) {
|
if (inAppPayment?.state == InAppPaymentTable.State.CREATED) {
|
||||||
SignalDatabase.inAppPayments.update(
|
SignalDatabase.inAppPayments.update(
|
||||||
inAppPayment.copy(
|
inAppPayment.copy(
|
||||||
@@ -184,7 +185,12 @@ class InAppPaymentOneTimeContextJob private constructor(
|
|||||||
|
|
||||||
if (inAppPayment.state != InAppPaymentTable.State.PENDING) {
|
if (inAppPayment.state != InAppPaymentTable.State.PENDING) {
|
||||||
warning("Invalid state: ${inAppPayment.state} but expected PENDING")
|
warning("Invalid state: ${inAppPayment.state} but expected PENDING")
|
||||||
throw IOException("InAppPayment is in an invalid state")
|
|
||||||
|
if (inAppPayment.state == InAppPaymentTable.State.CREATED) {
|
||||||
|
warning("onAdded failed to update payment state to PENDING. Updating now as long as the payment is valid otherwise.")
|
||||||
|
} else {
|
||||||
|
throw IOException("InAppPayment is in an invalid state: ${inAppPayment.state}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inAppPayment.data.redemption == null) {
|
if (inAppPayment.data.redemption == null) {
|
||||||
@@ -207,6 +213,7 @@ class InAppPaymentOneTimeContextJob private constructor(
|
|||||||
} ?: InAppPaymentsRepository.generateRequestCredential()
|
} ?: InAppPaymentsRepository.generateRequestCredential()
|
||||||
|
|
||||||
val updatedPayment = inAppPayment.copy(
|
val updatedPayment = inAppPayment.copy(
|
||||||
|
state = InAppPaymentTable.State.PENDING,
|
||||||
data = inAppPayment.data.copy(
|
data = inAppPayment.data.copy(
|
||||||
redemption = inAppPayment.data.redemption.copy(
|
redemption = inAppPayment.data.redemption.copy(
|
||||||
stage = InAppPaymentData.RedemptionState.Stage.CONVERSION_STARTED,
|
stage = InAppPaymentData.RedemptionState.Stage.CONVERSION_STARTED,
|
||||||
|
|||||||
@@ -185,7 +185,12 @@ class InAppPaymentRecurringContextJob private constructor(
|
|||||||
|
|
||||||
if (inAppPayment.state != InAppPaymentTable.State.PENDING) {
|
if (inAppPayment.state != InAppPaymentTable.State.PENDING) {
|
||||||
warning("Unexpected state. Got ${inAppPayment.state} but expected PENDING")
|
warning("Unexpected state. Got ${inAppPayment.state} but expected PENDING")
|
||||||
throw IOException("InAppPayment in unexpected state.")
|
|
||||||
|
if (inAppPayment.state == InAppPaymentTable.State.CREATED) {
|
||||||
|
warning("onAdded failed to update payment state to PENDING. Updating now as long as the payment is valid otherwise.")
|
||||||
|
} else {
|
||||||
|
throw IOException("InAppPayment is in an invalid state: ${inAppPayment.state}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inAppPayment.type.recurring) {
|
if (!inAppPayment.type.recurring) {
|
||||||
@@ -211,6 +216,7 @@ class InAppPaymentRecurringContextJob private constructor(
|
|||||||
return if (inAppPayment.data.redemption.receiptCredentialRequestContext == null) {
|
return if (inAppPayment.data.redemption.receiptCredentialRequestContext == null) {
|
||||||
val requestContext = InAppPaymentsRepository.generateRequestCredential()
|
val requestContext = InAppPaymentsRepository.generateRequestCredential()
|
||||||
val updatedPayment = inAppPayment.copy(
|
val updatedPayment = inAppPayment.copy(
|
||||||
|
state = InAppPaymentTable.State.PENDING,
|
||||||
data = inAppPayment.data.copy(
|
data = inAppPayment.data.copy(
|
||||||
redemption = inAppPayment.data.redemption.copy(
|
redemption = inAppPayment.data.redemption.copy(
|
||||||
stage = InAppPaymentData.RedemptionState.Stage.CONVERSION_STARTED,
|
stage = InAppPaymentData.RedemptionState.Stage.CONVERSION_STARTED,
|
||||||
|
|||||||
Reference in New Issue
Block a user