Skip to content

Commit

Permalink
Merge pull request #236 from synapsy-ai/vNext
Browse files Browse the repository at this point in the history
Version 2.2.1
  • Loading branch information
lpeyr authored Feb 8, 2024
2 parents 0c00c05 + e48a52e commit 8995a1a
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 106 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/nextjs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Build Next.js Site
on:
[push, pull_request]
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -10,13 +9,13 @@ jobs:
- name: Create .env with Github Secrets
run: |
touch .env
echo NEXT_PUBLIC_SUPABASE_ANON_KEY=$ENV_VAR_1 >> .env
echo NEXT_PUBLIC_SUPABASE_URL=$ENV_VAR_2 >> .env
echo NEXT_PUBLIC_SUPABASE_URL=$ENV_VAR_1 >> .env
echo NEXT_PUBLIC_SUPABASE_ANON_KEY=$ENV_VAR_2 >> .env
echo SUPABASE_SERVICE_ROLE_KEY=$ENV_VAR_3 >> .env
echo OPENAI_API_KEY=$ENV_VAR_4 >> .env
env:
ENV_VAR_1: ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
ENV_VAR_2: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
ENV_VAR_1: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
ENV_VAR_2: ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
ENV_VAR_3: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}
ENV_VAR_4: ${{ secrets.OPENAI_API_KEY }}
- name: Setup Node.js
Expand Down
2 changes: 1 addition & 1 deletion app/[lng]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default function Home({ params: { lng } }: { params: { lng: any } }) {
<p className="text-lg text-slate-700 dark:text-slate-300">
{t("features-desc")}
</p>
<Link href="/pricing">
<Link href={`/${lng}/pricing`}>
<Button variant="link">{t("pricing")}</Button>
</Link>
<Spotlight className="grid max-w-6xl grid-cols-1 gap-4 p-4 sm:grid-cols-2">
Expand Down
19 changes: 13 additions & 6 deletions app/api/create-checkout-session/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { Database } from "@/types_db";
export async function POST(req: Request) {
if (req.method === "POST") {
// 1. Destructure the price and quantity from the POST body
const { price, quantity = 1, metadata = {} } = await req.json();
const {
price,
trial = false,
quantity = 1,
metadata = {},
} = await req.json();

try {
// 2. Get the user from Supabase auth
Expand All @@ -27,7 +32,6 @@ export async function POST(req: Request) {
let session;
if (price.type === "recurring") {
session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
billing_address_collection: "required",
customer,
customer_update: {
Expand All @@ -41,9 +45,12 @@ export async function POST(req: Request) {
],
mode: "subscription",
allow_promotion_codes: true,
subscription_data: {
metadata,
},
subscription_data: trial
? {
trial_period_days: 2,
metadata,
}
: { metadata },
success_url: `${getURL()}/me`,
cancel_url: `${getURL()}/`,
});
Expand Down Expand Up @@ -77,7 +84,7 @@ export async function POST(req: Request) {
JSON.stringify({
error: { statusCode: 500, message: "Session is not defined" },
}),
{ status: 500 }
{ status: 500 },
);
}
} catch (err: any) {
Expand Down
14 changes: 11 additions & 3 deletions components/pricing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,23 @@ export default function Pricing({
if (subscriptions) {
for (let i = 0; i < subscriptions?.length; i++) {
if (subscriptions[i]?.prices?.product_id === price.product_id) {
return router.push("`/${lng}/me`");
return router.push(`/${lng}/me`);
}
}
}
let trial = true;
if (subscriptions) {
for (let i = 0; i < subscriptions.length; i++) {
if (subscriptions[i].trial_end) {
trial = false;
return;
}
}
}

try {
const { sessionId } = await postData({
url: "/api/create-checkout-session",
data: { price },
data: { price, trial },
});

const stripe = await getStripe();
Expand Down
1 change: 1 addition & 0 deletions lib/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Variable {
}

export function getVariableString(variables: Variable[]): string {
if (variables.length === 0) return "";
let result: string = " Data: ";
for (let i = 0; i < variables.length; i++) {
if (
Expand Down
Loading

0 comments on commit 8995a1a

Please sign in to comment.