3

我正在为 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 吗?

4

0 回答 0