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

[feature] added support for blik with code #361

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ public PayIn deserialize(JsonElement json, Type typeOfT, JsonDeserializationCont
PayInPaymentDetailsBlik payInPaymentDetailsBlik = new PayInPaymentDetailsBlik();
if (object.has("StatementDescriptor") && !object.get("StatementDescriptor").isJsonNull())
payInPaymentDetailsBlik.setStatementDescriptor(object.get("StatementDescriptor").getAsString());
if (object.has("Code") && !object.get("Code").isJsonNull())
payInPaymentDetailsBlik.setCode(object.get("Code").getAsString());
if (object.has("IpAddress") && !object.get("IpAddress").isJsonNull())
payInPaymentDetailsBlik.setIpAddress(object.get("IpAddress").getAsString());
if (object.has("BrowserInfo") && !object.get("BrowserInfo").isJsonNull())
payInPaymentDetailsBlik.setBrowserInfo((BrowserInfo) context.deserialize(object.get("BrowserInfo"), BrowserInfo.class));
payIn.setPaymentDetails(payInPaymentDetailsBlik);
break;
case MULTIBANCO:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public JsonElement serialize(PayIn src, Type typeOfSrc, JsonSerializationContext
break;
case "PayInPaymentDetailsBlik":
object.add("StatementDescriptor", context.serialize(((PayInPaymentDetailsBlik) src.getPaymentDetails()).getStatementDescriptor()));
object.add("Code", context.serialize(((PayInPaymentDetailsBlik) src.getPaymentDetails()).getCode()));
object.add("IpAddress", context.serialize(((PayInPaymentDetailsBlik) src.getPaymentDetails()).getIpAddress()));
object.add("BrowserInfo", context.serialize(((PayInPaymentDetailsBlik) src.getPaymentDetails()).getBrowserInfo()));
break;
case "PayInPaymentDetailsMultibanco":
object.add("StatementDescriptor", context.serialize(((PayInPaymentDetailsMultibanco) src.getPaymentDetails()).getStatementDescriptor()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ public class PayInPaymentDetailsBlik extends Dto implements PayInPaymentDetails
*/
@SerializedName("StatementDescriptor")
private String statementDescriptor;


/// Blik with "code" ///

/**
* The 6-digit code from the user’s banking application.
* Required when creating a Blik PayIn with code.
*/
@SerializedName("Code")
private String code;

/**
* The IP address of the end user initiating the transaction, in IPV4 or IPV6 format.
* Required when creating a Blik PayIn with code.
*/
@SerializedName("IpAddress")
private String ipAddress;

/**
* Information about the browser used by the end user (author) to perform the payment.
* Required when creating a Blik PayIn with code.
*/
@SerializedName("BrowserInfo")
private BrowserInfo browserInfo;

public String getStatementDescriptor() {
return statementDescriptor;
Expand All @@ -24,5 +48,30 @@ public PayInPaymentDetailsBlik setStatementDescriptor(String statementDescriptor
return this;
}


public BrowserInfo getBrowserInfo() {
return browserInfo;
}

public PayInPaymentDetailsBlik setBrowserInfo(BrowserInfo browserInfo) {
this.browserInfo = browserInfo;
return this;
}

public String getIpAddress() {
return ipAddress;
}

public PayInPaymentDetailsBlik setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
return this;
}

public String getCode() {
return code;
}

public PayInPaymentDetailsBlik setCode(String code) {
this.code = code;
return this;
}
}
10 changes: 10 additions & 0 deletions src/test/java/com/mangopay/core/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,16 @@ protected PayIn getNewPayInBlikWeb(String userId) throws Exception {
return this.api.getPayInApi().create(payIn);
}

protected PayIn getNewPayInBlikWebWithCode(String userId) throws Exception {
PayIn payIn = getPayInBlikWeb(userId);

((PayInPaymentDetailsBlik) payIn.getPaymentDetails()).setCode("777365");
((PayInPaymentDetailsBlik) payIn.getPaymentDetails()).setIpAddress("159.180.248.187");
((PayInPaymentDetailsBlik) payIn.getPaymentDetails()).setBrowserInfo(getNewBrowserInfo());

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

protected PayIn getNewPayInMultibancoWeb(String userId) throws Exception {
PayIn payIn = getPayInMultibancoWeb(userId);

Expand Down
25 changes: 25 additions & 0 deletions src/test/java/com/mangopay/core/PayInApiImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,31 @@ public void createBlikWebPayIn() {
}
}

@Test
public void createBlikWebPayInWithCode() {
try {
UserNatural user = this.getJohn();
PayIn created = this.getNewPayInBlikWebWithCode(user.getId());

assertNotNull(created);
assertEquals(TransactionStatus.CREATED, created.getStatus());
assertEquals(PayInPaymentType.BLIK, created.getPaymentType());
assertEquals(PayInExecutionType.WEB, created.getExecutionType());
assertNotNull(((PayInPaymentDetailsBlik) created.getPaymentDetails()).getCode());
assertNotNull(((PayInPaymentDetailsBlik) created.getPaymentDetails()).getIpAddress());
assertNotNull(((PayInPaymentDetailsBlik) created.getPaymentDetails()).getBrowserInfo());

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

@Test
public void createMultibancoWebPayIn() {
try {
Expand Down