関数
Create::post( string $chargeId, int $refundAmount, string $currencyCode, string $softDescriptor = '' )
Creates a Refund
説明 説明
- $chargeId
(文字列) (必須) Charge ID
- $refundAmount
(数値) (必須)
- $currencyCode
(文字列) (必須)
- $softDescriptor
(文字列) (任意) Default: ''
ファイル: src/API/Refund/Create.php
public function post( $chargeId, $refundAmount, $currencyCode, $softDescriptor = '' ) { $payload = [ 'chargeId' => $chargeId, 'refundAmount' => [ 'amount' => $refundAmount, 'currencyCode' => $currencyCode, ], ]; if (!empty($softDescriptor)) { $payload['softDescriptor'] = $softDescriptor; } $headers = ['x-amz-pay-Idempotency-Key' => uniqid()]; // $_ENV[SandboxSimulation::CREATE_REFUND_SIMCODE] = 'AmazonRejected'; $headers = (new SandboxSimulation($this->module))->createRefundSetSimCodeIfSandbox($headers); try { $client = $this->module->getAmazonClient(); $result = $client->createRefund($payload, $headers); if ($this->module->errors->hasError($result)) { $error = $this->module->errors->getAmzErrorResponse($result, $this); (new Logger())->logApiResponse(new Log( $this->order->getChargePermissionId(), Log::ACTION_ASYNC_REFUND, $error->errorcode, $refundAmount, $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->setRefundState( new State( $details['state'], $details['reasonCode'], $details['reasonDescription'] ), $response['refundId'], $refundAmount ); (new Logger())->logApiResponse(new Log( $this->order->getChargePermissionId(), Log::ACTION_ASYNC_REFUND, Log::RESPONSE_OK, $refundAmount )); return $result; }