数组项未推入 async.queue

Array items not pushed into async.queue

我有一组客户,我为其中的每个客户创建了一个队列来收费。它向第一位顾客收费,但不会将下一位顾客推到队列中。请问我错过了什么?下面是我的代码。

let q = async.queue(async(customer, callback) =>{
   let r =  await stripe.charges.create({
            amount: customer.amount ,
            currency: "usd",
            customer: customer.customerId,
            source: customer.token
        }, {
            idempotency_key: customer.uuid
        });  
 },1)
 async.forEach(customers, async(customer, callback)=> {
   q.push(customer, function(err){
        if(err){
            console.log(err,"errr==========")
        }
    })
 }) 

您在此处将 async/await 与回调混合使用,并且您从未调用 async.forEach() 回调。

let q = async.queue((customer, callback) => {
  stripe.charges.create({
    amount: customer.amount ,
    currency: "usd",
    customer: customer.customerId,
    source: customer.token
  }, {
    idempotency_key: customer.uuid
  }, callback);  
},1)

customers.forEach((customer) => {
  q.push(customer, (err, cus) => {
    if(err){
      console.log(err,"errr==========")
    }

    // Do whatever
  })
});

您还要确保customer.token是卡ID,不是令牌ID;如果是你用来创建Customer的Token ID,那么你不需要它,如果是新的card token,你需要先更新Customer或者添加到Customer中。