Skip to content

Commit fe85627

Browse files
authored
Merge pull request #209 from mwarzybok-sumoheavy/feature/SP-400
SP-400 Java SDK 8.x: DELETE /invoices/guid/:guid
2 parents e17a869 + ed7c6ea commit fe85627

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

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

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,8 @@ public Invoice cancelInvoice(String invoiceId) throws InvoiceCancellationExcepti
592592
}
593593

594594
/**
595-
* Delete a previously created BitPay invoice.
595+
* Cancellation will require EITHER an SMS or E-mail to have already been set if the invoice has proceeded to
596+
* the point where it may have been paid, unless using forceCancel parameter.
596597
*
597598
* @param invoiceId The Id of the BitPay invoice to be canceled.
598599
* @param forceCancel If 'true' it will cancel the invoice even if no contact information is present.
@@ -620,6 +621,57 @@ public Invoice cancelInvoice(String invoiceId, Boolean forceCancel) throws Invoi
620621
return invoice;
621622
}
622623

624+
/**
625+
* Cancellation will require EITHER an SMS or E-mail to have already been set if the invoice has proceeded to
626+
* the point where it may have been paid, unless using forceCancel parameter.
627+
*
628+
* @param guid GUID A passthru variable provided by the merchant and designed to be used by the merchant to
629+
* correlate the invoice with an order ID in their system, which can be used as a lookup variable
630+
* in Retrieve Invoice by GUID.
631+
* @return Invoice Invoice
632+
* @throws BitPayException BitPayException class
633+
*/
634+
public Invoice cancelInvoiceByGuid(String guid) throws BitPayException {
635+
return this.cancelInvoiceByGuid(guid, false);
636+
}
637+
638+
/**
639+
* Cancellation will require EITHER an SMS or E-mail to have already been set if the invoice has proceeded to
640+
* the point where it may have been paid, unless using forceCancel parameter.
641+
* @param guid GUID A passthru variable provided by the merchant and designed to be used by the merchant to
642+
* correlate the invoice with an order ID in their system, which can be used as a lookup variable
643+
* in Retrieve Invoice by GUID.
644+
* @param forceCancel Parameter that will cancel the invoice even if no contact information is present.
645+
* Note: Canceling a paid invoice without contact information requires a manual support
646+
* process and is not recommended.
647+
* @return Invoice Invoice
648+
* @throws BitPayException BitPayException class
649+
*/
650+
public Invoice cancelInvoiceByGuid(String guid, Boolean forceCancel) throws BitPayException {
651+
if (Objects.isNull(guid) || Objects.isNull(forceCancel)) {
652+
throw new InvoiceCancellationException(null, "missing required parameter");
653+
}
654+
655+
final List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
656+
params.add(new BasicNameValuePair("token", this.getAccessToken(Facade.Merchant)));
657+
if (forceCancel.equals(true)) {
658+
params.add(new BasicNameValuePair("forceCancel", forceCancel.toString()));
659+
}
660+
Invoice invoice;
661+
662+
try {
663+
HttpResponse response = this.delete("invoices/guid/" + guid, params);
664+
invoice = new ObjectMapper().readValue(this.responseToJsonString(response), Invoice.class);
665+
} catch (BitPayException ex) {
666+
throw new InvoiceCancellationException(ex.getStatusCode(), ex.getReasonPhrase());
667+
} catch (Exception e) {
668+
throw new InvoiceCancellationException(null,
669+
"failed to deserialize BitPay server response (Invoice) : " + e.getMessage());
670+
}
671+
672+
return invoice;
673+
}
674+
623675
/**
624676
* Create a refund for a BitPay invoice.
625677
*

0 commit comments

Comments
 (0)