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

Bancontact PayIn method #338

Merged
merged 2 commits into from
Aug 7, 2024
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
1 change: 1 addition & 0 deletions src/main/java/com/mangopay/core/APIs/ApiBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ protected MangoPayApi getRoot() {
put("payins_klarna-web_create", new String[]{"/payins/payment-methods/klarna", RequestType.POST.toString()});
put("payins_ideal-web_create", new String[]{"/payins/payment-methods/ideal", RequestType.POST.toString()});
put("payins_giropay-web_create", new String[]{"/payins/payment-methods/giropay", RequestType.POST.toString()});
put("payins_bancontact-web_create", new String[]{"/payins/payment-methods/bancontact", RequestType.POST.toString()});
put("add_tracking_info", new String[]{"/payins/%s/trackings", RequestType.PUT.toString()});

put("payment_method-metadata", new String[]{"/payment-methods/metadata", RequestType.POST.toString()});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@ public PayIn deserialize(JsonElement json, Type typeOfT, JsonDeserializationCont
payInPaymentDetailsGiropay.setStatementDescriptor(object.get("StatementDescriptor").getAsString());
payIn.setPaymentDetails(payInPaymentDetailsGiropay);
break;
case BCMC:
PayInPaymentDetailsBancontact payInPaymentDetailsBancontact = new PayInPaymentDetailsBancontact();
if (object.has("StatementDescriptor") && !object.get("StatementDescriptor").isJsonNull())
payInPaymentDetailsBancontact.setStatementDescriptor(object.get("StatementDescriptor").getAsString());
if (object.has("DeepLinkURL") && !object.get("DeepLinkURL").isJsonNull())
payInPaymentDetailsBancontact.setDeepLinkUrl(object.get("DeepLinkURL").getAsString());
if (object.has("Recurring") && !object.get("Recurring").isJsonNull())
payInPaymentDetailsBancontact.setRecurring(object.get("Recurring").getAsBoolean());
payIn.setPaymentDetails(payInPaymentDetailsBancontact);
break;
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ public enum PayInPaymentType {
/**
* GIROPAY payment type
*/
GIROPAY
GIROPAY,

/**
* BANCONTACT payment type
*/
BCMC


}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public JsonElement serialize(PayIn src, Type typeOfSrc, JsonSerializationContext
case "PayInPaymentDetailsGiropay":
object.add("StatementDescriptor", context.serialize(((PayInPaymentDetailsGiropay) src.getPaymentDetails()).getStatementDescriptor()));
break;
case "PayInPaymentDetailsBancontact":
object.add("DeepLinkURL", context.serialize(((PayInPaymentDetailsBancontact) src.getPaymentDetails()).getDeepLinkUrl()));
object.add("StatementDescriptor", context.serialize(((PayInPaymentDetailsBancontact) src.getPaymentDetails()).getStatementDescriptor()));
object.add("Recurring", context.serialize(((PayInPaymentDetailsBancontact) src.getPaymentDetails()).getRecurring()));
break;
default:
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/mangopay/entities/PayIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ public Map<String, Map<String, Map<String, Class<?>>>> getDependentObjects() {
put("PaymentDetails", PayInPaymentDetailsGiropay.class);
}}
);
put("BCMC", new HashMap<String, Class<?>>() {{
put("PaymentDetails", PayInPaymentDetailsBancontact.class);
}}
);
// ...and more in future...
}}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.mangopay.entities.subentities;

import com.google.gson.annotations.SerializedName;
import com.mangopay.core.Dto;
import com.mangopay.core.interfaces.PayInPaymentDetails;

/**
* Class representing the BANCONTACT type for mean of payment in PayIn entity.
*/
public class PayInPaymentDetailsBancontact extends Dto implements PayInPaymentDetails {

/**
* The URL where you should redirect your client in a mobile app experience
*/
@SerializedName("DeepLinkURL")
private String deepLinkUrl;

/**
* An optional value to be specified on the user's bank statement
* It can be up to 10 char alphanumeric and space.
*/
@SerializedName("StatementDescriptor")
private String statementDescriptor;

/**
* Whether the Bancontact pay-ins are being made to be re-used in a recurring payment flow
*/
@SerializedName("Recurring")
private Boolean recurring;

public String getDeepLinkUrl() {
return deepLinkUrl;
}

public void setDeepLinkUrl(String deepLinkUrl) {
this.deepLinkUrl = deepLinkUrl;
}

public String getStatementDescriptor() {
return statementDescriptor;
}

public void setStatementDescriptor(String statementDescriptor) {
this.statementDescriptor = statementDescriptor;
}

public Boolean getRecurring() {
return recurring;
}

public void setRecurring(Boolean recurring) {
this.recurring = recurring;
}
}
39 changes: 39 additions & 0 deletions src/test/java/com/mangopay/core/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,12 @@ protected PayIn getNewPayInGiropayWeb(String userId) throws Exception {
return this.api.getPayInApi().create(payIn);
}

protected PayIn getNewPayInBancontactWeb(String userId) throws Exception {
PayIn payIn = getPayInBancontactWeb(userId);

return this.api.getPayInApi().create(payIn);
}

private PayIn getPayInCardDirect(String userId) throws Exception {

Wallet wallet = this.getJohnsWalletWithMoney();
Expand Down Expand Up @@ -785,6 +791,39 @@ private PayIn getPayInGiropayWeb(String userId) throws Exception {
return payIn;
}

private PayIn getPayInBancontactWeb(String userId) throws Exception {

Wallet wallet = this.getJohnsWalletWithMoney();

if (userId == null) {
UserNatural user = this.getJohn();
userId = user.getId();
}

PayIn payIn = new PayIn();
payIn.setAuthorId(userId);
payIn.setCreditedWalletId(wallet.getId());
payIn.setDebitedFunds(new Money());
payIn.getDebitedFunds().setAmount(1000);
payIn.getDebitedFunds().setCurrency(CurrencyIso.EUR);
payIn.setFees(new Money());
payIn.getFees().setAmount(10);
payIn.getFees().setCurrency(CurrencyIso.EUR);

payIn.setPaymentDetails(new PayInPaymentDetailsBancontact());
((PayInPaymentDetailsBancontact) payIn.getPaymentDetails()).setStatementDescriptor("test");
((PayInPaymentDetailsBancontact) payIn.getPaymentDetails()).setRecurring(true);

// execution type as WEB
PayInExecutionDetailsWeb payInExecutionDetailsWeb = new PayInExecutionDetailsWeb();
payInExecutionDetailsWeb.setCulture(CultureCode.FR);
payInExecutionDetailsWeb.setReturnUrl("http://www.my-site.com/returnURL");
payIn.setExecutionDetails(payInExecutionDetailsWeb);

payIn.setTag("My Bancontact Tag");
return payIn;
}

private PayIn getPayInSatispayWeb(String userId) throws Exception {

Wallet wallet = this.getJohnsWalletWithMoney();
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/mangopay/core/PayInApiImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,27 @@ public void createGiropayWeb() {
}
}

@Test
public void createBancontactWeb() {
try {
UserNatural user = this.getJohn();
Wallet wallet = this.getJohnsWalletWithMoney();
PayIn created = this.getNewPayInBancontactWeb(user.getId());

assertNotNull(created);
assertEquals(TransactionStatus.CREATED, created.getStatus());
assertEquals(PayInPaymentType.BCMC, created.getPaymentType());
assertEquals(PayInExecutionType.WEB, created.getExecutionType());
assertEquals(wallet.getId(), created.getCreditedWalletId());

PayIn fetched = api.getPayInApi().get(created.getId());
assertNotNull(fetched);
assertEquals(created.getId(), fetched.getId());
} catch (Exception ex) {
fail(ex.getMessage());
}
}

@Test
public void createLegacyIdealPayIn() {
try {
Expand Down
Loading