Reputation: 1
I'm trying to auto charge customers on stripe in NodeJS
I have an issue where some customers have a:
My current workflow (C# WPF):
This works fine and payment are running well.
I also charge for SMS fees using a nodejs api:
async function chargeSMS(stripeCusID,chargeValue,chemistName,chemistID,countSMS){
//console.log(stripeCusID);
//console.log(chargeValue);
let customerObject;
let payMethodID;
customerObject = await stripe.customers.retrieve(
);
console.log("PaymentID received:" + customerObject.invoice_settings.default_payment_method);
payMethodID = customerObject.invoice_settings.default_payment_method;
await stripe.paymentIntents.create({
amount: chargeValue,
currency: 'aud',
customer: stripeCusID,
description: 'SMS Charges: ' + countSMS + " sent",
payment_method: payMethodID,
confirm: true
},
function(err, response) {
if (err) {
console.log("Charge", err.message,stripeCusID,chargeValue,chemistName);
return;
}
console.log("Successful SMS Charge:", response.id,chemistName);
chemCharged(chemistID);
})
}
This has also been working fine as a Cron on 1st of each month.
My issue is that recently one of my customer's cards expired. They used my WPF to open the portal and add a new card This worked.
HOWEVER this new card on the portal is only listed as customer.default_source
Their invoice_settings.default_payment_method
Is now null!
So my code above fails.
I've checked and:
I ahve no idea why this is the situation but I'm using the stripe customer portal so i would have thought they would add in the same way!
Any ideas how I can fix this or figure out what I've done wrong?
On the stripe web portal (my business) I can see that this customer DOES have a default card, and it looks the same as any other customer, but the api side has it registered under the different section!
Upvotes: 0
Views: 383
Reputation: 1971
You can add the Card as the Customer's invoice_settings.default_payment_method yourself by calling the Update Customer API.
FYI in a subscription the precedence chain is:
Upvotes: 0