Created
June 17, 2020 23:44
-
-
Save cjavilla-stripe/b25971032086e069b590b8b044cddeff to your computer and use it in GitHub Desktop.
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
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN}); // guessing this initializes stripe-node, and should be your platform's secret key, not the connected account's. | |
const pug = require('pug'); | |
const render = pug.compileFile('./payment.pug') | |
/** | |
* An HTTP endpoint that acts as a webhook for Custom API or Webhook request event | |
* @returns {object.http} result Your return value | |
*/ | |
module.exports = async (amount=null, frequency=null, email=null, firstname=null, lastname=null, street=null, zip=null, city=null, state=null, cellphone=null, occupation=null, employer=null) => { | |
const fec = { | |
amount, | |
frequency, | |
email, | |
firstname, | |
lastname, | |
street, | |
zip, | |
city, | |
state, | |
cellphone, | |
occupation, | |
employer | |
}; | |
const stripe = await lib.stripe.paymentintents['@0.0.1'].create({ | |
amount: amount * 100, | |
currency: `USD`, | |
confirm: false, | |
description: `Donation: Every Two Years`, | |
metadata: JSON.parse(JSON.stringify(fec)), | |
receipt_email: email, | |
statement_descriptor: `Every Two Years`, | |
capture_method: 'automatic', | |
confirmation_method: 'automatic', | |
}, { | |
stripeAccount: "acct_connectedStripeAccountID", // add | |
}); | |
return { | |
headers: {'Content-Type': 'text/html'}, | |
statusCode: 200, | |
body: Buffer.from(render({ | |
stripeKey: process.env.stripe_key, // guessing this might be the connected account's secret key, but you likely want this to be your platform secret key, and then you also likely want to send the ID of the connected account to the client, too. | |
clientSecret: stripe.client_secret, | |
name: `${firstname} ${lastname}`, | |
amount | |
})) | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment