I’m writing extenstion for the WooCommerce plugin and I got one problem with multiple payments.
I want to use PayPal and I think the best way to do that is implement PayPal Adaptive payments. I’ve read PayPal’s and WooCommerce’s documentation but I can’t figure it out.
I got defined new Payment Gateway, as documentations said:
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 ) {
}
}
But according to default PayPal payment which is implemented in WooCommerce it’s really messed up.
I know that:
– I must call API for PayKey
– I must use cURL
I don’t know how to redirect user to PayPal’s payment page and even how to get this PayKey within WooCommerce Gateway API. I used some snippets I found on SO but they didn’t work at all.
I will appreciate any help.
Thanks!
EDIT:
Right now I noticed that i can make redirection from WordPress to custom URL in process_payment method! But still I don’t know how to implement IPN. When I receive PayKey I can just redirect to url with it?