我一直在尝试将条纹付款实施到我的网页中,但在尝试弄清楚几个小时后,我仍然干涸。所以从我开始到目前为止看起来像这样
app.post('/charge', function(req, res) {
var stripeToken = req.body.stripeToken;
console.log("print the price "+req.params.name);
console.log("print the price "+req.params);
console.log("print the price "+req.body);
console.log("print the price "+req.params.amount);
console.log("print the price "+req.body.name);
console.log("print the price "+req.body.name);
var amount = req.params.data-amount;
stripe.charges.create({
card: stripeToken,
currency: 'usd',
amount: amount
},
function(err, charge) {
if (err) {
res.send(500, err);
} else {
res.send(204);
}
});
});
<form action="/charge" method="POST">
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="i took this out before i post on stackoverflow"
data-image="https://avatars3.githubusercontent.com/u/8978785?v=3&s=400"
data-name="sfsdfsdfsf"
data-description="Send lots to me plz"
data-amount="<%=data.price2%>"
data-billing-address="true"
data-label="I am poor help me plz"
>
</script>
<p name="<%=data.price2%>" ></p>
</form>
所以我想在var amount=
中的代码放在代码的上半部分。当我从我的目录中选择不同的项目时,收费的价格应该是动态的,所以我不必为我的目录上的每一个项目写一个收费页面。我有一堆打印语句尝试找到错误,但我不知道如何处理对象对象输出。我尝试了很多东西。
答案 0 :(得分:0)
这是我的解决方案:
$('#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',"PUBLIC KEY");
script.setAttribute('data-image', "IMAGE");
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);
});
您需要动态创建按钮以创建动态值。