0

I am newbie, working on codeigniter and I am using the razorpay payment gateway apis for transferring the amount using route concept as defined in the razorpay documentation. When I am calling the api using curl I am getting the error:

{ "error": { "code": "BAD_REQUEST_ERROR", "description": "Please provide your api key for authentication purposes.", "source": null, "step": null, "reason": null, "metadata": {} } }

the code i used is :

$url = 'https://api.razorpay.com/v1/payments/pay_E8JR8E0XyjUSZd/transfers';

/* Array Parameter Data */
$data = ['account' => 'va_FWSvFCwsaV1w5K', 'amount' => 90, 'currency' => 'INR'];

/* pass encoded JSON string to the POST fields */
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        
/* set the content type json */
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json','YOUR_KEY_ID','YOUR_KEY_SECRET'));
        
/* set return type json */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        
/* execute request */
$result = curl_exec($ch);
         
/* close cURL resource */
curl_close($ch);
print_r($result);

How should I place my key and secret in curl so that error does not occur.

Please help me out. Thanks in advance.

Cosmin Staicu
  • 1,809
  • 2
  • 20
  • 27
mohsin
  • 11
  • 1
  • 3

2 Answers2

0

The error message is pretty self-explanatory. This line:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json','YOUR_KEY_ID','YOUR_KEY_SECRET'));
    

Should contain your actual key and secret, not your_key_id and your_key_secret placeholder strings. Otherwise, authorization will fail

Javier Larroulet
  • 3,047
  • 3
  • 13
  • 30
0

You will require to encode key:secret in base64 format. And then add another header Authorization to make this API working.

headers = {
   "Content-Type": "application/json",
   "Authorization": "Basic " + encode_base64(Key:Secret)
}

In your case,

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json','Authorization:Basic (encoded_string)'));

Let me know if it works for you!

SangamAngre
  • 809
  • 8
  • 25