我已经自定义了一个自定义支付网关,以用于订阅。 我已经输入了所有必需的代码来生成续订付款,并且续订正在进行中,但是每次续订的时间都在改变。这是“每天”续订。您能帮我知道为什么续订付款时间被更改了吗?
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');
}
续订正在进行中,我还通过运行“计划续订”挂钩测试了续订。但是自动续订付款时间每天都在变化。