Skip to content

Commit

Permalink
Merge pull request #94 from javiersuweijie/fix/update-charge-to-allow…
Browse files Browse the repository at this point in the history
…-optional

fix: make charge request params optional
  • Loading branch information
ErvanAdetya authored Aug 10, 2021
2 parents 47050f1 + 0240ee1 commit 2bc377e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion xendit-java-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group 'com.xendit'
version '1.14.0'
version '1.15.0'

sourceCompatibility = 1.8

Expand Down
14 changes: 9 additions & 5 deletions xendit-java-lib/src/main/java/com/xendit/model/CreditCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public static CreditCardCharge createAuthorization(
params.put("token_id", tokenId);
params.put("external_id", externalId);
params.put("amount", amount);
params.put("authentication_id", authenticationId);
params.put("card_cvn", cardCVN);
if (isNotEmpty(authenticationId)) params.put("authentication_id", authenticationId);
if (isNotEmpty(cardCVN)) params.put("card_cvn", cardCVN);
params.put("capture", capture);
String url = String.format("%s%s", Xendit.getUrl(), "/credit_card_charges");

Expand Down Expand Up @@ -103,9 +103,9 @@ public static CreditCardCharge createCharge(
params.put("token_id", tokenId);
params.put("external_id", externalId);
params.put("amount", amount);
params.put("authentication_id", authenticationId);
params.put("card_cvn", cardCVN);
params.put("descriptor", descriptor);
if (isNotEmpty(authenticationId)) params.put("authentication_id", authenticationId);
if (isNotEmpty(cardCVN)) params.put("card_cvn", cardCVN);
if (isNotEmpty(descriptor)) params.put("descriptor", descriptor);
String url = String.format("%s%s", Xendit.getUrl(), "/credit_card_charges");

return Xendit.requestClient.request(
Expand Down Expand Up @@ -251,4 +251,8 @@ public static CreditCardRefund createRefund(
return Xendit.requestClient.request(
RequestResource.Method.POST, url, headers, params, CreditCardRefund.class);
}

private static boolean isNotEmpty(String param) {
return param != null && !"".equals(param);
}
}

0 comments on commit 2bc377e

Please sign in to comment.