← All changes
|
vendor/payplug/payplug-php/lib/Payplug/Resource/Payment.php
+53
-10
1.0.3
→
3.1.0
View file →
| @@ -33,11 +33,21 @@ | ||
| 33 | 33 | |
| 34 | 34 | if (isset($attributes['card'])) { |
| 35 | 35 | $this->card = PaymentCard::fromAttributes($attributes['card']); |
| 36 | 36 | } |
| 37 | + | |
| 38 | + /* | |
| 39 | + * @deprecated No longer used by API, use billing and shipping instead | |
| 40 | + */ | |
| 37 | 41 | if (isset($attributes['customer'])) { |
| 38 | 42 | $this->customer = PaymentCustomer::fromAttributes($attributes['customer']); |
| 39 | 43 | } |
| 44 | + if (isset($attributes['billing'])) { | |
| 45 | + $this->billing = PaymentBilling::fromAttributes($attributes['billing']); | |
| 46 | + } | |
| 47 | + if (isset($attributes['shipping'])) { | |
| 48 | + $this->shipping = PaymentShipping::fromAttributes($attributes['shipping']); | |
| 49 | + } | |
| 40 | 50 | if (isset($attributes['hosted_payment'])) { |
| 41 | 51 | $this->hosted_payment = PaymentHostedPayment::fromAttributes($attributes['hosted_payment']); |
| 42 | 52 | } |
| 43 | 53 | if (isset($attributes['failure'])) { |
| @@ -45,8 +55,11 @@ | ||
| 45 | 55 | } |
| 46 | 56 | if (isset($attributes['notification'])) { |
| 47 | 57 | $this->notification = PaymentNotification::fromAttributes($attributes['notification']); |
| 48 | 58 | } |
| 59 | + if (isset($attributes['authorization'])) { | |
| 60 | + $this->authorization = PaymentAuthorization::fromAttributes($attributes['authorization']); | |
| 61 | + } | |
| 49 | 62 | } |
| 50 | 63 | |
| 51 | 64 | /** |
| 52 | 65 | * Open a refund on the payment. |
| @@ -57,9 +70,9 @@ | ||
| 57 | 70 | * @return Refund|null the opened refund instance |
| 58 | 71 | * |
| 59 | 72 | * @throws Payplug\Exception\InvalidPaymentException when the id of the payment is invalid |
| 60 | 73 | */ |
| 61 | - public function refund(array $data = null, Payplug\Payplug $payplug = null) | |
| 74 | + public function refund($data = null, $payplug = null) | |
| 62 | 75 | { |
| 63 | 76 | if (!array_key_exists('id', $this->getAttributes())) { |
| 64 | 77 | throw new Payplug\Exception\InvalidPaymentException("This payment object has no id. It can't be refunded."); |
| 65 | 78 | } |
| @@ -76,9 +89,9 @@ | ||
| 76 | 89 | * |
| 77 | 90 | * @throws Payplug\Exception\InvalidPaymentException |
| 78 | 91 | * @throws Payplug\Exception\UnexpectedAPIResponseException |
| 79 | 92 | */ |
| 80 | - public function listRefunds(Payplug\Payplug $payplug = null) | |
| 93 | + public function listRefunds($payplug = null) | |
| 81 | 94 | { |
| 82 | 95 | if (!array_key_exists('id', $this->getAttributes())) { |
| 83 | 96 | throw new Payplug\Exception\InvalidPaymentException("This payment object has no id. You can't list refunds on it."); |
| 84 | 97 | } |
| @@ -94,9 +107,9 @@ | ||
| 94 | 107 | * @return null|Payment the aborted payment or null on error |
| 95 | 108 | * |
| 96 | 109 | * @throws Payplug\Exception\ConfigurationNotSetException |
| 97 | 110 | */ |
| 98 | - public function abort(Payplug\Payplug $payplug = null) | |
| 111 | + public function abort($payplug = null) | |
| 99 | 112 | { |
| 100 | 113 | if ($payplug === null) { |
| 101 | 114 | $payplug = Payplug\Payplug::getDefaultConfiguration(); |
| 102 | 115 | } |
| @@ -103,9 +116,9 @@ | ||
| 103 | 116 | |
| 104 | 117 | $httpClient = new Payplug\Core\HttpClient($payplug); |
| 105 | 118 | $response = $httpClient->patch( |
| 106 | 119 | Payplug\Core\APIRoutes::getRoute(Payplug\Core\APIRoutes::PAYMENT_RESOURCE, $this->id), |
| 107 | - array('abort' => true) | |
| 120 | + array('aborted' => true) | |
| 108 | 121 | ); |
| 109 | 122 | |
| 110 | 123 | return Payment::fromAttributes($response['httpResponse']); |
| 111 | 124 | } |
| @@ -110,23 +123,53 @@ | ||
| 110 | 123 | return Payment::fromAttributes($response['httpResponse']); |
| 111 | 124 | } |
| 112 | 125 | |
| 113 | 126 | /** |
| 127 | + * Captures a Payment. | |
| 128 | + * | |
| 129 | + * @param Payplug\Payplug $payplug the client configuration | |
| 130 | + * | |
| 131 | + * @return null|Payment the captured payment or null on error | |
| 132 | + * | |
| 133 | + * @throws Payplug\Exception\ConfigurationNotSetException | |
| 134 | + */ | |
| 135 | + public function capture($payplug = null) | |
| 136 | + { | |
| 137 | + if ($payplug === null) { | |
| 138 | + $payplug = Payplug\Payplug::getDefaultConfiguration(); | |
| 139 | + } | |
| 140 | + | |
| 141 | + $httpClient = new Payplug\Core\HttpClient($payplug); | |
| 142 | + $response = $httpClient->patch( | |
| 143 | + Payplug\Core\APIRoutes::getRoute(Payplug\Core\APIRoutes::PAYMENT_RESOURCE, $this->id), | |
| 144 | + array('captured' => true) | |
| 145 | + ); | |
| 146 | + | |
| 147 | + return Payment::fromAttributes($response['httpResponse']); | |
| 148 | + } | |
| 149 | + | |
| 150 | + /** | |
| 114 | 151 | * Retrieves a Payment. |
| 115 | 152 | * |
| 116 | 153 | * @param string $paymentId the payment ID |
| 117 | 154 | * @param Payplug\Payplug $payplug the client configuration |
| 118 | 155 | * |
| 119 | - * @return null|Payment the retrieved payment or null on error | |
| 156 | + * @return Payment the retrieved payment | |
| 120 | 157 | * |
| 121 | 158 | * @throws Payplug\Exception\ConfigurationNotSetException |
| 159 | + * @throws Payplug\Exception\UndefinedAttributeException | |
| 160 | + * @throws Payplug\Exception\NotFoundException | |
| 122 | 161 | */ |
| 123 | - public static function retrieve($paymentId, Payplug\Payplug $payplug = null) | |
| 162 | + public static function retrieve($paymentId, $payplug = null) | |
| 124 | 163 | { |
| 125 | 164 | if ($payplug === null) { |
| 126 | 165 | $payplug = Payplug\Payplug::getDefaultConfiguration(); |
| 127 | 166 | } |
| 128 | 167 | |
| 168 | + if (!$paymentId) { | |
| 169 | + throw new Payplug\Exception\UndefinedAttributeException('The parameter paymentId is not set.'); | |
| 170 | + } | |
| 171 | + | |
| 129 | 172 | $httpClient = new Payplug\Core\HttpClient($payplug); |
| 130 | 173 | $response = $httpClient->get( |
| 131 | 174 | Payplug\Core\APIRoutes::getRoute(Payplug\Core\APIRoutes::PAYMENT_RESOURCE, $paymentId) |
| 132 | 175 | ); |
| @@ -145,9 +188,9 @@ | ||
| 145 | 188 | * |
| 146 | 189 | * @throws Payplug\Exception\InvalidPaymentException |
| 147 | 190 | * @throws Payplug\Exception\UnexpectedAPIResponseException |
| 148 | 191 | */ |
| 149 | - public static function listPayments($perPage = null, $page = null, Payplug\Payplug $payplug = null) | |
| 192 | + public static function listPayments($perPage = null, $page = null, $payplug = null) | |
| 150 | 193 | { |
| 151 | 194 | if ($payplug === null) { |
| 152 | 195 | $payplug = Payplug\Payplug::getDefaultConfiguration(); |
| 153 | 196 | } |
| @@ -183,9 +226,9 @@ | ||
| 183 | 226 | * @return null|Payment the created payment instance |
| 184 | 227 | * |
| 185 | 228 | * @throws Payplug\Exception\ConfigurationNotSetException |
| 186 | 229 | */ |
| 187 | - public static function create(array $data, Payplug\Payplug $payplug = null) | |
| 230 | + public static function create(array $data, $payplug = null) | |
| 188 | 231 | { |
| 189 | 232 | if ($payplug === null) { |
| 190 | 233 | $payplug = Payplug\Payplug::getDefaultConfiguration(); |
| 191 | 234 | } |
| @@ -208,9 +251,9 @@ | ||
| 208 | 251 | * @return null|Payment the updated payment instance |
| 209 | 252 | * |
| 210 | 253 | * @throws Payplug\Exception\ConfigurationNotSetException |
| 211 | 254 | */ |
| 212 | - public function update(array $data, Payplug\Payplug $payplug = null) | |
| 255 | + public function update(array $data, $payplug = null) | |
| 213 | 256 | { |
| 214 | 257 | if ($payplug === null) { |
| 215 | 258 | $payplug = Payplug\Payplug::getDefaultConfiguration(); |
| 216 | 259 | } |
| @@ -232,9 +275,9 @@ | ||
| 232 | 275 | * @return Payplug\Resource\APIResource The consistent API resource. |
| 233 | 276 | * |
| 234 | 277 | * @throws Payplug\Exception\UndefinedAttributeException when the local resource is invalid. |
| 235 | 278 | */ |
| 236 | - function getConsistentResource(Payplug\Payplug $payplug = null) | |
| 279 | + function getConsistentResource($payplug = null) | |
| 237 | 280 | { |
| 238 | 281 | if (!array_key_exists('id', $this->_attributes)) { |
| 239 | 282 | throw new Payplug\Exception\UndefinedAttributeException('The id of the payment is not set.'); |
| 240 | 283 | } |