我正在为WooCommerce插件编写扩展程序,我遇到了多次付款的问题。 我想使用PayPal,我认为最好的方法是实施PayPal自适应支付。我已经阅读了PayPal和WooCommerce的文档,但我无法理解。
我已经定义了新的支付网关,正如文件所述: http://docs.woothemes.com/document/payment-gateway-api/
class WC_Gateway_Adaptive_PayPal extends WC_Payment_Gateway {
public $environment = 'sandbox';
public function __construct() {
$this->notify_url = str_replace( 'https:', 'http:', add_query_arg( 'wc-api', 'WC_Gateway_Adaptive_Paypal', home_url( '/' ) ) );
$this->id = 'adaptive_paypal';
$this->has_fields = false;
$this->method_title = 'PayPal';
$this->method_description = 'Handle payment with many receivers (up to 5)';
$this->init_form_fields();
$this->init_settings();
$this->title = $this->get_option( 'title' );
add_action( 'woocommerce_update_options_payment_gateways_'.$this->id, array( $this, 'process_admin_options' ) );
}
public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'wpgmpc' ),
'type' => 'checkbox',
'label' => __( 'Enable Adaptive PayPal Payment', 'wpgmpc' ),
'default' => 'yes'
),
'title' => array(
'title' => __( 'Title', 'wpgmpc' ),
'type' => 'text',
'description' => __( 'This controls the title which the user sees during checkout.', 'wpgmpc' ),
'default' => __( 'PayPal', 'wpgmpc' ),
'desc_tip' => true,
),
'description' => array(
'title' => __( 'Customer Message', 'wpgmpc' ),
'type' => 'textarea',
'default' => ''
),
'percentage' => array(
'title' => __( 'Fee', 'wpgmpc' ),
'type' => 'number',
'description' => __( 'Decide how much you want to take from each payment in %', 'wpgmpc' ),
'desc_tip' => true,
'default' => '0'
),
'receiver_email' => array(
'title' => __( 'Receiver Email', 'woocommerce' ),
'type' => 'email',
'description' => __( 'If this differs from the email entered above, input your main receiver email for your PayPal account. This is used to validate IPN requests.', 'woocommerce' ),
'default' => '',
'desc_tip' => true,
'placeholder' => 'you@youremail.com'
),
);
}
public function process_payment( $order_id ) {
}
}
但根据在WooCommerce中实施的默认PayPal付款,它真的搞砸了。
我知道: - 我必须为PayKey调用API - 我必须使用cURL
我不知道如何将用户重定向到PayPal的付款页面,甚至不知道如何在WooCommerce Gateway API中获取此PayKey。我使用了一些我在SO上找到的片段,但它们根本不起作用。
我将不胜感激任何帮助。 谢谢!
编辑: 现在我注意到我可以在process_payment方法中从WordPress重定向到自定义URL!但我仍然不知道如何实施IPN。当我收到PayKey时,我可以用它重定向到url?