diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java index 5087f2916..801ad0071 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java @@ -614,6 +614,10 @@ public class SubscriptionController { public String returnUrl; @NotEmpty public String cancelUrl; + + public CreatePayPalBoostRequest() { + super.paymentMethod = PaymentMethod.PAYPAL; + } } record CreatePayPalBoostResponse(String approvalUrl, String paymentId) { diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java index a3a99a3ba..ada096048 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/SubscriptionControllerTest.java @@ -67,6 +67,7 @@ import org.whispersystems.textsecuregcm.mappers.SubscriptionProcessorExceptionMa import org.whispersystems.textsecuregcm.storage.IssuedReceiptsManager; import org.whispersystems.textsecuregcm.storage.SubscriptionManager; import org.whispersystems.textsecuregcm.subscriptions.BraintreeManager; +import org.whispersystems.textsecuregcm.subscriptions.BraintreeManager.PayPalOneTimePaymentApprovalDetails; import org.whispersystems.textsecuregcm.subscriptions.ChargeFailure; import org.whispersystems.textsecuregcm.subscriptions.PaymentMethod; import org.whispersystems.textsecuregcm.subscriptions.ProcessorCustomer; @@ -231,6 +232,30 @@ class SubscriptionControllerTest { assertThat(response.getStatus()).isEqualTo(200); } + @Test + void testCreateBoostPayPal() { + final PayPalOneTimePaymentApprovalDetails payPalOneTimePaymentApprovalDetails = mock(PayPalOneTimePaymentApprovalDetails.class); + when(BRAINTREE_MANAGER.getSupportedCurrenciesForPaymentMethod(PaymentMethod.PAYPAL)) + .thenReturn(Set.of("usd", "jpy", "bif", "eur")); + when(BRAINTREE_MANAGER.createOneTimePayment(anyString(), anyLong(), anyString(), anyString(), anyString())) + .thenReturn(CompletableFuture.completedFuture(payPalOneTimePaymentApprovalDetails)); + when(payPalOneTimePaymentApprovalDetails.approvalUrl()).thenReturn("approvalUrl"); + when(payPalOneTimePaymentApprovalDetails.paymentId()).thenReturn("someId"); + + final Response response = RESOURCE_EXTENSION.target("/v1/subscription/boost/paypal/create") + .request() + .post(Entity.json(""" + { + "currency": "USD", + "amount": 300, + "cancelUrl": "cancelUrl", + "returnUrl": "returnUrl" + } + """ + )); + assertThat(response.getStatus()).isEqualTo(200); + } + @Test void createBoostReceiptInvalid() { final Response response = RESOURCE_EXTENSION.target("/v1/subscription/boost/receipt_credentials")