1: <?php
2:
3: /**
4: * Export a list of billing agreements
5: * @see https://app.syspay.com/bundles/emiuser/doc/merchant_api.html#get-a-list-of-billing-agreements
6: */
7: class Syspay_Merchant_BillingAgreementListRequest extends Syspay_Merchant_Request
8: {
9: const METHOD = 'GET';
10: const PATH = '/api/v1/merchant/billing-agreements/';
11:
12: /**
13: * @var array
14: */
15: private $filters;
16:
17: public function __construct()
18: {
19: $this->filters = array();
20: }
21:
22: /**
23: * {@inheritDoc}
24: */
25: public function getMethod()
26: {
27: return self::METHOD;
28: }
29:
30: /**
31: * {@inheritDoc}
32: */
33: public function getPath()
34: {
35: return sprintf(self::PATH);
36: }
37:
38: /**
39: * {@inheritDoc}
40: */
41: public function getData()
42: {
43: return $this->filters;
44: }
45:
46: /**
47: * Set a filter to use when querying the API
48: * @param string $key Filter key
49: * @param string $value Filter value
50: * @return self
51: */
52: public function addFilter($key, $value)
53: {
54: $this->filters[$key] = $value;
55: return $this;
56: }
57:
58: /**
59: * Delete a filter
60: * @param string $key Filter key to delete
61: * @return self
62: */
63: public function deleteFilter($key)
64: {
65: if (isset($this->filters[$key])) {
66: unset($this->filters[$key]);
67: }
68: return $this;
69: }
70:
71: /**
72: * {@inheritDoc}
73: */
74: public function buildResponse(stdClass $response)
75: {
76: if (!isset($response->billing_agreements) || !is_array($response->billing_agreements)) {
77: throw new Syspay_Merchant_UnexpectedResponseException(
78: 'Unable to retrieve "billing_agreements" data from response',
79: $response
80: );
81: }
82:
83: $billingAgreements = array();
84:
85: foreach ($response->billing_agreements as $ba) {
86: $billingAgreement = Syspay_Merchant_Entity_BillingAgreement::buildFromResponse($ba);
87: array_push($billingAgreements, $billingAgreement);
88: }
89:
90: return $billingAgreements;
91: }
92: }
93: