Skip to content

Commit 199c072

Browse files
SP-351 Java - PUT /refunds/guid/:guid
1 parent 8d3ca0f commit 199c072

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/main/java/com/bitpay/sdk/Client.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,47 @@ public Refund updateRefund(String refundId, String status) throws RefundUpdateEx
706706
return refund;
707707
}
708708

709+
/**
710+
* Update the status of a BitPay invoice.
711+
*
712+
* @param guid A BitPay refund Guid.
713+
* @param status The new status for the refund to be updated.
714+
* @return A BitPay generated Refund object.
715+
* @throws RefundUpdateException RefundUpdateException class
716+
* @throws BitPayException BitPayException class
717+
*/
718+
public Refund updateRefundByGuid(String guid, String status) throws RefundUpdateException, BitPayException {
719+
final Map<String, String> params = new HashMap<>();
720+
params.put("token", this.getAccessToken(Facade.Merchant));
721+
if (guid == null || status == null) {
722+
throw new RefundUpdateException(null, "Updating the refund requires a refund ID and a new status to be set.");
723+
}
724+
if (status != null) {
725+
params.put("status", status);
726+
}
727+
728+
ObjectMapper mapper = new ObjectMapper();
729+
String json;
730+
Refund refund;
731+
732+
try {
733+
json = mapper.writeValueAsString(params);
734+
} catch (JsonProcessingException e) {
735+
throw new RefundUpdateException(null, "failed to serialize object : " + e.getMessage());
736+
}
737+
738+
try {
739+
HttpResponse response = this.update("refunds/guid/" + guid, json);
740+
refund = new ObjectMapper().readValue(this.responseToJsonString(response), Refund.class);
741+
} catch (BitPayException ex) {
742+
throw new RefundUpdateException(ex.getStatusCode(), ex.getReasonPhrase());
743+
} catch (Exception e) {
744+
throw new RefundUpdateException(null, "failed to deserialize BitPay server response (Refund) : " + e.getMessage());
745+
}
746+
747+
return refund;
748+
}
749+
709750
/**
710751
* Send a refund notification.
711752
*

0 commit comments

Comments
 (0)