API curl request for refund

panicoschr
Contributor
Contributor

I am trying to make a partial refund using API. I used API request with client_id and secret and this generated the access token for me.

Then I used this token to make a partial refund as per the code below

 

 

        $amount = ['total' => $refundAmountwithVAT, 'currency' => 'USD'];
        $array = ['amount' => $amount, 'invoice_number' => $invoiceNo, 'description' => 'test'];
        $data = json_encode ($array);

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => 'https://api-m.sandbox.paypal.com/v1/payments/sale/' . $transactionId . '/refund',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_POSTFIELDS => $data,
            CURLOPT_HTTPHEADER => array(
                "Content-Type: application/json",
                "Authorization: Bearer " . $token,
            ),
        ));

 

 

 

and I got this response.

 

{"name":"PERMISSION_DENIED","message":"Permission denied.","information_link":"https://developer.paypal.com/docs/api/payments/#errors","debug_id":"fc82da1551cd5"} 

 Can you please help?

 

Thanks

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.