クラス
OrderEdit
Model for order_edit page operations.
ソース ソース
ファイル: src/Admin/OrderEdit.php
class OrderEdit extends OrderEditDI { /** * AmazonPay module object * * @var AmazonPay */ protected $module; /** * Error message for when an error occurs after executing an Amazon Pay * settlement operation by changing the 対応状況 * * @var null|string */ private $orderUpdateErrorMessage = null; /** * Loads assets and registers hooks for order edit page * * @author Evan D Shaw <evandanielshaw@gmail.com> * @return OrderEdit */ public function init() { add_filter('usces_filter_settle_info_field_meta_keys', [$this, 'filterSettlementInfoTableMetaKeys'], 10, 1); add_filter('usces_filter_settle_info_field_keys', [$this, 'filterSettlementInfoTableKeys'], 10, 1); $enqueue = function () { // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText $currency = __(usces_crcode('return'), 'usces'); try { $order = new OrderMeta($_REQUEST['order_id']); $currency = __($order->getPaymentCurrency(), 'usces'); } catch (InvalidArgumentException $e) { // not an Amazon Pay V2 order... return; } // phpcs:enable $semantic = new Semantic(); $semantic->loadDimmerCss(); $semantic->loadLoaderCss(); $semantic->loadToastCss(); $semantic->loadTransitionCss(); $semantic->loadSegmentCss(); $semantic->loadSemanticJS(); $semantic->loadMessageCss(); $slug = 'amazon-settlement-actions'; SettlementModulesUtils::loadTransactionStatesCss(); wp_enqueue_script( $slug, WCEXAAP_PLUGIN_URL . '/dist/settlementInfo.js', [], WCEXAAP_VERSION, true ); wp_localize_script($slug, AmazonPay::L10N, array_merge( $this->module->getScriptInjectionVariables(), [ 'orderId' => $_REQUEST['order_id'], 'currency' => $currency, 'chargeStateMap' => Charge\State::$stateMap, 'refundStateMap' => Refund\State::$stateMap, ] )); wp_set_script_translations($slug, 'wcexaap', WCEXAAP_LANGDIR); }; $this->loadMyModuleAssets($enqueue); return $this; } /** * Adds 審査ステータス HTML under 対応状況 dropdown * * @author Evan D Shaw <evandanielshaw@gmail.com> * @inheritDoc * @param array $data * @param array $cscs_meta * @param array $action_args * @return void */ protected function orderEditFormStatusBlockMiddle($data, $cscs_meta, $action_args) { $orderId = (int)$action_args['order_id']; try { $order = new OrderMeta($orderId); } catch (InvalidArgumentException $e) { // not an Amazon Pay V2 order... return; } $this->displayTransactionState($order->getTransactionState()); } /** * Filter search keys for order meta query * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param array $keys * @return array */ public function filterSettlementInfoTableMetaKeys($keys) { // V1 keys $keys = !empty($keys) ? $keys : []; $keys[] = 'amazon_orderid'; $keys[] = 'amazon_authid'; // V2 keys $keys[] = OrderMeta::CHARGE_PERMISSION_ID; $keys[] = OrderMeta::CHARGE_ID; $keys[] = OrderMeta::REFUND_ID; $keys[] = OrderMeta::LINK_KEY; return $keys; } /** * Filters list of keys checked during table construction under 支払情報 section * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param array $keys * @return array */ public function filterSettlementInfoTableKeys($keys) { // V1 keys $keys = !empty($keys) ? $keys : []; $keys[] = 'amazon_orderid'; $keys[] = 'amazon_authid'; // V2 keys $keys[] = OrderMeta::CHARGE_PERMISSION_ID; $keys[] = OrderMeta::CHARGE_ID; $keys[] = OrderMeta::REFUND_ID; $keys[] = OrderMeta::LINK_KEY; return $keys; } /** * 支払情報 section of order edit page * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param mixed $data * @param mixed $action_args ['order_action', 'order_id', 'cart'] * @return void */ protected function settlementInfo($data, $action_args) { ?> <div id="<?php echo AmazonPay::VUE_APP_MOUNT_EL; ?>"></div> <?php } /** * Called on completion status * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param \stdClass $new_orderdata * @param string $old_status * @param \stdClass $old_orderdata * @return void */ protected function updateOrderDataCompletion($new_orderdata, $old_status, $old_orderdata) { (new V1OrderEdit($this->module))->updateOrderDataCompletion($new_orderdata, $old_status, $old_orderdata); $opts = $this->module->getActingOpts(); if ($opts['sync_with_order_status_changes'] !== 'on') { return; } $orderId = (int)$old_orderdata->ID; try { $order = new OrderMeta($orderId); } catch (InvalidArgumentException $e) { // not an Amazon Pay V2 order... return; } if ($order->getTransactionState()->getState() !== Charge\State::AUTHORIZED) { return; } $result = (new API\Charge\Capture($this->module, $order))->post( $order->getChargeId(), $order->getMostRecentTransactionAmount(), $order->getPaymentCurrency() ); if ($result instanceof GenericError) { $this->orderUpdateErrorMessage = $result->message; } } /** * Called on cancel status * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param \stdClass $new_orderdata * @param string $old_status * @param \stdClass $old_orderdata * @return void */ protected function updateOrderDataCancel($new_orderdata, $old_status, $old_orderdata) { (new V1OrderEdit($this->module))->updateOrderDataCancel($new_orderdata, $old_status, $old_orderdata); $opts = $this->module->getActingOpts(); if ($opts['sync_with_order_status_changes'] !== 'on') { return; } $orderId = (int)$old_orderdata->ID; try { $order = new OrderMeta($orderId); } catch (InvalidArgumentException $e) { // not an Amazon Pay V2 order... return; } if ($order->getRefundState() !== null) { return; } $cstate = $order->getChargeState()->getState(); if ($cstate !== Charge\State::AUTHORIZED && $cstate !== Charge\State::DECLINED) { return; } $result = (new API\Charge\Cancel($this->module, $order))->delete($order->getChargeId(), ''); if ($result instanceof GenericError) { $this->orderUpdateErrorMessage = $result->message; } } /** * Set action status and message after single order update * * @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; (new V1OrderEdit($this->module))->setActionStatusAndMessage($order_id, $res); if (!empty($this->orderUpdateErrorMessage)) { $usces->set_action_status( 'error', Utils::adminMessageString($order_id, 'error', $this->orderUpdateErrorMessage, false) ); } } }
- filterSettlementInfoTableKeys — Filters list of keys checked during table construction under 支払情報 section
- filterSettlementInfoTableMetaKeys — Filter search keys for order meta query
- init — Loads assets and registers hooks for order edit page
- orderEditFormStatusBlockMiddle — Adds 審査ステータス HTML under 対応状況 dropdown
- setActionStatusAndMessage — Set action status and message after single order update
- settlementInfo — 支払情報 section of order edit page
- updateOrderDataCancel — Called on cancel status
- updateOrderDataCompletion — Called on completion status