Skip to content

Instantly share code, notes, and snippets.

@rlingineni
Created November 11, 2019 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlingineni/3b606adaab8b5e3ec80bcdbf389d0388 to your computer and use it in GitHub Desktop.
Save rlingineni/3b606adaab8b5e3ec80bcdbf389d0388 to your computer and use it in GitHub Desktop.
AWS Lambda and Stripe Example
var stripe = require('stripe')('STRIPE KEY HERE');
var Query = require('url-query-parser');
var AWS = require('aws-sdk');
Date.prototype.addDays = function(days) {
this.setDate(this.getDate() + parseInt(days));
return this;
};
exports.myHandler = function(event, context, callback) {
var query = Query.parse(event.body);
var randomString = shortid.generate();
var token = query.get('stripeToken')[0];
var email = query.get('stripeEmail')[0];
console.log(email , " ", token);
// Create a Customer:
stripe.customers.create({
email: email,
source: token,
},function(err,customer){
if(err){
console.log(err);
helper.sendError({msg:"Something went wrong! Send an e-mail to: help@example.com"},callback);
}
// Charge the user's card:
stripe.charges.create({
amount: 500,
currency: "usd",
description: "isLocation API",
customer: customer.id
}, function(err, charge) {
if(err){
console.log(err);
helper.sendError({msg:"Something went wrong! Send an e-mail to: help@example.com"},callback);
}
console.log(customer.id)
// Charge the user's card:
});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment