WC_Gateway_Paypal::process_payment
Process the payment and return the result.
Method of the class: WC_Gateway_Paypal{}
No Hooks.
Returns
Array.
Usage
$WC_Gateway_Paypal = new WC_Gateway_Paypal(); $WC_Gateway_Paypal->process_payment( $order_id );
- $order_id(int) (required)
- Order ID.
WC_Gateway_Paypal::process_payment() WC Gateway Paypal::process payment code WC 10.7.0
public function process_payment( $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order || ! $order instanceof WC_Order ) {
return array();
}
if ( $this->should_use_orders_v2() ) {
$paypal_request = new PayPalRequest( $this );
$paypal_order = $paypal_request->create_paypal_order( $order );
if ( ! $paypal_order || empty( $paypal_order['id'] ) || empty( $paypal_order['redirect_url'] ) ) {
throw new Exception(
esc_html__( 'We are unable to process your PayPal payment at this time. Please try again or use a different payment method.', 'woocommerce' )
);
}
$redirect_url = $paypal_order['redirect_url'];
} else {
include_once __DIR__ . '/includes/class-wc-gateway-paypal-request.php';
$paypal_request = new WC_Gateway_Paypal_Request( $this );
$redirect_url = $paypal_request->get_request_url( $order, $this->testmode );
}
return array(
'result' => 'success',
'redirect' => $redirect_url,
);
}