Skip to content

Commit

Permalink
Merge pull request #128 from omise/add-fpx-source-type-for-v3
Browse files Browse the repository at this point in the history
Add FPX to the list of source types for V3.x
  • Loading branch information
hpariwat authored Feb 22, 2021
2 parents 7a82dc2 + 17885bd commit cfa007b
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 7 deletions.
31 changes: 31 additions & 0 deletions src/main/java/co/omise/models/Bank.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package co.omise.models;

public class Bank {
private String code;
private String name;
private boolean active;

public String getCode() {
return this.code;
}

public void setCode(String code) {
this.code = code;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public boolean isActive() {
return this.active;
}

public void setActive(boolean active) {
this.active = active;
}
}
7 changes: 7 additions & 0 deletions src/main/java/co/omise/models/PaymentMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class PaymentMethod extends Model {
private List<String> cardBrands;
@JsonProperty("installment_terms")
private List<Integer> installmentTerms;
private List<Bank> banks;

public PaymentMethod() {
}
Expand Down Expand Up @@ -52,5 +53,11 @@ public void setInstallmentTerms(List<Integer> installmentTerms) {
this.installmentTerms = installmentTerms;
}

public List<Bank> getBanks() {
return this.banks;
}

public void setBanks(List<Bank> banks) {
this.banks = banks;
}
}
12 changes: 12 additions & 0 deletions src/main/java/co/omise/models/Source.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Source extends Model {
private FlowType flow;
private long amount;
private String currency;
private String bank;
private String barcode;
private References references;
private String email;
Expand Down Expand Up @@ -77,6 +78,10 @@ public void setCurrency(String currency) {
this.currency = currency;
}

public String getBank() { return this.bank; }

public void setBank(String bank) { this.bank = bank; }

public String getBarcode() {
return barcode;
}
Expand Down Expand Up @@ -176,6 +181,8 @@ public static class CreateRequestBuilder extends RequestBuilder<Source> {
@JsonProperty
private String description;
@JsonProperty
private String bank;
@JsonProperty
private String barcode;
@JsonProperty("store_id")
private String storeId;
Expand Down Expand Up @@ -236,6 +243,11 @@ public CreateRequestBuilder description(String description) {
return this;
}

public CreateRequestBuilder bank(String bank) {
this.bank = bank;
return this;
}

public CreateRequestBuilder barcode(String barcode) {
this.barcode = barcode;
return this;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/co/omise/models/SourceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public enum SourceType {
BarcodeAlipay,
@JsonProperty("econtext")
Econtext,
@JsonProperty("fpx")
Fpx,
@JsonProperty("truemoney")
TrueMoney,
@JsonProperty("installment_bay")
Expand Down Expand Up @@ -68,6 +70,8 @@ public String toString() {
return "barcode_alipay";
case Econtext:
return "econtext";
case Fpx:
return "fpx";
case TrueMoney:
return "truemoney";
case InstBankingBay:
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/co/omise/live/LiveSourceRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,28 @@ public void testLiveSourceZeroInterestInstallments() throws IOException, OmiseEx
assertEquals("THB", source.getCurrency());
assertTrue(source.isZeroInterestInstallments());
}

@Test
@Ignore("only hit the network when we need to.")
public void testLiveSourceFpx() throws IOException, OmiseException {
Request<Source> request = new Source.CreateRequestBuilder()
.type(SourceType.Fpx)
.amount(10000)
.currency("myr")
.bank("cimb")
.email("[email protected]")
.build();

Source source = client.sendRequest(request);

System.out.println("created source: " + source.getId());

assertNotNull(source.getId());
assertEquals("fpx", source.getType().toString());
assertEquals("redirect", source.getFlow().toString());
assertEquals(10000L, source.getAmount());
assertEquals("MYR", source.getCurrency());
assertEquals("cimb", source.getBank());
assertEquals("[email protected]", source.getEmail());
}
}
1 change: 1 addition & 0 deletions src/test/java/co/omise/models/SourceTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public void checkStringValue() {
assertEquals("econtext", SourceType.Econtext.toString());
assertEquals("truemoney", SourceType.TrueMoney.toString());
assertEquals("promptpay", SourceType.PromptPay.toString());
assertEquals("fpx", SourceType.Fpx.toString());
}
}
19 changes: 19 additions & 0 deletions src/test/java/co/omise/requests/CapabilityRequestTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package co.omise.requests;

import co.omise.models.Bank;
import co.omise.models.Capability;
import co.omise.models.OmiseException;
import co.omise.models.PaymentMethod;
import org.junit.Test;

import java.io.IOException;
import java.util.List;

public class CapabilityRequestTest extends RequestTest {

Expand All @@ -21,5 +24,21 @@ public void testGet() throws IOException, OmiseException {
assertTrue(capability.getBanks().size() > 0);
assertTrue(capability.getPaymentMethods().size() > 0);
assertFalse(capability.isZeroInterestInstallments());

List<PaymentMethod> paymentMethods = capability.getPaymentMethods();

for (PaymentMethod paymentMethod : paymentMethods) {
assertEquals("payment_method", paymentMethod.getObject());
assertTrue(paymentMethod.getCurrencies().size() > 0);

if (paymentMethod.getName().equals("fpx")) {
assertTrue(paymentMethod.getBanks().size() > 0);

Bank bank = paymentMethod.getBanks().get(0);
assertEquals("citi", bank.getCode());
assertEquals("Citibank", bank.getName());
assertFalse(bank.isActive());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"Visa",
"MasterCard"
],
"installment_terms": null
"installment_terms": null,
"banks": []
},
{
"object": "payment_method",
Expand All @@ -67,7 +68,8 @@
6,
9,
10
]
],
"banks": []
},
{
"object": "payment_method",
Expand All @@ -86,7 +88,8 @@
18,
24,
36
]
],
"banks": []
},
{
"object": "payment_method",
Expand All @@ -100,7 +103,8 @@
4,
6,
10
]
],
"banks": []
},
{
"object": "payment_method",
Expand All @@ -115,7 +119,8 @@
8,
9,
10
]
],
"banks": []
},
{
"object": "payment_method",
Expand All @@ -133,8 +138,35 @@
8,
9,
10
],
"banks": []
},
{
"object": "payment_method",
"name": "fpx",
"currencies": [
"MYR"
],
"card_brands": null,
"installment_terms": null,
"banks": [
{
"code": "citi",
"name": "Citibank",
"active": false
},
{
"code": "hongleong",
"name": "Hong Leong Bank",
"active": true
},
{
"code": "hsbc",
"name": "HSBC Bank",
"active": true
}
]
}
],
"zero_interest_installments": false
}
}
3 changes: 2 additions & 1 deletion src/test/resources/testdata/objects/capability_object.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
8,
9,
10
]
],
"banks": []
}
],
"zero_interest_installments": false
Expand Down

0 comments on commit cfa007b

Please sign in to comment.