1 | <?php |
||
15 | abstract class AbstractResource |
||
16 | { |
||
17 | private static $client; |
||
18 | |||
19 | private static $actions = array( |
||
20 | 'create', |
||
21 | 'capture', |
||
22 | 'retrieve', |
||
23 | 'listAll', |
||
24 | 'refund', |
||
25 | 'update', |
||
26 | 'delete' |
||
27 | ); |
||
28 | |||
29 | private static $resources = array( |
||
30 | 'tokens', |
||
31 | 'payments', |
||
32 | 'customers', |
||
33 | 'notifications' |
||
34 | ); |
||
35 | |||
36 | private static $clientOptions = array(); |
||
37 | |||
38 | /** |
||
39 | * Create a new resource object. |
||
40 | * See Resource class for more input info. |
||
41 | * |
||
42 | * @param array $params |
||
43 | * @return stdClass |
||
44 | */ |
||
45 | public static function create(array $params) |
||
49 | |||
50 | /** |
||
51 | * Retrieve an existing resource based on its token. |
||
52 | * |
||
53 | * @param string|stdClass $token A valid resource token returned from a |
||
54 | * successful resource creation. |
||
55 | * @return stdClass |
||
56 | */ |
||
57 | public static function retrieve($token) |
||
63 | |||
64 | /** |
||
65 | * Get a collection of given resource objects by applying some filters. |
||
66 | * Filters are optionals and include: |
||
67 | * - count: The number of objects to returns. Availabe range is 1 - 20. |
||
68 | * - offset: The offset of collection to return. Useful for pagination. |
||
69 | * - date_from: Return objects that created after that date. |
||
70 | * Format: YYYY-mm-dd |
||
71 | * - date_to: Return objects that created before that date. |
||
72 | * Format: YYYY-mm-dd |
||
73 | * |
||
74 | * @param array $filters Filter options. |
||
75 | * @return stdClass |
||
76 | */ |
||
77 | public static function listAll(array $filters = array()) |
||
81 | |||
82 | /** |
||
83 | * Update an existing resource. |
||
84 | * |
||
85 | * @param string|stdClass $token |
||
86 | * @param array $params |
||
87 | * @return stdClass |
||
88 | */ |
||
89 | public static function update($token, array $params) |
||
95 | |||
96 | /** |
||
97 | * Delete a resource. |
||
98 | * |
||
99 | * @param string|stdClass $token |
||
100 | * @return stdClass |
||
101 | */ |
||
102 | public static function delete($token, array $params = array()) |
||
108 | |||
109 | public static function setClientOption($option, $value) |
||
113 | |||
114 | public static function setClient(ClientInterface $client) |
||
118 | |||
119 | public static function resetClient() |
||
123 | |||
124 | protected static function invoke($action, $resourceName, array $params = array()) |
||
147 | |||
148 | private static function createClient() |
||
156 | |||
157 | /** |
||
158 | * Handle API response. |
||
159 | * |
||
160 | * @param \Everypay\Http\ResponseInterface $response |
||
161 | * @return \stdClass |
||
162 | * @throws \Everypay\Exception\ApiErrorException |
||
163 | */ |
||
164 | protected static function handleResponse($response) |
||
175 | |||
176 | private static function resolveContentType($response) |
||
185 | |||
186 | private static function resolveErrorResponse($response) |
||
197 | } |
||
198 |