関数
Create::post()
説明 説明
ファイル: src/API/CheckoutSession/Create.php
public function post() {
$opts = $this->module->getActingOpts();
$payload = [
'webCheckoutDetails' => [
'checkoutReviewReturnUrl' => $this->checkoutReviewUrl,
],
'platformId' => Constants::PLATFORM_ID,
'storeId' => $opts['client_id'],
];
$headers = ['x-amz-pay-Idempotency-Key' => uniqid()];
try {
$client = $this->module->getAmazonClient();
// call `generateButtonSignature` so that an error is thrown if the merchant's
// public/private key pair is not correct
$client->generateButtonSignature($payload);
$result = $client->createCheckoutSession($payload, $headers);
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()]
);
}
return json_decode($result['response'], true)['checkoutSessionId'];
}