Can We Create Checkout URL?

Can we create checkout URLs? If yes how can I create a checkout URL using Velo APIs that I can redirect user to.

I was not able to find an API for that.

It is possible, but in a complex way,

It depends on what you want to sell but I would use the Wix Ecom API, to first do a createCheckout(), and with that checkout created, I get the ‘_id’ value so I can create a URL. An example function:

PAGE CODE:

const options = {
    "lineItems": [{
        "quantity": 1,
        "catalogReference": {
            // Wix Stores appId
            "appId": "1380b703-ce81-ff05-f115-39571d94dfcd",
            // Wix Stores productId
            "catalogItemId": "someProductId" // extract from Products database from wix store
        }
    }],
    "channelType": "WEB"
}

myCreateCheckoutFunction(options)
    .then((newCheckout) => {
        console.log('Success! Checkout created:', newCheckout);

        const jsonParams = {
            checkoutId: newCheckout._id,
        }

        const generatedURL = generateURLFromJSON(jsonParams);
        console.log("URL:", generatedURL);
        $w('#url').link = generatedURL

        return newCheckout;
    })
    .catch((error) => {
        console.error(error);
        // Handle the error
    });

function generateURLFromJSON(jsonObj) {
    try {

        const encodedParams = encodeURIComponent(JSON.stringify(jsonObj));

        const url = `https://${yourdomain}/checkout?appSectionParams=${encodedParams}&checkoutOOI=true`;

        return url;
    } catch (error) {
        console.error("Error generating the URL from the JSON:", error);
        return null;
    }
}

BACKEND CODE

import { checkout } from 'wix-ecom-backend';

export async function myCreateCheckoutFunction(options) {
  try {
    const newCheckout = await checkout.createCheckout(options);
    console.log('Success! Checkout created, checkout:', newCheckout);
    return newCheckout;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
}

Then with the value ‘generatedURL’ you can do whatever you need to do to share the payment link.

For existing checkouts, you can get the checkout url by using the “get checkout URL” API.

https://dev.wix.com/docs/velo/api-reference/wix-ecom-backend/checkout/get-checkout-url

If you want to create a URL that you can share with multiple people (for example on social network), you can use “Checkout Templates” API.
In the checkout template API you provide items and more details if you want (like discounts, etc…), and when someone enter this URL, a new checkout will be created for him and he will be navigated directly to the checkout page.
https://dev.wix.com/docs/velo/api-reference/wix-ecom-backend/checkout-templates/create-checkout-template