My code includes a loop that fetches an array of users and attempts to retrieve the information of each user. However, I've encountered an issue where if there are multiple users, it ends up returning the same information (specifically, the details of the last user) twice. Consequently, when I attempt to update and save the user information, only the data of the last user gets saved.
for (i = 0; i < users.length; i++) {
var amount = users[i].monthlyAmount;
if(amount != '0') {
var stripeID = users[i].stripeID;
accountID = users[i];
stripe.charges.create({
amount: amount,
currency: "usd",
customer: stripeID,
description: "Monthly charge"
}, function(err, charge) {
if (err) return (err);
if(!err) {
console.log(accountID);
accountID.monthlyAmount = '0';
accountID.save();
}
});
}
}
Below is the current output:
{ billingInfo: 'true',
createdAt: Sun Nov 16 2014 14:05:21 GMT-0600 (CST),
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="85e4c5e4abe6eae8">[email protected]</a>',
encryptedPassword: '*removed',
monthlyAmount: 1000,
propertyCount: 0,
stripeID: '*removed',
updatedAt: Sun Nov 16 2014 15:10:59 GMT-0600 (CST),
id: '54690381c03a265b07c99564' }
{ billingInfo: 'true',
createdAt: Sun Nov 16 2014 14:05:21 GMT-0600 (CST),
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2a4b6a4b04494547">[email protected]</a>',
encryptedPassword: '*removed',
monthlyAmount: '0',
propertyCount: 0,
stripeID: '*removed',
updatedAt: Sun Nov 16 2014 15:10:59 GMT-0600 (CST),
id: '54690381c03a265b07c99564' }