我正在学习Appmaker上的企业商店教程。我试图通过集成条带支付方法来自定义模板。我使用了条纹checkout code template。我把它放在一个函数上并附加了一个onclick触发器来运行它。当我尝试完成收费流程时遇到问题,如官方Stripe-Go结帐指南的step 2所示。有人可以解释代码模板来完成付款
答案 0 :(得分:1)
你走了:
客户端脚本
var AMOUNT = 51;
// Callback to handle token ready event
function onTokenReady(token) {
// Call server script
google.script.run
.withFailureHandler(function() {
// TODO: handle error
})
.withSuccessHanlder(function() {
// TODO: handle success
})
.charge(token.id, AMOUNT);
}
// Initializes Stripe client-side API
// To make it work add https://checkout.stripe.com/checkout.js
// as external JavaScript resource (see screenshot above)
function onAppStart() {
window.handler = StripeCheckout.configure({
key: 'pk_test_6pRNASCoBOKtIshFeQd4XMUh',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
token: onTokenReady
});
}
// Handles payment button's click event
function onButtonClick() {
handler.open({
name: 'Stripe.com',
description: '2 widgets',
zipCode: true,
amount: AMOUNT
});
}
服务器脚本
function charge(tokenId, amount) {
var params = {
payload: {
amount: amount,
currency: 'usd',
description: 'Example charge',
source: tokenId
},
headers: {
// TODO: replace with real PLATFORM_SECRET_KEY
Authorization: 'Bearer sk_test_BQokikJOvBiI2HlWgH4olfQ2'
}
// uncomment to troubleshoot
// ,muteHttpExceptions: false
};
var response = UrlFetchApp.fetch('https://api.stripe.com/v1/charges', params);
console.log(response.getContentText());
}