Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable redirect to stripe checkout #58

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions apps/ticketing/src/pages/events/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ const CreateEvent: NextPageWithLayout = () => {
const placeHolderTicket: TicketInfoFormMetadata = {
name: 'General Admission',
denomination: 'Near',
salesValidThrough: {
startDate: Date.now(), // Milliseconds from Unix Epoch
startTime: '00:00', // Raw 24 hour time string such as 18:00
endDate: new Date().setDate(Date.now() + 14), // Milliseconds from start date
endTime: '00:00',
},
};

useEffect(() => {
Expand Down Expand Up @@ -457,6 +463,24 @@ const CreateEvent: NextPageWithLayout = () => {
})}
/>
</Flex>
<Flex stack="phone">
<Input
label="Sales Start Date"
type="date"
error={form.formState.errors.date?.message}
{...form.register(`tickets.${index}.salesValidThrough.startDate`, {
required: 'Please enter a date',
})}
/>
<Input
label="Sales End Date"
type="date"
error={form.formState.errors.date?.message}
{...form.register(`tickets.${index}.salesValidThrough.endDate`, {
required: 'Please enter a date',
})}
/>
</Flex>

<Card>
<Flex stack as="label">
Expand Down
20 changes: 11 additions & 9 deletions apps/ticketing/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface TicketInfoFormMetadata {
priceFiat?: string;
description?: string | undefined;
artwork?: FileList;
salesValidThrough?: DateAndTimeInfo;
salesValidThrough: DateAndTimeInfo;
passValidThrough?: DateAndTimeInfo;
}

Expand Down Expand Up @@ -50,7 +50,7 @@ export interface TicketMetadataExtra {
priceNear?: string;
priceFiat?: string;
maxSupply?: number;
salesValidThrough?: DateAndTimeInfo;
salesValidThrough: DateAndTimeInfo;
passValidThrough?: DateAndTimeInfo;
}

Expand Down Expand Up @@ -310,10 +310,8 @@ export const createPayload = async ({
const drop_ids: string[] = [];
const drop_configs: any = [];
const asset_datas: any = [];
const marketTicketInfo: Record<
string,
{ max_tickets: number; price: string; sale_start?: number; sale_end?: number }
> = {};
const marketTicketInfo: Record<string, { max_tickets: number; price: string; sale_start: number; sale_end: number }> =
{};

for (const ticket of formData.tickets) {
const dropId = `${Date.now().toString()}-${ticket.name.replaceAll(' ', '').toLocaleLowerCase()}`;
Expand All @@ -330,7 +328,11 @@ export const createPayload = async ({
dateCreated: Date.now().toString(),
priceNear: ticket.priceNear,
priceFiat: ticket.priceFiat,
salesValidThrough: ticket.salesValidThrough,
salesValidThrough: {
...ticket.salesValidThrough,
startDate: Date.parse(ticket.salesValidThrough.startDate.toString()),
endDate: Date.parse(ticket.salesValidThrough.endDate!.toString()),
},
passValidThrough: ticket.passValidThrough,
maxSupply: ticket.maxSupply,
limitPerUser: ticket.maxPurchases,
Expand All @@ -347,8 +349,8 @@ export const createPayload = async ({
marketTicketInfo[`${dropId}`] = {
max_tickets: ticket.maxSupply ?? 0,
price: parseNearAmount(ticket.priceNear || '0')!.toString(),
sale_start: Date.now() || undefined,
sale_end: Date.parse(formData.date) || undefined,
sale_start: Date.parse(ticket.salesValidThrough.startDate.toString()),
sale_end: Date.parse(ticket.salesValidThrough.endDate!.toString()),
};

const dropConfig = {
Expand Down
16 changes: 7 additions & 9 deletions apps/ticketing/src/utils/purchase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ type PurchaseTicketOptions = {
viewAccount: Account | null;
};

type PurchaseWorkerResponse = {
tickets: {
public_key: string;
secret_key: string;
}[];
};

type PurchasedTicket = {
secretKey: string;
};
Expand Down Expand Up @@ -135,8 +128,13 @@ export async function purchaseTickets({
});

if (response.ok) {
const data = (await response.json()) as PurchaseWorkerResponse;
data.tickets.forEach((t) => purchases.push({ secretKey: t.secret_key }));
const data = await response.json();
if (!ticketIsFree) {
// redirect to stripe for checkout
window.location.href = data.stripe_url;
} else {
data.tickets.forEach((t: { secret_key: any }) => purchases.push({ secretKey: t.secret_key }));
}
charleslavon marked this conversation as resolved.
Show resolved Hide resolved
} else {
/*
TODO: We'll need to think through how we redirect to Stripe after exiting this loop.
Expand Down