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