クラス
Get
Amazon Pay V2 SDK Get Refund.
ソース ソース
ファイル: src/API/Refund/Get.php
class Get { /** * AmazonPay module object * * @var AmazonPay */ private $module; /** * Amazon Pay order object * * @var OrderMeta */ private $order; /** * Sets `$module` member var with dependency injection. * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param AmazonPay $module * @param OrderMeta $order * @return void */ public function __construct(AmazonPay $module, OrderMeta $order) { $this->module = $module; $this->order = $order; } /** * Gets a Refund * * @see https://amazonpaycheckoutintegrationguide.s3.amazonaws.com/amazon-pay-api-v2/refund.html#get-refund * @author Evan D Shaw <evandanielshaw@gmail.com> * @param string $refundId Refund ID * @return array * @throws InvalidArgumentException Thrown by `getAmazonClient`. */ public function get($refundId) { try { $client = $this->module->getAmazonClient(); $result = $client->getRefund($refundId); if ($this->module->errors->hasError($result)) { return $this->module->errors->getAmzErrorResponse($result); } } catch (\Exception $e) { return $this->module->errors->getErrorResponse( GenericErrorStore::AMAZON_PAY_SDK_CLIENT_EXCEPTION, [$e->getMessage()] ); } $oldRefundState = $this->order->getRefundState(); $response = json_decode($result['response'], true); $details = $response['statusDetails']; $this->order->updateRefundState( new State( $details['state'], $details['reasonCode'], $details['reasonDescription'] ) ); if ($details['state'] !== $oldRefundState->getState() && !empty(State::STATE_TO_LOG_ACTION[$details['state']])) { (new Logger())->logApiResponse(new Log( $this->order->getChargePermissionId(), State::STATE_TO_LOG_ACTION[$details['state']], Log::RESPONSE_OK, $details['state'] === State::REFUNDED ? $this->order->getMostRecentTransactionAmount() : null )); } return $result; } }
- __construct — Sets $module member var with dependency injection.
- get — Gets a Refund