首页 文章

Woocommerce支付网关初始化

提问于
浏览
1

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

这是我的网址,我需要处理 the payment using woocommerce payment gateway .

如果调用此网址,我想初始化付款 .

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);

?>

运行此代码,我得到一个空白的白色屏幕 . 该页面未重定向到条带网站 .

Note: 我用商店页面测试了配置,并且工作正常 . 它重定向我的条纹页面 .

1 回答

  • 0

    以下是我的最终代码 . 一旦调用了process_payment,它将为您提供一个URL,我们需要使用javascript location.href将客户重定向到该URL .

    // 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));
    

    该重定向网址将导致用户将授权付款的条带页面 .

相关问题