diff --git a/src/main/java/com/checkout/GsonSerializer.java b/src/main/java/com/checkout/GsonSerializer.java index 8d1a45a1..5c02aadd 100644 --- a/src/main/java/com/checkout/GsonSerializer.java +++ b/src/main/java/com/checkout/GsonSerializer.java @@ -108,10 +108,12 @@ public class GsonSerializer implements Serializer { // Instruments CS2 .registerTypeAdapterFactory(RuntimeTypeAdapterFactory.of(com.checkout.instruments.create.CreateInstrumentResponse.class, CheckoutUtils.TYPE) .registerSubtype(com.checkout.instruments.create.CreateInstrumentBankAccountResponse.class, identifier(InstrumentType.BANK_ACCOUNT)) - .registerSubtype(com.checkout.instruments.create.CreateInstrumentTokenResponse.class, identifier(InstrumentType.CARD))) + .registerSubtype(com.checkout.instruments.create.CreateInstrumentTokenResponse.class, identifier(InstrumentType.CARD)) + .registerSubtype(com.checkout.instruments.create.CreateInstrumentSepaResponse.class, identifier(InstrumentType.SEPA))) .registerTypeAdapterFactory(RuntimeTypeAdapterFactory.of(com.checkout.instruments.get.GetInstrumentResponse.class, CheckoutUtils.TYPE) .registerSubtype(com.checkout.instruments.get.GetBankAccountInstrumentResponse.class, identifier(InstrumentType.BANK_ACCOUNT)) - .registerSubtype(com.checkout.instruments.get.GetCardInstrumentResponse.class, identifier(InstrumentType.CARD))) + .registerSubtype(com.checkout.instruments.get.GetCardInstrumentResponse.class, identifier(InstrumentType.CARD)) + .registerSubtype(com.checkout.instruments.get.GetSepaInstrumentResponse.class, identifier(InstrumentType.SEPA))) .registerTypeAdapterFactory(RuntimeTypeAdapterFactory.of(com.checkout.instruments.update.UpdateInstrumentResponse.class, CheckoutUtils.TYPE) .registerSubtype(com.checkout.instruments.update.UpdateInstrumentBankAccountResponse.class, identifier(InstrumentType.BANK_ACCOUNT)) .registerSubtype(com.checkout.instruments.update.UpdateInstrumentCardResponse.class, identifier(InstrumentType.CARD))) diff --git a/src/main/java/com/checkout/common/InstrumentType.java b/src/main/java/com/checkout/common/InstrumentType.java index 5c3bf654..73d8e7b4 100644 --- a/src/main/java/com/checkout/common/InstrumentType.java +++ b/src/main/java/com/checkout/common/InstrumentType.java @@ -14,6 +14,9 @@ public enum InstrumentType { CARD, @SerializedName("card_token") - CARD_TOKEN + CARD_TOKEN, + + @SerializedName("sepa") + SEPA } diff --git a/src/main/java/com/checkout/instruments/create/CreateInstrumentSepaRequest.java b/src/main/java/com/checkout/instruments/create/CreateInstrumentSepaRequest.java new file mode 100644 index 00000000..a7fb7340 --- /dev/null +++ b/src/main/java/com/checkout/instruments/create/CreateInstrumentSepaRequest.java @@ -0,0 +1,36 @@ +package com.checkout.instruments.create; + +import com.checkout.common.AccountHolder; +import com.checkout.common.AccountType; +import com.checkout.common.InstrumentType; +import com.google.gson.annotations.SerializedName; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public final class CreateInstrumentSepaRequest extends CreateInstrumentRequest { + + @SerializedName("instrument_data") + private InstrumentData instrumentData; + + @SerializedName("account_holder") + private AccountHolder accountHolder; + + @Builder + private CreateInstrumentSepaRequest(final InstrumentData instrumentData, + final AccountHolder accountHolder) { + super(InstrumentType.SEPA); + this.instrumentData = instrumentData; + this.accountHolder = accountHolder; + } + + public CreateInstrumentSepaRequest() { + super(InstrumentType.SEPA); + } +} diff --git a/src/main/java/com/checkout/instruments/create/CreateInstrumentSepaResponse.java b/src/main/java/com/checkout/instruments/create/CreateInstrumentSepaResponse.java new file mode 100644 index 00000000..88279e9b --- /dev/null +++ b/src/main/java/com/checkout/instruments/create/CreateInstrumentSepaResponse.java @@ -0,0 +1,21 @@ +package com.checkout.instruments.create; + +import com.checkout.common.CardCategory; +import com.checkout.common.CardType; +import com.checkout.common.CountryCode; +import com.checkout.common.InstrumentType; +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.time.Instant; + +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public final class CreateInstrumentSepaResponse extends CreateInstrumentResponse { + + private final InstrumentType type = InstrumentType.SEPA; + +} diff --git a/src/main/java/com/checkout/instruments/create/InstrumentData.java b/src/main/java/com/checkout/instruments/create/InstrumentData.java new file mode 100644 index 00000000..3c21d9f5 --- /dev/null +++ b/src/main/java/com/checkout/instruments/create/InstrumentData.java @@ -0,0 +1,36 @@ +package com.checkout.instruments.create; + +import com.checkout.common.CountryCode; +import com.checkout.common.Currency; +import com.checkout.payments.PaymentType; +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.Instant; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public final class InstrumentData { + + @SerializedName("account_number") + private String accoountNumber; + + private CountryCode country; + + private Currency currency; + + @SerializedName("payment_type") + private PaymentType paymentType; + + @SerializedName("mandate_id") + private String mandateId; + + @SerializedName("date_of_signature") + private Instant dateOfSignature; + +} diff --git a/src/main/java/com/checkout/instruments/get/GetSepaInstrumentResponse.java b/src/main/java/com/checkout/instruments/get/GetSepaInstrumentResponse.java new file mode 100644 index 00000000..6d0dc38a --- /dev/null +++ b/src/main/java/com/checkout/instruments/get/GetSepaInstrumentResponse.java @@ -0,0 +1,31 @@ +package com.checkout.instruments.get; + +import com.checkout.common.InstrumentType; +import com.checkout.instruments.create.InstrumentData; +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.time.Instant; + +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public final class GetSepaInstrumentResponse extends GetInstrumentResponse { + + private final InstrumentType type = InstrumentType.SEPA; + + @SerializedName("created_on") + private Instant createdOn; + + @SerializedName("modified_on") + private Instant modifiedOn; + + @SerializedName("vault_id") + private String vaultId; + + @SerializedName("instrument_data") + private InstrumentData instrumentData; + +} diff --git a/src/main/java/com/checkout/payments/request/PaymentRequest.java b/src/main/java/com/checkout/payments/request/PaymentRequest.java index fea7e470..5dfc6823 100644 --- a/src/main/java/com/checkout/payments/request/PaymentRequest.java +++ b/src/main/java/com/checkout/payments/request/PaymentRequest.java @@ -107,4 +107,6 @@ public final class PaymentRequest { private PaymentSegment segment; + private PaymentInstruction instruction ; + } diff --git a/src/test/java/com/checkout/instruments/SepaInstrumentsTestIT.java b/src/test/java/com/checkout/instruments/SepaInstrumentsTestIT.java new file mode 100644 index 00000000..0dc057fb --- /dev/null +++ b/src/test/java/com/checkout/instruments/SepaInstrumentsTestIT.java @@ -0,0 +1,53 @@ +package com.checkout.instruments; + +import com.checkout.common.AccountHolder; +import com.checkout.common.AccountHolderType; +import com.checkout.common.Address; +import com.checkout.common.CountryCode; +import com.checkout.common.Currency; +import com.checkout.common.Phone; +import com.checkout.instruments.create.CreateInstrumentSepaRequest; +import com.checkout.instruments.create.CreateInstrumentSepaResponse; +import com.checkout.instruments.create.InstrumentData; +import com.checkout.payments.AbstractPaymentsTestIT; +import com.checkout.payments.PaymentType; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class SepaInstrumentsTestIT extends AbstractPaymentsTestIT { + + @Test + void shouldCreateInstrumentSepa() { + + final CreateInstrumentSepaRequest request = CreateInstrumentSepaRequest.builder() + .instrumentData(InstrumentData.builder() + .accoountNumber("FR7630006000011234567890189") + .country(CountryCode.FR) + .currency(Currency.EUR) + .paymentType(PaymentType.RECURRING) + .build()) + .accountHolder(AccountHolder.builder() + .type(AccountHolderType.INDIVIDUAL) + .firstName("Ali") + .lastName("Farid") + .dateOfBirth("1986-01-01T00:00:00.000Z") + .billingAddress(Address.builder() + .addressLine1("Rue Exemple") + .addressLine2("1") + .city("Paris") + .zip("1234") + .country(CountryCode.FR) + .build()) + .phone(Phone.builder() + .countryCode("33") + .number("123456789") + .build()) + .build()) + .build(); + final CreateInstrumentSepaResponse response = blocking(() -> checkoutApi.instrumentsClient().create(request)); + assertNotNull(response); + assertNotNull(response.getId()); + assertNotNull(response.getFingerprint()); + } +} \ No newline at end of file diff --git a/src/test/java/com/checkout/payments/RequestApmPaymentsIT.java b/src/test/java/com/checkout/payments/RequestApmPaymentsIT.java index 98b1872d..9d0f9d78 100644 --- a/src/test/java/com/checkout/payments/RequestApmPaymentsIT.java +++ b/src/test/java/com/checkout/payments/RequestApmPaymentsIT.java @@ -544,7 +544,7 @@ void shouldMakeCvConnectPayment() { checkErrorItem(() -> paymentsClient.requestPayment(paymentRequest), PAYEE_NOT_ONBOARDED); } - @Disabled("Temporarily skipped") + @Test void shouldMakeSepaV4Payment() { final PaymentRequest paymentRequest = PaymentRequest.builder()