関数
Create::post( string $chargePermissionId, int $chargeAmount, string $currencyCode, bool $captureNow = false, bool $canHandlePendingAuthorization = false, string $softDescriptor = '' )
Creates a Charge
説明 説明
- $chargePermissionId
(文字列) (必須) Charge Permission ID
- $chargeAmount
(数値) (必須)
- $currencyCode
(文字列) (必須)
- $captureNow
(bool) (任意) Default:
false
- $canHandlePendingAuthorization
(bool) (任意) Default:
false
- $softDescriptor
(文字列) (任意) Default: ''
ファイル: src/API/Charge/Create.php
public function post( $chargePermissionId, $chargeAmount, $currencyCode, $captureNow = false, $canHandlePendingAuthorization = false, $softDescriptor = '' ) { $payload = [ 'chargePermissionId' => $chargePermissionId, 'captureAmount' => [ 'amount' => $chargeAmount, 'currencyCode' => $currencyCode, ], 'captureNow' => $captureNow, 'canHandlePendingAuthorization' => $canHandlePendingAuthorization, ]; if (!empty($softDescriptor)) { $payload['softDescriptor'] = $softDescriptor; } $headers = ['x-amz-pay-Idempotency-Key' => uniqid()]; $headers = (new SandboxSimulation($this->module))->createChargeSetSimCodeIfSandbox($headers); $actionType = Log::ACTION_AUTHORIZE; if ($captureNow === true) { $actionType = Log::ACTION_AUTHORIZE_AND_CAPTURE; } try { $client = $this->module->getAmazonClient(); $result = $client->createCharge($payload, $headers); if ($this->module->errors->hasError($result)) { $error = $this->module->errors->getAmzErrorResponse($result, $this); (new Logger())->logApiResponse(new Log( $this->order->getChargePermissionId(), $actionType, $error->errorcode, $chargeAmount, $error )); return $error; } } catch (\Exception $e) { return $this->module->errors->getErrorResponse( GenericErrorStore::AMAZON_PAY_SDK_CLIENT_EXCEPTION, [$e->getMessage()] ); } $response = json_decode($result['response'], true); $details = $response['statusDetails']; $this->order->setChargeState( new State( $details['state'], $details['reasonCode'], $details['reasonDescription'] ), $response['chargeId'], $chargeAmount ); (new Logger())->logApiResponse(new Log( $this->order->getChargePermissionId(), $actionType, Log::RESPONSE_OK, $chargeAmount )); return $result; }