vuejs2 - Stripe redirectToCheckout 方法在 .then 部分显示任何响应之前重定向到成功的 url
问题描述
我正在尝试在 stripe.redirectTocheckout 函数的 .then 部分中运行一段代码。但它会在 .then({}) 中显示任何响应/结果之前将我重定向到successfulUrl 部分,因此.then 部分中的代码不会运行。请帮助我。我被困在这里很久了。谢谢你。
stripe.redirectToCheckout({
items: [{ sku: 'abcssdd', quantity: 1 }],
successUrl:'https://your-website.com/congratulation',
cancelUrl: 'https://your-website.com/canceled',
})
.then(function (result) {
if (result.error) {
var displayError = document.getElementById('error-message');
displayError.textContent = result.error.message;
}
console.log("Inside Then");
})
解决方案
如果失败,该then
选项就在那里。如果它没有失败,则没有理由显示错误。
恕我直言,这有点令人困惑,因为then()
通常与成功和catch()
错误相关联。但请注意以下文档中的评论:
const stripe = Stripe('pk_test_TYauvdEDq54NiTpjx');
stripe.redirectToCheckout({
items: [
// Replace with the ID of your SKU
{sku: 'sku_123', quantity: 1}
],
successUrl: 'https://your-website.com/success',
cancelUrl: 'https://your-website.com/canceled',
}).then(({error}) => {
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer
// using `error.message`.
});
来源:https ://stripe.com/docs/stripe-js/reference#stripe-redirect-to-checkout
推荐阅读
- switch-statement - 如何在switch语句中使用变量
- jquery - Svelte 和 Jquery - Dropdown.svelte:7 Uncaught TypeError: jquery(...).dropdown is not a function
- python - 用不同的填充符号填充其他多边形内的多边形
- python - Python多项式回归绘制错误?
- image-processing - 为什么使用 x*cos(a)+y*sin(a)=r 而不是 a=-b*x+y 进行霍夫变换?
- google-cloud-functions - 谷歌云函数响应消息的数字签名
- javascript - 为 Highcharts 圆环图转换组 json
- python - 给定一个元组列表,如果第一个元素相同,我如何在每个相似的元组中添加第二个元素
- math - Xbee3 - 没有数学模块的三角值计算
- swift - 是否有执行并传递原始值的反应函数?