// backend/liveTranslate.jsw
import { fetch } from 'wix-fetch';
import { getSecret } from 'wix-secrets-backend';
const BACKEND_URL = 'https://api.livetranslate.app';
export async function syncMemberTier(email, planId, planName, status) {
const secret = await getSecret('LIVE_TRANSLATE_SYNC_SECRET');
const res = await fetch(`${BACKEND_URL}/api/v1/billing/wix/sync`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Wix-Sync-Secret': secret,
},
body: JSON.stringify({ email, plan_id: planId, plan_name: planName, status }),
});
if (!res.ok) throw new Error(await res.text());
return res.json();
}
export async function getApiKey(email) {
const secret = await getSecret('LIVE_TRANSLATE_SYNC_SECRET');
const res = await fetch(`${BACKEND_URL}/api/v1/auth/api-key`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Wix-Sync-Secret': secret,
},
body: JSON.stringify({ email }),
});
if (!res.ok) throw new Error(await res.text());
return res.json();
}
---
Step 3: Call from Account Page
On your Members Account page code:
import { currentMember } from 'wix-members-frontend';
import { orders } from 'wix-pricing-plans.v2';
import { syncMemberTier, getApiKey } from 'backend/liveTranslate.jsw';
$w.onReady(async function () {
const member = await currentMember.getMember();
if (!member?.loginEmail) return;
// Get active plan
const list = await orders.memberListOrders();
const active = list.orders?.find(o => o.status === 'ACTIVE');
// Sync to backend
await syncMemberTier(
member.loginEmail,
active?.planId ?? null,
active?.planName ?? null,
active?.status ?? null
);
// Get API key
const { api_key, tier } = await getApiKey(member.loginEmail);
// Display (add text elements #tierText and #apiKeyText to your page)
$w('#tierText').text = `Plan: ${tier}`;
$w('#apiKeyText').text = api_key;
});
top of page
bottom of page