即使密钥有效,Razorpay API 也会给出无效密钥错误
Razorpay API gives inavlid key error even though the key is valid
一直在使用 Flask 处理 Razorpay 支付API,一直以来都面临这个问题
import razorpay
import json
from flask import Flask, render_template, request ,jsonify
app = Flask(__name__)
razorpay_client = razorpay.Client(auth=("rzp_test_8ydfJQKGSKoloz", "7LNONq8PYWjg4ImLujHDxpst"))
order_id = ''
def app_create():
order_amount = 50000
order_currency = 'INR'
order_receipt = 'order_rcptid_100'
notes = {'Shipping address': 'Pune, Maharashtra'}
something = razorpay_client.order.create(dict(amount=order_amount, currency=order_currency, receipt=order_receipt, notes=notes))
return something['id']
@app.route('/')
def app_start() :
return render_template('app.html')
#@app.route('/create')
#def app_create():
# order_amount = 50000
# order_currency = 'INR'
# order_receipt = 'order_rcptid_100'
# notes = {'Shipping address': 'Pune, Maharashtra'}
# something = razorpay_client.order.create(dict(amount=order_amount, currency=order_currency, receipt=order_receipt, notes=notes))
# order_id = something['id']
# return(something)
@app.route('/pay')
def app_pay():
order_id = app_create()
razrp_config = {
"options" : {
"key": "7LNONq8PYWjg4ImLujHDxpst",
"amount": "50000",
"currency": "INR",
"name": "Acme Corp",
"description": "Test Transaction",
"order_id": order_id,
"callback_url": "https://eneqd3r9zrjok.x.pipedream.net/",
"notes": {
"address": "Razorpay Corporate Office"
},
"theme": {
"color": "#3399cc"
}
}
}
return jsonify(razrp_config)
@app.route('/charge', methods=['POST'])
def app_charge():
amount = 50000
payment_id = request.form['razorpay_payment_id']
razorpay_client.payment.capture(payment_id, amount)
return json.dumps(razorpay_client.payment.fetch(payment_id))
if __name__ == '__main__':
app.run()
那是 python 代码,javscript :
// Get data
//fetch('/create')
//.then((result) => { console.log( result.json() )})
fetch('/pay')
.then((result) => { return result.json(); })
.then((data) => {
// Initialize js
console.log(data)
const rzp1 = new Razorpay(data.options);
// Event handler
document.querySelector("#submitBtn").addEventListener("click", () => {
rzp1.open()
//fetch('/charge')
//.then((result) => { return result.json(); })
//.then((data) => {
// console.log(data);
// Redirect
//})
});
});
有很多评论,试着浏览一下,当我点击 html dom 上的按钮时出现错误:'serviceworker' should be a dict in网络应用程序清单
我收到 API key is invalid 错误,实际上它是有效的并且是最近的
您在选项中传递的密钥无效。
使用正确的键。尝试使用您在顶部提到的键。
"options" : {
"key": "rzp_test_8ydfJQKGSKoloz"
一直在使用 Flask 处理 Razorpay 支付API,一直以来都面临这个问题
import razorpay
import json
from flask import Flask, render_template, request ,jsonify
app = Flask(__name__)
razorpay_client = razorpay.Client(auth=("rzp_test_8ydfJQKGSKoloz", "7LNONq8PYWjg4ImLujHDxpst"))
order_id = ''
def app_create():
order_amount = 50000
order_currency = 'INR'
order_receipt = 'order_rcptid_100'
notes = {'Shipping address': 'Pune, Maharashtra'}
something = razorpay_client.order.create(dict(amount=order_amount, currency=order_currency, receipt=order_receipt, notes=notes))
return something['id']
@app.route('/')
def app_start() :
return render_template('app.html')
#@app.route('/create')
#def app_create():
# order_amount = 50000
# order_currency = 'INR'
# order_receipt = 'order_rcptid_100'
# notes = {'Shipping address': 'Pune, Maharashtra'}
# something = razorpay_client.order.create(dict(amount=order_amount, currency=order_currency, receipt=order_receipt, notes=notes))
# order_id = something['id']
# return(something)
@app.route('/pay')
def app_pay():
order_id = app_create()
razrp_config = {
"options" : {
"key": "7LNONq8PYWjg4ImLujHDxpst",
"amount": "50000",
"currency": "INR",
"name": "Acme Corp",
"description": "Test Transaction",
"order_id": order_id,
"callback_url": "https://eneqd3r9zrjok.x.pipedream.net/",
"notes": {
"address": "Razorpay Corporate Office"
},
"theme": {
"color": "#3399cc"
}
}
}
return jsonify(razrp_config)
@app.route('/charge', methods=['POST'])
def app_charge():
amount = 50000
payment_id = request.form['razorpay_payment_id']
razorpay_client.payment.capture(payment_id, amount)
return json.dumps(razorpay_client.payment.fetch(payment_id))
if __name__ == '__main__':
app.run()
那是 python 代码,javscript :
// Get data
//fetch('/create')
//.then((result) => { console.log( result.json() )})
fetch('/pay')
.then((result) => { return result.json(); })
.then((data) => {
// Initialize js
console.log(data)
const rzp1 = new Razorpay(data.options);
// Event handler
document.querySelector("#submitBtn").addEventListener("click", () => {
rzp1.open()
//fetch('/charge')
//.then((result) => { return result.json(); })
//.then((data) => {
// console.log(data);
// Redirect
//})
});
});
有很多评论,试着浏览一下,当我点击 html dom 上的按钮时出现错误:'serviceworker' should be a dict in网络应用程序清单
我收到 API key is invalid 错误,实际上它是有效的并且是最近的
您在选项中传递的密钥无效。
使用正确的键。尝试使用您在顶部提到的键。
"options" : { "key": "rzp_test_8ydfJQKGSKoloz"