1: | <?php |
2: | |
3: | namespace Hyperwallet; |
4: | |
5: | use Hyperwallet\Exception\HyperwalletApiException; |
6: | use Hyperwallet\Exception\HyperwalletArgumentException; |
7: | use Hyperwallet\Model\AuthenticationToken; |
8: | use Hyperwallet\Model\Balance; |
9: | use Hyperwallet\Model\BankAccount; |
10: | use Hyperwallet\Model\BankAccountStatusTransition; |
11: | use Hyperwallet\Model\BankCard; |
12: | use Hyperwallet\Model\BankCardStatusTransition; |
13: | use Hyperwallet\Model\BusinessStakeholder; |
14: | use Hyperwallet\Model\BusinessStakeholderStatusTransition; |
15: | use Hyperwallet\Model\HyperwalletVerificationDocument; |
16: | use Hyperwallet\Model\HyperwalletVerificationDocumentReason; |
17: | use Hyperwallet\Model\HyperwalletVerificationDocumentCollection; |
18: | use Hyperwallet\Model\HyperwalletVerificationDocumentReasonCollection; |
19: | use Hyperwallet\Model\IProgramAware; |
20: | use Hyperwallet\Model\PaperCheck; |
21: | use Hyperwallet\Model\PaperCheckStatusTransition; |
22: | use Hyperwallet\Model\Payment; |
23: | use Hyperwallet\Model\PaymentStatusTransition; |
24: | use Hyperwallet\Model\PayPalAccount; |
25: | use Hyperwallet\Model\PayPalAccountStatusTransition; |
26: | use Hyperwallet\Model\PrepaidCard; |
27: | use Hyperwallet\Model\PrepaidCardStatusTransition; |
28: | use Hyperwallet\Model\Program; |
29: | use Hyperwallet\Model\ProgramAccount; |
30: | use Hyperwallet\Model\Receipt; |
31: | use Hyperwallet\Model\StatusTransition; |
32: | use Hyperwallet\Model\Transfer; |
33: | use Hyperwallet\Model\TransferMethod; |
34: | use Hyperwallet\Model\TransferMethodConfiguration; |
35: | use Hyperwallet\Model\TransferRefund; |
36: | use Hyperwallet\Model\TransferStatusTransition; |
37: | use Hyperwallet\Model\User; |
38: | use Hyperwallet\Model\UserStatusTransition; |
39: | use Hyperwallet\Model\VenmoAccount; |
40: | use Hyperwallet\Model\VenmoAccountStatusTransition; |
41: | use Hyperwallet\Model\WebhookNotification; |
42: | use Hyperwallet\Response\ListResponse; |
43: | use Hyperwallet\Util\ApiClient; |
44: | |
45: | |
46: | |
47: | |
48: | |
49: | |
50: | class Hyperwallet { |
51: | |
52: | |
53: | |
54: | |
55: | |
56: | |
57: | private $programToken; |
58: | |
59: | |
60: | |
61: | |
62: | |
63: | |
64: | private $client; |
65: | |
66: | |
67: | |
68: | |
69: | |
70: | |
71: | |
72: | |
73: | |
74: | |
75: | |
76: | |
77: | |
78: | public function __construct($username, $password, $programToken = null, $server = 'https://api.sandbox.hyperwallet.com', $encryptionData = array(), $clientOptions = array()) { |
79: | if (empty($username) || empty($password)) { |
80: | throw new HyperwalletArgumentException('You need to specify your API username and password!'); |
81: | } |
82: | |
83: | $this->programToken = $programToken; |
84: | $this->client = new ApiClient($username, $password, $server, $clientOptions, $encryptionData); |
85: | } |
86: | |
87: | |
88: | |
89: | |
90: | |
91: | |
92: | |
93: | |
94: | |
95: | |
96: | |
97: | private function setDocumentAndReasonFromResponseHelper($bodyResponse) { |
98: | if (array_key_exists("documents", $bodyResponse)) { |
99: | $documents = $bodyResponse["documents"]; |
100: | foreach ($documents as &$dVal) { |
101: | if (array_key_exists("reasons", $dVal)) { |
102: | $reasons = $dVal["reasons"]; |
103: | foreach ($reasons as &$rVal) { |
104: | $rVal = new HyperwalletVerificationDocumentReason($rVal); |
105: | } |
106: | $dVal["reasons"] = new HyperwalletVerificationDocumentReasonCollection(...$reasons); |
107: | } |
108: | $dVal = new HyperwalletVerificationDocument($dVal); |
109: | } |
110: | $bodyResponse["documents"] = new HyperwalletVerificationDocumentCollection(...$documents); |
111: | } |
112: | return $bodyResponse; |
113: | } |
114: | |
115: | |
116: | |
117: | |
118: | |
119: | |
120: | |
121: | |
122: | |
123: | |
124: | |
125: | |
126: | |
127: | |
128: | public function createUser(User $user) { |
129: | $this->addProgramToken($user); |
130: | $body = $this->client->doPost('/rest/v4/users', array(), $user, array()); |
131: | return new User($body); |
132: | } |
133: | |
134: | |
135: | |
136: | |
137: | |
138: | |
139: | |
140: | |
141: | |
142: | |
143: | public function getUser($userToken) { |
144: | if (empty($userToken)) { |
145: | throw new HyperwalletArgumentException('userToken is required!'); |
146: | } |
147: | $body = $this->client->doGet('/rest/v4/users/{user-token}', array('user-token' => $userToken), array()); |
148: | return new User($body); |
149: | } |
150: | |
151: | |
152: | |
153: | |
154: | |
155: | |
156: | |
157: | |
158: | |
159: | |
160: | public function updateUser(User $user) { |
161: | if (!$user->getToken()) { |
162: | throw new HyperwalletArgumentException('token is required!'); |
163: | } |
164: | $body = $this->client->doPut('/rest/v4/users/{user-token}', array('user-token' => $user->getToken()), $user, array()); |
165: | return new User($body); |
166: | } |
167: | |
168: | |
169: | |
170: | |
171: | |
172: | |
173: | |
174: | |
175: | |
176: | public function listUsers($options = array()) { |
177: | if (!empty($options)) { |
178: | $filteredArr = array_diff_key($options, array_flip(User::FILTERS_ARRAY())); |
179: | if (!empty($filteredArr)) { |
180: | throw new HyperwalletArgumentException('Invalid filter'); |
181: | } |
182: | } |
183: | |
184: | $body = $this->client->doGet('/rest/v4/users', array(),$options) ; |
185: | return new ListResponse($body, function ($entry) { |
186: | return new User($entry); |
187: | }); |
188: | } |
189: | |
190: | |
191: | |
192: | |
193: | |
194: | |
195: | |
196: | |
197: | |
198: | |
199: | |
200: | public function getUserStatusTransition($userToken, $statusTransitionToken) { |
201: | if (empty($userToken)) { |
202: | throw new HyperwalletArgumentException('userToken is required!'); |
203: | } |
204: | if (empty($statusTransitionToken)) { |
205: | throw new HyperwalletArgumentException('statusTransitionToken is required!'); |
206: | } |
207: | |
208: | $body = $this->client->doGet('/rest/v4/users/{user-token}/status-transitions/{status-transition-token}', array( |
209: | 'user-token' => $userToken, |
210: | 'status-transition-token' => $statusTransitionToken |
211: | ), array()); |
212: | return new UserStatusTransition($body); |
213: | } |
214: | |
215: | |
216: | |
217: | |
218: | |
219: | |
220: | |
221: | |
222: | |
223: | |
224: | |
225: | public function listUserStatusTransitions($userToken, array $options = array()) { |
226: | if (empty($userToken)) { |
227: | throw new HyperwalletArgumentException('userToken is required!'); |
228: | } |
229: | if (!empty($options)) { |
230: | $filteredArr = array_diff_key( $options, array_flip(StatusTransition::FILTERS_ARRAY()) ); |
231: | if (!empty($filteredArr)) { |
232: | throw new HyperwalletArgumentException('Invalid filter'); |
233: | } |
234: | } |
235: | |
236: | $body = $this->client->doGet('/rest/v4/users/{user-token}/status-transitions', array( |
237: | 'user-token' => $userToken |
238: | ), $options); |
239: | return new ListResponse($body, function ($entry) { |
240: | return new UserStatusTransition($entry); |
241: | }); |
242: | } |
243: | |
244: | |
245: | |
246: | |
247: | |
248: | |
249: | |
250: | |
251: | |
252: | |
253: | |
254: | |
255: | |
256: | public function getAuthenticationToken($userToken) { |
257: | if (empty($userToken)) { |
258: | throw new HyperwalletArgumentException('userToken is required!'); |
259: | } |
260: | $body = $this->client->doPost('/rest/v4/users/{user-token}/authentication-token', array( |
261: | 'user-token' => $userToken, |
262: | ), null, array()); |
263: | return new AuthenticationToken($body); |
264: | } |
265: | |
266: | |
267: | |
268: | |
269: | |
270: | |
271: | |
272: | |
273: | |
274: | |
275: | |
276: | |
277: | |
278: | |
279: | |
280: | public function createPaperCheck($userToken, PaperCheck $paperCheck) { |
281: | if (empty($userToken)) { |
282: | throw new HyperwalletArgumentException('userToken is required!'); |
283: | } |
284: | $body = $this->client->doPost('/rest/v4/users/{user-token}/paper-checks', |
285: | array('user-token' => $userToken), $paperCheck, array()); |
286: | return new PaperCheck($body); |
287: | } |
288: | |
289: | |
290: | |
291: | |
292: | |
293: | |
294: | |
295: | |
296: | |
297: | |
298: | |
299: | public function getPaperCheck($userToken, $paperCheckToken) { |
300: | if (empty($userToken)) { |
301: | throw new HyperwalletArgumentException('userToken is required!'); |
302: | } |
303: | if (empty($paperCheckToken)) { |
304: | throw new HyperwalletArgumentException('paperCheckToken is required!'); |
305: | } |
306: | $body = $this->client->doGet('/rest/v4/users/{user-token}/paper-checks/{paper-check-token}', array( |
307: | 'user-token' => $userToken, |
308: | 'paper-check-token' => $paperCheckToken |
309: | ), array()); |
310: | return new PaperCheck($body); |
311: | } |
312: | |
313: | |
314: | |
315: | |
316: | |
317: | |
318: | |
319: | |
320: | |
321: | |
322: | |
323: | public function updatePaperCheck($userToken, PaperCheck $paperCheck) { |
324: | $body = $this->updateTransferMethod($userToken, $paperCheck, 'paper-checks'); |
325: | return new PaperCheck($body); |
326: | } |
327: | |
328: | |
329: | |
330: | |
331: | |
332: | |
333: | |
334: | |
335: | |
336: | |
337: | |
338: | public function listPaperChecks($userToken, $options = array()) { |
339: | if (empty($userToken)) { |
340: | throw new HyperwalletArgumentException('userToken is required!'); |
341: | } |
342: | if (!empty($options)) { |
343: | $filteredArr = array_diff_key($options, array_flip(PaperCheck::FILTERS_ARRAY())); |
344: | if (!empty($filteredArr)) { |
345: | throw new HyperwalletArgumentException('Invalid filter'); |
346: | } |
347: | } |
348: | |
349: | $body = $this->client->doGet('/rest/v4/users/{user-token}/paper-checks', array('user-token' => $userToken), $options); |
350: | return new ListResponse($body, function ($entry) { |
351: | return new PaperCheck($entry); |
352: | }); |
353: | } |
354: | |
355: | |
356: | |
357: | |
358: | |
359: | |
360: | |
361: | |
362: | |
363: | |
364: | |
365: | public function deactivatePaperCheck($userToken, $paperCheckToken) { |
366: | $transition = new PaperCheckStatusTransition(); |
367: | $transition->setTransition(PaperCheckStatusTransition::TRANSITION_DE_ACTIVATED); |
368: | |
369: | return $this->createPaperCheckStatusTransition($userToken, $paperCheckToken, $transition); |
370: | } |
371: | |
372: | |
373: | |
374: | |
375: | |
376: | |
377: | |
378: | |
379: | |
380: | |
381: | |
382: | |
383: | public function createPaperCheckStatusTransition($userToken, $paperCheckToken, PaperCheckStatusTransition $transition) { |
384: | if (empty($userToken)) { |
385: | throw new HyperwalletArgumentException('userToken is required!'); |
386: | } |
387: | if (empty($paperCheckToken)) { |
388: | throw new HyperwalletArgumentException('paperCheckToken is required!'); |
389: | } |
390: | |
391: | $body = $this->client->doPost('/rest/v4/users/{user-token}/paper-checks/{paper-check-token}/status-transitions', array( |
392: | 'user-token' => $userToken, |
393: | 'paper-check-token' => $paperCheckToken |
394: | ), $transition, array()); |
395: | return new PaperCheckStatusTransition($body); |
396: | } |
397: | |
398: | |
399: | |
400: | |
401: | |
402: | |
403: | |
404: | |
405: | |
406: | |
407: | |
408: | |
409: | public function getPaperCheckStatusTransition($userToken, $paperCheckToken, $statusTransitionToken) { |
410: | if (empty($userToken)) { |
411: | throw new HyperwalletArgumentException('userToken is required!'); |
412: | } |
413: | if (empty($paperCheckToken)) { |
414: | throw new HyperwalletArgumentException('paperCheckToken is required!'); |
415: | } |
416: | if (empty($statusTransitionToken)) { |
417: | throw new HyperwalletArgumentException('statusTransitionToken is required!'); |
418: | } |
419: | |
420: | $body = $this->client->doGet('/rest/v4/users/{user-token}/paper-checks/{paper-check-token}/status-transitions/{status-transition-token}', array( |
421: | 'user-token' => $userToken, |
422: | 'paper-check-token' => $paperCheckToken, |
423: | 'status-transition-token' => $statusTransitionToken |
424: | ), array()); |
425: | return new PaperCheckStatusTransition($body); |
426: | } |
427: | |
428: | |
429: | |
430: | |
431: | |
432: | |
433: | |
434: | |
435: | |
436: | |
437: | |
438: | |
439: | public function listPaperCheckStatusTransitions($userToken, $paperCheckToken, array $options = array()) { |
440: | if (empty($userToken)) { |
441: | throw new HyperwalletArgumentException('userToken is required!'); |
442: | } |
443: | if (empty($paperCheckToken)) { |
444: | throw new HyperwalletArgumentException('paperCheckToken is required!'); |
445: | } |
446: | if (!empty($options)) { |
447: | $filteredArr = array_diff_key($options, array_flip(StatusTransition::FILTERS_ARRAY())); |
448: | if (!empty($filteredArr)) { |
449: | throw new HyperwalletArgumentException('Invalid filter'); |
450: | } |
451: | } |
452: | |
453: | $body = $this->client->doGet('/rest/v4/users/{user-token}/paper-checks/{paper-check-token}/status-transitions', array( |
454: | 'user-token' => $userToken, |
455: | 'paper-check-token' => $paperCheckToken |
456: | ), $options); |
457: | return new ListResponse($body, function ($entry) { |
458: | return new PaperCheckStatusTransition($entry); |
459: | }); |
460: | } |
461: | |
462: | |
463: | |
464: | |
465: | |
466: | |
467: | |
468: | |
469: | |
470: | |
471: | |
472: | |
473: | |
474: | |
475: | public function createTransfer(Transfer $transfer) { |
476: | if (empty($transfer->getSourceToken())) { |
477: | throw new HyperwalletArgumentException('sourceToken is required!'); |
478: | } |
479: | if (empty($transfer->getDestinationToken())) { |
480: | throw new HyperwalletArgumentException('destinationToken is required!'); |
481: | } |
482: | if (empty($transfer->getClientTransferId())) { |
483: | throw new HyperwalletArgumentException('clientTransferId is required!'); |
484: | } |
485: | $body = $this->client->doPost('/rest/v4/transfers', array(), $transfer, array()); |
486: | return new Transfer($body); |
487: | } |
488: | |
489: | public function createTransferRefund($transferToken, $transferRefund) { |
490: | if (empty($transferRefund)) { |
491: | throw new HyperwalletArgumentException('transferRefund is required!'); |
492: | } |
493: | if (empty($transferToken)) { |
494: | throw new HyperwalletArgumentException('transferToken is required!'); |
495: | } |
496: | if (empty($transferRefund->getClientRefundId())) { |
497: | throw new HyperwalletArgumentException('clientRefundId is required!'); |
498: | } |
499: | $body = $this->client->doPost('/rest/v4/transfers/{transfer-token}/refunds', |
500: | array('transfer-token' => $transferToken), $transferRefund, array()); |
501: | return new TransferRefund($body); |
502: | } |
503: | |
504: | |
505: | |
506: | |
507: | |
508: | |
509: | |
510: | |
511: | |
512: | |
513: | public function getTransfer($transferToken) { |
514: | if (empty($transferToken)) { |
515: | throw new HyperwalletArgumentException('transferToken is required!'); |
516: | } |
517: | $body = $this->client->doGet('/rest/v4/transfers/{transfer-token}', array('transfer-token' => $transferToken), |
518: | array()); |
519: | return new Transfer($body); |
520: | } |
521: | |
522: | public function getTransferRefund($transferToken, $refundToken) { |
523: | if (empty($transferToken)) { |
524: | throw new HyperwalletArgumentException('transferToken is required!'); |
525: | } |
526: | if (empty($refundToken)) { |
527: | throw new HyperwalletArgumentException('refundToken is required!'); |
528: | } |
529: | $body = $this->client->doGet('/rest/v4/transfers/{transfer-token}/refunds/{refund-token}', array( |
530: | 'transfer-token' => $transferToken, |
531: | 'refund-token' => $refundToken), |
532: | array()); |
533: | return new TransferRefund($body); |
534: | } |
535: | |
536: | |
537: | |
538: | |
539: | |
540: | |
541: | |
542: | |
543: | |
544: | public function listTransfers($options = array()) { |
545: | if (!empty($options)) { |
546: | $filteredArr = array_diff_key($options, array_flip(Transfer::FILTERS_ARRAY())); |
547: | if (!empty($filteredArr)) { |
548: | throw new HyperwalletArgumentException('Invalid filter'); |
549: | } |
550: | } |
551: | |
552: | $body = $this->client->doGet('/rest/v4/transfers', array(), $options); |
553: | return new ListResponse($body, function ($entry) { |
554: | return new Transfer($entry); |
555: | }); |
556: | } |
557: | |
558: | |
559: | |
560: | |
561: | |
562: | |
563: | |
564: | |
565: | |
566: | public function listTransferRefunds($transferToken, array $options = array()) { |
567: | if (empty($transferToken)) { |
568: | throw new HyperwalletArgumentException('transferToken is required!'); |
569: | } |
570: | $body = $this->client->doGet('/rest/v4/transfers/{transfer-token}/refunds', array('transfer-token' => $transferToken), $options); |
571: | return new ListResponse($body, function ($entry) { |
572: | return new TransferRefund($entry); |
573: | }); |
574: | } |
575: | |
576: | |
577: | |
578: | |
579: | |
580: | |
581: | |
582: | |
583: | |
584: | |
585: | |
586: | public function createTransferStatusTransition($transferToken, TransferStatusTransition $transition) { |
587: | if (empty($transferToken)) { |
588: | throw new HyperwalletArgumentException('transferToken is required!'); |
589: | } |
590: | |
591: | $body = $this->client->doPost('/rest/v4/transfers/{transfer-token}/status-transitions', array( |
592: | 'transfer-token' => $transferToken |
593: | ), $transition, array()); |
594: | return new TransferStatusTransition($body); |
595: | } |
596: | |
597: | |
598: | |
599: | |
600: | |
601: | |
602: | |
603: | |
604: | |
605: | |
606: | |
607: | public function getTransferStatusTransition($transferToken, $statusTransitionToken) { |
608: | if (empty($transferToken)) { |
609: | throw new HyperwalletArgumentException('transferToken is required!'); |
610: | } |
611: | if (empty($statusTransitionToken)) { |
612: | throw new HyperwalletArgumentException('statusTransitionToken is required!'); |
613: | } |
614: | |
615: | $body = $this->client->doGet('/rest/v4/transfers/{transfer-token}/status-transitions/{status-transition-token}', array( |
616: | 'transfer-token' => $transferToken, |
617: | 'status-transition-token' => $statusTransitionToken |
618: | ), array()); |
619: | return new TransferStatusTransition($body); |
620: | } |
621: | |
622: | |
623: | |
624: | |
625: | |
626: | |
627: | |
628: | |
629: | |
630: | |
631: | |
632: | public function listTransferStatusTransitions($transferToken, array $options = array()) { |
633: | if (empty($transferToken)) { |
634: | throw new HyperwalletArgumentException('transfer token is required!'); |
635: | } |
636: | |
637: | $body = $this->client->doGet('/rest/v4/transfers/{transfer-token}/status-transitions', array( |
638: | 'transfer-token' => $transferToken |
639: | ), $options); |
640: | return new ListResponse($body, function ($entry) { |
641: | return new TransferStatusTransition($entry); |
642: | }); |
643: | } |
644: | |
645: | |
646: | |
647: | |
648: | |
649: | |
650: | |
651: | |
652: | |
653: | |
654: | |
655: | |
656: | |
657: | |
658: | |
659: | public function createPayPalAccount($userToken, PayPalAccount $payPalAccount) { |
660: | if (empty($userToken)) { |
661: | throw new HyperwalletArgumentException('userToken is required!'); |
662: | } |
663: | if (empty($payPalAccount->getTransferMethodCountry())) { |
664: | throw new HyperwalletArgumentException('transferMethodCountry is required!'); |
665: | } |
666: | if (empty($payPalAccount->getTransferMethodCurrency())) { |
667: | throw new HyperwalletArgumentException('transferMethodCurrency is required!'); |
668: | } |
669: | if (empty($payPalAccount->getEmail()) and empty($payPalAccount->getAccountId()) ) { |
670: | throw new HyperwalletArgumentException('email or accountId is required!'); |
671: | } |
672: | $body = $this->client->doPost('/rest/v4/users/{user-token}/paypal-accounts', array('user-token' => $userToken), $payPalAccount, array()); |
673: | return new PayPalAccount($body); |
674: | } |
675: | |
676: | |
677: | |
678: | |
679: | |
680: | |
681: | |
682: | |
683: | |
684: | |
685: | |
686: | public function getPayPalAccount($userToken, $payPalAccountToken) { |
687: | if (empty($userToken)) { |
688: | throw new HyperwalletArgumentException('userToken is required!'); |
689: | } |
690: | if (empty($payPalAccountToken)) { |
691: | throw new HyperwalletArgumentException('payPalAccountToken is required!'); |
692: | } |
693: | $body = $this->client->doGet('/rest/v4/users/{user-token}/paypal-accounts/{paypal-account-token}', array( |
694: | 'user-token' => $userToken, |
695: | 'paypal-account-token' => $payPalAccountToken |
696: | ), array()); |
697: | return new PayPalAccount($body); |
698: | } |
699: | |
700: | |
701: | |
702: | |
703: | |
704: | |
705: | |
706: | |
707: | |
708: | |
709: | |
710: | public function updatePayPalAccount($userToken, PayPalAccount $payPalAccount) { |
711: | $body = $this->updateTransferMethod($userToken, $payPalAccount, 'paypal-accounts'); |
712: | return new PayPalAccount($body); |
713: | } |
714: | |
715: | |
716: | |
717: | |
718: | |
719: | |
720: | |
721: | |
722: | |
723: | |
724: | public function listPayPalAccounts($userToken, $options = array()) { |
725: | if (empty($userToken)) { |
726: | throw new HyperwalletArgumentException('userToken is required!'); |
727: | } |
728: | if (!empty($options)) { |
729: | $filteredArr = array_diff_key($options, array_flip(PayPalAccount::FILTERS_ARRAY())); |
730: | if (!empty($filteredArr)) { |
731: | throw new HyperwalletArgumentException('Invalid filter'); |
732: | } |
733: | } |
734: | |
735: | $body = $this->client->doGet('/rest/v4/users/{user-token}/paypal-accounts', array('user-token' => $userToken), $options); |
736: | return new ListResponse($body, function ($entry) { |
737: | return new PayPalAccount($entry); |
738: | }); |
739: | } |
740: | |
741: | |
742: | |
743: | |
744: | |
745: | |
746: | |
747: | |
748: | |
749: | |
750: | |
751: | public function deactivatePayPalAccount($userToken, $payPalAccountToken) { |
752: | $transition = new PayPalAccountStatusTransition(); |
753: | $transition->setTransition(PayPalAccountStatusTransition::TRANSITION_DE_ACTIVATED); |
754: | |
755: | return $this->createPayPalAccountStatusTransition($userToken, $payPalAccountToken, $transition); |
756: | } |
757: | |
758: | |
759: | |
760: | |
761: | |
762: | |
763: | |
764: | |
765: | |
766: | |
767: | |
768: | |
769: | public function createPayPalAccountStatusTransition($userToken, $payPalAccountToken, PayPalAccountStatusTransition $transition) { |
770: | if (empty($userToken)) { |
771: | throw new HyperwalletArgumentException('userToken is required!'); |
772: | } |
773: | if (empty($payPalAccountToken)) { |
774: | throw new HyperwalletArgumentException('payPalAccountToken is required!'); |
775: | } |
776: | |
777: | $body = $this->client->doPost('/rest/v4/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions', array( |
778: | 'user-token' => $userToken, |
779: | 'payPal-account-token' => $payPalAccountToken |
780: | ), $transition, array()); |
781: | return new PayPalAccountStatusTransition($body); |
782: | } |
783: | |
784: | |
785: | |
786: | |
787: | |
788: | |
789: | |
790: | |
791: | |
792: | |
793: | |
794: | |
795: | public function getPayPalAccountStatusTransition($userToken, $payPalAccountToken, $statusTransitionToken) { |
796: | if (empty($userToken)) { |
797: | throw new HyperwalletArgumentException('userToken is required!'); |
798: | } |
799: | if (empty($payPalAccountToken)) { |
800: | throw new HyperwalletArgumentException('payPalAccountToken is required!'); |
801: | } |
802: | if (empty($statusTransitionToken)) { |
803: | throw new HyperwalletArgumentException('statusTransitionToken is required!'); |
804: | } |
805: | |
806: | $body = $this->client->doGet('/rest/v4/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions/{status-transition-token}', array( |
807: | 'user-token' => $userToken, |
808: | 'payPal-account-token' => $payPalAccountToken, |
809: | 'status-transition-token' => $statusTransitionToken |
810: | ), array()); |
811: | return new PayPalAccountStatusTransition($body); |
812: | } |
813: | |
814: | |
815: | |
816: | |
817: | |
818: | |
819: | |
820: | |
821: | |
822: | |
823: | |
824: | |
825: | public function listPayPalAccountStatusTransitions($userToken, $payPalAccountToken, array $options = array()) { |
826: | if (empty($userToken)) { |
827: | throw new HyperwalletArgumentException('userToken is required!'); |
828: | } |
829: | if (empty($payPalAccountToken)) { |
830: | throw new HyperwalletArgumentException('payPalAccountToken is required!'); |
831: | } |
832: | if (!empty($options)) { |
833: | $filteredArr = array_diff_key($options, array_flip(StatusTransition::FILTERS_ARRAY())); |
834: | if (!empty($filteredArr)) { |
835: | throw new HyperwalletArgumentException('Invalid filter'); |
836: | } |
837: | } |
838: | |
839: | $body = $this->client->doGet('/rest/v4/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions', array( |
840: | 'user-token' => $userToken, |
841: | 'payPal-account-token' => $payPalAccountToken |
842: | ), $options); |
843: | return new ListResponse($body, function ($entry) { |
844: | return new PayPalAccountStatusTransition($entry); |
845: | }); |
846: | } |
847: | |
848: | |
849: | |
850: | |
851: | |
852: | |
853: | |
854: | |
855: | |
856: | |
857: | |
858: | |
859: | |
860: | |
861: | |
862: | public function createPrepaidCard($userToken, PrepaidCard $prepaidCard) { |
863: | if (empty($userToken)) { |
864: | throw new HyperwalletArgumentException('userToken is required!'); |
865: | } |
866: | $body = $this->client->doPost('/rest/v4/users/{user-token}/prepaid-cards', array('user-token' => $userToken), $prepaidCard, array()); |
867: | return new PrepaidCard($body); |
868: | } |
869: | |
870: | |
871: | |
872: | |
873: | |
874: | |
875: | |
876: | |
877: | public function replacePrepaidCard($userToken, PrepaidCard $prepaidCard) { |
878: | if (empty($prepaidCard->getReplacementReason())) { |
879: | throw new HyperwalletArgumentException('replacementReason is required!'); |
880: | } |
881: | return $this->createPrepaidCard($userToken, $prepaidCard); |
882: | } |
883: | |
884: | |
885: | |
886: | |
887: | |
888: | |
889: | |
890: | |
891: | |
892: | |
893: | |
894: | public function getPrepaidCard($userToken, $prepaidCardToken) { |
895: | if (empty($userToken)) { |
896: | throw new HyperwalletArgumentException('userToken is required!'); |
897: | } |
898: | if (empty($prepaidCardToken)) { |
899: | throw new HyperwalletArgumentException('prepaidCardToken is required!'); |
900: | } |
901: | $body = $this->client->doGet('/rest/v4/users/{user-token}/prepaid-cards/{prepaid-card-token}', array( |
902: | 'user-token' => $userToken, |
903: | 'prepaid-card-token' => $prepaidCardToken |
904: | ), array()); |
905: | return new PrepaidCard($body); |
906: | } |
907: | |
908: | |
909: | |
910: | |
911: | |
912: | |
913: | |
914: | |
915: | |
916: | |
917: | |
918: | public function updatePrepaidCard($userToken, PrepaidCard $prepaidCard) { |
919: | $body = $this->updateTransferMethod($userToken, $prepaidCard, 'prepaid-cards'); |
920: | return new PrepaidCard($body); |
921: | } |
922: | |
923: | |
924: | |
925: | |
926: | |
927: | |
928: | |
929: | |
930: | |
931: | |
932: | |
933: | public function listPrepaidCards($userToken, $options = array()) { |
934: | if (empty($userToken)) { |
935: | throw new HyperwalletArgumentException('userToken is required!'); |
936: | } |
937: | if (!empty($options)) { |
938: | $filteredArr = array_diff_key($options, array_flip(PrepaidCard::FILTERS_ARRAY())); |
939: | if (!empty($filteredArr)) { |
940: | throw new HyperwalletArgumentException('Invalid filter'); |
941: | } |
942: | } |
943: | |
944: | $body = $this->client->doGet('/rest/v4/users/{user-token}/prepaid-cards', array('user-token' => $userToken), $options); |
945: | return new ListResponse($body, function ($entry) { |
946: | return new PrepaidCard($entry); |
947: | }); |
948: | } |
949: | |
950: | |
951: | |
952: | |
953: | |
954: | |
955: | |
956: | |
957: | |
958: | |
959: | |
960: | public function suspendPrepaidCard($userToken, $prepaidCardToken) { |
961: | $transition = new PrepaidCardStatusTransition(); |
962: | $transition->setTransition(PrepaidCardStatusTransition::TRANSITION_SUSPENDED); |
963: | |
964: | return $this->createPrepaidCardStatusTransition($userToken, $prepaidCardToken, $transition); |
965: | } |
966: | |
967: | |
968: | |
969: | |
970: | |
971: | |
972: | |
973: | |
974: | |
975: | |
976: | |
977: | public function unsuspendPrepaidCard($userToken, $prepaidCardToken) { |
978: | $transition = new PrepaidCardStatusTransition(); |
979: | $transition->setTransition(PrepaidCardStatusTransition::TRANSITION_UNSUSPENDED); |
980: | |
981: | return $this->createPrepaidCardStatusTransition($userToken, $prepaidCardToken, $transition); |
982: | } |
983: | |
984: | |
985: | |
986: | |
987: | |
988: | |
989: | |
990: | |
991: | |
992: | |
993: | |
994: | public function lostOrStolenPrepaidCard($userToken, $prepaidCardToken) { |
995: | $transition = new PrepaidCardStatusTransition(); |
996: | $transition->setTransition(PrepaidCardStatusTransition::TRANSITION_LOST_OR_STOLEN); |
997: | |
998: | return $this->createPrepaidCardStatusTransition($userToken, $prepaidCardToken, $transition); |
999: | } |
1000: | |
1001: | |
1002: | |
1003: | |
1004: | |
1005: | |
1006: | |
1007: | |
1008: | |
1009: | |
1010: | |
1011: | public function deactivatePrepaidCard($userToken, $prepaidCardToken) { |
1012: | $transition = new PrepaidCardStatusTransition(); |
1013: | $transition->setTransition(PrepaidCardStatusTransition::TRANSITION_DE_ACTIVATED); |
1014: | |
1015: | return $this->createPrepaidCardStatusTransition($userToken, $prepaidCardToken, $transition); |
1016: | } |
1017: | |
1018: | |
1019: | |
1020: | |
1021: | |
1022: | |
1023: | |
1024: | |
1025: | |
1026: | |
1027: | |
1028: | public function lockPrepaidCard($userToken, $prepaidCardToken) { |
1029: | $transition = new PrepaidCardStatusTransition(); |
1030: | $transition->setTransition(PrepaidCardStatusTransition::TRANSITION_LOCKED); |
1031: | |
1032: | return $this->createPrepaidCardStatusTransition($userToken, $prepaidCardToken, $transition); |
1033: | } |
1034: | |
1035: | |
1036: | |
1037: | |
1038: | |
1039: | |
1040: | |
1041: | |
1042: | |
1043: | |
1044: | |
1045: | public function unlockPrepaidCard($userToken, $prepaidCardToken) { |
1046: | $transition = new PrepaidCardStatusTransition(); |
1047: | $transition->setTransition(PrepaidCardStatusTransition::TRANSITION_UNLOCKED); |
1048: | |
1049: | return $this->createPrepaidCardStatusTransition($userToken, $prepaidCardToken, $transition); |
1050: | } |
1051: | |
1052: | |
1053: | |
1054: | |
1055: | |
1056: | |
1057: | |
1058: | |
1059: | |
1060: | |
1061: | |
1062: | |
1063: | public function createPrepaidCardStatusTransition($userToken, $prepaidCardToken, PrepaidCardStatusTransition $transition) { |
1064: | if (empty($userToken)) { |
1065: | throw new HyperwalletArgumentException('userToken is required!'); |
1066: | } |
1067: | if (empty($prepaidCardToken)) { |
1068: | throw new HyperwalletArgumentException('prepaidCardToken is required!'); |
1069: | } |
1070: | |
1071: | $body = $this->client->doPost('/rest/v4/users/{user-token}/prepaid-cards/{prepaid-card-token}/status-transitions', array( |
1072: | 'user-token' => $userToken, |
1073: | 'prepaid-card-token' => $prepaidCardToken |
1074: | ), $transition, array()); |
1075: | return new PrepaidCardStatusTransition($body); |
1076: | } |
1077: | |
1078: | |
1079: | |
1080: | |
1081: | |
1082: | |
1083: | |
1084: | |
1085: | |
1086: | |
1087: | |
1088: | |
1089: | public function getPrepaidCardStatusTransition($userToken, $prepaidCardToken, $statusTransitionToken) { |
1090: | if (empty($userToken)) { |
1091: | throw new HyperwalletArgumentException('userToken is required!'); |
1092: | } |
1093: | if (empty($prepaidCardToken)) { |
1094: | throw new HyperwalletArgumentException('prepaidCardToken is required!'); |
1095: | } |
1096: | if (empty($statusTransitionToken)) { |
1097: | throw new HyperwalletArgumentException('statusTransitionToken is required!'); |
1098: | } |
1099: | |
1100: | $body = $this->client->doGet('/rest/v4/users/{user-token}/prepaid-cards/{prepaid-card-token}/status-transitions/{status-transition-token}', array( |
1101: | 'user-token' => $userToken, |
1102: | 'prepaid-card-token' => $prepaidCardToken, |
1103: | 'status-transition-token' => $statusTransitionToken |
1104: | ), array()); |
1105: | return new PrepaidCardStatusTransition($body); |
1106: | } |
1107: | |
1108: | |
1109: | |
1110: | |
1111: | |
1112: | |
1113: | |
1114: | |
1115: | |
1116: | |
1117: | |
1118: | |
1119: | public function listPrepaidCardStatusTransitions($userToken, $prepaidCardToken, array $options = array()) { |
1120: | if (empty($userToken)) { |
1121: | throw new HyperwalletArgumentException('userToken is required!'); |
1122: | } |
1123: | if (empty($prepaidCardToken)) { |
1124: | throw new HyperwalletArgumentException('prepaidCardToken is required!'); |
1125: | } |
1126: | if (!empty($options)) { |
1127: | $filteredArr = array_diff_key($options, array_flip(StatusTransition::FILTERS_ARRAY())); |
1128: | if (!empty($filteredArr)) { |
1129: | throw new HyperwalletArgumentException('Invalid filter'); |
1130: | } |
1131: | } |
1132: | |
1133: | $body = $this->client->doGet('/rest/v4/users/{user-token}/prepaid-cards/{prepaid-card-token}/status-transitions', array( |
1134: | 'user-token' => $userToken, |
1135: | 'prepaid-card-token' => $prepaidCardToken |
1136: | ), $options); |
1137: | return new ListResponse($body, function ($entry) { |
1138: | return new PrepaidCardStatusTransition($entry); |
1139: | }); |
1140: | } |
1141: | |
1142: | |
1143: | |
1144: | |
1145: | |
1146: | |
1147: | |
1148: | |
1149: | |
1150: | |
1151: | |
1152: | |
1153: | |
1154: | |
1155: | |
1156: | public function createBankAccount($userToken, BankAccount $bankAccount) { |
1157: | if (empty($userToken)) { |
1158: | throw new HyperwalletArgumentException('userToken is required!'); |
1159: | } |
1160: | $body = $this->client->doPost('/rest/v4/users/{user-token}/bank-accounts', array('user-token' => $userToken), $bankAccount, array()); |
1161: | return new BankAccount($body); |
1162: | } |
1163: | |
1164: | |
1165: | |
1166: | |
1167: | |
1168: | |
1169: | |
1170: | |
1171: | |
1172: | |
1173: | |
1174: | public function getBankAccount($userToken, $bankAccountToken) { |
1175: | if (empty($userToken)) { |
1176: | throw new HyperwalletArgumentException('userToken is required!'); |
1177: | } |
1178: | if (empty($bankAccountToken)) { |
1179: | throw new HyperwalletArgumentException('bankAccountToken is required!'); |
1180: | } |
1181: | $body = $this->client->doGet('/rest/v4/users/{user-token}/bank-accounts/{bank-account-token}', array( |
1182: | 'user-token' => $userToken, |
1183: | 'bank-account-token' => $bankAccountToken |
1184: | ), array()); |
1185: | return new BankAccount($body); |
1186: | } |
1187: | |
1188: | |
1189: | |
1190: | |
1191: | |
1192: | |
1193: | |
1194: | |
1195: | |
1196: | |
1197: | |
1198: | public function updateBankAccount($userToken, BankAccount $bankAccount) { |
1199: | $body = $this->updateTransferMethod($userToken, $bankAccount, 'bank-accounts'); |
1200: | return new BankAccount($body); |
1201: | } |
1202: | |
1203: | |
1204: | |
1205: | |
1206: | |
1207: | |
1208: | |
1209: | |
1210: | |
1211: | |
1212: | |
1213: | public function listBankAccounts($userToken, $options = array()) { |
1214: | if (empty($userToken)) { |
1215: | throw new HyperwalletArgumentException('userToken is required!'); |
1216: | } |
1217: | if (!empty($options)) { |
1218: | $filteredArr = array_diff_key($options, array_flip(BankAccount::FILTERS_ARRAY())); |
1219: | if (!empty($filteredArr)) { |
1220: | throw new HyperwalletArgumentException('Invalid filter'); |
1221: | } |
1222: | } |
1223: | |
1224: | $body = $this->client->doGet('/rest/v4/users/{user-token}/bank-accounts', array('user-token' => $userToken), $options); |
1225: | return new ListResponse($body, function ($entry) { |
1226: | return new BankAccount($entry); |
1227: | }); |
1228: | } |
1229: | |
1230: | |
1231: | |
1232: | |
1233: | |
1234: | |
1235: | |
1236: | |
1237: | |
1238: | |
1239: | |
1240: | public function deactivateBankAccount($userToken, $bankAccountToken) { |
1241: | $transition = new BankAccountStatusTransition(); |
1242: | $transition->setTransition(BankAccountStatusTransition::TRANSITION_DE_ACTIVATED); |
1243: | |
1244: | return $this->createBankAccountStatusTransition($userToken, $bankAccountToken, $transition); |
1245: | } |
1246: | |
1247: | |
1248: | |
1249: | |
1250: | |
1251: | |
1252: | |
1253: | |
1254: | |
1255: | |
1256: | |
1257: | |
1258: | public function createBankAccountStatusTransition($userToken, $bankAccountToken, BankAccountStatusTransition $transition) { |
1259: | if (empty($userToken)) { |
1260: | throw new HyperwalletArgumentException('userToken is required!'); |
1261: | } |
1262: | if (empty($bankAccountToken)) { |
1263: | throw new HyperwalletArgumentException('bankAccountToken is required!'); |
1264: | } |
1265: | |
1266: | $body = $this->client->doPost('/rest/v4/users/{user-token}/bank-accounts/{bank-account-token}/status-transitions', array( |
1267: | 'user-token' => $userToken, |
1268: | 'bank-account-token' => $bankAccountToken |
1269: | ), $transition, array()); |
1270: | return new BankAccountStatusTransition($body); |
1271: | } |
1272: | |
1273: | |
1274: | |
1275: | |
1276: | |
1277: | |
1278: | |
1279: | |
1280: | |
1281: | |
1282: | |
1283: | |
1284: | public function getBankAccountStatusTransition($userToken, $bankAccountToken, $statusTransitionToken) { |
1285: | if (empty($userToken)) { |
1286: | throw new HyperwalletArgumentException('userToken is required!'); |
1287: | } |
1288: | if (empty($bankAccountToken)) { |
1289: | throw new HyperwalletArgumentException('bankAccountToken is required!'); |
1290: | } |
1291: | if (empty($statusTransitionToken)) { |
1292: | throw new HyperwalletArgumentException('statusTransitionToken is required!'); |
1293: | } |
1294: | |
1295: | $body = $this->client->doGet('/rest/v4/users/{user-token}/bank-accounts/{bank-account-token}/status-transitions/{status-transition-token}', array( |
1296: | 'user-token' => $userToken, |
1297: | 'bank-account-token' => $bankAccountToken, |
1298: | 'status-transition-token' => $statusTransitionToken |
1299: | ), array()); |
1300: | return new BankAccountStatusTransition($body); |
1301: | } |
1302: | |
1303: | |
1304: | |
1305: | |
1306: | |
1307: | |
1308: | |
1309: | |
1310: | |
1311: | |
1312: | |
1313: | |
1314: | public function listBankAccountStatusTransitions($userToken, $bankAccountToken, array $options = array()) { |
1315: | if (empty($userToken)) { |
1316: | throw new HyperwalletArgumentException('userToken is required!'); |
1317: | } |
1318: | if (empty($bankAccountToken)) { |
1319: | throw new HyperwalletArgumentException('bankAccountToken is required!'); |
1320: | } |
1321: | if (!empty($options)) { |
1322: | $filteredArr = array_diff_key($options, array_flip(StatusTransition::FILTERS_ARRAY())); |
1323: | if (!empty($filteredArr)) { |
1324: | throw new HyperwalletArgumentException('Invalid filter'); |
1325: | } |
1326: | } |
1327: | |
1328: | $body = $this->client->doGet('/rest/v4/users/{user-token}/bank-accounts/{bank-account-token}/status-transitions', array( |
1329: | 'user-token' => $userToken, |
1330: | 'bank-account-token' => $bankAccountToken |
1331: | ), $options); |
1332: | return new ListResponse($body, function ($entry) { |
1333: | return new BankAccountStatusTransition($entry); |
1334: | }); |
1335: | } |
1336: | |
1337: | |
1338: | |
1339: | |
1340: | |
1341: | |
1342: | |
1343: | |
1344: | |
1345: | |
1346: | |
1347: | |
1348: | |
1349: | |
1350: | |
1351: | public function createBankCard($userToken, BankCard $bankCard) { |
1352: | if (empty($userToken)) { |
1353: | throw new HyperwalletArgumentException('userToken is required!'); |
1354: | } |
1355: | $body = $this->client->doPost('/rest/v4/users/{user-token}/bank-cards', array('user-token' => $userToken), $bankCard, array()); |
1356: | return new BankCard($body); |
1357: | } |
1358: | |
1359: | |
1360: | |
1361: | |
1362: | |
1363: | |
1364: | |
1365: | |
1366: | |
1367: | |
1368: | |
1369: | public function getBankCard($userToken, $bankCardToken) { |
1370: | if (empty($userToken)) { |
1371: | throw new HyperwalletArgumentException('userToken is required!'); |
1372: | } |
1373: | if (empty($bankCardToken)) { |
1374: | throw new HyperwalletArgumentException('bankCardToken is required!'); |
1375: | } |
1376: | $body = $this->client->doGet('/rest/v4/users/{user-token}/bank-cards/{bank-card-token}', array( |
1377: | 'user-token' => $userToken, |
1378: | 'bank-card-token' => $bankCardToken |
1379: | ), array()); |
1380: | return new BankCard($body); |
1381: | } |
1382: | |
1383: | |
1384: | |
1385: | |
1386: | |
1387: | |
1388: | |
1389: | |
1390: | |
1391: | |
1392: | |
1393: | |
1394: | public function updateBankCard($userToken, BankCard $bankCard) { |
1395: | $body = $this->updateTransferMethod($userToken, $bankCard, 'bank-cards'); |
1396: | return new BankCard($body); |
1397: | } |
1398: | |
1399: | |
1400: | |
1401: | |
1402: | |
1403: | |
1404: | |
1405: | |
1406: | |
1407: | |
1408: | |
1409: | public function listBankCards($userToken, $options = array()) { |
1410: | if (empty($userToken)) { |
1411: | throw new HyperwalletArgumentException('userToken is required!'); |
1412: | } |
1413: | if (!empty($options)) { |
1414: | $filteredArr = array_diff_key($options, array_flip(BankCard::FILTERS_ARRAY())); |
1415: | if (!empty($filteredArr)) { |
1416: | throw new HyperwalletArgumentException('Invalid filter'); |
1417: | } |
1418: | } |
1419: | |
1420: | $body = $this->client->doGet('/rest/v4/users/{user-token}/bank-cards', array('user-token' => $userToken), $options); |
1421: | return new ListResponse($body, function ($entry) { |
1422: | return new BankCard($entry); |
1423: | }); |
1424: | } |
1425: | |
1426: | |
1427: | |
1428: | |
1429: | |
1430: | |
1431: | |
1432: | |
1433: | |
1434: | public function deactivateBankCard($userToken, $bankCardToken) { |
1435: | $transition = new BankCardStatusTransition(); |
1436: | $transition->setTransition(BankCardStatusTransition::TRANSITION_DE_ACTIVATED); |
1437: | |
1438: | return $this->createBankCardStatusTransition($userToken, $bankCardToken, $transition); |
1439: | } |
1440: | |
1441: | |
1442: | |
1443: | |
1444: | |
1445: | |
1446: | |
1447: | |
1448: | |
1449: | |
1450: | |
1451: | |
1452: | public function createBankCardStatusTransition($userToken, $bankCardToken, BankCardStatusTransition $transition) { |
1453: | if (empty($userToken)) { |
1454: | throw new HyperwalletArgumentException('userToken is required!'); |
1455: | } |
1456: | if (empty($bankCardToken)) { |
1457: | throw new HyperwalletArgumentException('bankCardToken is required!'); |
1458: | } |
1459: | |
1460: | $body = $this->client->doPost('/rest/v4/users/{user-token}/bank-cards/{bank-card-token}/status-transitions', array( |
1461: | 'user-token' => $userToken, |
1462: | 'bank-card-token' => $bankCardToken |
1463: | ), $transition, array()); |
1464: | return new BankCardStatusTransition($body); |
1465: | } |
1466: | |
1467: | |
1468: | |
1469: | |
1470: | |
1471: | |
1472: | |
1473: | |
1474: | |
1475: | |
1476: | |
1477: | |
1478: | public function getBankCardStatusTransition($userToken, $bankCardToken, $statusTransitionToken) { |
1479: | if (empty($userToken)) { |
1480: | throw new HyperwalletArgumentException('userToken is required!'); |
1481: | } |
1482: | if (empty($bankCardToken)) { |
1483: | throw new HyperwalletArgumentException('bankCardToken is required!'); |
1484: | } |
1485: | if (empty($statusTransitionToken)) { |
1486: | throw new HyperwalletArgumentException('statusTransitionToken is required!'); |
1487: | } |
1488: | |
1489: | $body = $this->client->doGet('/rest/v4/users/{user-token}/bank-cards/{bank-card-token}/status-transitions/{status-transition-token}', array( |
1490: | 'user-token' => $userToken, |
1491: | 'bank-card-token' => $bankCardToken, |
1492: | 'status-transition-token' => $statusTransitionToken |
1493: | ), array()); |
1494: | return new BankCardStatusTransition($body); |
1495: | } |
1496: | |
1497: | |
1498: | |
1499: | |
1500: | |
1501: | |
1502: | |
1503: | |
1504: | |
1505: | |
1506: | |
1507: | |
1508: | public function listBankCardStatusTransitions($userToken, $bankCardToken, array $options = array()) { |
1509: | if (empty($userToken)) { |
1510: | throw new HyperwalletArgumentException('userToken is required!'); |
1511: | } |
1512: | if (empty($bankCardToken)) { |
1513: | throw new HyperwalletArgumentException('bankCardToken is required!'); |
1514: | } |
1515: | if (!empty($options)) { |
1516: | $filteredArr = array_diff_key($options, array_flip(StatusTransition::FILTERS_ARRAY())); |
1517: | if (!empty($filteredArr)) { |
1518: | throw new HyperwalletArgumentException('Invalid filter'); |
1519: | } |
1520: | } |
1521: | |
1522: | $body = $this->client->doGet('/rest/v4/users/{user-token}/bank-cards/{bank-card-token}/status-transitions', array( |
1523: | 'user-token' => $userToken, |
1524: | 'bank-card-token' => $bankCardToken |
1525: | ), $options); |
1526: | return new ListResponse($body, function ($entry) { |
1527: | return new BankCardStatusTransition($entry); |
1528: | }); |
1529: | } |
1530: | |
1531: | |
1532: | |
1533: | |
1534: | |
1535: | |
1536: | |
1537: | |
1538: | |
1539: | |
1540: | |
1541: | |
1542: | |
1543: | |
1544: | |
1545: | |
1546: | public function createTransferMethod($userToken, $jsonCacheToken, TransferMethod $transferMethod = null) { |
1547: | if (empty($userToken)) { |
1548: | throw new HyperwalletArgumentException('userToken is required!'); |
1549: | } |
1550: | if (empty($jsonCacheToken)) { |
1551: | throw new HyperwalletArgumentException('jsonCacheToken is required!'); |
1552: | } |
1553: | $body = $this->client->doPost('/rest/v4/users/{user-token}/transfer-methods', array('user-token' => $userToken), $transferMethod, array(), array( |
1554: | 'Json-Cache-Token' => $jsonCacheToken |
1555: | )); |
1556: | if ($body['type'] === PrepaidCard::TYPE_PREPAID_CARD) { |
1557: | return new PrepaidCard($body); |
1558: | } |
1559: | return new BankAccount($body); |
1560: | } |
1561: | |
1562: | |
1563: | |
1564: | |
1565: | |
1566: | |
1567: | |
1568: | |
1569: | |
1570: | |
1571: | |
1572: | |
1573: | |
1574: | |
1575: | public function listBalancesForUser($userToken, $options = array()) { |
1576: | if (empty($userToken)) { |
1577: | throw new HyperwalletArgumentException('userToken is required!'); |
1578: | } |
1579: | if (!empty($options)) { |
1580: | $filteredArr = array_diff_key($options, array_flip(Balance::FILTERS_ARRAY_USER())); |
1581: | if (!empty($filteredArr)) { |
1582: | throw new HyperwalletArgumentException('Invalid filter'); |
1583: | } |
1584: | } |
1585: | |
1586: | $body = $this->client->doGet('/rest/v4/users/{user-token}/balances', array('user-token' => $userToken), $options); |
1587: | $listResponse = new ListResponse($body, function ($entry) { |
1588: | return new Balance($entry); |
1589: | }); |
1590: | call_user_func(array($listResponse, 'unsetLinksAttribute')); |
1591: | return $listResponse; |
1592: | } |
1593: | |
1594: | |
1595: | |
1596: | |
1597: | |
1598: | |
1599: | |
1600: | |
1601: | |
1602: | |
1603: | |
1604: | public function listBalancesForPrepaidCard($userToken, $prepaidCardToken, $options = array()) { |
1605: | if (empty($userToken)) { |
1606: | throw new HyperwalletArgumentException('userToken is required!'); |
1607: | } |
1608: | if (empty($prepaidCardToken)) { |
1609: | throw new HyperwalletArgumentException('prepaidCardToken is required!'); |
1610: | } |
1611: | if (!empty($options)) { |
1612: | $filteredArr = array_diff_key($options, array_flip(Balance::FILTERS_ARRAY_PREPAID_CARD())); |
1613: | if (!empty($filteredArr)) { |
1614: | throw new HyperwalletArgumentException('Invalid filter'); |
1615: | } |
1616: | } |
1617: | |
1618: | $body = $this->client->doGet('/rest/v4/users/{user-token}/prepaid-cards/{prepaid-card-token}/balances', array( |
1619: | 'user-token' => $userToken, |
1620: | 'prepaid-card-token' => $prepaidCardToken |
1621: | ), $options); |
1622: | $listResponse = new ListResponse($body, function ($entry) { |
1623: | return new Balance($entry); |
1624: | }); |
1625: | call_user_func(array($listResponse, 'unsetLinksAttribute')); |
1626: | return $listResponse; |
1627: | } |
1628: | |
1629: | |
1630: | |
1631: | |
1632: | |
1633: | |
1634: | |
1635: | |
1636: | |
1637: | |
1638: | |
1639: | public function listBalancesForAccount($programToken, $accountToken, $options = array()) { |
1640: | if (empty($programToken)) { |
1641: | throw new HyperwalletArgumentException('programToken is required!'); |
1642: | } |
1643: | if (empty($accountToken)) { |
1644: | throw new HyperwalletArgumentException('accountToken is required!'); |
1645: | } |
1646: | if (!empty($options)) { |
1647: | $filteredArr = array_diff_key($options, array_flip(Balance::FILTERS_ARRAY_ACCOUNT())); |
1648: | if (!empty($filteredArr)) { |
1649: | throw new HyperwalletArgumentException('Invalid filter'); |
1650: | } |
1651: | } |
1652: | |
1653: | $body = $this->client->doGet('/rest/v4/programs/{program-token}/accounts/{account-token}/balances', array( |
1654: | 'program-token' => $programToken, |
1655: | 'account-token' => $accountToken |
1656: | ), $options); |
1657: | $listResponse = new ListResponse($body, function ($entry) { |
1658: | return new Balance($entry); |
1659: | }); |
1660: | call_user_func(array($listResponse, 'unsetLinksAttribute')); |
1661: | return $listResponse; |
1662: | } |
1663: | |
1664: | |
1665: | |
1666: | |
1667: | |
1668: | |
1669: | |
1670: | |
1671: | |
1672: | |
1673: | |
1674: | |
1675: | |
1676: | public function createPayment(Payment $payment) { |
1677: | $this->addProgramToken($payment); |
1678: | $body = $this->client->doPost('/rest/v4/payments', array(), $payment, array()); |
1679: | return new Payment($body); |
1680: | } |
1681: | |
1682: | |
1683: | |
1684: | |
1685: | |
1686: | |
1687: | |
1688: | |
1689: | |
1690: | |
1691: | public function getPayment($paymentToken) { |
1692: | if (empty($paymentToken)) { |
1693: | throw new HyperwalletArgumentException('paymentToken is required!'); |
1694: | } |
1695: | $body = $this->client->doGet('/rest/v4/payments/{payment-token}', array('payment-token' => $paymentToken), array()); |
1696: | return new Payment($body); |
1697: | } |
1698: | |
1699: | |
1700: | |
1701: | |
1702: | |
1703: | |
1704: | |
1705: | |
1706: | |
1707: | public function listPayments($options = array()) { |
1708: | if (!empty($options)) { |
1709: | $filteredArr = array_diff_key($options, array_flip(Payment::FILTERS_ARRAY())); |
1710: | if (!empty($filteredArr)) { |
1711: | throw new HyperwalletArgumentException('Invalid filter'); |
1712: | } |
1713: | } |
1714: | |
1715: | $body = $this->client->doGet('/rest/v4/payments', array(), $options); |
1716: | return new ListResponse($body, function ($entry) { |
1717: | return new Payment($entry); |
1718: | }); |
1719: | } |
1720: | |
1721: | |
1722: | |
1723: | |
1724: | |
1725: | |
1726: | |
1727: | |
1728: | |
1729: | |
1730: | |
1731: | public function createPaymentStatusTransition($paymentToken, PaymentStatusTransition $transition) { |
1732: | if (empty($paymentToken)) { |
1733: | throw new HyperwalletArgumentException('paymentToken is required!'); |
1734: | } |
1735: | |
1736: | $body = $this->client->doPost('/rest/v4/payments/{payment-token}/status-transitions', array( |
1737: | 'payment-token' => $paymentToken |
1738: | ), $transition, array()); |
1739: | return new PaymentStatusTransition($body); |
1740: | } |
1741: | |
1742: | |
1743: | |
1744: | |
1745: | |
1746: | |
1747: | |
1748: | |
1749: | |
1750: | |
1751: | |
1752: | public function getPaymentStatusTransition($paymentToken, $statusTransitionToken) { |
1753: | if (empty($paymentToken)) { |
1754: | throw new HyperwalletArgumentException('paymentToken is required!'); |
1755: | } |
1756: | if (empty($statusTransitionToken)) { |
1757: | throw new HyperwalletArgumentException('statusTransitionToken is required!'); |
1758: | } |
1759: | |
1760: | $body = $this->client->doGet('/rest/v4/payments/{payment-token}/status-transitions/{status-transition-token}', array( |
1761: | 'payment-token' => $paymentToken, |
1762: | 'status-transition-token' => $statusTransitionToken |
1763: | ), array()); |
1764: | return new PaymentStatusTransition($body); |
1765: | } |
1766: | |
1767: | |
1768: | |
1769: | |
1770: | |
1771: | |
1772: | |
1773: | |
1774: | |
1775: | |
1776: | |
1777: | public function listPaymentStatusTransitions($paymentToken, array $options = array()) { |
1778: | if (empty($paymentToken)) { |
1779: | throw new HyperwalletArgumentException('paymentToken is required!'); |
1780: | } |
1781: | if (!empty($options)) { |
1782: | $filteredArr = array_diff_key($options, array_flip(StatusTransition::FILTERS_ARRAY())); |
1783: | if (!empty($filteredArr)) { |
1784: | throw new HyperwalletArgumentException('Invalid filter'); |
1785: | } |
1786: | } |
1787: | |
1788: | $body = $this->client->doGet('/rest/v4/payments/{payment-token}/status-transitions', array( |
1789: | 'payment-token' => $paymentToken |
1790: | ), $options); |
1791: | return new ListResponse($body, function ($entry) { |
1792: | return new PaymentStatusTransition($entry); |
1793: | }); |
1794: | } |
1795: | |
1796: | |
1797: | |
1798: | |
1799: | |
1800: | |
1801: | |
1802: | |
1803: | |
1804: | |
1805: | |
1806: | |
1807: | |
1808: | |
1809: | public function getProgram($programToken) { |
1810: | if (empty($programToken)) { |
1811: | throw new HyperwalletArgumentException('programToken is required!'); |
1812: | } |
1813: | $body = $this->client->doGet('/rest/v4/programs/{program-token}', array('program-token' => $programToken), array()); |
1814: | return new Program($body); |
1815: | } |
1816: | |
1817: | |
1818: | |
1819: | |
1820: | |
1821: | |
1822: | |
1823: | |
1824: | |
1825: | |
1826: | |
1827: | |
1828: | |
1829: | |
1830: | |
1831: | public function getProgramAccount($programToken, $accountToken) { |
1832: | if (empty($programToken)) { |
1833: | throw new HyperwalletArgumentException('programToken is required!'); |
1834: | } |
1835: | if (empty($accountToken)) { |
1836: | throw new HyperwalletArgumentException('accountToken is required!'); |
1837: | } |
1838: | $body = $this->client->doGet('/rest/v4/programs/{program-token}/accounts/{account-token}', array( |
1839: | 'program-token' => $programToken, |
1840: | 'account-token' => $accountToken |
1841: | ), array()); |
1842: | return new ProgramAccount($body); |
1843: | } |
1844: | |
1845: | |
1846: | |
1847: | |
1848: | |
1849: | |
1850: | |
1851: | |
1852: | |
1853: | |
1854: | |
1855: | |
1856: | |
1857: | |
1858: | |
1859: | |
1860: | |
1861: | |
1862: | public function getTransferMethodConfiguration($userToken, $country, $currency, $type, $profileType) { |
1863: | if (empty($userToken)) { |
1864: | throw new HyperwalletArgumentException('userToken is required!'); |
1865: | } |
1866: | if (empty($country)) { |
1867: | throw new HyperwalletArgumentException('country is required!'); |
1868: | } |
1869: | if (empty($currency)) { |
1870: | throw new HyperwalletArgumentException('currency is required!'); |
1871: | } |
1872: | if (empty($type)) { |
1873: | throw new HyperwalletArgumentException('type is required!'); |
1874: | } |
1875: | if (empty($profileType)) { |
1876: | throw new HyperwalletArgumentException('profileType is required!'); |
1877: | } |
1878: | |
1879: | $body = $this->client->doGet('/rest/v4/transfer-method-configurations', array(), array( |
1880: | 'userToken' => $userToken, |
1881: | 'country' => $country, |
1882: | 'currency' => $currency, |
1883: | 'type' => $type, |
1884: | 'profileType' => $profileType |
1885: | )); |
1886: | return new TransferMethodConfiguration($body); |
1887: | } |
1888: | |
1889: | |
1890: | |
1891: | |
1892: | |
1893: | |
1894: | |
1895: | |
1896: | |
1897: | |
1898: | |
1899: | public function listTransferMethodConfigurations($userToken, $options = array()) { |
1900: | if (empty($userToken)) { |
1901: | throw new HyperwalletArgumentException('userToken is required!'); |
1902: | } |
1903: | if (!empty($options)) { |
1904: | $filteredArr = array_diff_key($options, array_flip(TransferMethodConfiguration::FILTERS_ARRAY())); |
1905: | if (!empty($filteredArr)) { |
1906: | throw new HyperwalletArgumentException('Invalid filter'); |
1907: | } |
1908: | } |
1909: | |
1910: | $body = $this->client->doGet('/rest/v4/transfer-method-configurations', array(), array_merge(array( |
1911: | 'userToken' => $userToken, |
1912: | ), $options)); |
1913: | return new ListResponse($body, function ($entity) { |
1914: | return new TransferMethodConfiguration($entity); |
1915: | }); |
1916: | } |
1917: | |
1918: | |
1919: | |
1920: | |
1921: | |
1922: | |
1923: | |
1924: | |
1925: | |
1926: | |
1927: | |
1928: | |
1929: | |
1930: | |
1931: | |
1932: | |
1933: | public function listReceiptsForProgramAccount($programToken, $accountToken, $options = array()) { |
1934: | if (empty($programToken)) { |
1935: | throw new HyperwalletArgumentException('programToken is required!'); |
1936: | } |
1937: | if (empty($accountToken)) { |
1938: | throw new HyperwalletArgumentException('accountToken is required!'); |
1939: | } |
1940: | if (!empty($options)) { |
1941: | $filteredArr = array_diff_key($options, array_flip(Receipt::FILTERS_ARRAY_ACCOUNT())); |
1942: | if (!empty($filteredArr)) { |
1943: | throw new HyperwalletArgumentException('Invalid filter'); |
1944: | } |
1945: | } |
1946: | |
1947: | $body = $this->client->doGet('/rest/v4/programs/{program-token}/accounts/{account-token}/receipts', array( |
1948: | 'program-token' => $programToken, |
1949: | 'account-token' => $accountToken |
1950: | ), $options); |
1951: | return new ListResponse($body, function ($entry) { |
1952: | return new Receipt($entry); |
1953: | }); |
1954: | } |
1955: | |
1956: | |
1957: | |
1958: | |
1959: | |
1960: | |
1961: | |
1962: | |
1963: | |
1964: | |
1965: | |
1966: | public function listReceiptsForUser($userToken, $options = array()) { |
1967: | if (empty($userToken)) { |
1968: | throw new HyperwalletArgumentException('userToken is required!'); |
1969: | } |
1970: | if (!empty($options)) { |
1971: | $filteredArr = array_diff_key($options, array_flip(Receipt::FILTERS_ARRAY_USER())); |
1972: | if (!empty($filteredArr)) { |
1973: | throw new HyperwalletArgumentException('Invalid filter'); |
1974: | } |
1975: | } |
1976: | |
1977: | $body = $this->client->doGet('/rest/v4/users/{user-token}/receipts', array( |
1978: | 'user-token' => $userToken |
1979: | ), $options); |
1980: | return new ListResponse($body, function ($entry) { |
1981: | return new Receipt($entry); |
1982: | }); |
1983: | } |
1984: | |
1985: | |
1986: | |
1987: | |
1988: | |
1989: | |
1990: | |
1991: | |
1992: | |
1993: | |
1994: | |
1995: | |
1996: | public function listReceiptsForPrepaidCard($userToken, $prepaidCardToken, $options = array()) { |
1997: | if (empty($userToken)) { |
1998: | throw new HyperwalletArgumentException('userToken is required!'); |
1999: | } |
2000: | if (empty($prepaidCardToken)) { |
2001: | throw new HyperwalletArgumentException('prepaidCardToken is required!'); |
2002: | } |
2003: | if (!empty($options)) { |
2004: | $filteredArr = array_diff_key($options, array_flip(Receipt::FILTERS_ARRAY_PREPAID_CARD())); |
2005: | if (!empty($filteredArr)) { |
2006: | throw new HyperwalletArgumentException('Invalid filter'); |
2007: | } |
2008: | } |
2009: | |
2010: | $body = $this->client->doGet('/rest/v4/users/{user-token}/prepaid-cards/{prepaid-card-token}/receipts', array( |
2011: | 'user-token' => $userToken, |
2012: | 'prepaid-card-token' => $prepaidCardToken |
2013: | ), $options); |
2014: | return new ListResponse($body, function ($entry) { |
2015: | return new Receipt($entry); |
2016: | }); |
2017: | } |
2018: | |
2019: | |
2020: | |
2021: | |
2022: | |
2023: | |
2024: | |
2025: | |
2026: | |
2027: | |
2028: | |
2029: | |
2030: | |
2031: | |
2032: | public function getWebhookNotification($webhookNotificationToken) { |
2033: | if (empty($webhookNotificationToken)) { |
2034: | throw new HyperwalletArgumentException('webhookNotificationToken is required!'); |
2035: | } |
2036: | $body = $this->client->doGet('/rest/v4/webhook-notifications/{webhook-notification-token}', array('webhook-notification-token' => $webhookNotificationToken), array()); |
2037: | return new WebhookNotification($body); |
2038: | } |
2039: | |
2040: | |
2041: | |
2042: | |
2043: | |
2044: | |
2045: | |
2046: | |
2047: | |
2048: | public function listWebhookNotifications($options = array()) { |
2049: | if (!empty($options)) { |
2050: | $filteredArr = array_diff_key($options, array_flip(WebhookNotification::FILTERS_ARRAY())); |
2051: | if (!empty($filteredArr)) { |
2052: | throw new HyperwalletArgumentException('Invalid filter'); |
2053: | } |
2054: | } |
2055: | |
2056: | $body = $this->client->doGet('/rest/v4/webhook-notifications', array(), $options); |
2057: | return new ListResponse($body, function ($entry) { |
2058: | return new WebhookNotification($entry); |
2059: | }); |
2060: | } |
2061: | |
2062: | |
2063: | |
2064: | |
2065: | |
2066: | |
2067: | |
2068: | |
2069: | |
2070: | |
2071: | private function addProgramToken(IProgramAware $model) { |
2072: | if (empty($this->programToken)) { |
2073: | return; |
2074: | } |
2075: | if ($model->getProgramToken()) { |
2076: | return; |
2077: | } |
2078: | $model->setProgramToken($this->programToken); |
2079: | } |
2080: | |
2081: | |
2082: | |
2083: | |
2084: | |
2085: | |
2086: | |
2087: | |
2088: | |
2089: | |
2090: | |
2091: | |
2092: | private function updateTransferMethod($userToken, $transferMethod, $transferMethodName) { |
2093: | if (empty($userToken)) { |
2094: | throw new HyperwalletArgumentException('userToken is required!'); |
2095: | } |
2096: | if (!$transferMethod->getToken()) { |
2097: | throw new HyperwalletArgumentException('transfer method token is required!'); |
2098: | } |
2099: | |
2100: | return $this->client->doPut('/rest/v4/users/{user-token}/{transfer-method-name}/{transfer-method-token}', array( |
2101: | 'user-token' => $userToken, |
2102: | 'transfer-method-token' => $transferMethod->getToken(), |
2103: | 'transfer-method-name' => $transferMethodName, |
2104: | ), $transferMethod, array()); |
2105: | } |
2106: | |
2107: | |
2108: | |
2109: | |
2110: | |
2111: | |
2112: | |
2113: | |
2114: | |
2115: | |
2116: | public function updateVerificationStatus($userToken, $verificationStatus){ |
2117: | if (empty($userToken)) { |
2118: | throw new HyperwalletArgumentException('userToken is required!'); |
2119: | } |
2120: | if (empty($verificationStatus)) { |
2121: | throw new HyperwalletArgumentException('verificationStatus is required!'); |
2122: | } |
2123: | $user = new User(array('verificationStatus'=> $verificationStatus)); |
2124: | $responseUser = $this->client->doPut('/rest/v4/users/{user-token}', array('user-token' => $userToken), $user, array()); |
2125: | return new User($responseUser); |
2126: | } |
2127: | |
2128: | |
2129: | |
2130: | |
2131: | |
2132: | |
2133: | |
2134: | |
2135: | |
2136: | |
2137: | public function createUserStatusTransition($userToken, UserStatusTransition $transition) { |
2138: | if (empty($userToken)) { |
2139: | throw new HyperwalletArgumentException('userToken is required!'); |
2140: | } |
2141: | if (empty($transition->getTransition())) { |
2142: | throw new HyperwalletArgumentException('userStatusTransition is required!'); |
2143: | } |
2144: | $body = $this->client->doPost('/rest/v4/users/{user-token}/status-transitions', array( |
2145: | 'user-token' => $userToken), $transition, array()); |
2146: | return new UserStatusTransition($body); |
2147: | } |
2148: | |
2149: | |
2150: | |
2151: | |
2152: | |
2153: | |
2154: | |
2155: | |
2156: | |
2157: | public function activateUser($userToken) { |
2158: | $transition = new UserStatusTransition(); |
2159: | $transition->setTransition(UserStatusTransition::TRANSITION_ACTIVATED); |
2160: | return $this->createUserStatusTransition($userToken, $transition); |
2161: | } |
2162: | |
2163: | |
2164: | |
2165: | |
2166: | |
2167: | |
2168: | |
2169: | |
2170: | |
2171: | public function deactivateUser($userToken) { |
2172: | $transition = new UserStatusTransition(); |
2173: | $transition->setTransition(UserStatusTransition::TRANSITION_DE_ACTIVATED); |
2174: | return $this->createUserStatusTransition($userToken, $transition); |
2175: | } |
2176: | |
2177: | |
2178: | |
2179: | |
2180: | |
2181: | |
2182: | |
2183: | |
2184: | |
2185: | public function lockUser($userToken) { |
2186: | $transition = new UserStatusTransition(); |
2187: | $transition->setTransition(UserStatusTransition::TRANSITION_LOCKED); |
2188: | return $this->createUserStatusTransition($userToken, $transition); |
2189: | } |
2190: | |
2191: | |
2192: | |
2193: | |
2194: | |
2195: | |
2196: | |
2197: | |
2198: | |
2199: | public function freezeUser($userToken) { |
2200: | $transition = new UserStatusTransition(); |
2201: | $transition->setTransition(UserStatusTransition::TRANSITION_FROZEN); |
2202: | return $this->createUserStatusTransition($userToken, $transition); |
2203: | } |
2204: | |
2205: | |
2206: | |
2207: | |
2208: | |
2209: | |
2210: | |
2211: | |
2212: | |
2213: | public function preactivateUser($userToken) { |
2214: | $transition = new UserStatusTransition(); |
2215: | $transition->setTransition(UserStatusTransition::TRANSITION_PRE_ACTIVATED); |
2216: | return $this->createUserStatusTransition($userToken, $transition); |
2217: | } |
2218: | |
2219: | |
2220: | |
2221: | |
2222: | |
2223: | |
2224: | |
2225: | |
2226: | |
2227: | |
2228: | |
2229: | |
2230: | |
2231: | |
2232: | |
2233: | |
2234: | |
2235: | |
2236: | |
2237: | |
2238: | |
2239: | |
2240: | |
2241: | |
2242: | |
2243: | |
2244: | |
2245: | |
2246: | |
2247: | |
2248: | public function uploadDocumentsForUser($userToken, $options) { |
2249: | if (empty($userToken)) { |
2250: | throw new HyperwalletArgumentException('userToken is required!'); |
2251: | } |
2252: | $body = $this->client->putMultipartData('/rest/v4/users/{user-token}', array('user-token' => $userToken), $options); |
2253: | $body = $this->setDocumentAndReasonFromResponseHelper($body); |
2254: | return new User($body); |
2255: | } |
2256: | |
2257: | |
2258: | |
2259: | |
2260: | |
2261: | |
2262: | |
2263: | |
2264: | |
2265: | |
2266: | |
2267: | |
2268: | |
2269: | |
2270: | |
2271: | public function createVenmoAccount($userToken, VenmoAccount $venmoAccount) { |
2272: | if (empty($userToken)) { |
2273: | throw new HyperwalletArgumentException('userToken is required!'); |
2274: | } |
2275: | if (empty($venmoAccount->getTransferMethodCountry())) { |
2276: | throw new HyperwalletArgumentException('transferMethodCountry is required!'); |
2277: | } |
2278: | if (empty($venmoAccount->getTransferMethodCurrency())) { |
2279: | throw new HyperwalletArgumentException('transferMethodCurrency is required!'); |
2280: | } |
2281: | if (empty($venmoAccount->getAccountId())) { |
2282: | throw new HyperwalletArgumentException('Venmo account is required!'); |
2283: | } |
2284: | $body = $this->client->doPost('/rest/v4/users/{user-token}/venmo-accounts', array('user-token' => $userToken), $venmoAccount, array()); |
2285: | return new VenmoAccount($body); |
2286: | } |
2287: | |
2288: | |
2289: | |
2290: | |
2291: | |
2292: | |
2293: | |
2294: | |
2295: | |
2296: | |
2297: | |
2298: | public function getVenmoAccount($userToken, $venmoAccountToken) { |
2299: | if (empty($userToken)) { |
2300: | throw new HyperwalletArgumentException('userToken is required!'); |
2301: | } |
2302: | if (empty($venmoAccountToken)) { |
2303: | throw new HyperwalletArgumentException('venmoAccountToken is required!'); |
2304: | } |
2305: | $body = $this->client->doGet('/rest/v4/users/{user-token}/venmo-accounts/{venmo-account-token}', array( |
2306: | 'user-token' => $userToken, |
2307: | 'venmo-account-token' => $venmoAccountToken |
2308: | ), array()); |
2309: | return new VenmoAccount($body); |
2310: | } |
2311: | |
2312: | |
2313: | |
2314: | |
2315: | |
2316: | |
2317: | |
2318: | |
2319: | |
2320: | public function updateVenmoAccount($userToken, VenmoAccount $venmoAccount) { |
2321: | $body = $this->updateTransferMethod($userToken, $venmoAccount, 'venmo-accounts'); |
2322: | return new VenmoAccount($body); |
2323: | } |
2324: | |
2325: | |
2326: | |
2327: | |
2328: | |
2329: | |
2330: | |
2331: | |
2332: | |
2333: | |
2334: | public function listVenmoAccounts($userToken, $options = array()) { |
2335: | if (empty($userToken)) { |
2336: | throw new HyperwalletArgumentException('userToken is required!'); |
2337: | } |
2338: | if (!empty($options)) { |
2339: | $filteredArr = array_diff_key($options, array_flip(VenmoAccount::FILTERS_ARRAY())); |
2340: | if (!empty($filteredArr)) { |
2341: | throw new HyperwalletArgumentException('Invalid filter'); |
2342: | } |
2343: | } |
2344: | |
2345: | $body = $this->client->doGet('/rest/v4/users/{user-token}/venmo-accounts', array('user-token' => $userToken), $options); |
2346: | return new ListResponse($body, function ($entry) { |
2347: | return new VenmoAccount($entry); |
2348: | }); |
2349: | } |
2350: | |
2351: | |
2352: | |
2353: | |
2354: | |
2355: | |
2356: | |
2357: | |
2358: | |
2359: | |
2360: | |
2361: | public function deactivateVenmoAccount($userToken, $venmoAccountToken) { |
2362: | $transition = new VenmoAccountStatusTransition(); |
2363: | $transition->setTransition(VenmoAccountStatusTransition::TRANSITION_DE_ACTIVATED); |
2364: | |
2365: | return $this->createVenmoAccountStatusTransition($userToken, $venmoAccountToken, $transition); |
2366: | } |
2367: | |
2368: | |
2369: | |
2370: | |
2371: | |
2372: | |
2373: | |
2374: | |
2375: | |
2376: | |
2377: | |
2378: | |
2379: | public function createVenmoAccountStatusTransition($userToken, $venmoAccountToken, VenmoAccountStatusTransition $transition) { |
2380: | if (empty($userToken)) { |
2381: | throw new HyperwalletArgumentException('userToken is required!'); |
2382: | } |
2383: | if (empty($venmoAccountToken)) { |
2384: | throw new HyperwalletArgumentException('venmoAccountToken is required!'); |
2385: | } |
2386: | |
2387: | $body = $this->client->doPost('/rest/v4/users/{user-token}/venmo-accounts/{venmo-account-token}/status-transitions', array( |
2388: | 'user-token' => $userToken, |
2389: | 'venmo-account-token' => $venmoAccountToken |
2390: | ), $transition, array()); |
2391: | return new VenmoAccountStatusTransition($body); |
2392: | } |
2393: | |
2394: | |
2395: | |
2396: | |
2397: | |
2398: | |
2399: | |
2400: | |
2401: | |
2402: | |
2403: | |
2404: | |
2405: | public function getVenmoAccountStatusTransition($userToken, $venmoAccountToken, $statusTransitionToken) { |
2406: | if (empty($userToken)) { |
2407: | throw new HyperwalletArgumentException('userToken is required!'); |
2408: | } |
2409: | if (empty($venmoAccountToken)) { |
2410: | throw new HyperwalletArgumentException('venmoAccountToken is required!'); |
2411: | } |
2412: | if (empty($statusTransitionToken)) { |
2413: | throw new HyperwalletArgumentException('statusTransitionToken is required!'); |
2414: | } |
2415: | |
2416: | $body = $this->client->doGet('/rest/v4/users/{user-token}/venmo-accounts/{venmo-account-token}/status-transitions/{status-transition-token}', array( |
2417: | 'user-token' => $userToken, |
2418: | 'venmo-account-token' => $venmoAccountToken, |
2419: | 'status-transition-token' => $statusTransitionToken |
2420: | ), array()); |
2421: | return new VenmoAccountStatusTransition($body); |
2422: | } |
2423: | |
2424: | |
2425: | |
2426: | |
2427: | |
2428: | |
2429: | |
2430: | |
2431: | |
2432: | |
2433: | |
2434: | |
2435: | public function listVenmoAccountStatusTransitions($userToken, $venmoAccountToken, array $options = array()) { |
2436: | if (empty($userToken)) { |
2437: | throw new HyperwalletArgumentException('userToken is required!'); |
2438: | } |
2439: | if (empty($venmoAccountToken)) { |
2440: | throw new HyperwalletArgumentException('venmoAccountToken is required!'); |
2441: | } |
2442: | if (!empty($options)) { |
2443: | $filteredArr = array_diff_key($options, array_flip(StatusTransition::FILTERS_ARRAY())); |
2444: | if (!empty($filteredArr)) { |
2445: | throw new HyperwalletArgumentException('Invalid filter'); |
2446: | } |
2447: | } |
2448: | |
2449: | $body = $this->client->doGet('/rest/v4/users/{user-token}/venmo-accounts/{venmo-account-token}/status-transitions', array( |
2450: | 'user-token' => $userToken, |
2451: | 'venmo-account-token' => $venmoAccountToken |
2452: | ), $options); |
2453: | return new ListResponse($body, function ($entry) { |
2454: | return new VenmoAccountStatusTransition($entry); |
2455: | }); |
2456: | } |
2457: | |
2458: | |
2459: | |
2460: | |
2461: | |
2462: | |
2463: | |
2464: | |
2465: | |
2466: | |
2467: | |
2468: | |
2469: | |
2470: | |
2471: | |
2472: | |
2473: | |
2474: | |
2475: | |
2476: | |
2477: | |
2478: | |
2479: | |
2480: | |
2481: | |
2482: | |
2483: | |
2484: | |
2485: | |
2486: | |
2487: | public function uploadDocumentsForBusinessStakeholder($userToken, $businessToken, $options) { |
2488: | if (empty($userToken)) { |
2489: | throw new HyperwalletArgumentException('userToken is required!'); |
2490: | } |
2491: | if (empty($businessToken)) { |
2492: | throw new HyperwalletArgumentException('businessToken is required!'); |
2493: | } |
2494: | $body = $this->client->putMultipartData('/rest/v4/users/{user-token}/business-stakeholders/{business-token}', array('user-token' => $userToken,'business-token' => $businessToken), $options); |
2495: | $body = $this->setDocumentAndReasonFromResponseHelper($body); |
2496: | return new BusinessStakeholder($body); |
2497: | } |
2498: | |
2499: | |
2500: | |
2501: | |
2502: | |
2503: | |
2504: | |
2505: | |
2506: | |
2507: | |
2508: | |
2509: | public function createBusinessStakeholder($userToken, $businessStakeholder) { |
2510: | if (empty($userToken)) { |
2511: | throw new HyperwalletArgumentException('userToken is required!'); |
2512: | } |
2513: | $body = $this->client->doPost('/rest/v4/users/{user-token}/business-stakeholders', array('user-token' => $userToken), $businessStakeholder, array()); |
2514: | return new BusinessStakeholder($body); |
2515: | } |
2516: | |
2517: | |
2518: | |
2519: | |
2520: | |
2521: | |
2522: | |
2523: | |
2524: | |
2525: | public function updateBusinessStakeholder($userToken, $businessToken, $businessStakeholder) { |
2526: | if (empty($userToken)) { |
2527: | throw new HyperwalletArgumentException('userToken is required!'); |
2528: | } |
2529: | if (empty($businessToken)) { |
2530: | throw new HyperwalletArgumentException('businessToken is required!'); |
2531: | } |
2532: | $body = $this->client->doPut('/rest/v4/users/{user-token}/business-stakeholders/{business-token}', array('user-token' => $userToken,'business-token' => $businessToken), $businessStakeholder, array()); |
2533: | return new BusinessStakeholder($body); |
2534: | } |
2535: | |
2536: | |
2537: | |
2538: | |
2539: | |
2540: | |
2541: | |
2542: | |
2543: | |
2544: | |
2545: | public function listBusinessStakeholders($userToken , $options) { |
2546: | if (empty($userToken)) { |
2547: | throw new HyperwalletArgumentException('userToken is required!'); |
2548: | } |
2549: | if (!empty($options)) { |
2550: | $filteredArr = array_diff_key($options, array_flip(BusinessStakeholder::FILTERS_ARRAY())); |
2551: | if (!empty($filteredArr)) { |
2552: | throw new HyperwalletArgumentException('Invalid filter'); |
2553: | } |
2554: | } |
2555: | $body = $this->client->doGet('/rest/v4/users/{user-token}/business-stakeholders',array( |
2556: | 'user-token' => $userToken |
2557: | ), $options); |
2558: | return new ListResponse($body, function ($entry) { |
2559: | return new BusinessStakeholder($entry); |
2560: | }); |
2561: | } |
2562: | |
2563: | |
2564: | |
2565: | |
2566: | |
2567: | |
2568: | |
2569: | |
2570: | |
2571: | |
2572: | |
2573: | |
2574: | public function createBusinessStakeholderStatusTransition($userToken, $businessToken, BusinessStakeholderStatusTransition $transition) { |
2575: | if (empty($userToken)) { |
2576: | throw new HyperwalletArgumentException('userToken is required!'); |
2577: | } |
2578: | if (empty($businessToken)) { |
2579: | throw new HyperwalletArgumentException('businessToken is required!'); |
2580: | } |
2581: | |
2582: | $body = $this->client->doPost('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array( |
2583: | 'user-token' => $userToken, |
2584: | 'business-token' => $businessToken |
2585: | ), $transition, array()); |
2586: | return new BusinessStakeholderStatusTransition($body); |
2587: | } |
2588: | |
2589: | |
2590: | |
2591: | |
2592: | |
2593: | |
2594: | |
2595: | |
2596: | |
2597: | |
2598: | |
2599: | public function activateBusinessStakeholder($userToken, $businessToken) { |
2600: | $transition = new BusinessStakeholderStatusTransition(); |
2601: | $transition->setTransition(BusinessStakeholderStatusTransition::TRANSITION_ACTIVATED); |
2602: | |
2603: | return $this->createBusinessStakeholderStatusTransition($userToken, $businessToken, $transition); |
2604: | } |
2605: | |
2606: | |
2607: | |
2608: | |
2609: | |
2610: | |
2611: | |
2612: | |
2613: | |
2614: | |
2615: | |
2616: | public function deactivateBusinessStakeholder($userToken, $businessToken) { |
2617: | $transition = new BusinessStakeholderStatusTransition(); |
2618: | $transition->setTransition(BusinessStakeholderStatusTransition::TRANSITION_DE_ACTIVATED); |
2619: | |
2620: | return $this->createBusinessStakeholderStatusTransition($userToken, $businessToken, $transition); |
2621: | } |
2622: | |
2623: | |
2624: | |
2625: | |
2626: | |
2627: | |
2628: | |
2629: | |
2630: | |
2631: | |
2632: | |
2633: | |
2634: | public function getBusinessStakeholderStatusTransition($userToken, $businessToken, $statusTransitionToken) { |
2635: | if (empty($userToken)) { |
2636: | throw new HyperwalletArgumentException('userToken is required!'); |
2637: | } |
2638: | if (empty($businessToken)) { |
2639: | throw new HyperwalletArgumentException('businessToken is required!'); |
2640: | } |
2641: | if (empty($statusTransitionToken)) { |
2642: | throw new HyperwalletArgumentException('statusTransitionToken is required!'); |
2643: | } |
2644: | |
2645: | $body = $this->client->doGet('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions/{status-transition-token}', array( |
2646: | 'user-token' => $userToken, |
2647: | 'business-token' => $businessToken, |
2648: | 'status-transition-token' => $statusTransitionToken |
2649: | ), array()); |
2650: | return new BusinessStakeholderStatusTransition($body); |
2651: | } |
2652: | |
2653: | |
2654: | |
2655: | |
2656: | |
2657: | |
2658: | |
2659: | |
2660: | |
2661: | |
2662: | |
2663: | |
2664: | public function listBusinessStakeholderStatusTransitions($userToken, $businessToken, array $options = array()) { |
2665: | if (empty($userToken)) { |
2666: | throw new HyperwalletArgumentException('userToken is required!'); |
2667: | } |
2668: | if (empty($businessToken)) { |
2669: | throw new HyperwalletArgumentException('businessToken is required!'); |
2670: | } |
2671: | if (!empty($options)) { |
2672: | $filteredArr = array_diff_key($options, array_flip(StatusTransition::FILTERS_ARRAY())); |
2673: | if (!empty($filteredArr)) { |
2674: | throw new HyperwalletArgumentException('Invalid filter'); |
2675: | } |
2676: | } |
2677: | |
2678: | $body = $this->client->doGet('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array( |
2679: | 'user-token' => $userToken, |
2680: | 'business-token' => $businessToken |
2681: | ), $options); |
2682: | return new ListResponse($body, function ($entry) { |
2683: | return new BusinessStakeholderStatusTransition($entry); |
2684: | }); |
2685: | } |
2686: | |
2687: | |
2688: | |
2689: | |
2690: | |
2691: | |
2692: | |
2693: | |
2694: | |
2695: | public function listTransferMethods($userToken, $options = array()) { |
2696: | if (empty($userToken)) { |
2697: | throw new HyperwalletArgumentException('userToken is required!'); |
2698: | } |
2699: | |
2700: | $body = $this->client->doGet('/rest/v4/users/{user-token}/transfer-methods', array( |
2701: | 'user-token' => $userToken |
2702: | ), $options); |
2703: | return new ListResponse($body, function ($entry) { |
2704: | return new TransferMethod($entry); |
2705: | }); |
2706: | } |
2707: | } |
2708: | |