関数
Capture::post( string $chargeId, int $amount, string $currencyCode, string $softDescriptor = '' )
説明 説明
- $chargeId
(文字列) (必須) Charge ID
- $amount
(数値) (必須)
- $currencyCode
(文字列) (必須) should be the same as was set during checkout
- $softDescriptor
(文字列) (任意)
ファイル: src/API/Charge/Capture.php
public function post($chargeId, $amount, $currencyCode, $softDescriptor = '') {
$payload = [
'captureAmount' => [
'amount' => $amount,
'currencyCode' => $currencyCode,
],
];
if (!empty($softDescriptor)) {
$payload['softDescriptor'] = $softDescriptor;
}
$headers = ['x-amz-pay-Idempotency-Key' => uniqid()];
// $_ENV[SandboxSimulation::CAPTURE_CHARGE_SIMCODE] = 'CaptureInitiated';
// $_ENV[SandboxSimulation::CAPTURE_CHARGE_SIMCODE] = 'HardDeclined';
$headers = (new SandboxSimulation($this->module))->captureChargeSetSimCodeIfSandbox($headers);
try {
$client = $this->module->getAmazonClient();
$result = $client->captureCharge($chargeId, $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_CAPTURE_PAYMENTS,
$error->errorcode,
$amount,
$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->updateChargeState(
new State(
$details['state'],
$details['reasonCode'],
$details['reasonDescription']
)
);
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;
}