21
21
use BitPaySDK \Exceptions \PayoutQueryException ;
22
22
use BitPaySDK \Exceptions \RateQueryException ;
23
23
use BitPaySDK \Exceptions \RefundCreationException ;
24
+ use BitPaySDK \Exceptions \RefundCancellationException ;
24
25
use BitPaySDK \Exceptions \RefundQueryException ;
25
26
use BitPaySDK \Exceptions \SettlementQueryException ;
26
27
use BitPaySDK \Exceptions \SubscriptionCreationException ;
32
33
use BitPaySDK \Model \Invoice \Refund ;
33
34
use BitPaySDK \Model \Ledger \Ledger ;
34
35
use BitPaySDK \Model \Payout \PayoutBatch ;
36
+ use BitPaySDK \Model \Payout \PayoutRecipient ;
37
+ use BitPaySDK \Model \Payout \PayoutRecipients ;
35
38
use BitPaySDK \Model \Rate \Rates ;
36
39
use BitPaySDK \Model \Settlement \Settlement ;
37
40
use BitPaySDK \Model \Subscription \Subscription ;
44
47
* Class Client
45
48
* @package Bitpay
46
49
* @author Antonio Buedo
47
- * @version 4 .0.2006
50
+ * @version 5 .0.2011
48
51
* See bitpay.com/api for more information.
49
- * date 19.06 .2020
52
+ * date 30.10 .2020
50
53
*/
51
54
class Client
52
55
{
@@ -253,13 +256,13 @@ public function getInvoices(
253
256
if ($ status ) {
254
257
$ params ["status " ] = $ status ;
255
258
}
256
- if ($ status ) {
259
+ if ($ orderId ) {
257
260
$ params ["orderId " ] = $ orderId ;
258
261
}
259
- if ($ status ) {
262
+ if ($ limit ) {
260
263
$ params ["limit " ] = $ limit ;
261
264
}
262
- if ($ status ) {
265
+ if ($ offset ) {
263
266
$ params ["offset " ] = $ offset ;
264
267
}
265
268
@@ -402,7 +405,7 @@ public function getRefund(
402
405
* @param $refund Refund The BitPay invoice having the associated refund to be canceled. Must have been obtained
403
406
* using the merchant facade.
404
407
* @return bool True if the refund was successfully canceled, false otherwise.
405
- * @throws BitPayException BitPayException class
408
+ * @throws RefundCancellationException RefundCancellationException class
406
409
*/
407
410
public function cancelRefund (string $ invoiceId , Refund $ refund ): bool
408
411
{
@@ -412,14 +415,14 @@ public function cancelRefund(string $invoiceId, Refund $refund): bool
412
415
413
416
$ responseJson = $ this ->_RESTcli ->delete ("invoices/ " .$ invoiceId ."/refunds/ " .$ refund ->getId (), $ params );
414
417
} catch (Exception $ e ) {
415
- throw new PayoutCancellationException ("failed to serialize server object : " .$ e ->getMessage ());
418
+ throw new RefundCancellationException ("failed to serialize server object : " .$ e ->getMessage ());
416
419
}
417
420
418
421
try {
419
422
$ result = strtolower (trim ($ responseJson , '" ' )) === "success " ;
420
423
421
424
} catch (Exception $ e ) {
422
- throw new PayoutCancellationException (
425
+ throw new RefundCancellationException (
423
426
"failed to deserialize BitPay server response (Refund) : " .$ e ->getMessage ());
424
427
}
425
428
@@ -429,7 +432,7 @@ public function cancelRefund(string $invoiceId, Refund $refund): bool
429
432
/**
430
433
* Create a BitPay Bill.
431
434
*
432
- * @param $bill string A Bill object with request parameters defined.
435
+ * @param $bill Bill A Bill object with request parameters defined.
433
436
* @param $facade string The facade used to create it.
434
437
* @param $signRequest bool Signed request.
435
438
* @return Bill A BitPay generated Bill object.
@@ -701,6 +704,148 @@ public function getLedgers(): array
701
704
return $ ledgers ;
702
705
}
703
706
707
+ /**
708
+ * Submit BitPay Payout Recipients.
709
+ *
710
+ * @param $recipients PayoutRecipients A PayoutRecipients object with request parameters defined.
711
+ * @return array A list of BitPay PayoutRecipients objects..
712
+ * @throws PayoutCreationException BitPayException class
713
+ */
714
+ public function submitPayoutRecipients (PayoutRecipients $ recipients ): array
715
+ {
716
+ try {
717
+ $ recipients ->setToken ($ this ->_tokenCache ->getTokenByFacade (Facade::Payroll));
718
+ $ recipients ->setGuid (Util::guid ());
719
+
720
+ $ responseJson = $ this ->_RESTcli ->post ("recipients " , $ recipients ->toArray ());
721
+ } catch (Exception $ e ) {
722
+ throw new PayoutCreationException ("failed to serialize PayoutRecipients object : " .$ e ->getMessage ());
723
+ }
724
+
725
+ try {
726
+ $ mapper = new JsonMapper ();
727
+ $ recipients = $ mapper ->mapArray (
728
+ json_decode ($ responseJson ),
729
+ [],
730
+ 'BitPaySDK\Model\Payout\PayoutRecipient '
731
+ );
732
+
733
+ } catch (Exception $ e ) {
734
+ throw new PayoutCreationException (
735
+ "failed to deserialize BitPay server response (PayoutRecipients) : " .$ e ->getMessage ());
736
+ }
737
+
738
+ return $ recipients ;
739
+ }
740
+
741
+ /**
742
+ * Retrieve a collection of BitPay Payout Recipients.
743
+ *
744
+ * @param $status string|null The recipient status you want to query on.
745
+ * @param $limit int|null Maximum results that the query will return (useful for paging results).
746
+ * result).
747
+ * @return array A list of BitPayRecipient objects.
748
+ * @throws BitPayException BitPayException class
749
+ */
750
+ public function getPayoutRecipients (
751
+ string $ status = null ,
752
+ int $ limit = null
753
+ ): array {
754
+ try {
755
+ $ params = [];
756
+ $ params ["token " ] = $ this ->_tokenCache ->getTokenByFacade (Facade::Payroll);
757
+ if ($ status ) {
758
+ $ params ["status " ] = $ status ;
759
+ }
760
+ if ($ limit ) {
761
+ $ params ["limit " ] = $ limit ;
762
+ }
763
+
764
+ $ responseJson = $ this ->_RESTcli ->get ("recipients " , $ params );
765
+ } catch (Exception $ e ) {
766
+ throw new PayoutQueryException ("failed to serialize PayoutRecipients object : " .$ e ->getMessage ());
767
+ }
768
+
769
+ try {
770
+ $ mapper = new JsonMapper ();
771
+ $ recipients = $ mapper ->mapArray (
772
+ json_decode ($ responseJson ),
773
+ [],
774
+ 'BitPaySDK\Model\Payout\PayoutRecipient '
775
+ );
776
+
777
+ } catch (Exception $ e ) {
778
+ throw new PayoutQueryException (
779
+ "failed to deserialize BitPay server response (PayoutRecipients) : " .$ e ->getMessage ());
780
+ }
781
+
782
+ return $ recipients ;
783
+ }
784
+
785
+ /**
786
+ * Retrieve a BitPay payout recipient by batch id using. The client must have been previously authorized for the
787
+ * payroll facade.
788
+ *
789
+ * @param $recipientId string The id of the recipient to retrieve.
790
+ * @return PayoutRecipient A BitPay PayoutRecipient object.
791
+ * @throws PayoutQueryException BitPayException class
792
+ */
793
+ public function getPayoutRecipient (string $ recipientId ): PayoutRecipient
794
+ {
795
+ try {
796
+ $ params = [];
797
+ $ params ["token " ] = $ this ->_tokenCache ->getTokenByFacade (Facade::Payroll);
798
+
799
+ $ responseJson = $ this ->_RESTcli ->get ("recipients/ " .$ recipientId , $ params );
800
+ } catch (Exception $ e ) {
801
+ throw new PayoutQueryException ("failed to serialize PayoutRecipient object : " .$ e ->getMessage ());
802
+ }
803
+
804
+ try {
805
+ $ mapper = new JsonMapper ();
806
+ $ recipient = $ mapper ->map (
807
+ json_decode ($ responseJson ),
808
+ new PayoutRecipient ()
809
+ );
810
+
811
+ } catch (Exception $ e ) {
812
+ throw new PayoutQueryException (
813
+ "failed to deserialize BitPay server response (PayoutRecipient) : " .$ e ->getMessage ());
814
+ }
815
+
816
+ return $ recipient ;
817
+ }
818
+
819
+ // TODO Resource inopperative
820
+ // /**
821
+ // * Notify BitPay Payout Recipients.
822
+ // *
823
+ // * @param $recipientId string The id of the recipient to notify.
824
+ // * @return bool True if the notification was successfully sent, false otherwise.
825
+ // * @throws PayoutCreationException BitPayException class
826
+ // */
827
+ // public function notifyPayoutRecipient(string $recipientId): array
828
+ // {
829
+ // try {
830
+ // $content = [];
831
+ // $content["token"] = $this->_tokenCache->getTokenByFacade(Facade::Payroll);
832
+ //
833
+ // $responseJson = $this->_RESTcli->post("recipients/".$recipientId."/notifications", $content);
834
+ // } catch (Exception $e) {
835
+ // throw new PayoutCreationException("failed to serialize PayoutRecipients object : ".$e->getMessage());
836
+ // }
837
+ //
838
+ // try {
839
+ // $result = json_decode($responseJson)->success;
840
+ //
841
+ // } catch (Exception $e) {
842
+ // throw new PayoutCreationException(
843
+ // "failed to deserialize BitPay server response (PayoutRecipients) : ".$e->getMessage());
844
+ // }
845
+ //
846
+ // return $result;
847
+ // }
848
+
704
849
/**
705
850
* Submit a BitPay Payout batch.
706
851
*
@@ -902,7 +1047,7 @@ public function getSettlements(
902
1047
/**
903
1048
* Retrieves a summary of the specified settlement.
904
1049
*
905
- * @param $settlementId Settlement Id.
1050
+ * @param $settlementId string Settlement Id.
906
1051
* @return Settlement A BitPay Settlement object.
907
1052
* @throws BitPayException BitPayException class
908
1053
*/
@@ -968,7 +1113,7 @@ public function getSettlementReconciliationReport(Settlement $settlement): Settl
968
1113
/**
969
1114
* Create a BitPay Subscription.
970
1115
*
971
- * @param $subscription string A Subscription object with request parameters defined.
1116
+ * @param $subscription Subscription A Subscription object with request parameters defined.
972
1117
* @return Subscription A BitPay generated Subscription object.
973
1118
* @throws BitPayException BitPayException class
974
1119
*/
0 commit comments