Skip to content

Commit

Permalink
Merge pull request #862 from basedosdados/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
AldemirLucas authored May 29, 2024
2 parents e8057c8 + 9a8c788 commit bc267f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 4 additions & 2 deletions next/pages/api/stripe/createCustomer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -21,7 +23,7 @@ async function createCustomer(token, userBD) {
createStripeCustomer (
input: {
name: "${trimName()}"
email: "${userBD.email}"
email: "${user.email}"
}
) {
customer {
Expand Down
4 changes: 3 additions & 1 deletion next/pages/api/stripe/removeSubscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async function removeSubscription(id, token) {
subscription {
id
}
errors
}
}
`
Expand All @@ -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)
}
4 changes: 4 additions & 0 deletions next/pages/user/[username].js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit bc267f0

Please sign in to comment.