From 7cca332041a28b835f899b899c93add87cfaefe0 Mon Sep 17 00:00:00 2001 From: aldemirlucas Date: Wed, 29 May 2024 01:19:27 -0300 Subject: [PATCH] fix: err in create customers --- next/pages/api/stripe/createCustomer.js | 6 ++++-- next/pages/api/stripe/removeSubscription.js | 4 +++- next/pages/user/[username].js | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/next/pages/api/stripe/createCustomer.js b/next/pages/api/stripe/createCustomer.js index bf8134db..33c18c15 100644 --- a/next/pages/api/stripe/createCustomer.js +++ b/next/pages/api/stripe/createCustomer.js @@ -3,8 +3,10 @@ import axios from "axios"; const API_URL= `${process.env.NEXT_PUBLIC_API_URL}/api/v1/graphql` async function createCustomer(token, userBD) { + const user = JSON.parse(userBD) + function trimName() { - const name = userBD.firstName + userBD?.lastName || "" + const name = user.firstName + user?.lastName || "" return name.replace(/\s+/g, ' ').trim() } @@ -21,7 +23,7 @@ async function createCustomer(token, userBD) { createStripeCustomer ( input: { name: "${trimName()}" - email: "${userBD.email}" + email: "${user.email}" } ) { customer { diff --git a/next/pages/api/stripe/removeSubscription.js b/next/pages/api/stripe/removeSubscription.js index a9ab18ff..c1c50740 100644 --- a/next/pages/api/stripe/removeSubscription.js +++ b/next/pages/api/stripe/removeSubscription.js @@ -17,6 +17,7 @@ async function removeSubscription(id, token) { subscription { id } + errors } } ` @@ -35,7 +36,8 @@ export default async function handler(req, res) { const result = await removeSubscription(atob(req.query.p), token) if(result.errors) return res.status(500).json({error: result.errors}) + if(result?.data?.deleteStripeSubscription.errors.length > 0) return res.status(500).json({error: result.data.deleteStripeSubscription.errors, success: false }) if(result === "err") return res.status(500).json({error: "err"}) - res.status(200).json(result?.data?.deleteStripeSubscription) + res.status(200).json(result?.data?.deleteStripeSubscription.subscription) } diff --git a/next/pages/user/[username].js b/next/pages/user/[username].js index 2708e4fa..1edb18b7 100644 --- a/next/pages/user/[username].js +++ b/next/pages/user/[username].js @@ -1570,6 +1570,10 @@ const PlansAndPayment = ({ userData }) => { const result = await fetch(`/api/stripe/removeSubscription?p=${btoa(subs[0]?.node._id)}`, {method: "GET"}) .then(res => res.json()) + if(result?.success === false) { + setIsLoadingCanSub(false) + } + do { const statusSub = await fetch(`/api/stripe/userGetSubscription?p=${btoa(id)}`, {method: "GET"}) .then(res => res.json())