Magento2: Credit Memo REST API Critical Bug

Created on 27 Apr 2016  Â·  23Comments  Â·  Source: magento/magento2

I am trying to create a Credit Memo for a billed unshipped sales order in Magento (version 2.0.4) of a Simple item via API. Here are the list of issues with while using REST API POST: /v1/creditmemo
Order Details

  1. contains single simple item price $20, no tax and no discount.
  2. Shipping cost of $5 fixed.
  3. paid by credit card.

image

Issues

  1. Order Status doesn't change to closed even though the credit memo is created successfully.
  2. Can create multiple Credit memos for same orders as Order is not reflect that item is refunded ending up in refunding more than what was sold for.
  3. row total, Subtotal and Grand Total fields are not auto calculated as a result I can set those fields values to any higher value without any rational logic and still successfully creating the credit memo record. (i think payment gateway takes care of failing this transaction from refund but still these two values shouldn't be editable)
  4. When orderId field is not provided in the request to the api it throws 500 Internal Server error.
    "Fatal Error: 'Call to a member function getId() on a non-object' in '/vendor/magento/module-sales/Model/ResourceModel/Order/Creditmemo.php' on line 50"

Here is the request which was successfully creating the credit memo
{
"entity": {
"orderId": 7,
"subtotal": 100,
"grand_total": 2000,
"items": [
{
"orderItemId": 7,
"qty": 1,
"price": 20,
"row_total": 20
}
],
"comments": [
],
"extensionAttributes": {}
}
}
Here is the screenshot of the credit memo created.
image

After credit memo for that item is created it is still as order status is not reflected that change.
image

Here is the request of credit memo for which it was failing with error.
{
"entity": {
"subtotal": 100,
"grand_total": 2000,
"items": [
{
"orderItemId": 7,
"qty": 1,
"price": 20,
"row_total": 20
}
],
"comments": [
],
"extensionAttributes": {}
}
}

Can you please take a look and help on what I am doing wrong?

FrameworWebapi Fixed in 2.2.x Fixed in 2.3.x Confirmed Format is not valid Ready for Work Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x bug report

All 23 comments

Hi

Any Update on this issue?

Guys, any update on this? I am also facing the same issue.

@mbrinton01 can you ping the API team on this issue?

Created internal P1 ticket MAGETWO-52613.

@mbrinton01 there are comments in the internal ticket that might explain this - please transfer here.

Please note! A new webapi method has been introduced. POST /V1/creditmemo/refund
Sample body for request:

{ "creditmemo": 
                   { "orderId": 11, "subtotal": 9, "grand_total": 14, "base_grand_total": 14, "shipping_amount": 5,  "base_shipping_amount": 5,  "shippingAddressId": 21, "billingAddressId": 22, "invoiceId": 11, 
                   "items": [ { "orderItemId": 11, "qty": 1, "price": 9, "row_total": 9} ], "comments": [ ], "extensionAttributes": {} }, 

           "offlineRequested": true }

Repository save method for credit memo must be used only for persisting data if you already build credit memo

For refund shipment:

"shipping_amount" and "base_shipping_amount"

should be set in creditmemo.

@mbrinton01 : I think this update was corresponding to Issue#4436. I think the code is still to be merged into develop branch as i don't see that api in sales/etc/webapi.xml or I am looking at wrong place may be.

Thank you for this refund feature it will certainly help us better integrate System to Magento.

@srinivasanithin, the fix has been delivered. Please see 27c034c, 6705ff50.

@mbrinton01 @slavvka : This issue also includes that if we don't give subtotal, grandtotal, rowtotal values these fields needs to be auto-calculated rather then setting them as zero value. Business needs these passed values to be validated as well rather than setting them.

Please reopen as their are other issues which are not resolved
On May 15, 2016 12:39 AM, "Sviatoslav Mankivskyi" [email protected]
wrote:

@srinivasanithin https://github.com/srinivasanithin, the fix has been
delivered. Please see 27c034c, 6705ff50.

—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/magento/magento2/issues/4329#issuecomment-219237720

+1 Please reopen this issue

Mark--can you look at this issue in terms of should it be closed (issue resolved) and tracked as a feature request or if the issue stays open given there is a technical issue vs what we have stated should be available?

As explained above, send the following data to the method /V1/creditmemo/refund POST should be enough:

{
    "creditmemo": {
        "orderId": 11,
        "invoiceId": 11, 
        "items": [
            {
                "orderItemId": 11,
                "qty": 1
            }
        ]
    },
    "offlineRequested": true
}

If not provided, the other values (grand total, subtotal, store id etc.) should be automatically calculated by Magento.

Hello @srinivasanithin, the original issue has been fixed in the 2.1.0 Release, that's why I'm closing it. If you have any questions or additional information regarding the issue feel free to reopen it or create a new one.

Sorry, the issue has been closed by mistake, additional details of investigation will be given a little bit later.

Hi ,
internal ticked MAGETWO-55337 was created to track the problem about autogenerated fields for Credit Memo.

Hi,
i tried to create a credit memo (V1/creditmemo/refund) by rest api from my magento 2.1.1 it is throwing an error
{ "creditmemo": { "adjustment_negative": 0, "adjustment_positive": 0, "order_id": 1, "shipping_amount": 5, "billing_address_id": 2, "shipping_address_id": 1, "invoice_id": 7, "items": [ { "order_item_id": 1, "qty": 1 } ], "comments": [ { "comment": "Test" } ], "extension_attributes": {} }, "offlineRequested": true }

image

the bug is still there

@NadiyaS, we should wait 2.1.3/2.0.11 releases with new API services

@NadiyaS : is it confirmed that new API will be available in Magento 2.1.3 release ?

@srinivasanithin, thank you for your report.
We've created internal ticket(s) MAGETWO-55337 to track progress on the issue.

Hi @srinivasanithin thank you for your report. In release 2.2.0 we introduced new service for refunds. Please check the commits with the message: MAGETWO-57776: Introduce new service refundInvoice or you ca try latest 2.2 release.
Sorry for delay with response.

hi @srinivasanithin, we recommend using the following API endpoints
POST /V1/invoice/:invoiceId/refund
POST V1/order/:orderId/refund
This should solve the initial issue

@fascinosum I've used POST V1/order/:orderId/refund and the status has changed from processing to complete could it be because it wasn't complete to move to the next status which is closed? I need the status to be closed when a refund is issued!

Was this page helpful?
0 / 5 - 0 ratings