Razorpay 如何使用 firebase 调用函数生成 orderId?
How to Razorpay generate orderId using firebase call function?
我已经试过了,但得到的错误不为空
const instance = new Razorpay({
key_id: "myKey",
key_secret: "mySecret"
});
exports.generateOrder = functions.https.onCall((data, context) => {
const options = {
amount: data.amount,
currency: "INR",
receipt: "recipt by me" //req.body.receipt
};
instance.orders.create(options, (err, order) => {
if(err !== null){
console.log("ORDERID null");
return null;
}else{
console.log("ORDERID "+order);
return order;
}
});
});
如果出现任何错误,您应该登录 err
并检查。但是,如果订单已创建,您可以简单地 return orderId,如下所示:
exports.generateOrder = functions.https.onCall((data, context) => {
const options = {
amount: data.amount,
currency: "INR",
receipt: "recipt by me" //req.body.receipt
};
return createOrder(options).then((orderId) => {
return { orderId }
}).catch(e => {
return { error: e }
})
});
function createOrder(options) {
return new Promise((resolve, reject) => {
instance.orders.create(options, (err, order) => {
if(err !== null){
console.log("failed to create order", err);
return reject(err);
} else {
console.log("ORDERID "+order.id);
return resolve(order.id);
}
});
})
}
我已经试过了,但得到的错误不为空
const instance = new Razorpay({
key_id: "myKey",
key_secret: "mySecret"
});
exports.generateOrder = functions.https.onCall((data, context) => {
const options = {
amount: data.amount,
currency: "INR",
receipt: "recipt by me" //req.body.receipt
};
instance.orders.create(options, (err, order) => {
if(err !== null){
console.log("ORDERID null");
return null;
}else{
console.log("ORDERID "+order);
return order;
}
});
});
如果出现任何错误,您应该登录 err
并检查。但是,如果订单已创建,您可以简单地 return orderId,如下所示:
exports.generateOrder = functions.https.onCall((data, context) => {
const options = {
amount: data.amount,
currency: "INR",
receipt: "recipt by me" //req.body.receipt
};
return createOrder(options).then((orderId) => {
return { orderId }
}).catch(e => {
return { error: e }
})
});
function createOrder(options) {
return new Promise((resolve, reject) => {
instance.orders.create(options, (err, order) => {
if(err !== null){
console.log("failed to create order", err);
return reject(err);
} else {
console.log("ORDERID "+order.id);
return resolve(order.id);
}
});
})
}