首页 > 解决方案 > 为什么此代码的 axios 响应为空?

问题描述

我收到控制台消息:

“IntegrationError:stripe.redirectToCheckout:您必须提供 lineItems、items 或 sessionId 之一。”

我相信 sessionId 是空的,因为 response.data 是来自 console.log(response.data)的“空字符串”。

这段代码来自一个教程的github。它应该非常接近正确,但我相信有一点不准确。

stripe.checkout.sessions.create({
    success_url: 'https://example.com/success',
    cancel_url: 'https://example.com/cancel',
    payment_method_types: ["card"],
    line_items: results
}, function(err, session) {
    response.send(session)
});

axios.get('https://us-central1-webstore-vuejs.cloudfunctions.net/CheckoutSession', {
    params: {
        products: data
    }
}).then(response => {
    this.sessionId = response.data  

    console.log(response.data)
          
    stripe.redirectToCheckout({                 
        sessionId: this.sessionId.id
    }).then(function(result) {              
    });
})

标签: vue.jsaxiosstripe-paymentscheckout

解决方案


}, function(err, session) {
    response.send(session)
});

我怀疑您在这里发生了错误;我会记录它,看看它可能是什么。

理想情况下,您应该始终至少抛出(或理想情况下处理!)错误,以便您知道何时出现问题。


推荐阅读