const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers":
"authorization, x-client-info, apikey, content-type",
};
serve(async (req) => {
if (req.method === "OPTIONS") {
return new Response("ok", { headers: corsHeaders });
}
try {
const { amount, currency } = await req.json();
const paymentIntent = await stripe.paymentIntents.create({
amount, // e.g., 1000 = $10.00
currency: currency || "usd",
payment_method_types: ["card"],
});
return new Response(
JSON.stringify({ clientSecret: paymentIntent.client_secret }),
{
status: 200,
headers: { ...corsHeaders, "Content-Type": "application/json" },
}
);
} catch (error) {
return new Response(
JSON.stringify({ error: "Failed to create payment intent" }),
{
status: 400,
headers: { ...corsHeaders, "Content-Type": "application/json" },
}
);
}
});
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers":
"authorization, x-client-info, apikey, content-type",
};
serve(async (req) => {
if (req.method === "OPTIONS") {
return new Response("ok", { headers: corsHeaders });
}
try {
const { amount, currency } = await req.json();
const paymentIntent = await stripe.paymentIntents.create({
amount, // e.g., 1000 = $10.00
currency: currency || "usd",
payment_method_types: ["card"],
});
return new Response(
JSON.stringify({ clientSecret: paymentIntent.client_secret }),
{
status: 200,
headers: { ...corsHeaders, "Content-Type": "application/json" },
}
);
} catch (error) {
return new Response(
JSON.stringify({ error: "Failed to create payment intent" }),
{
status: 400,
headers: { ...corsHeaders, "Content-Type": "application/json" },
}
);
}
});