Javascript 创建客户和订单/发货地址等
我使用盖茨比react和aws lambda创建了条带支付页面。但此代码不会创建客户数据,如发货地址、电子邮件等 Lamdba码Javascript 创建客户和订单/发货地址等,javascript,node.js,reactjs,aws-lambda,stripe-payments,Javascript,Node.js,Reactjs,Aws Lambda,Stripe Payments,我使用盖茨比react和aws lambda创建了条带支付页面。但此代码不会创建客户数据,如发货地址、电子邮件等 Lamdba码 const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY); module.exports.handler = (event, context, callback) => { console.log("creating charge..."); // Pull out the amo
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
module.exports.handler = (event, context, callback) => {
console.log("creating charge...");
// Pull out the amount and id for the charge from the POST
console.log(event);
const requestData = JSON.parse(event.body);
console.log(requestData);
const amount = requestData.amount;
const token = requestData.token.id;
// Headers to prevent CORS issues
const headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Content-Type"
};
return stripe.charges
.create({
// Create Stripe charge with token
amount,
source: token,
currency: "usd",
description: "Tshirt"
})
.then(charge => {
// Success response
console.log(charge);
const response = {
headers,
statusCode: 200,
body: JSON.stringify({
message: `Charge processed!`,
charge
})
};
callback(null, response);
})
.catch(err => {
// Error response
console.log(err);
const response = {
headers,
statusCode: 500,
body: JSON.stringify({
error: err.message
})
};
callback(null, response);
});
};
盖茨比支付代码
代码起作用了,付款起作用了。但运输细节不起作用
openStripeCheckout(event) {
event.preventDefault();
this.setState({ disabled: true, buttonText: "WAITING..." });
this.stripeHandler.open({
name: "Demo Product",
amount: amount,
shippingAddress: true,
billingAddress: true,
description: "",
token: (token, args) => {
fetch(`AWS_LAMBDA_URL`, {
method: "POST",
body: JSON.stringify({
token,
args,
amount,
}),
headers: new Headers({
"Content-Type": "application/json",
}),
})
.then(res => {
console.log("Transaction processed successfully");
this.resetButton();
this.setState({ paymentMessage: "Payment Successful!" });
return res.json();
})
.catch(error => {
console.error("Error:", error);
this.setState({ paymentMessage: "Payment Failed" });
});
},
});
}
我想查看客户数据、发货地址等
谢谢你的帮助 账单和发货地址都可以在您正在收集的令牌回调的args参数中找到
在您的后端,您似乎提取了金额和令牌id,但没有提取发货数据。当您使用console.logrequestData时;您是否看到在前端输入的装运数据的args内容?您可以从requestData.token.email@duck中提取电子邮件谢谢您的回答。但我不知道我该怎么做?你能写示例代码吗?
var handler = StripeCheckout.configure({
key: 'pk_test_xxx',
locale: 'auto',
token: function(token, args) {
// Print the token response
$('#tokenResponse').html(JSON.stringify(token, null, '\t'));
// There will only be args returned if you include shipping address in your config
$('#argsResponse').html(JSON.stringify(args, null, '\t'));
}
});