Skip to content

Commit

Permalink
Fix account holder payment context source. Partial Authorization (#427)
Browse files Browse the repository at this point in the history
* Fix account holder payment context source

* Add partial authorization in payment request
  • Loading branch information
armando-rodriguez-cko authored Jul 31, 2024
1 parent 8e17ba0 commit b822ab6
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 17 deletions.
17 changes: 10 additions & 7 deletions src/main/java/com/checkout/common/AccountHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -42,11 +52,4 @@ public final class AccountHolder {

private AccountHolderIdentification identification;

private String email;

private String gender;

@SerializedName("middle_name")
private String middleName;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@NoArgsConstructor
public final class PaymentContextDetailsResponse extends HttpMetadata {

private PaymentContextDetailsStatusType status;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
13 changes: 13 additions & 0 deletions src/test/java/com/checkout/GsonSerializerTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -113,6 +118,7 @@ private PaymentResponse makeIncrementalAuthorizationPayment() {
.threeDS(null)
.successUrl(null)
.failureUrl(null)
.partialAuthorization(partialAuthorization)
.build();

return blocking(() -> checkoutApi.paymentsClient().requestPayment(request));
Expand Down
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"full_name": "Matthew Abbott"
},
"type": "paypal"
},
"success_url": "https://www.spaseekers.com/checkout/checkoutdotcom3/payment-successful"
},
"status": "Created"
}

0 comments on commit b822ab6

Please sign in to comment.