|
1 |
| -<?php |
2 |
| - |
3 |
| -namespace GlobalPayments\Api\Entities; |
4 |
| - |
5 |
| -use GlobalPayments\Api\ServicesContainer; |
6 |
| -use GlobalPayments\Api\Entities\Exceptions\ApiException; |
7 |
| -use GlobalPayments\Api\Entities\Exceptions\UnsupportedTransactionException; |
8 |
| -use GlobalPayments\Api\PaymentMethods\RecurringPaymentMethod; |
9 |
| -use GlobalPayments\Api\Services\RecurringService; |
10 |
| - |
11 |
| -/** |
12 |
| - * Base implementation for recurring resource types. |
13 |
| - * </summary> |
14 |
| - */ |
15 |
| -abstract class RecurringEntity implements IRecurringEntity |
16 |
| -{ |
17 |
| - /** |
18 |
| - * All resource should be supplied a merchant-/application-defined ID. |
19 |
| - * |
20 |
| - * @var string |
21 |
| - */ |
22 |
| - public $id; |
23 |
| - |
24 |
| - /** |
25 |
| - * All resources should be supplied a gateway-defined ID. |
26 |
| - * |
27 |
| - * @var string |
28 |
| - */ |
29 |
| - public $key; |
30 |
| - |
31 |
| - /** |
32 |
| - * {@inheritDoc} |
33 |
| - */ |
34 |
| - public function create() |
35 |
| - { |
36 |
| - return RecurringService::create($this); |
37 |
| - } |
38 |
| - |
39 |
| - /** |
40 |
| - * {@inheritDoc} |
41 |
| - */ |
42 |
| - public function delete($force = false) |
43 |
| - { |
44 |
| - try { |
45 |
| - return RecurringService::delete($this, $force); |
46 |
| - } catch (ApiException $exc) { |
47 |
| - throw new ApiException('Failed to delete record, see inner exception for more details', $exc); |
48 |
| - } |
49 |
| - } |
50 |
| - |
51 |
| - /** |
52 |
| - * {@inheritDoc} |
53 |
| - */ |
54 |
| - public static function find($id, $configName = 'default') |
55 |
| - { |
56 |
| - $client = ServicesContainer::instance()->getRecurringClient($configName); |
57 |
| - if (!$client->supportsRetrieval) { |
58 |
| - throw new UnsupportedTransactionException(); |
59 |
| - } |
60 |
| - |
61 |
| - $identifier = static::getIdentifierName(); |
62 |
| - $response = RecurringService::search(static::class) |
63 |
| - ->addSearchCriteria($identifier, $id) |
64 |
| - ->execute(); |
65 |
| - $entity = isset($response[0]) ? $response[0] : null; |
66 |
| - |
67 |
| - if ($entity !== null) { |
68 |
| - return RecurringService::get($entity); |
69 |
| - } |
70 |
| - |
71 |
| - return null; |
72 |
| - } |
73 |
| - |
74 |
| - /** |
75 |
| - * {@inheritDoc} |
76 |
| - */ |
77 |
| - public static function findAll($configName = 'default') |
78 |
| - { |
79 |
| - $client = ServicesContainer::instance()->getRecurringClient($configName); |
80 |
| - if (!$client->supportsRetrieval) { |
81 |
| - throw new UnsupportedTransactionException(); |
82 |
| - } |
83 |
| - |
84 |
| - return RecurringService::search(static::class)->execute(); |
85 |
| - } |
86 |
| - |
87 |
| - /** |
88 |
| - * {@inheritDoc} |
89 |
| - */ |
90 |
| - public function saveChanges($configName = 'default') |
91 |
| - { |
92 |
| - try { |
93 |
| - return RecurringService::edit($this); |
94 |
| - } catch (ApiException $exc) { |
95 |
| - throw new ApiException('Update failed, see inner exception for more details', $exc); |
96 |
| - } |
97 |
| - } |
98 |
| - |
99 |
| - protected static function getIdentifierName() |
100 |
| - { |
101 |
| - if (static::class === Customer::class) { |
102 |
| - return 'customerIdentifier'; |
103 |
| - } elseif (static::class === RecurringPaymentMethod::class) { |
104 |
| - return 'paymentMethodIdentifier'; |
105 |
| - } elseif (static::class === Schedule::class) { |
106 |
| - return 'scheduleIdentifier'; |
107 |
| - } |
108 |
| - return ''; |
109 |
| - } |
110 |
| -} |
| 1 | +<?php |
| 2 | + |
| 3 | +namespace GlobalPayments\Api\Entities; |
| 4 | + |
| 5 | +use GlobalPayments\Api\ServicesContainer; |
| 6 | +use GlobalPayments\Api\Entities\Exceptions\ApiException; |
| 7 | +use GlobalPayments\Api\Entities\Exceptions\UnsupportedTransactionException; |
| 8 | +use GlobalPayments\Api\PaymentMethods\RecurringPaymentMethod; |
| 9 | +use GlobalPayments\Api\Services\RecurringService; |
| 10 | + |
| 11 | +/** |
| 12 | + * Base implementation for recurring resource types. |
| 13 | + * </summary> |
| 14 | + */ |
| 15 | +abstract class RecurringEntity implements IRecurringEntity |
| 16 | +{ |
| 17 | + /** |
| 18 | + * All resource should be supplied a merchant-/application-defined ID. |
| 19 | + * |
| 20 | + * @var string |
| 21 | + */ |
| 22 | + public $id; |
| 23 | + |
| 24 | + /** |
| 25 | + * All resources should be supplied a gateway-defined ID. |
| 26 | + * |
| 27 | + * @var string |
| 28 | + */ |
| 29 | + public $key; |
| 30 | + |
| 31 | + /** |
| 32 | + * {@inheritDoc} |
| 33 | + */ |
| 34 | + public function create() |
| 35 | + { |
| 36 | + return RecurringService::create($this); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * {@inheritDoc} |
| 41 | + */ |
| 42 | + public function delete($force = false) |
| 43 | + { |
| 44 | + try { |
| 45 | + return RecurringService::delete($this, $force); |
| 46 | + } catch (ApiException $exc) { |
| 47 | + throw new ApiException('Failed to delete record, see inner exception for more details', $exc); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * {@inheritDoc} |
| 53 | + */ |
| 54 | + public static function find($id, $configName = 'default') |
| 55 | + { |
| 56 | + $client = ServicesContainer::instance()->getRecurringClient($configName); |
| 57 | + if (!$client->supportsRetrieval) { |
| 58 | + throw new UnsupportedTransactionException(); |
| 59 | + } |
| 60 | + |
| 61 | + $identifier = static::getIdentifierName(); |
| 62 | + $response = RecurringService::search(static::class) |
| 63 | + ->addSearchCriteria($identifier, $id) |
| 64 | + ->execute(); |
| 65 | + |
| 66 | + foreach ($response as $entity) { |
| 67 | + if ($entity->id === $id) { |
| 68 | + return RecurringService::get($entity); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + return null; |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * {@inheritDoc} |
| 77 | + */ |
| 78 | + public static function findAll($configName = 'default') |
| 79 | + { |
| 80 | + $client = ServicesContainer::instance()->getRecurringClient($configName); |
| 81 | + if (!$client->supportsRetrieval) { |
| 82 | + throw new UnsupportedTransactionException(); |
| 83 | + } |
| 84 | + |
| 85 | + return RecurringService::search(static::class)->execute(); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * {@inheritDoc} |
| 90 | + */ |
| 91 | + public function saveChanges($configName = 'default') |
| 92 | + { |
| 93 | + try { |
| 94 | + return RecurringService::edit($this); |
| 95 | + } catch (ApiException $exc) { |
| 96 | + throw new ApiException('Update failed, see inner exception for more details', $exc); |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + protected static function getIdentifierName() |
| 101 | + { |
| 102 | + if (static::class === Customer::class) { |
| 103 | + return 'customerIdentifier'; |
| 104 | + } elseif (static::class === RecurringPaymentMethod::class) { |
| 105 | + return 'paymentMethodIdentifier'; |
| 106 | + } elseif (static::class === Schedule::class) { |
| 107 | + return 'scheduleIdentifier'; |
| 108 | + } |
| 109 | + return ''; |
| 110 | + } |
| 111 | +} |
0 commit comments