-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #955 from basedosdados/staging
Staging
- Loading branch information
Showing
12 changed files
with
582 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import axios from "axios"; | ||
|
||
const API_URL= `${process.env.NEXT_PUBLIC_API_URL}/api/v1/graphql` | ||
|
||
async function validateStripeCoupon({id, coupon, token}) { | ||
try { | ||
const res = await axios({ | ||
url: API_URL, | ||
method: "POST", | ||
headers: { | ||
Authorization: `Bearer ${token}` | ||
}, | ||
data: { | ||
query:` | ||
mutation { | ||
validateStripeCoupon (priceId: ${id}, coupon: "${coupon}") { | ||
isValid | ||
discountAmount | ||
duration | ||
durationInMonths | ||
errors | ||
} | ||
} | ||
` | ||
} | ||
}) | ||
const data = res.data | ||
return data | ||
} catch (error) { | ||
console.error(error) | ||
return "err" | ||
} | ||
} | ||
|
||
export default async function handler(req, res) { | ||
const token = req.cookies.token | ||
const result = await validateStripeCoupon({ | ||
id: atob(req.query.p), | ||
coupon: atob(req.query.c), | ||
token: token | ||
}) | ||
|
||
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?.validateStripeCoupon) | ||
} |
Oops, something went wrong.