クラス
API
Amazon Pay V1 API methods for backwards compatibility
ソース ソース
ファイル: src/V1/API.php
class API { /** * AmazonPay module object * * @var AmazonPay */ private $module; /** * Sets `$module` member var with dependency injection. * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param AmazonPay $module * @return void */ public function __construct(AmazonPay $module) { $this->module = $module; } /** * Captures and closes an ORO * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param string $authid * @param string $orderid * @return array */ 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; } /** * Cancels an ORO * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param int $orderid * @return array */ public function cancelOrder($orderid) { $client = $this->module->getAmazonV1Client(); $return_obj = []; $return_obj['method'] = 'cancel'; $request_parameters = []; $request_parameters['amazon_order_reference_id'] = $orderid; $res = $client->cancelOrderReference($request_parameters); $res_json = json_decode($res->toJson()); if ($client->success) { $return_obj['status'] = 'success'; $return_obj['message'] = __('Amazon order cancellation successful.', 'wcexaap'); } elseif ($res_json->Error) { $return_obj['status'] = 'error'; $return_obj['code'] = $res_json->Error->Code; $return_obj['message'] = $res_json->Error->Message . __('Either this order has already been canceled, or payments have already been captured, thus completing the order.', 'wcexaap'); } return $return_obj; } }
- __construct — Sets $module member var with dependency injection.
- cancelOrder — Cancels an ORO
- capturePayments — Captures and closes an ORO