39
loading...
This website collects cookies to deliver better user experience
?wanted=true
as request parameter of the URL.wanted
parameter, he will directly land at the checkout and can purchase your product - Gumroad is taking care of the rest. 🙌&Twitter%20Username=dominiksumer
import type { NextApiRequest, NextApiResponse } from 'next';
import { addPro, isPro } from '../../utils/auth-util';
export default async function (req: NextApiRequest, res: NextApiResponse) {
const { product_id: productId, test } = req.body;
if (!test && req.method.toUpperCase() === 'POST' && productId === 'YOUR_PRODUCT_ID') {
const userName = req.body['Twitter Username'];
if (!(await isPro(userName))) {
await addPro(userName);
}
}
res.status(200).send('');
}
test
is false (would be true if you’re testing a purchase on your own) and if the productId is matching the id of your product. Like this, you also secure the endpoint against someone just calling it and therefore you should keep the product id a secret.Hint: When Gumroad is redirecting the user to your website after a purchase, it can be the case that Gumroad Ping didn’t notify your application about it yet. So make sure to deal with this asynchrony.