mirror of
https://github.com/domfelipe/mika-agent-assist.git
synced 2026-08-07 10:16:43 +00:00
Changes
Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com>
This commit is contained in:
parent
13b3951a1e
commit
5ef5bab121
9 changed files with 512 additions and 0 deletions
42
supabase/functions/get-paddle-price/index.ts
Normal file
42
supabase/functions/get-paddle-price/index.ts
Normal 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,
|
||||
});
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue