How to create a callback URL in WooCommerce

I was working on a payment gateway for WooCommerce and had to create a special URL that will then load the specified class method. Sometimes the information does not reach all parties e.g. if you close the browser and the status of the payment between the payment’s and merchant’s server remains unclear. The WooCommerce API allows you to create a callback URL.

Creating a callback URL

Calling a callback URL

Before WooCommerce 2.0, you could use:

Home

In WoCommerce 2.0+:
http://yoursite.com/wc-api/wc_gateway_my_gateway/

Join the Conversation

7 Comments

  1. How to get the $order->get_total() in callback url. I am exactly looking for this solution i am getting response in javascript event i need to process the payment through ajax. Please help me out. how to get the $order_id in call back url

    1. Hi Gopinathan, The payment provider submits the callback url and sends you the data via HTTP POST method. Usually, by doing this $data = file_get_contents(“php://input”); You can see the order id and other info. When you have the order ID, you can do $order = new WC_Order( $order_id ); , then get $order->get_total(). Try to log the response (POST) from your payment provider in a file. However, not every payment provider includes order_id, sometimes you only get the transaction ID and you need to do an extra call to their API to get the order id and other info. Hope this helps, good luck!

  2. I am getting transaction id in javascript event and need to process the payment through call back handler via jquery ajax.

  3. Hi dominykas, I try your tutorial, but when i hit callback url, it show shop page not firing my function, can you help? thx.

Leave a comment

Your email address will not be published. Required fields are marked *