refundCreate mutation - transaction already captured error

refundCreate mutation - transaction already captured error

Saso-WD
Shopify Partner
26 1 13

Hello, I'm trying to issue refunds with refundCreate mutation but keep getting this error:
"The authorized transaction has already been captured"

Any idea why this is?

Here's my GQL:

mutation refundCreate($input: RefundInput!) {
                 refundCreate(input: $input) {
                    refund {
                        id
                    }
                    order {
                        id
                    }
                    userErrors {
                       field
                       message
                    }
                 }
               }
            ',
                'variables'=> array(
                    'input'=> array(
                        "notify" => true,
                        "orderId" => $order->id,
                        "note" => $comment,
                        "transactions" => array (
                            "amount" => $amount,
                            "gateway" => $transaction->gateway,
                            "kind" => $transaction->kind,
                            "orderId" => $order->id,
                            "parentId" => $transaction->parentTransaction->id
                        )
                    )
                )
Replies 3 (3)

ShopifyDevSup
Shopify Staff
1453 238 509

Hey @Saso-WD, generally, that error indicates that a transaction has already been processed (the payment or refunded funds have been captured by the payment processor). One thing we can do to confirm if this is the case is to query the order you're trying to create the refund for and see if a refund has already been applied. As an example, you could use a query like this:

{
 order (id:"") {
   edges {
     node {
       id
       transactions (first:10) {
         status
         kind
       }
     }
   }
 }
}

 

The status and kind fields would show if there was a successful transaction and what type of transaction it is (refund, sale, etc.). We could use this to confirm if there's not already a refund completed on the order. Sometimes, merchants can process refunds manually through the admin - which can cause issues like this if you are creating a refund ad-hoc.

 

That said, if that's not the case here, and you can confirm that there is no successful refund transaction already on the order, can you reply back here and let us know? Happy to continue investigating if need be. Hope this helps!

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Saso-WD
Shopify Partner
26 1 13

Hello @ShopifyDevSup, there were two transactions on the order, first kind was AUTHORIZATION and second one was CAPTURE. There was no existing refund transactions on the order.


I got it working through REST API and maybe I'm not understanding how this works through GraphQL. Is it that it's not possible to refund already captured transactions through GraphQL? Since with REST API you have to calculate the refund first in order to issue it? Do we need to do something similar through GraphQL? It's not really clear in the documentation.

ShopifyDevSup
Shopify Staff
1453 238 509

Hey @Saso-WD, you shouldn't need to calculate the refund first if you're using the createRefund mutation in GraphQL and you should be able to authorize a refund on a captured payment. Just to be sure, I tested the mutation on my development store and was able to successfully put a "test" refund through. Here's the mutation structure I used:

mutation refundCreate($input: RefundInput!) {
 refundCreate(input: $input) {
   order {
     id
   }
   refund {
     id
   }
   userErrors {
     field
     message
   }
 }
}

 

and then the variables:

{
 "input": {
   "currency": "CAD",
   "note": "test",
   "notify": true,
   "orderId": "gid://shopify/Order/[order-id]",
   "refundLineItems": [
     {
       "lineItemId": "gid://shopify/LineItem/[line-item-id]",
       "locationId": "gid://shopify/Location/[inventory-location-id]",
       "quantity": 1,
       "restockType": "RETURN"
     }
   ],
   "transactions": [
     {
       "amount": "11.3",
       "gateway": "shopify",
       "kind": "REFUND",
       "orderId": "gid://shopify/Order/[order-id]",
       "parentId": "gid://shopify/OrderTransaction/[transaction-id]"
     }
   ]
 }
}

 

One thing to note is that you do need the parent order transaction ID and the gateway name that initially captured the transaction in order to process the refund. Hope this helps - as always, just let us know if we can clarify anything, happy to help! 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog