Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// formkeep-stripe-checkout.js on
// 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'', (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: '',
amount: `$10`,
// Post the data to FormKeep using axios
return, 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, ` donation was received`);
.catch(function(err) {
// If it fails, redirect to the FormKeep thank you page
// (but with an error message)
res.redirect(301, ` 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