Last active
December 18, 2017 13:58
-
-
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
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
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