Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot] 2026-04-17 17:47:29 +00:00
parent 13b3951a1e
commit 5ef5bab121
9 changed files with 512 additions and 0 deletions

View file

@ -0,0 +1,42 @@
import { gatewayFetch, type PaddleEnv } from '../_shared/paddle.ts';
const corsHeaders = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
'Content-Type': 'application/json',
};
Deno.serve(async (req) => {
if (req.method === 'OPTIONS') {
return new Response(null, { headers: corsHeaders });
}
try {
const { priceId, environment } = await req.json();
if (!priceId) {
return new Response(JSON.stringify({ error: 'priceId required' }), {
status: 400,
headers: corsHeaders,
});
}
const env = (environment || 'sandbox') as PaddleEnv;
const response = await gatewayFetch(env, `/prices?external_id=${encodeURIComponent(priceId)}`);
const data = await response.json();
if (!data.data?.length) {
return new Response(JSON.stringify({ error: 'Price not found' }), {
status: 404,
headers: corsHeaders,
});
}
return new Response(JSON.stringify({ paddleId: data.data[0].id }), { headers: corsHeaders });
} catch (e) {
console.error('get-paddle-price error:', e);
return new Response(JSON.stringify({ error: (e as Error).message }), {
status: 500,
headers: corsHeaders,
});
}
});