我正在建立一个使用React-Static的小网站。网站已全部建成,但我需要集成基本的捐赠功能。我有几个问题把我难住了。按照Thomasz的here指南,我遇到了一些障碍。
1.)当页面最初加载为html时,将创建按钮。但是,一旦react启动,它就会移除我的按钮。我想我需要通过React集成form JS,而不是当前的内联。
<form action="WEBTASK.IO_URL" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key={my_public_stripe_key}
data-image=""
data-name=""
data-description=""
data-amount="2500"
data-zip-code="true"
data-currency="usd"
data-locale="auto"
data-panel-label="Donate"
data-label="">
</script>
</form>2.)如果我强行点击一个按钮,我就会完成最初的条纹结账,然后它就会发布到webtask.io的url上。然而,我得到了一个错误:
"code": 500,
"error": "Script generated an unhandled synchronous exception.",
"details": "TypeError: Cannot read property 'stripeToken' of undefined"这是我的webtask.io脚本。我已经包含了NPM模块和正确的秘密。
'use latest';
import bodyParser from 'body-parser';
import stripe from 'stripe';
bodyParser.urlencoded();
module.exports = function (ctx, req, res) {
stripe(ctx.secrets.stripeSecretKey).charges.create({
amount: 2500,
currency: 'usd',
source: ctx.body.stripeToken,
description: 'Contribute to the Campaign'
}, function (error, charge) {
var status = error ? 400 : 200;
var message = error ? error.message : 'Thank You for your Contribution!';
res.writeHead(status, { 'Content-Type': 'text/html' });
return res.end('<h1>' + message + '</h1>');
});
};发布于 2018-06-15 16:06:42
尝试使用req.body.stripeToken而不是从ctx获取stripeToken
module.exports = function (ctx, req, res) {
stripe(ctx.secrets.stripeSecretKey).charges.create({
amount: 2500,
currency: 'usd',
source: req.body.stripeToken,
description: 'Contribute to the Campaign'
}, function (error, charge) {
var status = error ? 400 : 200;
var message = error ? error.message : 'Thank You for your Contribution!';
res.writeHead(status, { 'Content-Type': 'text/html' });
return res.end('<h1>' + message + '</h1>');
});
};发布于 2018-09-14 02:09:10
在导出express应用程序(而不是简单的函数)时,您将需要使用参数--meta wt-compiler=webtask-tools/express显式定义programming model (或者您可以使用webtask-tools)。
因此,最后的命令行变成:
$ wt create index.js --meta wt-compiler=webtask-tools/expresshttps://stackoverflow.com/questions/50863125
复制相似问题