У меня проблема с продлением подписки с помощью пользовательского платежного шлюза в Woocommerce - PullRequest
0 голосов
/ 18 июня 2019

Я настроил собственный платежный шлюз для работы с подписками. Я поместил весь необходимый код для генерации платежей за продление, и обновление происходит, но время для каждого обновления меняется. Это продление подписки на один день. Можете ли вы помочь мне узнать, почему меняется время оплаты продления?

class WC_Everypay_Gateway extends WC_Payment_Gateway
    {
        /**
         * The Public key
         *
         * @var type String
         */
        private $everypayPublicKey;
        /**
         * The secret key
         *
         * @var type String
         */
        private $everypaySecretKey;
        public function __construct()
        {
            $this->id = 'everypay';
            $this->icon = apply_filters('woocommerce_everypay_icon', plugins_url('images/pay-via-everypay.png', __FILE__));
            $this->has_fields = true;
            $this->method_title = pll__('Everypay Cards Settings');;
            $this->init_form_fields();
            $this->init_settings();
            $this->supports = array(
                'products', 
                'refunds', 
                'subscriptions', 
                'subscription_cancellation',
                'subscription_suspension',
                'subscription_reactivation',
                'subscription_amount_changes',
                'subscription_date_changes',
                'subscription_payment_method_change',
                'tokenization',
                );
            $this->nag_name = 'everypay_nag_notice_' . date('W');
            $this->title = pll__($this->get_option('everypay_title'));
            $this->description = pll__($this->get_option('description'));;
            $this->everypayPublicKey = $this->get_option('everypayPublicKey');
            $this->everypaySecretKey = $this->get_option('everypaySecretKey');
            $this->everypayMaxInstallments = $this->get_option('everypay_maximum_installments');
            //$this->everypay_storecurrency = $this->get_option('everypay_storecurrency');
            $this->everypay_sandbox = $this->get_option('everypay_sandbox');
            $this->errors = array();
            $this->fee = 0;
            if (!defined("EVERYPAY_SANDBOX")) {
                define("EVERYPAY_SANDBOX", ($this->everypay_sandbox == 'yes' ? true : false));
            }
            if (EVERYPAY_SANDBOX) {
                Everypay::setTestMode();
            }
            // The hooks
            add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
            add_filter('woocommerce_available_payment_gateways', array($this, 'everypay_payment_gateway_disable'));
            add_filter('woocommerce_payment_gateways', array($this, 'add_everypay_gateway_class'));
            add_filter('query_vars', array($this, 'add_everypay_var'));
            add_action('wp_enqueue_scripts', array($this, 'add_everypay_js'));
            //add_action('woocommerce_cart_calculate_fees', array($this, 'calculate_order_totals'));
            add_action('admin_init', array($this, 'nag_everypay'));
            add_action('admin_notices', array($this, 'show_everypay_notices'));
            add_action('admin_enqueue_scripts', array($this, 'load_everypay_admin'));
            if (is_admin()) {
                add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
            }
        }

public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) {
            $user     = new WP_User( $renewal_order->get_user_id() );
            $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $renewal_order->id : $renewal_order->get_id();
            $_subscription_renewal_done = get_post_meta($order_id, '_subscription_renewal_done', true);

            if ( $_subscription_renewal_done == "yes" ) {
                return;
            }
            $customer_token = get_user_meta( $renewal_order->get_user_id(), 'crd_token', true );

            $data = array(
                'description'  => 'Renewal Payment',
                'amount' => $this->format_the_amount($amount_to_charge),
                'token' => $customer_token,
            );
            Everypay::setApiKey($this->everypaySecretKey);
            $response = Everypay::addPayment($data);

            //update_post_meta($subscription->get_id(), '_cst_recent_renewal', date());
            if (isset($response['body']['error'])) {
                $error = $response['body']['error']['message'];
                $trimmed = trim($this->get_option('everypay_error_message'));
                if (!empty($trimmed)) {
                    $error = $this->get_option('everypay_error_message');
                }
                $renewal_order->update_status( 'failed', 'Everypay Subscription renewal transaction failed ('.$error.')' );
            } else {
                $renewal_order->update_status( 'processing', 'Everypay Subscription renewal transaction submitted' );
            }
            update_post_meta($order_id, '_subscription_renewal_done', 'yes');
        }

Обновление происходит, я также проверил обновление, запустив хуки обновления расписаний. Но время оплаты автоматического продления меняется каждый день.

...