Skip to content

Instantly share code, notes, and snippets.

@r3-yamauchi
Last active December 18, 2017 13:58
Show Gist options
  • Save r3-yamauchi/8e8a8411b30ba1c3d71cfd28f1c5911c to your computer and use it in GitHub Desktop.
Save r3-yamauchi/8e8a8411b30ba1c3d71cfd28f1c5911c to your computer and use it in GitHub Desktop.
kintone に Stripe を組み込んで チャリン♪チャリン♪ https://blog.r3it.com/react-stripe-elements-on-kintone-14bb9452ab8d
const stripe = require("stripe")(process.env.SK);
exports.handler = (event, context, callback) => {
console.log("Received event:", JSON.stringify(event, null, 2));
const done = (err, res) => callback(null, {
statusCode: err ? "400" : "200",
body: err ? err.message : JSON.stringify(res),
headers: {
"Content-Type": "application/json; charset=utf-8"
},
});
let body;
try {
body = JSON.parse(event.body);
} catch (e) {
return done(null, { "message": "[Bad Request] invalid payload" });
}
// Stripe charges API 呼び出し
stripe.charges.create({
amount: body.amount,
currency: body.currency,
description: body.description,
source: body.stripeToken.id
}, (err, charge) => {
console.log("Stripe charge:", JSON.stringify(charge, null, 2));
console.log("Stripe err:", JSON.stringify(err, null, 2));
if (!err && charge) {
return done(null, { "my_msg": "OK" });
} else {
return done(null, { "message": JSON.stringify(err, null, 2) });
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment