• プラグイン一覧
    - WCEX Item Combo Set
    - WCEX Amazon Pay
    - WCEX Wishlist お気に入りリスト
  • リリース情報
  • お役立ちコラム
  • お問い合わせ
  • サポート
    • よくある質問
      • WCEX Amazon Pay
      • WCEX Wishlist お気に入りリスト
      • wcex-item-combo-set
    • リファレンス
      • WCEX Amazon Pay
      • WCEX Wishlist お気に入りリスト
      • wcex-item-combo-set
新規会員登録
ログイン
新規会員登録
ログイン
カート
  • プラグイン一覧
    • - WCEX Item Combo Set
    • - WCEX Amazon Pay
    • - WCEX Wishlist お気に入りリスト
  • リリース情報
  • お役立ちコラム
  • サポート
    • - よくある質問
      • - WCEX Amazon Pay
      • - WCEX Wishlist お気に入りリスト
      • - wcex-item-combo-set
    • - リファレンス
      • - WCEX Amazon Pay
      • - WCEX Wishlist お気に入りリスト
      • - wcex-item-combo-set
  • お問い合わせ
Aivec APPs > WCEX Amazon Pay > クラス > PollingCron
レファレンス
バージョン
2.6.4
絞り込み:

目次

  • ソース
  • 関数

フック

  • アクション
  • フィルター

ファンクション

    クラス

    PollingCron

    Cron job for polling Amazon Pay APIs as a fallback in case IPNs don’t work

    ソース #ソース

    ファイル: src/Admin/PollingCron.php

    class PollingCron
    {
    
        /**
         * Cron event name
         */
        const EVENT_NAME = 'AmazonPayPolling';
    
        /**
         * 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;
        }
    
        /**
         * Clear cron event
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @return void
         */
        public function clearEvent() {
            wp_clear_scheduled_hook(self::EVENT_NAME);
        }
    
        /**
         * Schedules polling cron if not already scheduled
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @return bool
         */
        public function scheduleEvent() {
            add_action(self::EVENT_NAME, [$this, 'updateAllOrders']);
            $cron = wp_next_scheduled(self::EVENT_NAME);
            if ($cron) {
                return false;
            }
    
            $unixts = (new DateTime('now', new DateTimeZone('UTC')))->getTimestamp();
    
            return wp_schedule_event($unixts, 'hourly', self::EVENT_NAME);
        }
    
        /**
         * Loops through all Amazon Pay orders and updates transaction states accordingly
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @return void
         * @throws InvalidArgumentException Thrown by `OrderMeta` constructor if order doesn't exist.
         */
        public function updateAllOrders() {
            $orderIds = $this->getAllAmazonPayOrders();
            foreach ($orderIds as $oa) {
                $orderId = (int)$oa['order_id'];
                $ometa = new Models\OrderMeta($orderId);
                // order state is updated automatically by these API calls
                if ($ometa->getChargeId() !== null) {
                    $chargeState = $ometa->getChargeState();
                    if (!$chargeState->isCanceled() && !$chargeState->isCaptured()) {
                        (new API\Charge\Get($this->module, $ometa))->get($ometa->getChargeId());
                    }
                }
                if ($ometa->getRefundId() !== null) {
                    (new API\Refund\Get($this->module, $ometa))->get($ometa->getRefundId());
                }
            }
        }
    
        /**
         * Returns all order IDs associated with an Amazon Pay order
         *
         * @author Evan D Shaw <evandanielshaw@gmail.com>
         * @global \wpdb $wpdb
         * @return array
         */
        public function getAllAmazonPayOrders() {
            global $wpdb;
    
            $order_meta_table_name = $wpdb->prefix . 'usces_order_meta';
            $query = $wpdb->prepare(
                "SELECT order_id
                FROM {$order_meta_table_name}
                WHERE meta_key = %s
                ORDER BY order_id ASC",
                Models\OrderMeta::CHARGE_PERMISSION_ID
            );
            $orderIds = $wpdb->get_results($query, ARRAY_A);
            if (empty($orderIds)) {
                return [];
            }
    
            return $orderIds;
        }
    }
    

    ソースを伸ばす ソースを縮める


    関数 #関数

    Top ↑

    • __construct — Sets `$module` member var with dependency injection.
    • clearEvent — Clear cron event
    • getAllAmazonPayOrders — Returns all order IDs associated with an Amazon Pay order
    • scheduleEvent — Schedules polling cron if not already scheduled
    • updateAllOrders — Loops through all Amazon Pay orders and updates transaction states accordingly

    • 新規会員登録
    • ログイン
      • プラグイン一覧
      • 会社概要
      • リリース情報
      • よくある質問
      • お役立ちコラム
      • お問い合わせ
      • 個人情報保護方針
      • 特定商取引法に基づく表記
      • 情報セキュリティ基本方針
      • 利用規約

    アイベック合同会社は「Welcart」「Amazon Pay」の公式パートナーです。

    ※Amazon、Amazon.co.jp、Amazon Payおよびそれらのロゴは、Amazon.com,inc.またはその関連会社の商標です。
    ※LINE Pay、およびLINE Pay 提携サービスのロゴは、法律上保護を受ける商標です。

    © 2025 Aivec llc All Rights Reserved.