Skip to content

Commit

Permalink
Merge pull request #352 from Mangopay/feature/twint-payin
Browse files Browse the repository at this point in the history
[Feature] Twint PayIn
  • Loading branch information
iulian03 authored Feb 10, 2025
2 parents 79e2cc0 + 6101781 commit f73632d
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 3 deletions.
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 @@ -101,6 +101,7 @@ protected MangoPayApi getRoot() {
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("payins_twint-web_create", new String[]{"/payins/payment-methods/twint", 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 @@ -262,6 +262,12 @@ public PayIn deserialize(JsonElement json, Type typeOfT, JsonDeserializationCont
payInPaymentDetailsBancontact.setRecurring(object.get("Recurring").getAsBoolean());
payIn.setPaymentDetails(payInPaymentDetailsBancontact);
break;
case TWINT:
PayInPaymentDetailsTwint payInPaymentDetailsTwint = new PayInPaymentDetailsTwint();
if (object.has("StatementDescriptor") && !object.get("StatementDescriptor").isJsonNull())
payInPaymentDetailsTwint.setStatementDescriptor(object.get("StatementDescriptor").getAsString());
payIn.setPaymentDetails(payInPaymentDetailsTwint);
break;
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ public enum PayInPaymentType {
/**
* BANCONTACT payment type
*/
BCMC

BCMC,

/**
* TWINT payment type
*/
TWINT
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ public JsonElement serialize(PayIn src, Type typeOfSrc, JsonSerializationContext
object.add("StatementDescriptor", context.serialize(((PayInPaymentDetailsBancontact) src.getPaymentDetails()).getStatementDescriptor()));
object.add("Recurring", context.serialize(((PayInPaymentDetailsBancontact) src.getPaymentDetails()).getRecurring()));
break;
case "PayInPaymentDetailsTwint":
object.add("StatementDescriptor", context.serialize(((PayInPaymentDetailsTwint) src.getPaymentDetails()).getStatementDescriptor()));
break;
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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 TWINT type for mean of payment in PayIn entity.
*/
public class PayInPaymentDetailsTwint extends Dto implements PayInPaymentDetails {

/**
* Max. length: 10 characters; only alphanumeric and spaces
* <p></p>
* Custom description to appear on the user’s bank statement along with the platform name.
* Different banks may show more or less information. See the <a href="https://docs.mangopay.com/bank-statements">Customizing bank statement references</a> article for details.
*/
@SerializedName("StatementDescriptor")
private String statementDescriptor;

public String getStatementDescriptor() {
return statementDescriptor;
}

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

}
47 changes: 46 additions & 1 deletion src/test/java/com/mangopay/core/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,19 @@ protected Wallet getJohnsWallet() throws Exception {
return BaseTest.JOHNS_WALLET;
}

protected Wallet getNewWallet(CurrencyIso currencyIso) throws Exception {
UserNatural john = this.getJohn();

Wallet wallet = new Wallet();
wallet.setOwners(new ArrayList<String>());
wallet.getOwners().add(john.getId());

wallet.setCurrency(currencyIso);
wallet.setDescription(String.format("WALLET IN %s", currencyIso.toString()));

return this.api.getWalletApi().create(wallet);
}

/**
* Creates wallet for John, loaded with 10k EUR (John's got lucky) if not
* created yet, or returns an existing one.
Expand Down Expand Up @@ -714,7 +727,6 @@ protected PayIn getNewPayInMultibancoWeb(String userId) throws Exception {
return this.api.getPayInApi().create(payIn);
}


protected PayIn getNewPayInKlarnaWeb(String userId) throws Exception {
PayIn payIn = getPayInKlarnaWeb(userId);

Expand All @@ -739,6 +751,11 @@ protected PayIn getNewPayInBancontactWeb(String userId) throws Exception {
return this.api.getPayInApi().create(payIn);
}

protected PayIn getNewPayInTwintWeb(String userId, String walletId) throws Exception {
PayIn payIn = getPayInTwintWeb(userId, walletId);
return this.api.getPayInApi().create(payIn);
}

private PayIn getPayInCardDirect(String userId) throws Exception {

Wallet wallet = this.getJohnsWalletWithMoney();
Expand Down Expand Up @@ -1128,6 +1145,34 @@ protected PayIn getNewPayInCardDirectWithIpAddress() throws Exception {
return this.api.getPayInApi().create(payIn);
}

private PayIn getPayInTwintWeb(String userId, String walletId) throws Exception {
if (userId == null) {
UserNatural user = this.getJohn();
userId = user.getId();
}

PayIn payIn = new PayIn();
payIn.setAuthorId(userId);
payIn.setCreditedWalletId(walletId);
payIn.setDebitedFunds(new Money());
payIn.getDebitedFunds().setAmount(100);
payIn.getDebitedFunds().setCurrency(CurrencyIso.CHF);
payIn.setFees(new Money());
payIn.getFees().setAmount(0);
payIn.getFees().setCurrency(CurrencyIso.CHF);

payIn.setPaymentDetails(new PayInPaymentDetailsTwint());
((PayInPaymentDetailsTwint) payIn.getPaymentDetails()).setStatementDescriptor("Twint");

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

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

protected PayOut getJohnsPayOutBankWire() throws Exception {
if (BaseTest.JOHNS_PAYOUT_BANKWIRE == null) {
Wallet wallet = this.getJohnsWallet();
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 @@ -1280,6 +1280,27 @@ public void createGiropayWeb() {
}
}

@Test
public void createTwintWeb() {
try {
UserNatural user = this.getJohn();
Wallet wallet = this.getNewWallet(CurrencyIso.CHF);
PayIn created = this.getNewPayInTwintWeb(user.getId(), wallet.getId());

assertNotNull(created);
assertEquals(TransactionStatus.CREATED, created.getStatus());
assertEquals(PayInPaymentType.TWINT, 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 createBancontactWeb() {
try {
Expand Down

0 comments on commit f73632d

Please sign in to comment.