fix(webhook): add detailed logging to Stripe URL generation and CTA button sending to diagnose paywall fallback issue
This commit is contained in:
parent
eb2ceab354
commit
fc34444bcd
1 changed files with 11 additions and 2 deletions
|
|
@ -145,9 +145,14 @@ async function sendWhatsAppInteractiveMessage(remoteJid: string, text: string, b
|
|||
body: JSON.stringify(payload)
|
||||
});
|
||||
if (!res.ok) {
|
||||
const errBody = await res.text();
|
||||
console.error(`[META-WH] CTA URL failed (${res.status}): ${errBody}`);
|
||||
await sendWhatsAppMessage(remoteJid, `${text}\n\n👉 Acesse: ${linkUrl}`);
|
||||
} else {
|
||||
console.log(`[META-WH] CTA URL sent OK for ${remoteJid}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("[META-WH] CTA URL exception:", err);
|
||||
await sendWhatsAppMessage(remoteJid, `${text}\n\n👉 Acesse: ${linkUrl}`);
|
||||
}
|
||||
}
|
||||
|
|
@ -224,6 +229,7 @@ async function sendWhatsAppListMenu(remoteJid: string, header: string, body: str
|
|||
async function generateStripeCheckoutUrl(userId: string): Promise<string> {
|
||||
const fallback = "https://foodsnap.com.br?checkout=true";
|
||||
try {
|
||||
console.log(`[WH] Generating Stripe URL for user: ${userId}`);
|
||||
const res = await fetch(`${SUPABASE_URL}/functions/v1/stripe-checkout`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
@ -233,8 +239,11 @@ async function generateStripeCheckoutUrl(userId: string): Promise<string> {
|
|||
body: JSON.stringify({ user_id: userId, plan: "mensal" })
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data?.url) return data.url;
|
||||
console.error("[WH] Stripe checkout generation failed:", data?.error);
|
||||
if (data?.url) {
|
||||
console.log(`[WH] Stripe URL generated OK: ${data.url.substring(0, 60)}...`);
|
||||
return data.url;
|
||||
}
|
||||
console.error("[WH] Stripe checkout generation failed. Status:", res.status, "Response:", JSON.stringify(data));
|
||||
return fallback;
|
||||
} catch (err) {
|
||||
console.error("[WH] Error generating Stripe URL:", err);
|
||||
|
|
|
|||
Loading…
Reference in a new issue