2
EDIT:明確にするために、充電は実際に処理されますが、私ができないのは充電量を動的に設定することだけです。ストライプとNodeJS - 充電する量を渡す
私は一日中働いていて、解決策は見つかりませんでした。ここにserver.jsがあります。
app.post('/charge', function(req, res) {
var stripeToken = req.body.stripeToken;
var amount = 12000;
console.log(req);
stripe.charges.create({
card: stripeToken,
currency: 'usd',
amount: amount
},
function(err, charge) {
if (err) {
res.send(500, err);
} else {
res.send(204);
}
});
});
ここに私のダイナミックストライプボタンがあります。
$('#calcTransAmount').click(function(event) {
var amount = $('#transAmount').scope().totall;
//console.log(amount);
var holder = document.getElementById('hello');
var script = document.createElement('script');
script.src = 'https://checkout.stripe.com/checkout.js';
script.setAttribute('class', 'stripe-button');
script.setAttribute('data-amount', amount);
script.setAttribute('data-key',"KEY");
script.setAttribute('data-image', "IMG");
script.setAttribute('data-name', "NAME");
script.setAttribute('data-billing-address', "true");
script.setAttribute('data-description', "Purchase");
script.setAttribute('data-locale', "auto");
document.getElementById('btnCont').appendChild(script);
});
ボタンは、今、私はちょうど/charge
への投稿は金額を受け取り、変数として設定方法を見つけ出すように見えることはできません、動的な量、すべてで動作します。
これは私のreq
オブジェクトです:
{ stripeToken: 'tok_19t9jcLhf04QCVXXXXXXXX',
stripeTokenType: 'card',
stripeEmail: '[email protected]',
stripeBillingName: 'Clark',
stripeBillingAddressCountry: 'United States',
stripeBillingAddressCountryCode: 'US',
stripeBillingAddressZip: 'Zip',
stripeBillingAddressLine1: 'My address',
stripeBillingAddressCity: 'City',
stripeBillingAddressState: 'State' }
そして、私は動的な量を充電するために、サーバへのボタンから自分のデータ量の属性を取得する方法を見つけることができません。
おかげ
ここでの問題は、あなたが本当に量がクライアントから来るしたくないということです。誰でもその金額を変更し、注文のために$ 99ではなく$ 1を支払うことができます。この金額は、セキュリティ上の理由から顧客が注文しているものに基づいて、サーバー側で把握する必要があります。 – koopajah
それは実際には素晴らしいポイントです!ありがとうございました!だから私のフォローアップの質問は、カスタム変数をStripeボタンを通してサーバー側に渡し、サーバーがDB内のカートを参照できるようにする方法ですか? –