クラス
Get
Amazon Pay V2 SDK Get Charge.
ソース ソース
ファイル: src/API/Charge/Get.php
class Get { /** * AmazonPay module object * * @var AmazonPay */ private $module; /** * Amazon Pay order object * * @var OrderMeta|null */ private $order; /** * Sets `$module` member var with dependency injection. * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param AmazonPay $module * @param OrderMeta|null $order * @return void */ public function __construct(AmazonPay $module, OrderMeta $order = null) { $this->module = $module; $this->order = $order; } /** * Gets a Charge * * @see https://amazonpaycheckoutintegrationguide.s3.amazonaws.com/amazon-pay-api-v2/charge.html#get-charge * @author Evan D Shaw <evandanielshaw@gmail.com> * @param string $chargeId Charge ID * @return array * @throws InvalidArgumentException Thrown by `getAmazonClient`. */ public function get($chargeId) { try { $client = $this->module->getAmazonClient(); $result = $client->getCharge($chargeId); 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()] ); } if ($this->order instanceof OrderMeta) { $oldChargeState = $this->order->getChargeState(); $response = json_decode($result['response'], true); $details = $response['statusDetails']; $this->order->updateChargeState( new State( $details['state'], $details['reasonCode'], $details['reasonDescription'] ) ); if ($details['state'] !== $oldChargeState->getState()) { $amount = null; if ($details['state'] === State::CAPTURED || $details['state'] === State::AUTHORIZED) { $amount = $this->order->getMostRecentTransactionAmount(); } if (!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, $amount )); } } } return $result; } }
- __construct — Sets $module member var with dependency injection.
- get — Gets a Charge