関数
API::capturePayments( string $authid, string $orderid )
パラメータ パラメータ
- $authid
(文字列) (必須)
- $orderid
(文字列) (必須)
ファイル: src/V1/API.php
public function capturePayments($authid, $orderid) {
$client = $this->module->getAmazonV1Client();
$return_obj = [];
$return_obj['method'] = 'capture';
if (!$authid) {
$return_obj['status'] = 'error';
$return_obj['code'] = __('Authorization ID Does Not Exist', 'wcexaap');
$return_obj['message'] = __('The Authorization ID used to confirm the order amount did not match any existing Amazon orders.', 'wcexaap');
return $return_obj;
}
$request_parameters = [];
$request_parameters['amazon_authorization_id'] = $authid;
$auth_details_res = $client->getAuthorizationDetails($request_parameters);
if ($client->success) {
$auth_details = json_decode($auth_details_res->toJson());
$total_amount = $auth_details->GetAuthorizationDetailsResult->AuthorizationDetails->AuthorizationAmount->Amount;
$request_parameters = [];
$request_parameters['amazon_authorization_id'] = $authid;
$request_parameters['capture_reference_id'] = uniqid();
$request_parameters['capture_amount'] = $total_amount;
$capture_res = $client->capture($request_parameters);
$capture_res_json = json_decode($capture_res->toJson());
if ($client->success) {
$request_parameters = [];
$request_parameters['amazon_order_reference_id'] = $orderid;
$request_parameters['closure_reason'] = __('Item(s) shipped. Funds captured.', 'wcexaap');
$close_res = $client->closeOrderReference($request_parameters);
$return_obj['status'] = 'success';
$return_obj['message'] = __('Payments were successfully captured.', 'wcexaap');
} else {
if ($capture_res_json->Error) {
$return_obj['status'] = 'error';
$code = $capture_res_json->Error->Code;
$return_obj['code'] = $code;
if ($code === 'InvalidAuthorizationStatus') {
$return_obj['message'] = $capture_res_json->Error->Message . __('Either this order has already been canceled, or payments have already been captured, thus completing the order.', 'wcexaap');
} else {
$return_obj['message'] = __('An unknown error occured while capturing payments for this order. Either the Authorization ID is incorrect or the order is too old.', 'wcexaap');
}
}
}
} else {
$return_obj['status'] = 'error';
$return_obj['code'] = 'GetAuthorizationDetails Error';
$return_obj['message'] = __('Failed getting Auth details. The Authorization ID used to confirm the order amount did not match any existing Amazon orders.', 'wcexaap');
}
return $return_obj;
}