Created
November 24, 2016 05:24
-
-
Save Manny7311/ecd471c3af885f14a624e85a0b896ab7 to your computer and use it in GitHub Desktop.
Webtask Stripe
This file contains hidden or 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
'use latest'; | |
import express from 'express'; | |
import { fromExpress } from 'webtask-tools'; | |
import bodyParser from 'body-parser'; | |
import stripe from 'stripe'; | |
var app = express(); | |
app.use(bodyParser.json()); | |
app.post('/payment', (req,res) => { | |
var ctx = req.webtaskContext; | |
var STRIPE_SECRET_KEY = ctx.secrets.STRIPE_SECRET_KEY; | |
stripe(STRIPE_SECRET_KEY).charges.create({ | |
amount: ctx.data.amount, | |
currency: ctx.data.currency, | |
source: ctx.body.stripeToken, | |
description: ctx.data.description | |
}, (err, charge) => { | |
const status = err ? 400 : 200; | |
const message = err ? err.message : 'Payment done!'; | |
res.writeHead(status, { 'Content-Type': 'text/html' }); | |
return res.end('<h1>' + message + '</h1>'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment