【问题标题】:Why is axios response empty with this code?为什么此代码的 axios 响应为空?
【发布时间】:2020-09-10 00:50:09
【问题描述】:

我收到控制台消息:

“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.js axios stripe-payments checkout


    【解决方案1】:
    }, function(err, session) {
        response.send(session)
    });
    

    我怀疑你这里发生了错误;我会记录下来看看它可能是什么。

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

    【讨论】:

      猜你喜欢
      • 2013-02-02
      • 1970-01-01
      • 1970-01-01
      • 2015-08-25
      • 1970-01-01
      • 1970-01-01
      • 2015-12-30
      • 1970-01-01
      相关资源
      最近更新 更多