@@ -791,6 +791,47 @@ public Refund updateRefund(String refundId, String status) throws RefundUpdateEx
791791 return refund ;
792792 }
793793
794+ /**
795+ * Update the status of a BitPay invoice.
796+ *
797+ * @param guid A BitPay refund Guid.
798+ * @param status The new status for the refund to be updated.
799+ * @return A BitPay generated Refund object.
800+ * @throws RefundUpdateException RefundUpdateException class
801+ * @throws BitPayException BitPayException class
802+ */
803+ public Refund updateRefundByGuid (String guid , String status ) throws RefundUpdateException , BitPayException {
804+ final Map <String , String > params = new HashMap <>();
805+ params .put ("token" , this .getAccessToken (Facade .Merchant ));
806+ if (guid == null || status == null ) {
807+ throw new RefundUpdateException (null , "Updating the refund requires a refund ID and a new status to be set." );
808+ }
809+ if (status != null ) {
810+ params .put ("status" , status );
811+ }
812+
813+ ObjectMapper mapper = new ObjectMapper ();
814+ String json ;
815+ Refund refund ;
816+
817+ try {
818+ json = mapper .writeValueAsString (params );
819+ } catch (JsonProcessingException e ) {
820+ throw new RefundUpdateException (null , "failed to serialize object : " + e .getMessage ());
821+ }
822+
823+ try {
824+ HttpResponse response = this .update ("refunds/guid/" + guid , json );
825+ refund = new ObjectMapper ().readValue (this .responseToJsonString (response ), Refund .class );
826+ } catch (BitPayException ex ) {
827+ throw new RefundUpdateException (ex .getStatusCode (), ex .getReasonPhrase ());
828+ } catch (Exception e ) {
829+ throw new RefundUpdateException (null , "failed to deserialize BitPay server response (Refund) : " + e .getMessage ());
830+ }
831+
832+ return refund ;
833+ }
834+
794835 /**
795836 * Send a refund notification.
796837 *
0 commit comments