Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
require('dotenv').load();
var qs = require('qs');

var stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);

exports.handler = function(event, context) {
exports.handler = function(event, context, callback) {
console.log("event: \n" + JSON.stringify(event, null, 4));
var data = qs.parse(event.body);
console.log("body: \n" + JSON.stringify(data, null, 4));

stripe.charges.create({
amount: event.amount,
source: event.source,
currency: event.currency || 'usd',
description: event.description || 'Stripe payment '+event.order_id,
receipt_email: event.receipt_email || null
var customer = stripe.customers.create({
source: data.stripeToken,
email: data.stripeEmail,
description: "Customer for " + data.stripeEmail,
plan: 'littleFriendIG500'
}, function(err, charge) {
if (err && err.type === 'card_error') {
context.fail(new Error(err.message));
} else if(err){
context.fail(err);
if (err) {
console.log(err.type + ": " + err.message + ". (code: " + err.code + ")");
context.succeed({
"statusCode": 302,
"headers": { "Location" : "http://littlefriend.co/error?type=" + err.type },
"body": ""
});
} else {
context.succeed({ status: charge.status, success : true });
context.succeed({
"statusCode": 302,
"headers": { "Location" : "http://littlefriend.co/success" },
"body": ""
});
}
//if (err && err.type === 'card_error') {
// context.fail(new Error(err.message));
//} else if(err){
// context.fail(err);
//} else {
// context.succeed({ status: charge.status, success : true });
//}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't be able to pull these changes in with this PR; they appear to be specific to your use case.

Copy link
Author

@staringispolite staringispolite Nov 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ugh. I keep forgetting that PRs aren't frozen in time, so you can't continue to push to your own branch. Can you pull in only that first commit? Or do I need to re-fork and make another?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would need to make a new PR with just the one commit that adds the error logging.

});
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"dotenv": "^1.2.0",
"load-grunt-tasks": "^3.4.1",
"qs": "^6.5.1",
"stripe": "^4.0.0"
},
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions tasks/build_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ module.exports = function(grunt) {
"exp_year": 2017,
"cvc": "123"
},function(err, token){
if (err) {
grunt.log.writeln(err);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

fs.writeFile("event.json", JSON.stringify({
"source" : token,
"amount" : 2000,
Expand Down