Skip to content

Commit

Permalink
Add SEPA Direct Debit Core Support (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
armando-rodriguez-cko authored Apr 16, 2024
1 parent a5d1cea commit 3cb3417
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/checkout/GsonSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/checkout/common/InstrumentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public enum InstrumentType {
CARD,

@SerializedName("card_token")
CARD_TOKEN
CARD_TOKEN,

@SerializedName("sepa")
SEPA

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

}
36 changes: 36 additions & 0 deletions src/main/java/com/checkout/instruments/create/InstrumentData.java
Original file line number Diff line number Diff line change
@@ -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;

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,6 @@ public final class PaymentRequest {

private PaymentSegment segment;

private PaymentInstruction instruction ;

}
53 changes: 53 additions & 0 deletions src/test/java/com/checkout/instruments/SepaInstrumentsTestIT.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ void shouldMakeCvConnectPayment() {
checkErrorItem(() -> paymentsClient.requestPayment(paymentRequest), PAYEE_NOT_ONBOARDED);
}

@Disabled("Temporarily skipped")

@Test
void shouldMakeSepaV4Payment() {
final PaymentRequest paymentRequest = PaymentRequest.builder()
Expand Down

0 comments on commit 3cb3417

Please sign in to comment.