1
votes

http://mywebsiteurl/process-payment/?order-id=138

This is my url where i need to process the payment using woocommerce payment gateway.

I want to initialize the payment if this url is called.

Below is my full code:

<?php

$orderId = $_GET['order-id'];

// // Process Payment
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();

var_dump($available_gateways['stripe_ideal']); //not null i am getting some texts printed on the screen.

$available_gateways['stripe_ideal']->process_payment($orderId);

?>

Running this code, I'm getting a blank white screen. The page isn't redirecting to stripe website.

Note: I tested the configuration with shop page and its working fine. Its redirecting me stripe page.

1
did you got the solution? - Abhishek Singh
@AbhishekSingh please check my answer - Alaksandar Jesus Gene

1 Answers

0
votes

Below is my final code. Once the process_payment is called, it will give you an URL to which we need to redirect the customer to that url, using javascript location.href.

// Store Order ID in session so it can be re-used after payment failure
        WC()->session->order_awaiting_payment = $order->id;
        $redirect = '';
        $available_gateways = WC()->payment_gateways->get_available_payment_gateways();

        $result = $available_gateways['stripe_ideal']->process_payment($order->id);



        if ($result['result'] == 'success') {
            $result = apply_filters('woocommerce_payment_successful_result', $result, $order->id);
            $redirect = $result['redirect'];
        }

        wp_send_json(array("success" => true, "redirect" => $redirect, 
        "order_id"=>$order->id));

That redirect url will lead to stripe page where the user will authorize the payment.