Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// formkeep-stripe-checkout.js on webtask.io
// Load NPM dependencies (specified in the settings)
const webtask = require('webtask-tools');
const express = require('express');
const axios = require('axios');
// Initialize an express app
const app = express();
// Add a single endpoint at the root, to handle the request
app.post('', (req, res) => {
// Grab FormKeep URL from secrets (added in settings)
const formkeepUrl = req.webtaskContext.secrets.formkeepUrl;
// Standard header to post JSON to the FormKeep endpoint
const formkeepHeaders = { "Content-Type": "application/json" };
// Some sample data to post for now
const formkeepData = {
email: 'test@example.com',
amount: `$10`,
};
// Post the data to FormKeep using axios
return axios.post(formkeepUrl, formkeepData, { headers: formkeepHeaders })
.then(function() {
// If it succeeds, redirect to the FormKeep thank you page
// (you can then add a different page to thank your donors)
res.redirect(301, `https://formkeep.com/thanks?h=Thanks&s=Your donation was received`);
})
.catch(function(err) {
// If it fails, redirect to the FormKeep thank you page
// (but with an error message)
console.error(err);
res.redirect(301, `https://formkeep.com/thanks?h=Sorry&s=Your payment couldn't be processed`);
});
});
// Use webtask helpers to export the express app as webtask serverless function
module.exports = webtask.fromExpress(app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.