Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEPA Direct Debit Core Support #401

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Dismissed Show dismissed Hide dismissed
@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)
Dismissed Show dismissed Hide dismissed
@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)
Dismissed Show dismissed Hide dismissed
@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
Loading