From 8a9f6356cb2b13263b5b589357f064ba5c965d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20Rodr=C3=ADguez?= <127134616+armando-rodriguez-cko@users.noreply.github.com> Date: Tue, 30 Jul 2024 18:43:18 +0200 Subject: [PATCH 1/2] Fix account holder payment context source --- .../com/checkout/common/AccountHolder.java | 17 ++++--- .../PaymentContextDetailsResponse.java | 1 - .../contexts/PaymentContextsResponse.java | 7 +++ ...AbstractPaymentContextsResponseSource.java | 15 +++++- .../PaymentContextsKlarnaResponseSource.java | 13 +++-- .../PaymentContextsPayPalResponseSource.java | 13 +++-- .../java/com/checkout/GsonSerializerTest.java | 13 +++++ ...yment_context_paypal_details_response.json | 50 +++++++++++++++++++ 8 files changed, 112 insertions(+), 17 deletions(-) create mode 100644 src/test/resources/mocks/payments/response/contexts/payment_context_paypal_details_response.json diff --git a/src/main/java/com/checkout/common/AccountHolder.java b/src/main/java/com/checkout/common/AccountHolder.java index d907a4e7..3d0ff795 100644 --- a/src/main/java/com/checkout/common/AccountHolder.java +++ b/src/main/java/com/checkout/common/AccountHolder.java @@ -14,12 +14,22 @@ public final class AccountHolder { private AccountHolderType type; + @SerializedName("full_name") + private String fullName; + @SerializedName("first_name") private String firstName; + @SerializedName("middle_name") + private String middleName; + @SerializedName("last_name") private String lastName; + private String email; + + private String gender; + @SerializedName("company_name") private String companyName; @@ -42,11 +52,4 @@ public final class AccountHolder { private AccountHolderIdentification identification; - private String email; - - private String gender; - - @SerializedName("middle_name") - private String middleName; - } diff --git a/src/main/java/com/checkout/payments/contexts/PaymentContextDetailsResponse.java b/src/main/java/com/checkout/payments/contexts/PaymentContextDetailsResponse.java index 7ec96ef0..97d7280a 100644 --- a/src/main/java/com/checkout/payments/contexts/PaymentContextDetailsResponse.java +++ b/src/main/java/com/checkout/payments/contexts/PaymentContextDetailsResponse.java @@ -10,7 +10,6 @@ @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -@NoArgsConstructor public final class PaymentContextDetailsResponse extends HttpMetadata { private PaymentContextDetailsStatusType status; diff --git a/src/main/java/com/checkout/payments/contexts/PaymentContextsResponse.java b/src/main/java/com/checkout/payments/contexts/PaymentContextsResponse.java index 155f431b..7b3446fe 100644 --- a/src/main/java/com/checkout/payments/contexts/PaymentContextsResponse.java +++ b/src/main/java/com/checkout/payments/contexts/PaymentContextsResponse.java @@ -1,8 +1,15 @@ package com.checkout.payments.contexts; import com.checkout.payments.response.source.contexts.ResponseSource; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) public final class PaymentContextsResponse extends PaymentContexts { private ResponseSource source; + } diff --git a/src/main/java/com/checkout/payments/response/source/contexts/AbstractPaymentContextsResponseSource.java b/src/main/java/com/checkout/payments/response/source/contexts/AbstractPaymentContextsResponseSource.java index 0870c7b5..7b9f9c27 100644 --- a/src/main/java/com/checkout/payments/response/source/contexts/AbstractPaymentContextsResponseSource.java +++ b/src/main/java/com/checkout/payments/response/source/contexts/AbstractPaymentContextsResponseSource.java @@ -1,10 +1,23 @@ package com.checkout.payments.response.source.contexts; +import com.checkout.accounts.payout.schedule.ScheduleFrequency; +import com.checkout.common.AccountHolder; import com.checkout.common.PaymentSourceType; +import com.google.gson.annotations.SerializedName; import lombok.Data; +import lombok.ToString; @Data +@ToString(callSuper = true) public abstract class AbstractPaymentContextsResponseSource { - public PaymentSourceType type; + private final PaymentSourceType type; + + @SerializedName("account_holder") + protected AccountHolder accountHolder; + + protected AbstractPaymentContextsResponseSource(final PaymentSourceType type) { + this.type = type; + } + } diff --git a/src/main/java/com/checkout/payments/response/source/contexts/PaymentContextsKlarnaResponseSource.java b/src/main/java/com/checkout/payments/response/source/contexts/PaymentContextsKlarnaResponseSource.java index 25b3a1b9..8bf76761 100644 --- a/src/main/java/com/checkout/payments/response/source/contexts/PaymentContextsKlarnaResponseSource.java +++ b/src/main/java/com/checkout/payments/response/source/contexts/PaymentContextsKlarnaResponseSource.java @@ -1,14 +1,19 @@ package com.checkout.payments.response.source.contexts; -import lombok.Data; +import com.checkout.common.PaymentSourceType; import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; +import lombok.Getter; +import lombok.Setter; import lombok.ToString; -@Data +@Getter +@Setter @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -@NoArgsConstructor public final class PaymentContextsKlarnaResponseSource extends AbstractPaymentContextsResponseSource implements ResponseSource { + public PaymentContextsKlarnaResponseSource() { + super(PaymentSourceType.KLARNA); + } + } diff --git a/src/main/java/com/checkout/payments/response/source/contexts/PaymentContextsPayPalResponseSource.java b/src/main/java/com/checkout/payments/response/source/contexts/PaymentContextsPayPalResponseSource.java index 63329c9a..e29f0ee0 100644 --- a/src/main/java/com/checkout/payments/response/source/contexts/PaymentContextsPayPalResponseSource.java +++ b/src/main/java/com/checkout/payments/response/source/contexts/PaymentContextsPayPalResponseSource.java @@ -1,14 +1,19 @@ package com.checkout.payments.response.source.contexts; -import lombok.Data; +import com.checkout.common.PaymentSourceType; import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; +import lombok.Getter; +import lombok.Setter; import lombok.ToString; -@Data +@Getter +@Setter @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -@NoArgsConstructor public final class PaymentContextsPayPalResponseSource extends AbstractPaymentContextsResponseSource implements ResponseSource { + public PaymentContextsPayPalResponseSource() { + super(PaymentSourceType.PAYPAL); + } + } diff --git a/src/test/java/com/checkout/GsonSerializerTest.java b/src/test/java/com/checkout/GsonSerializerTest.java index 77139bd1..eb7a183f 100644 --- a/src/test/java/com/checkout/GsonSerializerTest.java +++ b/src/test/java/com/checkout/GsonSerializerTest.java @@ -1,13 +1,16 @@ package com.checkout; +import com.checkout.common.PaymentSourceType; import com.checkout.financial.FinancialActionsQueryResponse; import com.checkout.issuing.cardholders.CardholderCardsResponse; import com.checkout.issuing.cards.responses.PhysicalCardDetailsResponse; import com.checkout.issuing.cards.responses.VirtualCardDetailsResponse; +import com.checkout.payments.contexts.PaymentContextDetailsResponse; import com.checkout.payments.previous.response.GetPaymentResponse; import com.checkout.payments.previous.response.PaymentResponse; import com.checkout.payments.previous.response.destination.PaymentResponseAlternativeDestination; import com.checkout.payments.previous.response.destination.PaymentResponseCardDestination; +import com.checkout.payments.response.source.contexts.PaymentContextsPayPalResponseSource; import com.checkout.payments.sender.PaymentCorporateSender; import com.checkout.payments.sender.ResponseAlternativeSender; import com.checkout.payments.sender.SenderType; @@ -118,6 +121,16 @@ void shouldGetFinancial() { assertNotNull(actionsQueryResponse.getData().get(0).getRequestedOn()); } + @Test + void shouldSerializePaymentContextsPayPalDetailsResponseFromJson() { + + final PaymentContextDetailsResponse paymentContextsPayPalResponseSource = serializer.fromJson(getMock("/mocks/payments/response/contexts/payment_context_paypal_details_response.json"), PaymentContextDetailsResponse.class); + + assertNotNull(paymentContextsPayPalResponseSource); + assertTrue(paymentContextsPayPalResponseSource.getPaymentRequest().getSource() instanceof PaymentContextsPayPalResponseSource); + assertEquals(PaymentSourceType.PAYPAL, paymentContextsPayPalResponseSource.getPaymentRequest().getSource().getType()); + } + @Test void shouldDeserializeMultipleDateFormats() { Instant instant = Instant.parse("2021-06-08T12:25:01Z"); diff --git a/src/test/resources/mocks/payments/response/contexts/payment_context_paypal_details_response.json b/src/test/resources/mocks/payments/response/contexts/payment_context_paypal_details_response.json new file mode 100644 index 00000000..338fcfb7 --- /dev/null +++ b/src/test/resources/mocks/payments/response/contexts/payment_context_paypal_details_response.json @@ -0,0 +1,50 @@ +{ + "partner_metadata": { + "customer_id": "WXZ3YUKYW27V4", + "order_id": "0UX64350RX431305J" + }, + "payment_request": { + "amount": 2500, + "authorization_type": "Final", + "capture": true, + "currency": "GBP", + "failure_url": "https://www.spaseekers.com/checkout/checkoutdotcom3/payment-failed", + "items": [ + { + "discount_amount": 0, + "name": "£25.00 Voucher", + "quantity": 1, + "tax_amount": 0, + "total_amount": 2500, + "unit_price": 2500 + } + ], + "payment_type": "Regular", + "processing": { + "shipping_amount": 0, + "user_action": "PAY_NOW" + }, + "processing_channel_id": "pc_strugfrty47ellyymdfg6fzhc4i", + "reference": "770859", + "shipping": { + "address": { + "address_line1": "6 May Close", + "address_line2": "Goring-by-Sea", + "city": "Worthing", + "country": "GB", + "state": "WEST SUSSEX", + "zip": "BN12 6HW" + }, + "first_name": "Matthew Abbott" + }, + "source": { + "account_holder": { + "email": "me+paypal@matthewabbott.dev", + "full_name": "Matthew Abbott" + }, + "type": "paypal" + }, + "success_url": "https://www.spaseekers.com/checkout/checkoutdotcom3/payment-successful" + }, + "status": "Created" +} \ No newline at end of file From 0b9930a8d4021839542904d10280e348e537d606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20Rodr=C3=ADguez?= <127134616+armando-rodriguez-cko@users.noreply.github.com> Date: Tue, 30 Jul 2024 18:50:20 +0200 Subject: [PATCH 2/2] Add partial authorization in payment request --- .../payments/request/PartialAuthorization.java | 16 ++++++++++++++++ .../payments/request/PaymentRequest.java | 3 +++ .../payments/PaymentAuthorizationsTestIT.java | 6 ++++++ 3 files changed, 25 insertions(+) create mode 100644 src/main/java/com/checkout/payments/request/PartialAuthorization.java diff --git a/src/main/java/com/checkout/payments/request/PartialAuthorization.java b/src/main/java/com/checkout/payments/request/PartialAuthorization.java new file mode 100644 index 00000000..0abcabce --- /dev/null +++ b/src/main/java/com/checkout/payments/request/PartialAuthorization.java @@ -0,0 +1,16 @@ +package com.checkout.payments.request; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public final class PartialAuthorization { + + private Boolean enabled; + +} diff --git a/src/main/java/com/checkout/payments/request/PaymentRequest.java b/src/main/java/com/checkout/payments/request/PaymentRequest.java index 5dfc6823..dba92412 100644 --- a/src/main/java/com/checkout/payments/request/PaymentRequest.java +++ b/src/main/java/com/checkout/payments/request/PaymentRequest.java @@ -50,6 +50,9 @@ public final class PaymentRequest { @SerializedName("authorization_type") private AuthorizationType authorizationType; + @SerializedName("partial_authorization") + private PartialAuthorization partialAuthorization; + private Boolean capture; @SerializedName("capture_on") diff --git a/src/test/java/com/checkout/payments/PaymentAuthorizationsTestIT.java b/src/test/java/com/checkout/payments/PaymentAuthorizationsTestIT.java index a2e408f8..cb9675db 100644 --- a/src/test/java/com/checkout/payments/PaymentAuthorizationsTestIT.java +++ b/src/test/java/com/checkout/payments/PaymentAuthorizationsTestIT.java @@ -9,6 +9,7 @@ import com.checkout.common.CountryCode; import com.checkout.common.Currency; import com.checkout.payments.request.AuthorizationRequest; +import com.checkout.payments.request.PartialAuthorization; import com.checkout.payments.request.PaymentRequest; import com.checkout.payments.request.source.RequestCardSource; import com.checkout.payments.response.AuthorizationResponse; @@ -102,6 +103,10 @@ private PaymentResponse makeIncrementalAuthorizationPayment() { .build()) .build(); + final PartialAuthorization partialAuthorization = PartialAuthorization.builder() + .enabled(true) + .build(); + final PaymentRequest request = PaymentRequest.builder() .source(source) .sender(sender) @@ -113,6 +118,7 @@ private PaymentResponse makeIncrementalAuthorizationPayment() { .threeDS(null) .successUrl(null) .failureUrl(null) + .partialAuthorization(partialAuthorization) .build(); return blocking(() -> checkoutApi.paymentsClient().requestPayment(request));