Skip to content
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
38 changes: 38 additions & 0 deletions src/main/java/co/omise/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ void captureCharge() throws IOException, OmiseException, ClientException {
System.out.printf("captured charge: %s", charge.getId());
}

void partialCaptureCharge() throws IOException, OmiseException, ClientException {
Request<Charge> captureChargeRequest =
new Charge.CaptureRequestBuilder("chrg_test_4xso2s8ivdej29pqnhz")
.captureAmount(10000)
.build();
Charge charge = client().sendRequest(captureChargeRequest);

System.out.printf("captured charge: %s", charge.getId());
}

void chargeWithCard() throws IOException, OmiseException, ClientException {
Request<Charge> createChargeRequest =
new Charge.CreateRequestBuilder()
Expand Down Expand Up @@ -118,6 +128,34 @@ void chargeWithToken() throws IOException, OmiseException, ClientException {
System.out.printf("created charge: %s", charge.getId());
}

void createPartialCaptureCharge() throws IOException, OmiseException, ClientException {
Request<Token> request = new Token.CreateRequestBuilder()
.card(new Card.Create()
.name("Somchai Prasert")
.number("4242424242424242")
.expirationMonth(10)
.expirationYear(2022)
.city("Bangkok")
.postalCode("10320")
.securityCode("123"))
.build();
Token token = client().sendRequest(request);

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

Request<Charge> createChargeRequest =
new Charge.CreateRequestBuilder()
.amount(100000) // 1,000 THB
.currency("thb")
.card(token.getId())
.authorizationType(AuthorizationType.PreAuth)
.capture(false)
.build();
Charge charge = client().sendRequest(createChargeRequest);

System.out.printf("created charge: %s", charge.getId());
}

void listCharges() throws IOException, OmiseException, ClientException {
Request<ScopedList<Charge>> listChargeRequest = new Charge.ListRequestBuilder().build();
ScopedList<Charge> charges = client().sendRequest(listChargeRequest);
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/co/omise/models/Charge.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public class Charge extends Model {
private boolean zeroInterestInstallments;
@JsonProperty("authorization_type")
private AuthorizationType authorizationType;
@JsonProperty("authorized_amount")
private long authorizedAmount;
@JsonProperty("captured_amount")
private long capturedAmount;

public long getAmount() {
return this.amount;
Expand Down Expand Up @@ -470,6 +474,22 @@ public void setAuthorizationType(AuthorizationType authorizationType) {
this.authorizationType = authorizationType;
}

public long getAuthorizedAmount() {
return authorizedAmount;
}

public void setAuthorizedAmount(long authorizedAmount) {
this.authorizedAmount = authorizedAmount;
}

public long getCapturedAmount() {
return capturedAmount;
}

public void setCapturedAmount(long capturedAmount) {
this.capturedAmount = capturedAmount;
}

public static class ListRequestBuilder extends RequestBuilder<ScopedList<Charge>> {
private ScopedList.Options options;

Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/testdata/objects/charge_object.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"amount": 100000,
"currency": "thb",
"authorization_type": "pre_auth",
"authorized_amount": 10000,
"captured_amount": 0,
"description": null,
"capture": true,
"authorized": true,
Expand Down