Implement pending one-time donation error handling.

This commit is contained in:
Alex Hart
2023-10-23 12:50:54 -04:00
committed by GitHub
parent d497ed4195
commit 10eec025d2
19 changed files with 615 additions and 22 deletions

View File

@@ -113,6 +113,7 @@ import org.whispersystems.signalservice.internal.contacts.entities.KeyBackupResp
import org.whispersystems.signalservice.internal.contacts.entities.TokenResponse;
import org.whispersystems.signalservice.internal.crypto.AttachmentDigest;
import org.whispersystems.signalservice.internal.push.exceptions.DonationProcessorError;
import org.whispersystems.signalservice.internal.push.exceptions.DonationReceiptCredentialError;
import org.whispersystems.signalservice.internal.push.exceptions.ForbiddenException;
import org.whispersystems.signalservice.internal.push.exceptions.GroupExistsException;
import org.whispersystems.signalservice.internal.push.exceptions.GroupMismatchedDevicesException;
@@ -1174,6 +1175,16 @@ public class PushServiceSocket {
NO_HEADERS,
(code, body) -> {
if (code == 204) throw new NonSuccessfulResponseCodeException(204);
if (code == 402) {
DonationReceiptCredentialError donationReceiptCredentialError;
try {
donationReceiptCredentialError = JsonUtil.fromJson(body.string(), DonationReceiptCredentialError.class);
} catch (IOException e) {
throw new NonSuccessfulResponseCodeException(402);
}
throw donationReceiptCredentialError;
}
});
ReceiptCredentialResponseJson responseJson = JsonUtil.fromJson(response, ReceiptCredentialResponseJson.class);
@@ -2668,11 +2679,14 @@ public class PushServiceSocket {
}
if (responseCode == 440) {
DonationProcessorError exception;
try {
throw JsonUtil.fromJson(body.string(), DonationProcessorError.class);
exception = JsonUtil.fromJson(body.string(), DonationProcessorError.class);
} catch (IOException e) {
throw new NonSuccessfulResponseCodeException(440);
}
throw exception;
} else {
throw new NonSuccessfulResponseCodeException(responseCode);
}

View File

@@ -0,0 +1,25 @@
/*
* Copyright 2023 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.signalservice.internal.push.exceptions
import com.fasterxml.jackson.annotation.JsonCreator
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException
import org.whispersystems.signalservice.api.subscriptions.ActiveSubscription.ChargeFailure
/**
* HTTP 402 Exception when trying to submit credentials for a donation with
* a failed payment.
*/
class DonationReceiptCredentialError @JsonCreator constructor(
val chargeFailure: ChargeFailure
) : NonSuccessfulResponseCodeException(402) {
override fun toString(): String {
return """
DonationReceiptCredentialError (402)
Charge Failure: $chargeFailure
""".trimIndent()
}
}