【问题标题】:How to add a quantity field to Stripe Charge? JavaScript如何向 Stripe Charge 添加数量字段? JavaScript
【发布时间】:2018-10-09 08:19:07
【问题描述】:

在创建 Stripe Checkouts 表单时,我似乎找不到任何选项来向 Stripe Charge 方法添加数量,以便客户可以看到客户订购了多少。我搜索了Stripe's API docs,找不到任何关于向收费方法添加数量的内容(订阅计划有一个数量参数,但这不是我想要的)。有没有我缺少的关键字?还是 Stripe 不支持数量?

stripe(STRIPE_SECRET_KEY).charges.create({
    quantity: 2,
    receipt_email: body.stripeEmail,
    amount: body.amount,
    currency: body.currency,
    source: body.stripeToken, 
    description: body.description
  }, (err, charge) => {
    console.log(body.amount, body.currency);
    const status = err ? 400: 200;
    const message = err ? err.message: 'Payment successfully completed!';
    res.writeHead(status, { 'Content-Type': 'text/html' });
    return res.end('<h1>' + message + '</h1>');
  });
});

【问题讨论】:

    标签: node.js stripe-payments stripe.js


    【解决方案1】:

    对于此类一次性费用,数量不是 Charge 对象上可用的属性。如果您希望为用户提供大量购买的能力,您应该在您自己的应用程序逻辑中定义这一点,计算总数,然后指示 Stripe 收取最终金额。您可以将数量存储在metadata 以供您自己记录。或者,也许您可​​以考虑使用Orders

    stripe.charges.create({
        metadata: {'quantity': 2, 'order_id': 'A6735'},
        receipt_email: body.stripeEmail,
        amount: body.amount,
        currency: body.currency,
        source: body.stripeToken, 
        description: body.description
    }) 
    

    ...

    【讨论】:

      猜你喜欢
      • 2018-01-22
      • 2016-04-17
      • 2018-11-04
      • 1970-01-01
      • 2017-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多