【问题标题】:Working With Stripe and Node / Express to Charge Existing Customer with No Card使用 Stripe 和 Node / Express 向无卡现有客户收费
【发布时间】:2019-03-27 14:54:13
【问题描述】:

我在 Stripe 创建的客户没有来自外部集成的卡片。

所以客户对象存在,但它没有卡片。

我希望客户能够转到付款页面并通过结帐进行付款。但是,客户 ID 是已知的。所以我们只是要求客户输入他们的“参考”,然后输入一张卡并付款。

我有这个代码:

app.post('/charge', (req, res) => {

  stripe.charges.create({
    amount: 4000,
    description: 'Sample Charge',
    currency: 'gbp',
    customer: req.body.stripeId
  },function(err,result){

    console.log(err);

    res.render('charge'});
  });
});

但是这会返回错误:

Error: Cannot charge a customer that has no active card

我认为结帐的全部意义在于它为客户创建了一张卡片。

如何存储通过结帐输入的卡对指定客户和收费?

结帐码是:

 <script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="pk_test_Some_key"
    data-email="customer email"
    data-billing-address="true"
    data-allow-remember-me="false"
    data-name="Company Limited"
    data-description="Example charge"
    data-image="an-image.jpg"
    data-locale="auto"
    data-zip-code="true"
    data-currency="gbp">
  </script>

【问题讨论】:

    标签: node.js express stripe-payments checkout


    【解决方案1】:

    我认为结帐的全部意义在于它为客户创建了一张卡片。

    它会创建一张卡片,但您仍需要自己将其附加到客户身上:

    stripe.customers.update(req.body.stripeId, { // I assume this is the customer ID (`cus_xxx`)
      source: req.body.stripeToken // `tok_xxx` generated by Stripe Checkout
    }, function(err, customer) {
      stripe.charges.create({
        amount: 4000,
        description: 'Sample Charge',
        currency: 'gbp',
        customer: customer.id
      }) ... 
    });
    

    https://stripe.com/docs/saving-cards + https://stripe.com/docs/api/customers/update?lang=node#update_customer-source

    【讨论】:

      猜你喜欢
      • 2015-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-05
      • 2017-03-17
      • 1970-01-01
      • 2017-03-12
      相关资源
      最近更新 更多