Razorpay集成.问题:请提供您的api密钥以进行身份验证 [英] Razorpay integration. Issue: Please provide your api key for authentication purposes
问题描述
我正在将此cURL代码转换为javascript.
curl -u< YOUR_KEY_ID>:< YOUR_KEY_SECRET>\-X POST https://api.razorpay.com/v1/customers \-H内容类型:application/json" \-d'{名称":"Gaurav Kumar1"电子邮件":"gaurav.kumar+1@example.com"联系人":"9123456781"}'
< script>函数createCustomer(){console.log("createCustomer");const url ="https://api.razorpay.com/v1/customers";fetch(url,{方法:发布",标头:{"x-api-key":"MY_KEY_ID","content-type":"application/json","cache-control":"no-cache"},身体: {名称":"Gaurav Kumar1","email":"gaurav.kumar+1@example.com",联系人":"9123456781"}}).then(response => response.json()).then((data)=> {console.log("data",data)})}</script>
当我在邮递员中检查此邮件时,它会给出正确的响应.但是,当我在我的网站上使用它时,它给出了错误.
POST
I am converting this cURL code to javascript.
curl -u <YOUR_KEY_ID>:<YOUR_KEY_SECRET> \ -X POST https://api.razorpay.com/v1/customers \ -H "Content-Type: application/json" \ -d '{ "name": "Gaurav Kumar1" "email": "gaurav.kumar+1@example.com" "contact": "9123456781" }'
<script> function createCustomer() { console.log("createCustomer"); const url="https://api.razorpay.com/v1/customers"; fetch(url, { method: 'post', headers: { "x-api-key": "MY_KEY_ID", "content-type": "application/json", "cache-control": "no-cache" }, body: { "name": "Gaurav Kumar1", "email": "gaurav.kumar+1@example.com", "contact": "9123456781" } }) .then(response => response.json()) .then((data) => { console.log("data",data) }) } </script>
when i check this in postman it is giving the correct response. But when i use this in my site it is giving the error.
POST https://api.razorpay.com/v1/customers 401 (Unauthorized) data : error: {code: "BAD_REQUEST_ERROR", description: "Please provide your api key for authentication purposes."}
解决方案You are missing the header
Authorization
, have a look at this I use jquery AJAX for it I get the code from postman itself.var settings = { "async": true, "crossDomain": true, "url": "https://api.razorpay.com/v1/customers", "method": "POST", "headers": { "Content-Type": "application/x-www-form-urlencoded", "Authorization": "Basic cnpwX2xpdmVfa2V5OmFfbG9uZ19wYXNzd29yZA==", "User-Agent": "PostmanRuntime/7.13.0", "Accept": "*/*", "Cache-Control": "no-cache", "Postman-Token": "f1c3919b-d2b8-4646-8ce0-caa60f2dfc3a,9dd079e3-ddab-41a8-8b1d-5ac53c00e07b", "Host": "api.razorpay.com", "accept-encoding": "gzip, deflate", "content-length": "59", "Connection": "keep-alive", "cache-control": "no-cache" }, "data": { "name": "Gaurav Kumar1", "email": "gaurav.kumar+1@example.com", "contact": "9123456781" } } $.ajax(settings).done(function (response) { console.log(response); });
Refer to the steps to Generate the Authorization Key and Secret this is from the official documentation.
https://razorpay.com/docs/assets/images/generate-api-keys.gif
Hope this helps :)
这篇关于Razorpay集成.问题:请提供您的api密钥以进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!