prettier fixes #16

This commit is contained in:
Michael Dausmann
2023-10-24 21:18:03 +11:00
parent dc9d64ebf5
commit a7f8c37f99
56 changed files with 1706 additions and 935 deletions

View File

@@ -6,20 +6,31 @@ import { AccountWithMembers } from '~~/lib/services/service.types';
const config = useRuntimeConfig();
const stripe = new Stripe(config.stripeSecretKey, { apiVersion: '2022-11-15' });
export default defineEventHandler(async (event) => {
const body = await readBody(event)
let { price_id, account_id} = body;
account_id = +account_id
console.log(`session.post.ts recieved price_id:${price_id}, account_id:${account_id}`);
export default defineEventHandler(async event => {
const body = await readBody(event);
let { price_id, account_id } = body;
account_id = +account_id;
console.log(
`session.post.ts recieved price_id:${price_id}, account_id:${account_id}`
);
const accountService = new AccountService();
const account: AccountWithMembers = await accountService.getAccountById(account_id);
let customer_id: string
if(!account.stripe_customer_id){
const account: AccountWithMembers = await accountService.getAccountById(
account_id
);
let customer_id: string;
if (!account.stripe_customer_id) {
// need to pre-emptively create a Stripe user for this account so we know who they are when the webhook comes back
const owner = account.members.find(member => (member.access == ACCOUNT_ACCESS.OWNER))
console.log(`Creating account with name ${account.name} and email ${owner?.user.email}`);
const customer = await stripe.customers.create({ name: account.name, email: owner?.user.email });
const owner = account.members.find(
member => member.access == ACCOUNT_ACCESS.OWNER
);
console.log(
`Creating account with name ${account.name} and email ${owner?.user.email}`
);
const customer = await stripe.customers.create({
name: account.name,
email: owner?.user.email
});
customer_id = customer.id;
accountService.updateAccountStipeCustomerId(account_id, customer.id);
} else {
@@ -31,8 +42,8 @@ export default defineEventHandler(async (event) => {
line_items: [
{
price: price_id,
quantity: 1,
},
quantity: 1
}
],
// {CHECKOUT_SESSION_ID} is a string literal; do not change it!
// the actual Session ID is returned in the query parameter when your customer
@@ -42,11 +53,9 @@ export default defineEventHandler(async (event) => {
customer: customer_id
});
if(session?.url){
if (session?.url) {
return sendRedirect(event, session.url, 303);
} else {
return sendRedirect(event, `${config.public.siteRootUrl}/fail`, 303);
}
});