// backend/http-functions.js
import { response } from 'wix-http-functions';
import { addToCurrentCart, updateCurrentCart } from 'wix-ecom-backend/current-cart';
import { createCheckoutFromCurrentCart } from 'wix-ecom-backend/current-cart';
import { getCheckoutUrl } from 'wix-ecom-backend/checkout';
// GET /_functions/metaCheckout?products=123:2,456:1
export async function get_metaCheckout(request) {
try {
const url = new URL(request.url);
const raw = url.searchParams.get('products'); // Meta sends URL-encoded; Wix gives you raw here
if (!raw) return badRequest('Missing products');
// 1) Clear the cart (set to empty)
await updateCurrentCart({ lineItems: [] }); // clears any stale items
// 2) Parse items like "123:2,456:1"
const lineItems = [];
decodeURIComponent(raw).split(',').forEach(pair => {
const [idStr, qtyStr] = pair.split(':');
const productId = (idStr || '').trim();
const quantity = Number(qtyStr);
if (productId && quantity > 0) {
lineItems.push({
quantity,
catalogReference: {
// Wix Stores appId (keep as-is)
appId: '1380b703-ce81-ff05-f115-39571d94dfcd',
catalogItemId: productId
// If you use variants, include variant info per your catalog setup.
}
});
}
});
if (!lineItems.length) return badRequest('No valid products');
// 3) Add all items to the current visitor's cart
await addToCurrentCart({ lineItems });
// 4) Create a checkout based on the current cart
const { checkout } = await createCheckoutFromCurrentCart();
// 5) Get the native Wix checkout URL and 302 redirect the shopper there
const { checkoutUrl } = await getCheckoutUrl(checkout._id);
return redirect302(checkoutUrl);
} catch (err) {
console.error('metaCheckout error:', err);
return response({
status: 500,
headers: { 'Content-Type': 'application/json' },
body: { error: 'server_error' }
});
}
}
function badRequest(msg) {
return response({
status: 400,
headers: { 'Content-Type': 'application/json' },
body: { error: msg }
});
}
function redirect302(location) {
return response({
status: 302, // temporary redirect
headers: { Location: location }
});
}
top of page
FREQUENTLY ASKED
QUESTIONS
Frequently asked questions
Weight Loss
Menopause Management
Skin Care
Collagen Stimulation
Medical weight loss is a science-backed approach, guided by professionals, to help you lose weight safely and effectively. Unlike fad diets, we tailor a plan specifically for you, factoring in things like your metabolism, medical history, and lifestyle. This isn’t just about losing pounds – it's about creating sustainable, healthy habits.
No extreme diets here! We focus on balance and moderation, not deprivation. Our plans include a variety of foods that you actually enjoy, with plenty of flexibility for life’s little indulgences (because pizza happens, and that’s okay!).
Every body is different, so the timeline varies, but most people start seeing progress within the first few weeks. We'll be there to celebrate every milestone, big or small, and adjust your plan to keep you moving toward your goals.
Exercise is encouraged but not mandatory. We create a plan that works for you, whether you're a gym rat or prefer to get your steps in during a Netflix binge. Movement is important, but we make it work for your lifestyle.
100%! All our treatments are supervised by medical professionals who monitor your progress and make adjustments as needed. Our top priority is your health and well-being, so we ensure everything is tailored to suit your body’s needs.
Once you reach your goal, we help you maintain it! Our focus isn’t just on losing the weight but on keeping it off, too. We’ll provide ongoing support and guidance so you can live your healthiest life long after the program.