Abhishek Goswami
Abhishek Goswami

Reputation: 100

How to collect payment with default payment method in stripe subscription?

I am trying to subscribe the customer with multiple subscription having different intervals

first of all, I am creating a subscription, then using payment_intent in subscription object, I am rendering the payment_elements and asking users for the card details and confirmating payment.

now I want a user to subscribe to the other plans also without confirming or entering the payment details

FYI - The user knows at this time that the payment_methods and card details are being used for total how much money

I have created the other subscription using below code

let subs = {
    "customer": "cus_NWCqvdBhiQRQ2a",
    "items": [
        {
            "price_data": {
                "currency": "usd",
                "product": "prod_N8tG4peHRPUrsn",
                "recurring": { "interval": "month" },
                "unit_amount_decimal": "2150"
            },
            "quantity": 2
        }],
    "metadata": {
       
    }
}

Now the problem is that the invoice is failed and the subscription status is incomplete. How can I collect payment from the default attached payment method ?

Upvotes: 0

Views: 995

Answers (1)

soma
soma

Reputation: 2219

For this to work, you need to:

  1. Make sure the Customer has a default PaymentMethod set. If not, update the invoice_settings.default_payment_method property of the Customer object.
  2. Create the second Subscription with payment_behavior: allow_incomplete
  3. Check the subscription status. If it's active then great. If it's incomplete, it means the bank requested 3DS flow. In this case you need to ask the user to come back to your website/app and confirm the PaymentIntent of the first Invoice with confirmCardPayment to start the 3DS flow.

Upvotes: 2

Related Questions