i am returning order_id from my backend code but function does not wait for the backend code to finish and console log “undefined”.
When i am console logging order_id on backend it is working fine but not able to return it to the front end.
BACKEND CODE -
import {fetch} from 'wix-fetch';
import wixData from 'wix-data';
const Razorpay = require('razorpay');
export function checkout() {
var order_id;
var instance = new Razorpay({
key_id: 'keyid',
key_secret: 'secretkey'
});
var order = {
"amount": 1000,
"currency": 'INR',
"receipt": 'helo1',
"payment_capture": true
}
instance.orders.create(order).then((data) => {
order_id=data.id;
});
return order_id;
}
FRONT END CODE
export function button11_click(event) {
checkout()
.then( (order_id) => {
console.log(order_id);
} );
}
Please help me out