Title: woocommerce_rest_cannot_create_order_refund
Last modified: July 31, 2023

---

# woocommerce_rest_cannot_create_order_refund

 *  Resolved [Vaibhav](https://wordpress.org/support/users/vaibhav9017/)
 * (@vaibhav9017)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/woocommerce_rest_cannot_create_order_refund/)
 * Hello All,
 * I am new to woocommerce API development. I am observing specific issue. I have
   created an order using REST API at Woocommerce and when trying to apply refund
   on same order using API, I am getting an error of “‘woocommerce_rest_cannot_create_order_refund’
   data: 500 message:’The payment gateway for this order does not support automatic
   refunds.’ “. However, on same worder if I manually apply for refund; I am getting
   success in it.
 * Also, If I create order not using API, and on that I am able to apply refund 
   using Refund API. I dont know the reason. Can any one help on same?
 * Woocommerce Version is 7.8.0 and Word press version is – 6.2.2
    1. I want to create an order and apply refund on it.
    2. Also, If product price is 100 then wanted to create partial order using partial
       payment and then process full payment on same order.
 * Please guide me on above two cases as well.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Support [Shameem – a11n](https://wordpress.org/support/users/shameemreza/)
 * (@shameemreza)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/woocommerce_rest_cannot_create_order_refund/#post-16950185)
 * Hi [@vaibhav9017](https://wordpress.org/support/users/vaibhav9017/)
 * From your provided information, I understand that you’re encountering a problem
   when trying to automatically refund an order created via the REST API. The error
   message you’re seeing typically indicates that the payment gateway used for the
   order does not support automatic refunds.
 * However, it’s interesting that you’re able to manually refund the same order 
   and also successfully apply refunds using the Refund API on orders not created
   via the REST API. This suggests that the issue might be related to how the order
   is created via the REST API.
 * I’d recommend checking the payment method used when creating the order via the
   API. Ensure that it’s a method that supports automatic refunds. Some gateways
   don’t support this feature, which could be causing the error.
 * Regarding the two cases you mentioned:
    1. To create an order and apply a refund on it, you should first create the order
       using the [Create an Order endpoint](https://woocommerce.github.io/woocommerce-rest-api-docs/#orders)(/
       wp-json/wc/v3/orders). After the order is created, you can then use the [Create a Refund endpoint](https://woocommerce.github.io/woocommerce-rest-api-docs/#create-a-refund)(/
       wp-json/wc/v3/orders/<id>/refunds) to apply a refund to the order.
    2. To create a partial order using partial payment, you would need to create the
       order with a status of ‘pending’ or ‘on-hold’. Once the full payment is ready
       to be processed, you can then update the order status to ‘processing’ or ‘completed’,
       depending on your workflow. This can be done using the Update an Order endpoint(/
       wp-json/wc/v3/orders/).
 * Further information on WooCommerce REST API can be found here: [https://woocommerce.github.io/woocommerce-rest-api-docs/#introduction](https://woocommerce.github.io/woocommerce-rest-api-docs/#introduction)
 * I hope the above information helps! If you have any further questions or need
   additional clarification, please don’t hesitate to ask.
 * Thanks!
 *  Thread Starter [Vaibhav](https://wordpress.org/support/users/vaibhav9017/)
 * (@vaibhav9017)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/woocommerce_rest_cannot_create_order_refund/#post-16950446)
 * Hello [Shameem (woo-hc)](https://wordpress.org/support/users/shameemreza/);
 * Thank you for your valuable inputs. I am using same order API of which url you
   shared, still causing an issue of refund on same order. Will look more in details
   and post if found anything. Below is sample code of order creation, please have
   a look and suggest if have any thing suspected in it.
 *     ```wp-block-code
       const orderData = {
   
                   payment_method: 'bacs', // Payment method
   
                   payment_method_title: 'Direct Bank Transfer', // Payment method title
   
                   set_paid: true, // Set to true to mark the order as paid
   
                   billing: {
   
                     first_name: 'Vaibhav',
   
                     last_name: 'Bhutkar',
   
                     address_1: '123 Main Street',
   
                     city: 'Pune',
   
                     state: 'Maharashtra',
   
                     postcode: '411028',
   
                     country: 'India',
   
                     email: '',
   
                     phone: '123-456-7890',
   
                   },
   
                   shipping: {
   
                     first_name: 'Vaibhav',
   
                     last_name: 'Bhutkar',
   
                     address_1: '456 Shipping Street',
   
                     city: 'Pune',
   
                     state: 'Maharashtra',
   
                     postcode: '411028',
   
                     country: 'India',
   
                   },
   
                   line_items: [
   
                     {
   
                       product_id: 78011, // Replace with the actual product ID
   
                       quantity: 1,
   
                     },
   
                     // Add more line items as needed
   
                   ],
   
                 };
   
                 const response = await WooCommerce.post("orders", orderData);          
   
                 if(response){
   
                   res.status(200).json(response.data);
   
                   //return response.data;
   
                 }
       ```
   
 * Able to place order successfully, however if aply reund on same getting the above
   error.
 * Thank you,
 * Vaibhav Bhutkar
 *  Plugin Support [Shameem – a11n](https://wordpress.org/support/users/shameemreza/)
 * (@shameemreza)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/woocommerce_rest_cannot_create_order_refund/#post-16952275)
 * Hi [@vaibhav9017](https://wordpress.org/support/users/vaibhav9017/)
 * From the code snippet you’ve shared, I see that you’re creating an order with
   the API correctly. However, the refund process is not included in this code.
 * To create a refund, you will need to use the Create a Refund API endpoint. The
   URL should look something like this: `json/wc/v3/orders/<id>/refunds` where `
   <id>` is the ID of the order you want to refund.
 * The payload for the refund API should look like this:
 *     ```wp-block-code
       {
       "amount": "10",
       "reason": "Optional refund reason"
       }
       ```
   
 * You can replace `"10"` with the amount you want to refund, and `"Optional refund
   reason"` with a brief description of why the refund is being made.
 * Here’s how you might implement this in your code:
 *     ```wp-block-code
       const refundData = {
       amount: '10', // Replace with the amount to be refunded
       reason: 'Optional refund reason' // Replace with the refund reason
       };
   
       const refundResponse = await WooCommerce.post(orders/${response.data.id}/refunds, refundData);
   
       if (refundResponse) {
       res.status(200).json(refundResponse.data);
       }
       ```
   
 * Please replace the placeholders with the actual values you want to use. This 
   should create a refund for the order.
 * If you’re still encountering issues after trying this, Please note that we can’t
   provide support for code customization as [per our support policy](https://www.woocommerce.com/support-policy/).
   However, if you have any further questions on development or custom coding, don’t
   hesitate to reach out to some of our great resources available for support. Our
   WooCommerce community is brimming with skilled open-source developers who are
   active on the following channels:
    - [WooCommerce Developer Resources Portal](https://developer.woocommerce.com/)
    - [WooCommerce Advanced Facebook group](https://www.facebook.com/groups/advanced.woocommerce/)
    - [WooCommerce Developer Slack Channel](https://woocommerce.com/community-slack/)
    - Hire a [WooCommerce Expert](https://woocommerce.com/experts/)
 * I hope this helps! If you have any other questions, feel free to ask.
 * Thanks!
 *  Thread Starter [Vaibhav](https://wordpress.org/support/users/vaibhav9017/)
 * (@vaibhav9017)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/woocommerce_rest_cannot_create_order_refund/#post-16952642)
 * Hello [Shameem (woo-hc)](https://wordpress.org/support/users/shameemreza/) ,
 * Thank you for your reply. I am using the same code for refund, what you shared.
   Below is the sample of it.
 *     ```wp-block-code
        //To get order id fromm request
   
               const orderId: any = req.body?.OrderId;      
   
               const refundData = {
   
                   amount: '1.00', // The amount to be refunded
   
                   reason: 'Customer requested a refund', // The reason for the refund
   
                 };        
   
               //Verify order ID before calling Refund API
   
               if(orderId) {
   
                   const response = await WooCommerce.post(orders/${orderId}/refunds, refundData);
   
                   if(response){
   
                       res.status(200).json(response.data);
   
                       //return response.data;
   
                   }
   
               }else {
   
                   res.status(200).json({ message: Order Id not passed, please verify});
   
               }    
   
             }
       ```
   
 * Also, I am not looking for code customization, I am checking is any one having
   same issue in past or not and that will be helpfull.
 * Thank you for your valuable inputs and throught.
 * Thank You,
 *  [Saif](https://wordpress.org/support/users/babylon1999/)
 * (@babylon1999)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/woocommerce_rest_cannot_create_order_refund/#post-16966584)
 * Hello [@vaibhav9017](https://wordpress.org/support/users/vaibhav9017/),
   Thank
   you for the clarification!I’m getting the same error with BACS and COD orders.
   Seems like the `/wp-json/wc/v3/orders` only works with a paid order using a real
   payment gateway like Stripe, WooPayments, etc.I opened a [**new GitHub report about**](https://github.com/woocommerce/woocommerce/issues/39695)
   this as I’m not sure if this is done by design or a bug.
 * We don’t have an exact timeline for when the team will investigate or resolve
   the issue, as bug reports are prioritized based on a few criteria.
 * I suggest you subscribe to the report to receive updates. :‎)
 * Cheers!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘woocommerce_rest_cannot_create_order_refund’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 5 replies
 * 3 participants
 * Last reply from: [Saif](https://wordpress.org/support/users/babylon1999/)
 * Last activity: [2 years, 9 months ago](https://wordpress.org/support/topic/woocommerce_rest_cannot_create_order_refund/#post-16966584)
 * Status: resolved