returning Undefined

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

If you have a backend function, then you will need to import that into your front end, otherwise they will not talk to each other.

Something like this.

 import {checkout} from 'backend/your-backend-file-name';

imported but still now working

Make sure that you are using Wix Fetch correctly.
https://www.wix.com/corvid/reference/wix-fetch.html
https://support.wix.com/en/article/corvid-accessing-third-party-services-with-the-fetch-api

Also, check previous forum posts too.
https://www.wix.com/corvid/forum/community-discussion/how-do-i-integrate-a-thrid-party-payment-gateway-such-as-http-razorpay-com-with-corvid-on-my-wix-store-paypal-isn-t-user-friendly
https://www.wix.com/corvid/forum/community-discussion/how-to-integrate-razorpay-payment-gateway

sir i am not using fetch. Kindly ignore import fetch

So why have it in your code then?

BACKEND CODE -

import {fetch} from 'wix-fetch';
import wixData from 'wix-data';

You are best waiting to see if Shan replies to you with the code sample then…
https://www.wix.com/corvid/forum/community-discussion/how-to-integrate-razorpay-payment-gateway

@givemeawhisky yup… Actually the problem is that front end part is not waiting for backend function to get executed.

@tejwindersingh98
Look at using async and await then.