From 37e0e940ccc91a3cd4e01c10c324f941e11fcc46 Mon Sep 17 00:00:00 2001 From: Vinicius Aguiar Date: Mon, 6 May 2024 10:23:04 -0300 Subject: [PATCH 1/3] chore: update backend url (#823) (#824) --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 516efacd..a90eed31 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ export NODE_ENV="development" -export NEXT_PUBLIC_API_URL="https://development.api.basedosdados.org" +export NEXT_PUBLIC_API_URL="https://development.backend.basedosdados.org" export NEXT_PUBLIC_SITE_NAME="Base dos Dados" export NEXT_PORT=3000 From 14fa504a4ce7935fef9bd0b0b4b3c615c88054c1 Mon Sep 17 00:00:00 2001 From: Vinicius Aguiar Date: Mon, 6 May 2024 17:25:00 -0300 Subject: [PATCH 2/3] feat: trigger release image by workflow dispatch (#827) --- .github/workflows/{cd.yaml => cd-prod.yaml} | 0 .github/workflows/release-dev.yaml | 3 ++- .github/workflows/{release.yaml => release-prod.yaml} | 5 +++-- .github/workflows/release-staging.yaml | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) rename .github/workflows/{cd.yaml => cd-prod.yaml} (100%) rename .github/workflows/{release.yaml => release-prod.yaml} (95%) diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd-prod.yaml similarity index 100% rename from .github/workflows/cd.yaml rename to .github/workflows/cd-prod.yaml diff --git a/.github/workflows/release-dev.yaml b/.github/workflows/release-dev.yaml index bf8bd7ed..d5eb20b5 100644 --- a/.github/workflows/release-dev.yaml +++ b/.github/workflows/release-dev.yaml @@ -7,9 +7,10 @@ on: paths: - ".github/workflows/release-dev.yaml" - "next/**/*" + workflow_dispatch: jobs: - release-docker-image-development: + release: name: Release Docker Image (Development) runs-on: ubuntu-latest environment: diff --git a/.github/workflows/release.yaml b/.github/workflows/release-prod.yaml similarity index 95% rename from .github/workflows/release.yaml rename to .github/workflows/release-prod.yaml index 2d3f80ff..6b8c23c9 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release-prod.yaml @@ -5,11 +5,12 @@ on: branches: - main paths: - - ".github/workflows/release.yaml" + - ".github/workflows/release-prod.yaml" - "next/**/*" + workflow_dispatch: jobs: - release-docker-image-production: + release: name: Release Docker Image (Production) runs-on: ubuntu-latest environment: diff --git a/.github/workflows/release-staging.yaml b/.github/workflows/release-staging.yaml index 7aecfecb..b8796fc3 100644 --- a/.github/workflows/release-staging.yaml +++ b/.github/workflows/release-staging.yaml @@ -7,9 +7,10 @@ on: paths: - ".github/workflows/release-staging.yaml" - "next/**/*" + workflow_dispatch: jobs: - release-docker-image-development: + release: name: Release Docker Image (Staging) runs-on: ubuntu-latest environment: From 94559a77a675cc72f8d736fb1485461c3bdce484 Mon Sep 17 00:00:00 2001 From: Jhony Lucas Date: Sun, 11 Aug 2024 16:19:18 -0300 Subject: [PATCH 3/3] feat: Add support for setup intents in PaymentForm --- next/components/organisms/PaymentSystem.js | 58 ++++++++++++--------- next/pages/api/stripe/createSubscription.js | 7 +-- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/next/components/organisms/PaymentSystem.js b/next/components/organisms/PaymentSystem.js index 870618d2..28633997 100644 --- a/next/components/organisms/PaymentSystem.js +++ b/next/components/organisms/PaymentSystem.js @@ -21,20 +21,35 @@ import { const stripePromise = loadStripe(process.env.NEXT_PUBLIC_KEY_STRIPE) -const PaymentForm = ({ onSucess, onErro }) => { +const PaymentForm = ({ onSucess, onErro, clientSecret}) => { const stripe = useStripe() const elements = useElements() const handlerSubmit = async (e) => { e.preventDefault() - const data = await stripe.confirmPayment({ - elements, - redirect: 'if_required', - }) - - if(data?.error?.code === "card_declined") return onErro() - if(data?.paymentIntent?.status === "succeeded") return onSucess() + const isSetupIntent = clientSecret.startsWith('seti_'); + if (isSetupIntent) { + await elements.submit(); + + const data = await stripe.confirmSetup({ + elements, + clientSecret: clientSecret, + redirect: 'if_required', + }); + + if (data?.error?.code === "card_declined") return onErro(); + if (data?.setupIntent?.status === "succeeded") return onSucess(); + + } else { + const data = await stripe.confirmPayment({ + elements, + redirect: 'if_required', + }) + + if(data?.error?.code === "card_declined") return onErro() + if(data?.paymentIntent?.status === "succeeded") return onSucess() + } } return ( @@ -89,26 +104,12 @@ export default function PaymentSystem({ userData, plan, onSucess, onErro }) { } const customerCreatPost = async (id) => { - let secret = "" - - const subscriptionCreate = await fetch(`/api/stripe/createSubscription?p=${btoa(id)}`, {method: "GET"}) + const clientSecret = await fetch(`/api/stripe/createSubscription?p=${btoa(id)}`, {method: "GET"}) .then(res => res.json()) - if(subscriptionCreate?.clientSecret) { - secret = subscriptionCreate?.clientSecret + if (clientSecret) { + setClientSecret(clientSecret) } - if(secret !== "") return setClientSecret(secret) - - const result = await fetch(`/api/stripe/createCustomer`, {method: "GET"}) - .then(res => res.json()) - - if(result?.id) { - const subscriptionCreate = await fetch(`/api/stripe/createSubscription?p=${btoa(id)}`, {method: "GET"}) - .then(res => res.json()) - secret = subscriptionCreate?.clientSecret - } - - return setClientSecret(secret) } async function customerCreat(plan) { @@ -169,7 +170,12 @@ export default function PaymentSystem({ userData, plan, onSucess, onErro }) { return ( - + ) } \ No newline at end of file diff --git a/next/pages/api/stripe/createSubscription.js b/next/pages/api/stripe/createSubscription.js index 91f8b8eb..814e1d07 100644 --- a/next/pages/api/stripe/createSubscription.js +++ b/next/pages/api/stripe/createSubscription.js @@ -14,10 +14,7 @@ async function createSubscription(id, token) { query: ` mutation { createStripeSubscription (priceId: ${id}) { - subscription { - id - clientSecret - } + clientSecret } } ` @@ -38,5 +35,5 @@ export default async function handler(req, res) { if(result.errors) return res.status(500).json({error: result.errors}) if(result === "err") return res.status(500).json({error: "err"}) - res.status(200).json(result?.data?.createStripeSubscription?.subscription) + res.status(200).json(result?.data?.createStripeSubscription?.clientSecret) }