-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the CORS headers to the billing functions
- Loading branch information
1 parent
cf5f62a
commit 6f98bb4
Showing
7 changed files
with
23 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
import { corsHeaders } from "../_shared/cors.ts"; | ||
import { billingResponseHeaders } from "./shared.ts"; | ||
import { setupIntent } from "./setup_intent.ts"; | ||
import { getTenantPaymentMethods } from "./get_tenant_payment_methods.ts"; | ||
import { deleteTenantPaymentMethod } from "./delete_tenant_payment_method.ts"; | ||
|
@@ -21,6 +21,7 @@ serve(async (req) => { | |
const requested_tenant = request.tenant; | ||
// Create a Supabase client with the Auth context of the logged in user. | ||
// This is required in order to get the user's name and email address | ||
|
||
const supabaseClient = createClient( | ||
Deno.env.get("SUPABASE_URL") ?? "", | ||
Deno.env.get("SUPABASE_ANON_KEY") ?? "", | ||
|
@@ -43,7 +44,7 @@ serve(async (req) => { | |
|
||
if (!(grants.data ?? []).find((grant) => grant.object_role === requested_tenant)) { | ||
res = [JSON.stringify({ error: `Not authorized to requested grant` }), { | ||
headers: { "Content-Type": "application/json" }, | ||
headers: billingResponseHeaders, | ||
status: 401, | ||
}]; | ||
} else { | ||
|
@@ -59,20 +60,20 @@ serve(async (req) => { | |
res = await getTenantInvoice(request, req); | ||
} else { | ||
res = [JSON.stringify({ error: "unknown_operation" }), { | ||
headers: { "Content-Type": "application/json" }, | ||
headers: billingResponseHeaders, | ||
status: 400, | ||
}]; | ||
} | ||
} | ||
} | ||
} catch (e) { | ||
res = [JSON.stringify({ error: e.message }), { | ||
headers: { "Content-Type": "application/json" }, | ||
headers: billingResponseHeaders, | ||
status: 400, | ||
}]; | ||
} | ||
|
||
res[1] = { ...res[1], headers: { ...res[1]?.headers || {}, ...corsHeaders } }; | ||
res[1] = { ...res[1], headers: { ...res[1]?.headers || {} } }; | ||
|
||
return new Response(...res); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { SupabaseClient, User } from "https://esm.sh/@supabase/[email protected]"; | ||
import { customerQuery, StripeClient, TENANT_METADATA_KEY } from "./shared.ts"; | ||
import { billingResponseHeaders, customerQuery, StripeClient, TENANT_METADATA_KEY } from "./shared.ts"; | ||
|
||
async function findOrCreateCustomer(tenant: string, user: User) { | ||
if (!user.email) { | ||
|
@@ -50,7 +50,7 @@ export async function setupIntent( | |
|
||
if (!user) { | ||
return [JSON.stringify({ error: "User not found" }), { | ||
headers: { "Content-Type": "application/json" }, | ||
headers: billingResponseHeaders, | ||
status: 400, | ||
}]; | ||
} | ||
|
@@ -65,7 +65,7 @@ export async function setupIntent( | |
}); | ||
|
||
return [JSON.stringify({ intent_secret: intent.client_secret }), { | ||
headers: { "Content-Type": "application/json" }, | ||
headers: billingResponseHeaders, | ||
status: 200, | ||
}]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters