简体   繁体   中英

Which payment method to use for Stripe Payment intent

I'm trying to auto charge customers on stripe in NodeJS

I have an issue where some customers have a:

  • default_source and some have
  • invoice_settings.default_payment_method

My current workflow (C# WPF):

  • Create customer + Add subscription to customer
  • Get URL for portal
  • Customer adds card details on stripe portal

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:

  • All new customers using portal have their cards saved as invoice_settings.default_payment_method
  • any time a customer adds a new card it is only added as defult_source

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!

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:

  1. Subscription's default_payment_method
  2. Subscription's default_source
  3. Customer's invoice_settings.default_payment_method
  4. Customer's default_source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM