首页 > 解决方案 > 调用 Stripe API 但没有采取任何行动

问题描述

我有一个问题stripe.customers.create。我的意图是使用 currentUser 的电子邮件地址创建一个 Stripe 客户,然后使用返回的customer.id.

stripe.customers.create返回一个承诺,但在thenorcatch语句中没有触发任何内容。没有创建 Stripe 客户,看起来 Stripe API 调用甚至没有发送到 Stripe。

stripe.customers.create({
  email: state.getters.currentUser.email
})
.then(customer => {
  console.log("promise resolved");
  console.log(`customer.id: ${customer.id}`);
  if (customer.email === state.getters.currentUser.email) {
    state.dispatch("updateUserProperty", {
      customerId: customer.id
    });
  }
})
.catch(err => {
  console.log("promise error");
  console.error(err);
});

我也尝试过这种语法,但没有运气:

async () => {
  const params: Stripe.CustomerCreateParams = {
    email: state.getters.currentUser.email
  };
  const customer: Stripe.Customer = await stripe.customers.create(params);
  console.log(customer.id);
};

我正在使用https://github.com/stripe/stripe-node并且没有抛出错误或警告。state.getters.currentUser.email确实有想要的价值。

我在这里想念什么?谢谢您的帮助。

标签: javascriptvue.jsstripe-payments

解决方案


该库必须在节点环境中使用,vue 或客户端不能使用该库


推荐阅读