From 18e58dd21f51c5db88735cb4820f5c9a028c63ca Mon Sep 17 00:00:00 2001 From: Ravi Khadiwala Date: Mon, 31 Aug 2026 15:47:45 -0500 Subject: [PATCH] Improve error response documentation in subscription.proto --- .../grpc/SubscriptionsGrpcService.java | 29 +++++----- .../storage/SubscriptionManager.java | 10 ++-- .../org/signal/chat/one_time_donations.proto | 5 +- .../proto/org/signal/chat/subscriptions.proto | 54 ++++++++++++++----- 4 files changed, 65 insertions(+), 33 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/SubscriptionsGrpcService.java b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/SubscriptionsGrpcService.java index 4f57c88fb..002069552 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/SubscriptionsGrpcService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/SubscriptionsGrpcService.java @@ -267,22 +267,26 @@ public class SubscriptionsGrpcService extends SimpleSubscriptionsGrpc.Subscripti }; final Subscriptions.Record record = subscriptionManager.getSubscriber(subscriberCredentials); - return record.getProcessorCustomer().map( - processorCustomer -> setDefaultPaymentMethodForCustomer(manager, processorCustomer, paymentMethodId, - record.subscriptionId)).orElseGet(() -> + return record.getProcessorCustomer() + .map(processorCustomer -> + setDefaultPaymentMethodForCustomer(manager, processorCustomer, paymentMethodId, record.subscriptionId)) // a missing customer ID indicates the client made requests out of order, // and needs to call create_payment_method to create a customer for the given payment method - SetDefaultPaymentMethodResponse.newBuilder().setPaymentMethodNotSetUp(FailedPrecondition.newBuilder().build()) + .orElseGet(() -> SetDefaultPaymentMethodResponse.newBuilder() + .setPaymentMethodNotSetUp(FailedPrecondition.newBuilder().build()) .build()); } catch (final SubscriptionNotFoundException e) { return SetDefaultPaymentMethodResponse.newBuilder().setSubscriberNotFound(NotFound.newBuilder().build()).build(); } catch (final SubscriptionForbiddenException e) { - return SetDefaultPaymentMethodResponse.newBuilder().setSubscriberIdMismatch( - FailedUnidentifiedAuthorization.newBuilder().setDescription(e.errorDetail().orElse("")).build()).build(); + return SetDefaultPaymentMethodResponse.newBuilder() + .setSubscriberIdMismatch(FailedUnidentifiedAuthorization.newBuilder() + .setDescription(e.errorDetail().orElse("")) + .build()) + .build(); } catch (final SubscriptionProcessorConflictException e) { return SetDefaultPaymentMethodResponse.newBuilder() - .setSubscriptionProcessorConflict( - FailedPrecondition.newBuilder().setDescription(e.errorDetail().orElse("")).build()).build(); + .setPaymentMethodNotSetUp(FailedPrecondition.newBuilder().build()) + .build(); } } @@ -310,10 +314,11 @@ public class SubscriptionsGrpcService extends SimpleSubscriptionsGrpc.Subscripti request.getSubscriberId().toByteArray(), clock); try { final Subscriptions.Record record = subscriptionManager.getSubscriber(subscriberCredentials); - return record.getProcessorCustomer().map( - processorCustomer -> setSubscriptionLevelForCustomer(processorCustomer, subscriberCredentials, record, - request)).orElseGet(() -> SetSubscriptionLevelResponse.newBuilder() - .setPaymentMethodNotSetUp(FailedPrecondition.newBuilder().build()).build()); + return record.getProcessorCustomer().map(processorCustomer -> + setSubscriptionLevelForCustomer(processorCustomer, subscriberCredentials, record, request)) + .orElseGet(() -> SetSubscriptionLevelResponse.newBuilder() + .setPaymentMethodNotSetUp(FailedPrecondition.newBuilder().build()) + .build()); } catch (final SubscriptionNotFoundException e) { return SetSubscriptionLevelResponse.newBuilder().setSubscriberNotFound(NotFound.newBuilder().build()).build(); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/SubscriptionManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/SubscriptionManager.java index 5508dd2b6..23662d275 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/SubscriptionManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/SubscriptionManager.java @@ -248,8 +248,7 @@ public class SubscriptionManager { * @param An exception thrown by the paymentSetupFunction * @return The return value of the paymentSetupFunction * @throws SubscriptionForbiddenException if the subscriber credentials were incorrect - * @throws SubscriptionNotFoundException if the subscriber did not exist or did not have a subscription - * attached + * @throws SubscriptionNotFoundException if the subscriber did not exist * @throws SubscriptionProcessorConflictException if the new payment processor does not match the existing processor associated with * the subscriberId */ @@ -373,8 +372,8 @@ public class SubscriptionManager { * play store * @return the subscription level for the accepted subscription * @throws SubscriptionForbiddenException if the subscriber credentials were incorrect - * @throws SubscriptionNotFoundException if the subscriber did not exist or did not have a subscription - * attached + * @throws SubscriptionNotFoundException if the subscriber did not exist, or the purchaseToken was not found + * in the play store * @throws SubscriptionProcessorConflictException if the new payment processor does not match the existing processor associated with * the subscriberId * @throws SubscriptionPaymentRequiredException if the subscription is not in a state that grants the user an @@ -426,7 +425,8 @@ public class SubscriptionManager { * the app store * @return the subscription level for the accepted subscription * @throws SubscriptionForbiddenException if the subscriber credentials are incorrect - * @throws SubscriptionNotFoundException if the originalTransactionId does not exist + * @throws SubscriptionNotFoundException if the subscriber did not exist, or the originalTransactionId does + * not exist * @throws SubscriptionProcessorConflictException if the new payment processor does not match the existing processor associated with * the subscriber * @throws SubscriptionInvalidArgumentsException if the originalTransactionId is malformed or does not represent a diff --git a/service/src/main/proto/org/signal/chat/one_time_donations.proto b/service/src/main/proto/org/signal/chat/one_time_donations.proto index 8ab95ff68..de5abcde7 100644 --- a/service/src/main/proto/org/signal/chat/one_time_donations.proto +++ b/service/src/main/proto/org/signal/chat/one_time_donations.proto @@ -29,8 +29,9 @@ service OneTimeDonations { // Once the payment is complete, call ConfirmPayPalBoost with the payment ID // and token. // - // The presented billing agreement may be localized. Callers should set their - // language preferences via an "Accept-Language" header on the request: + // The PayPal approval page presented to the user may be localized. Callers + // should set their language preferences via an "Accept-Language" header on + // the request: // https://datatracker.ietf.org/doc/html/rfc3282#section-3 rpc CreatePayPalBoost(CreatePayPalBoostRequest) returns (CreatePayPalBoostResponse) {} diff --git a/service/src/main/proto/org/signal/chat/subscriptions.proto b/service/src/main/proto/org/signal/chat/subscriptions.proto index 5948c1bb1..957705e87 100644 --- a/service/src/main/proto/org/signal/chat/subscriptions.proto +++ b/service/src/main/proto/org/signal/chat/subscriptions.proto @@ -124,7 +124,8 @@ message UpdateSubscriberRequest { message UpdateSubscriberResponse { oneof response { google.protobuf.Empty success = 1; - // subscriberId authentication failure + // The subscriber-key embedded in the subscriber-id did not match the stored + // key for the subscriber-user embedded in the subscriber-id errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 2 [(tag.reason) = "subscriber_id_mismatch"]; // The donation permit was expired or already spent errors.FailedZkAuthentication permit_rejected = 3 [(tag.reason) = "permit_rejected"]; @@ -138,6 +139,7 @@ message DeleteSubscriberRequest { message DeleteSubscriberResponse { oneof response { google.protobuf.Empty success = 1; + // The subscriber did not exist errors.NotFound subscriber_not_found = 2 [(tag.reason) = "subscriber_not_found"]; // The associated subscription is not a type that can be cancelled by the server. Cancel client-side, and then retry. errors.FailedPrecondition cannot_cancel_subscription = 3 [(tag.reason) = "cannot_cancel_subscription"]; @@ -197,10 +199,13 @@ message CreatePaymentMethodResponse { oneof response { CreatePaymentMethodResult result = 1; + // The subscriber did not exist errors.NotFound subscriber_not_found = 2 [(tag.reason) = "subscriber_not_found"]; - // subscriberId authentication failure + // The subscriber-key embedded in the subscriber-id did not match the stored + // key for the subscriber-user embedded in the subscriber-id errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 3 [(tag.reason) = "subscriber_id_mismatch"]; - // New payment processor does not match existing processor associated with the subscription + // New payment processor does not match existing processor associated with + // the subscription errors.FailedPrecondition subscription_processor_conflict = 4 [(tag.reason) = "subscription_processor_conflict"]; // The donation permit was expired or already spent errors.FailedZkAuthentication permit_rejected = 5 [(tag.reason) = "permit_rejected"]; @@ -225,10 +230,13 @@ message CreatePayPalPaymentMethodResponse { oneof response { CreatePayPalPaymentMethodResult result = 1; + // The subscriber did not exist errors.NotFound subscriber_not_found = 2 [(tag.reason) = "subscriber_not_found"]; - // subscriberId authentication failure + // The subscriber-key embedded in the subscriber-id did not match the stored + // key for the subscriber-user embedded in the subscriber-id errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 3 [(tag.reason) = "subscriber_id_mismatch"]; - // New payment processor does not match existing processor associated with the subscription + // New payment processor does not match existing processor associated with + // the subscription errors.FailedPrecondition subscription_processor_conflict = 4 [(tag.reason) = "subscription_processor_conflict"]; } } @@ -255,12 +263,14 @@ message SetDefaultPaymentMethodRequest { message SetDefaultPaymentMethodResponse { oneof response { google.protobuf.Empty success = 1; + // The subscriber did not exist, or the referenced setup intent was not found errors.NotFound subscriber_not_found = 2 [(tag.reason) = "subscriber_not_found"]; - // subscriberId authentication failure + // The subscriber-key embedded in the subscriber-id did not match the stored + // key for the subscriber-user embedded in the subscriber-id errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 3 [(tag.reason) = "subscriber_id_mismatch"]; + // No payment method has been created for the subscriber, or the provided + // payment method has not finished being set up with the processor errors.FailedPrecondition payment_method_not_set_up = 4 [(tag.reason) = "payment_method_not_set_up"]; - // Payment processor does not match existing processor associated with the subscription - errors.FailedPrecondition subscription_processor_conflict = 5 [(tag.reason) = "subscription_processor_conflict"]; } } @@ -315,11 +325,15 @@ message SetSubscriptionLevelResponse { oneof response { SetSubscriptionLevelResult success = 1; + // The subscriber did not exist errors.NotFound subscriber_not_found = 2 [(tag.reason) = "subscriber_not_found"]; - // subscriberId authentication failure + // The subscriber-key embedded in the subscriber-id did not match the stored + // key for the subscriber-user embedded in the subscriber-id errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 3 [(tag.reason) = "subscriber_id_mismatch"]; - // New payment processor does not match existing processor associated with the subscription + // New payment processor does not match existing processor associated with + // the subscription errors.FailedPrecondition subscription_processor_conflict = 4 [(tag.reason) = "subscription_processor_conflict"]; + // No payment method has been created for the subscriber errors.FailedPrecondition payment_method_not_set_up = 5 [(tag.reason) = "payment_method_not_set_up"]; // The payment processor does not support this operation errors.FailedPrecondition unsupported_operation = 6 [(tag.reason) = "unsupported_operation"]; @@ -360,12 +374,19 @@ message SetIapSubscriptionResponse { oneof response { SetIapSubscriptionResult success = 1; + // The subscriber did not exist or the provided purchase identifier does not exist errors.NotFound subscriber_not_found = 2 [(tag.reason) = "subscriber_not_found"]; - // subscriberId authentication failure + // The subscriber-key embedded in the subscriber-id did not match the stored + // key for the subscriber-user embedded in the subscriber-id errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 3 [(tag.reason) = "subscriber_id_mismatch"]; - // New payment processor does not match existing processor associated with the subscription + // New payment processor does not match existing processor associated with + // the subscription errors.FailedPrecondition subscription_processor_conflict = 4 [(tag.reason) = "subscription_processor_conflict"]; + // The subscription is not in a purchase state that grants the user an + // entitlement errors.FailedPrecondition payment_required = 5 [(tag.reason) = "payment_required"]; + // The provided purchase identifier is malformed or the identified + // transaction is not supported for use at this endpoint errors.FailedPrecondition invalid_transaction = 6 [(tag.reason) = "invalid_transaction"]; } } @@ -382,8 +403,10 @@ message GetReceiptCredentialsResponse { oneof response { GetReceiptCredentialsResult success = 1; + // The subscriber did not exist or it did not have an associated subscription errors.NotFound subscriber_not_found = 2 [(tag.reason) = "subscriber_not_found"]; - // subscriberId authentication failure + // The subscriber-key embedded in the subscriber-id did not match the stored + // key for the subscriber-user embedded in the subscriber-id errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 3 [(tag.reason) = "subscriber_id_mismatch"]; // No invoice has been issued for this subscription OR invoice is in 'draft' or 'open' state errors.FailedPrecondition no_paid_invoice = 4 [(tag.reason) = "no_paid_invoice"]; @@ -428,9 +451,12 @@ message GetSubscriptionInformationResponse { oneof response { Subscription success = 1; + // The subscriber exists but has no subscription with a payment processor google.protobuf.Empty no_subscription = 2; + // The subscriber did not exist errors.NotFound subscriber_not_found = 3 [(tag.reason) = "subscriber_not_found"]; - // subscriberId authentication failure + // The subscriber-key embedded in the subscriber-id did not match the stored + // key for the subscriber-user embedded in the subscriber-id errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 4 [(tag.reason) = "subscriber_id_mismatch"]; } }