クラス
OrderEdit
Amazon Pay V1 order edit page operations
ソース ソース
ファイル: src/V1/OrderEdit.php
class OrderEdit { /** * AmazonPay module object * * @var AmazonPay */ protected $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; } /** * Updates ORO (Amazon Order Reference Object) based on selected order status. * => 発送済み = calls capture * * @author Evan D Shaw <evandanielshaw@gmail.com> * @global \use_e_shop $usces * @param \stdClass $new_orderdata * @param string $old_status * @param \stdClass $old_orderdata * @return void */ public function updateOrderDataCompletion($new_orderdata, $old_status, $old_orderdata) { global $usces; $amazon_order_state = $usces->get_order_meta_value('amazon_order_state', $old_orderdata->ID); if (!empty($amazon_order_state)) { $amazon_authid = $usces->get_order_meta_value('amazon_authid', $old_orderdata->ID); $amazon_orderid = $usces->get_order_meta_value('amazon_orderid', $old_orderdata->ID); $res = []; if ($amazon_order_state === 'captured') { $res['message'] = __('I completed collective operation.', 'usces'); $res['method'] = 'capture'; $res['status'] = 'success'; } elseif ($amazon_order_state === 'canceled') { $res = Utils::adminErrorResponse('capture', $amazon_order_state); $res['message'] = Utils::adminMessageString( $old_orderdata->ID, $res['status'], $res['message'], true ); } else { $api = new API($this->module); $res = $api->capturePayments($amazon_authid, $amazon_orderid); $res['message'] = Utils::adminMessageString( $old_orderdata->ID, $res['status'], $res['message'], true ); } $_SESSION['amazon_admin_msg'] = $res; } } /** * Updates ORO (Amazon Order Reference Object) based on selected order status. * * => キャンセル = calls cancel * * @author Evan D Shaw <evandanielshaw@gmail.com> * @global \use_e_shop $usces * @param \stdClass $new_orderdata * @param string $old_status * @param \stdClass $old_orderdata * @return void */ public function updateOrderDataCancel($new_orderdata, $old_status, $old_orderdata) { global $usces; $amazon_order_state = $usces->get_order_meta_value('amazon_order_state', $old_orderdata->ID); if (!empty($amazon_order_state)) { $amazon_orderid = $usces->get_order_meta_value('amazon_orderid', $old_orderdata->ID); $res = []; if ($amazon_order_state === 'canceled') { $res['message'] = __('I completed collective operation.', 'usces'); $res['method'] = 'cancel'; $res['status'] = 'success'; } elseif ($amazon_order_state === 'captured') { $res = Utils::adminErrorResponse('cancel', $amazon_order_state); $res['message'] = Utils::adminMessageString( $old_orderdata->ID, $res['status'], $res['message'], true ); } else { $api = new API($this->module); $res = $api->cancelOrder($amazon_orderid); $res['message'] = Utils::adminMessageString( $old_orderdata->ID, $res['status'], $res['message'], true ); } $_SESSION['amazon_admin_msg'] = $res; } } /** * Sets action status and updates amazon_order_state meta value which is checked against * to avoid unnecessary Amazon API calls. * * @author Evan D Shaw <evandanielshaw@gmail.com> * @global \usc_e_shop $usces * @param int $order_id * @param array $res * @return void */ public function setActionStatusAndMessage($order_id, $res) { global $usces; if (isset($_SESSION['amazon_admin_msg'])) { $res = $_SESSION['amazon_admin_msg']; unset($_SESSION['amazon_admin_msg']); switch ($res['method']) { case 'capture': $usces->set_action_status($res['status'], $res['message']); if (!($res['status'] === 'error')) { ModuleUtils::updateOrderReceipt($order_id, 'receipted'); usces_action_acting_getpoint($order_id); $usces->set_order_meta_value('amazon_order_state', 'captured', $order_id); } break; case 'cancel': $usces->set_action_status($res['status'], $res['message']); if (!($res['status'] === 'error')) { ModuleUtils::updateOrderReceipt($order_id, 'noreceipt'); $usces->set_order_meta_value('amazon_order_state', 'canceled', $order_id); } break; } } } }
- __construct — Sets $module member var with dependency injection.
- setActionStatusAndMessage — Sets action status and updates amazon_order_state meta value which is checked against to avoid unnecessary Amazon API calls.
- updateOrderDataCancel — Updates ORO (Amazon Order Reference Object) based on selected order status.
- updateOrderDataCompletion — Updates ORO (Amazon Order Reference Object) based on selected order status.