Skip to content

Commit

Permalink
Support api 2019 (#178)
Browse files Browse the repository at this point in the history
* Add missing request params

* Restore old sonar organization

* Revert "Restore old sonar organization"

This reverts commit 3631241.

* Revert "Revert "Restore old sonar organization""

This reverts commit bbf5fe7.

* Update Card test

* Update charge request test

* Update customer tests

* Update recipient tests

* Update source test
  • Loading branch information
AnasNaouchi authored Sep 10, 2024
1 parent 1118ed5 commit 9514ff1
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 7 deletions.
23 changes: 23 additions & 0 deletions bin/test/testdata/fixtures/api.omise.co/recipients-post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"object": "recipient",
"id": "recp_test_50894vc13y8z4v51iuc",
"livemode": false,
"location": "/recipients/recp_test_50894vc13y8z4v51iuc",
"verified": true,
"active": true,
"name": "[email protected]",
"email": "[email protected]",
"description": "Default recipient",
"type": "individual",
"tax_id": null,
"bank_account": {
"object": "bank_account",
"brand": "test",
"last_digits": "6789",
"name": "JOHN DOE",
"created_at": "2015-06-02T09:26:59Z",
"account_number": "1111"
},
"failure_code": null,
"created_at": "2015-06-02T09:26:59Z"
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ buildscript {

dependencies {
classpath "io.github.goooler.shadow:shadow-gradle-plugin:8.1.8"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.15.0'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.42.0'
classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:5.1.0.4882")
}
}
Expand Down Expand Up @@ -175,7 +175,7 @@ dependencies {
sonar {
properties {
property 'sonar.host.url', 'https://sonarcloud.io'
property 'sonar.organization', 'omise-1'
property 'sonar.organization', 'omise'
property 'sonar.projectName', 'omise-java'
property 'sonar.projectKey', 'omise_omise-java'
property 'sonar.coverage.jacoco.xmlReportPaths', "${project.buildDir}/reports/jacoco/jacocoTestReport/jacocoTestReport.xml"
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/co/omise/models/BankAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class BankAccount extends Model {
private String name;
@JsonProperty("type")
private String accountType;
@JsonProperty("account_number")
private String accountNumber;

public String getBankCode() {
return this.bankCode;
Expand Down Expand Up @@ -67,6 +69,14 @@ public void setAccountType(String accountType) {
this.accountType = accountType;
}

public String getAccountNumber() {
return this.accountNumber;
}

public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}

public static class Params extends co.omise.models.Params {
@JsonProperty("bank_code")
private String bankCode;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/co/omise/models/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ public static class Create extends co.omise.models.Params {
@JsonProperty
private String street2;

@JsonProperty
private String email;

public Create city(String city) {
this.city = city;
return this;
Expand Down Expand Up @@ -290,6 +293,11 @@ public Create street2(String street2) {
return this;
}

public Create email(String email) {
this.email = email;
return this;
}

public Create expiration(YearMonth expiration) {
return expirationMonth(expiration.getMonthValue())
.expirationYear(expiration.getYear());
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/co/omise/models/Charge.java
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,14 @@ public static class CreateRequestBuilder extends RequestBuilder<Charge> {
private AuthorizationType authorizationType;
@JsonProperty("webhook_endpoints")
private List<String> webhookEndpoints;
@JsonProperty("first_charge")
private String firstCharge;
@JsonProperty("linked_account")
private String linkedAccount;
@JsonProperty("recurring_reason")
private String recurringReason;
@JsonProperty("transaction_indicator")
private String transactionIndicator;

@Override
protected String method() {
Expand Down Expand Up @@ -665,6 +673,26 @@ public CreateRequestBuilder webhookEndpoints(List<String> webhookEndpoints) {
return this;
}

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

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

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

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

@Override
protected RequestBody payload() throws IOException {
return serialize();
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/co/omise/models/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public static class UpdateRequestBuilder extends RequestBuilder<Customer> {
private String email;
@JsonProperty
private Map<String, Object> metadata;
@JsonProperty("linked_account")
private String linkedAccount;
public UpdateRequestBuilder(String customerId) {
this.customerId = customerId;
}
Expand Down Expand Up @@ -173,6 +175,11 @@ public UpdateRequestBuilder metadata(Map<String, Object> metadata) {
return this;
}

public UpdateRequestBuilder linkedAccount(String linkedAccount) {
this.linkedAccount = linkedAccount;
return this;
}

@Override
protected RequestBody payload() throws IOException {
return serialize();
Expand Down Expand Up @@ -225,6 +232,8 @@ public static class CreateRequestBuilder extends RequestBuilder<Customer> {
private String email;
@JsonProperty
private Map<String, Object> metadata;
@JsonProperty("linked_account")
private String linkedAccount;

@Override
protected String method() {
Expand Down Expand Up @@ -261,6 +270,11 @@ public CreateRequestBuilder metadata(Map<String, Object> metadata) {
return this;
}

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

@Override
protected RequestBody payload() throws IOException {
return serialize();
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/co/omise/models/Source.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ public static class CreateRequestBuilder extends RequestBuilder<Source> {
private String phoneNumber;
@JsonProperty("items")
private List<Item> items;

@JsonProperty
private Shipping billing;
@JsonProperty("promotion_code")
private String promotionCode;

@Override
protected String method() {
return POST;
Expand Down Expand Up @@ -361,6 +365,16 @@ public CreateRequestBuilder platformType(PlatformType platformType) {
return this;
}

public CreateRequestBuilder billing(Shipping billing) {
this.billing = billing;
return this;
}

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

@Override
protected RequestBody payload() throws IOException {
return serialize();
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/co/omise/requests/ChargeRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void testCreateWithWebhooks() throws IOException, OmiseException {
Charge charge = getTestRequester().sendRequest(createChargeRequest);

assertRequested("POST", "/charges", 200);
assertRequestBody("{\"amount\":100000,\"capture\":false,\"card\":null,\"currency\":\"thb\",\"customer\":null,\"description\":null,\"ip\":null,\"metadata\":null,\"reference\":null,\"source\":null,\"zero_interest_installments\":false,\"expires_at\":null,\"platform_fee\":null,\"return_uri\":null,\"authorization_type\":null,\"webhook_endpoints\":[\"https://webhook.site/123\"]}");
assertRequestBody("{\"amount\":100000,\"capture\":false,\"card\":null,\"currency\":\"thb\",\"customer\":null,\"description\":null,\"ip\":null,\"metadata\":null,\"reference\":null,\"source\":null,\"zero_interest_installments\":false,\"expires_at\":null,\"platform_fee\":null,\"return_uri\":null,\"authorization_type\":null,\"webhook_endpoints\":[\"https://webhook.site/123\"],\"first_charge\":null,\"linked_account\":null,\"recurring_reason\":null,\"transaction_indicator\":null}");
assertNotNull(charge);
}

Expand Down Expand Up @@ -93,12 +93,16 @@ public void testCreatePartialCaptureCharge() throws IOException, OmiseException
.capture(false)
.authorizationType(AuthorizationType.PreAuth)
.returnUri("http://example.com/orders/345678/complete")
.firstCharge(CHARGE_ID)
.linkedAccount("acc_id")
.recurringReason("reason")
.transactionIndicator("trans_id")
.build();

Charge charge = getTestRequester().sendRequest(createChargeRequest);

assertRequested("POST", "/charges", 200);
assertRequestBody("{\"amount\":100000,\"capture\":false,\"card\":null,\"currency\":\"thb\",\"customer\":null,\"description\":null,\"ip\":null,\"metadata\":null,\"reference\":null,\"source\":null,\"zero_interest_installments\":false,\"expires_at\":null,\"platform_fee\":null,\"return_uri\":\"http://example.com/orders/345678/complete\",\"authorization_type\":\"pre_auth\",\"webhook_endpoints\":null}");
assertRequestBody("{\"amount\":100000,\"capture\":false,\"card\":null,\"currency\":\"thb\",\"customer\":null,\"description\":null,\"ip\":null,\"metadata\":null,\"reference\":null,\"source\":null,\"zero_interest_installments\":false,\"expires_at\":null,\"platform_fee\":null,\"return_uri\":\"http://example.com/orders/345678/complete\",\"authorization_type\":\"pre_auth\",\"webhook_endpoints\":null,\"first_charge\":\"chrg_test_4yq7duw15p9hdrjp8oq\",\"linked_account\":\"acc_id\",\"recurring_reason\":\"reason\",\"transaction_indicator\":\"trans_id\"}");
assertNotNull(charge);
}

Expand Down
5 changes: 5 additions & 0 deletions src/test/java/co/omise/requests/CustomerRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ public void testCreate() throws IOException, OmiseException {
Request<Customer> request = new Customer.CreateRequestBuilder()
.email("[email protected]")
.description("John Doe (id: 30)")
.linkedAccount("acc_id")
.build();

Customer customer = getTestRequester().sendRequest(request);

assertRequested("POST", "/customers", 200);
assertRequestBody("{\"card\":null,\"description\":\"John Doe (id: 30)\",\"email\":\"[email protected]\",\"metadata\":null,\"linked_account\":\"acc_id\"}");


assertEquals("customer", customer.getObject());
assertEquals(CUSTOMER_ID, customer.getId());
Expand All @@ -44,10 +47,12 @@ public void testGet() throws IOException, OmiseException {
public void testUpdate() throws IOException, OmiseException {
Request<Customer> request = new Customer.UpdateRequestBuilder(CUSTOMER_ID)
.email("[email protected]")
.linkedAccount("acc_id")
.build();
Customer customer = getTestRequester().sendRequest(request);

assertRequested("PATCH", "/customers/" + CUSTOMER_ID, 200);
assertRequestBody("{\"email\":\"[email protected]\",\"linked_account\":\"acc_id\"}");

assertEquals(CUSTOMER_ID, customer.getId());
assertEquals("[email protected]", customer.getEmail());
Expand Down
1 change: 1 addition & 0 deletions src/test/java/co/omise/requests/RecipientRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void testCreate() throws IOException, OmiseException {
assertEquals(RECIPIENT_ID, recipient.getId());
assertEquals("[email protected]", recipient.getEmail());
assertEquals("6789", recipient.getBankAccount().getLastDigits());
assertEquals("1111", recipient.getBankAccount().getAccountNumber());
assertEquals("Default recipient", recipient.getDescription());
}

Expand Down
10 changes: 10 additions & 0 deletions src/test/java/co/omise/requests/SourceRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;

import co.omise.models.OmiseException;
import co.omise.models.Shipping;
import co.omise.models.Source;
import co.omise.models.SourceType;
import co.omise.testutils.TestSourceRequestBuilder;
Expand All @@ -15,13 +16,22 @@ public class SourceRequestTest extends RequestTest {

@Test
public void testCreate() throws IOException, OmiseException {

Shipping shipping = new Shipping();
shipping.country = "TH";
shipping.postalCode = "000000";
shipping.street1 = "Street";

Request<Source> request = new Source.CreateRequestBuilder()
.amount(100000)
.currency("thb")
.type(SourceType.Alipay)
.billing(shipping)
.promotionCode("code")
.build();

Source source = getTestRequester().sendRequest(request);
assertRequestBody("{\"amount\":100000,\"bank\":null,\"barcode\":null,\"currency\":\"thb\",\"email\":null,\"ip\":null,\"name\":null,\"type\":\"alipay\",\"shipping\":null,\"billing\":{\"street1\":\"Street\",\"street2\":null,\"city\":null,\"state\":null,\"country\":\"TH\",\"postal_code\":\"000000\"},\"installment_term\":0,\"mobile_number\":null,\"store_id\":null,\"store_name\":null,\"terminal_id\":null,\"zero_interest_installments\":false,\"platform_type\":null,\"phone_number\":null,\"items\":null,\"promotion_code\":\"code\"}");

assertRequested("POST", "/sources", 200);
assertEquals(100000L, source.getAmount());
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/co/omise/requests/TokenRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ public void testCreate() throws IOException, OmiseException {
.expiration(YearMonth.now().plusYears(1))
.securityCode("123")
.city("Bangkok")
.postalCode("10240"))
.postalCode("10240")
.email("[email protected]")
)
.build();

Token token = getTestRequester().sendRequest(request);

assertRequested("POST", "/tokens", 200);
assertVaultRequest();
assertRequestBody("{\"card\":{\"city\":\"Bangkok\",\"country\":null,\"name\":\"JOHN DOE\",\"number\":\"4242424242424242\",\"state\":null,\"street1\":null,\"street2\":null,\"email\":\"[email protected]\",\"expiration_month\":9,\"expiration_year\":2025,\"phone_number\":null,\"postal_code\":\"10240\",\"security_code\":\"123\"}}");

assertEquals(TOKEN_ID, token.getId());
assertFalse(token.isLiveMode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"brand": "test",
"last_digits": "6789",
"name": "JOHN DOE",
"created_at": "2015-06-02T09:26:59Z"
"created_at": "2015-06-02T09:26:59Z",
"account_number": "1111"
},
"failure_code": null,
"created_at": "2015-06-02T09:26:59Z"
Expand Down

0 comments on commit 9514ff1

Please sign in to comment.