Fully allow donations from linked devices.

This commit is contained in:
Alex Hart
2026-08-11 16:59:14 -03:00
parent 52eff4aa29
commit a3f0f08491
2 changed files with 33 additions and 2 deletions
@@ -154,9 +154,9 @@ class InAppPaymentRecurringContextJob private constructor(
throw Exception("Unregistered users cannot perform this job.")
}
if (SignalStore.account.isLinkedDevice) {
if (SignalStore.account.isLinkedDevice && SignalDatabase.inAppPayments.getById(inAppPaymentId)?.type == InAppPaymentType.RECURRING_BACKUP) {
warning("Linked device. Failing.")
throw Exception("Linked devices cannot not perform this job")
throw Exception("Linked devices cannot perform this job for backups")
}
val (inAppPayment, requestContext) = getAndValidateInAppPayment()
@@ -171,6 +171,37 @@ class InAppPaymentRecurringContextJobTest {
assertThat(result.isSuccess).isTrue()
}
@Test
fun `Given a linked device, when I run for a donation, then I expect success`() {
every { mockSignalStore.account.isLinkedDevice } returns true
val activeSubscription = inAppPaymentsTestRule.createActiveSubscription()
inAppPaymentsTestRule.initializeActiveSubscriptionMock(activeSubscription = activeSubscription)
val iap = insertInAppPayment()
val job = InAppPaymentRecurringContextJob.create(iap)
job.onAdded()
val result = job.run()
assertThat(result.isSuccess).isTrue()
}
@Test
fun `Given a linked device, when I run for a backup, then I expect failure`() {
every { mockSignalStore.account.isLinkedDevice } returns true
val activeSubscription = inAppPaymentsTestRule.createActiveSubscription()
inAppPaymentsTestRule.initializeActiveSubscriptionMock(activeSubscription = activeSubscription)
val iap = insertInAppPayment(type = InAppPaymentType.RECURRING_BACKUP)
val job = InAppPaymentRecurringContextJob.create(iap)
job.onAdded()
val result = job.run()
assertThat(result.isFailure).isTrue()
verify(atLeast = 0, atMost = 0) { AppDependencies.donationsService.submitReceiptCredentialRequestSync(any(), any()) }
}
@Test
fun `Given END state, when I run, then I expect failure`() {
val iap = insertInAppPayment(