We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Refund Request Due to Transaction Error ("expected Hash to be an Array")

Refund Request Due to Transaction Error ("expected Hash to be an Array")

abadat3928
Shopify Partner
15 1 3

Hi team,

I'm creating the order refund request on rest API using curl in PHP. and getting an error 

{ "errors": { "transactions": "expected Hash to be a Array" } }



This is my order refund function 

 

 

 

  function orderRefund($shopify, $order_id, $reason) {
              $refundcalarray = array(
				"currency" =>  "INR",
				"shipping" => array("full_refund")
			);
            $datarefundcal = array("refund"=>$refundcalarray);
            $datarefundcal = $shopify->rest_api('/admin/api/2024-01/orders/'.$order_id .'/refunds/calculate.json',  $datarefundcal, 'POST'); 
            $apioutputrefundcal = json_decode($datarefundcal['body'],true);
            $transactiondata = $apioutputrefundcal['refund']['transactions'];
            $refundtransactionarray = array();
            $refundtransactionarray['parent_id'] = $transactiondata[0]['parent_id'];
            $refundtransactionarray['amount'] = (float)$transactiondata[0]['maximum_refundable'];
            $refundtransactionarray['kind'] = 'refund';
            $refundtransactionarray['gateway'] = $transactiondata[0]['gateway'];
            $refundarray = array(
				"currency" =>  "INR",	
                "notify" => true,
                "note" => (string)$reason,
                "shipping" => array("full_refund" => true),
                "transactions" => array($refundtransactionarray)	    
			);
			  $datarefund = array("refund"=>$refundarray);  
            echo json_encode($datarefund, JSON_PRETTY_PRINT); echo "\n";

            $refund = $shopify->rest_api('/admin/api/2024-01/orders/'.$order_id .'/refunds.json',  $datarefund, 'POST');  
            $refund = json_decode($refund['body'], true);
            echo json_encode($refund, JSON_PRETTY_PRINT); echo "\n";
            return   $response = array( "message" => $refund['refund'] );
  }

 

 

 

 

This is my $datarefund Responce in json 

 

 

 

{
    "refund": {
        "currency": "INR",
        "notify": true,
        "note": "test",
        "shipping": {
            "full_refund": true
        },
        "transactions": [
            {
                "parent_id": 7050521444583,
                "amount": 474.05,
                "kind": "refund",
                "gateway": "Gokwik UPI"
            }
        ]
    }
}

 

 

 


And this is the $response Error 

 

 

 

{
    "errors": {
        "transactions": "expected Hash to be a Array"
    }
}

 

 

 

 

Where i'm doing mistakes?

Replies 0 (0)