首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义WooCommerce网关

自定义WooCommerce网关
EN

Stack Overflow用户
提问于 2015-05-09 16:13:14
回答 1查看 829关注 0票数 1

我正试图为WooCommerce插件开发一个自定义支付网关,但我在结帐页面上遇到了问题。我想要的是在签出最后一步页面上插入一个表单,在5秒后自动提交。

我的代码是:

代码语言:javascript
复制
        ...
    add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page'));
    add_action('woocommerce_api_wc_' . $this->id, array($this, 'handle_callback'));
}

function handle_callback() {
    wp_die('handle_callback');
}

function receipt_page( $order ) 
{   
    echo "receipt page";
    $this->generate_submit_form_elements( $order );
}

问题是"receipt_page“操作没有被触发。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-15 10:49:18

哦,这是因为您忘了将has_fields标志设置为true。

代码语言:javascript
复制
//after setting the id and method_title, set the has_fields to true
          $this -> id = 'kiwipay';
          $this -> method_title = 'KiwiPay';

          $this->has_fields = true; // if you want credit card payment fields to show on the users checkout page

然后在process_payment函数中放置如下:

代码语言:javascript
复制
// Payload would look something like this.
$payload = array(
"amount" => $order.get_total(), 
"reference" => $order->get_order_number(),
"orderid" => $order->id,
"return_url" => $this->get_return_url($order)  //return to thank you page.
);

response = wp_remote_post( $environment_url, array(
                'method'    => 'POST',
                'body'      => http_build_query( $payload ),
                'timeout'   => 90,
                'sslverify' => false,
            ) );

// Retrieve the body's response if no errors found
$response_body = wp_remote_retrieve_body( $response );
$response_headers = wp_remote_retrieve_headers( $response );

//use this if you need to redirect the user to the payment page of the bank.
$querystring = http_build_query( $payload );

return array(
            'result'   => 'success',
            'redirect' => $environment_url . '?' . $querystring,
        );
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30142241

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档