#sergixel04

1 messages · Page 1 of 1 (latest)

crimson magnetBOT
#

Hello sergixel04, we'll be with you shortly! Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
sergixel04, 1 hour ago, 13 messages
sergixel04, 2 days ago, 23 messages
sergixel04, 5 days ago, 37 messages
sergixel04, 5 days ago, 78 messages

chilly sigil
#
$createdSubscription = $stripe->subscriptions->create([
                'customer' => $user->stripe_id,
                'items' => [
                    ['price' => $priceId],
                ],
                'description' => 'Extra business: ' . $request->name,
            ]);

            if ($createdSubscription->status !== 'active') {
                return back()->with('error', 'The payment could not be completed. Please try again or contact support.');
            }
rancid vigil
#

Where did you find this code snippet?

chilly sigil
#

Got payment_intent.canceled, but the customer has a payment method available

#

I did it

rancid vigil
#

Could you please share an example Subscription ID?

chilly sigil
#

Can I send u pi_id?

The subscription was not created, it was canceled

rancid vigil
#

Ok

#

Could you please copy and paste the ID here.

chilly sigil
#

Sure! pi_3O5SemKYINwhn6n419QHa8QH

#

But don't understand this error. Because the user has a payment source

#

cus_OtF3QA4Ab2HJNn

#

Even this test customer has one subscription. Just trying to add another different subscription to this customer

rancid vigil
#

Sources is a legacy concept, you need to either set Customer.invoice_settings.default_payment_method, or set Subscription.default_payment_method when creating it.

chilly sigil
#

the problem is that the first subscription is always using Stripe Checkout interface, don't know how to handle to automatically set the card the user used to default payment method

#

I think a solution maybe is, in this code, to detect if a user has a payment method, if not, catch every payment source, and the first one select it as default payment method

#

Do you know how can I get every payment source of a user?

And how to set a default payment method?

rancid vigil
crimson magnetBOT
chilly sigil
#

When you register in the SaaS you have to suscribe for an acount (first sub).

If u want more accounts, you suscribe for more

rancid vigil
chilly sigil
#

It has to be independent subscriptions and invoices. So if a user wants 8 accounts, there is going to be a main subscription and 7 other subscriptions

#

But don't know why I am getting that error. In the past, I had it with subscription quantities, and when updating the subscription and charging I didn't get any error of payment intent

oak flume
#

👋 stepping in as vanya needs to step away

#

When you create a Subscription with Checkout, that sets the default_payment_method on the Subscription itself. You are asking how to then set this PaymentMethod as the Customer's default PM overall so it is used for other Subscriptions?

chilly sigil
#

yes!

oak flume
#

So it sounds like what you mostly want to do in that case is listen for checkout.session.completed and then grab the PaymentMethod that is associated with that Checkout Session and update the Customer to set the invoice_settings.default_payment_method

chilly sigil
#

which field in checkout.session.completed webhook is the default payment method?

#

Well, I mean the payment inetntion to make it default

oak flume
#

You can retrieve the Checkout Session and expand the Subscription

#

To see the PaymentMethod that was set as the default_payment_method on the Subscription

chilly sigil
#

what API I have to use to do that?

For example I have this checkout sesssion id (not sure if I can share this) cs_test_b14DllO9WoghxJqsE5UKdpJd8i92aMIFfDSUoUfVmGLJSEZh5m7eMYqEZW

oak flume
#

Yes it is fine to share object IDs. They are useless without your secret key

chilly sigil
#

Thank you. Alright I just see a problem and the checkout.session.completed the payment_intent ID is null. The response I am looking at, is the one of the first subscription I told you (with Stripe Checkout). Here it is a part of it:

  "mode": "subscription",
  "payment_intent": null,
  "payment_link": null,
  "payment_method_collection": "always",
  "payment_method_configuration_details": null,
  "payment_method_options": null,
  "payment_method_types": [
    "card"
  ],
  "payment_status": "paid",
  "phone_number_collection": {
    "enabled": false
  },
  "recovered_from": null,
  "setup_intent": null,
  "shipping": null,
  "shipping_address_collection": null,
  "shipping_options": [
  ],
  "shipping_rate": null,
  "status": "complete",
  "submit_type": null,
  "subscription": "sub_1O5SZsKYINwhn6n4ijoOswXY",
oak flume
#

Yep so see how it has a Subscription ID?

#

When you retrieve the Checkout Session you want to use expand: ['subscription']

#

Then instead of just seeing the ID there you will see the entire Subscription object

chilly sigil
#
return $stripe->checkout->sessions->retrieve(
            'cs_test_b14DllO9WoghxJqsE5UKdpJd8i92aMIFfDSUoUfVmGLJSEZh5m7eMYqEZW',
            ['expand' => ['subscription']]
        );
#
"subscription": {
"id": "sub_1O5SZsKYINwhn6n4ijoOswXY",
"object": "subscription",
"application": null,
"application_fee_percent": null,
"automatic_tax": {
"enabled": false
},
"billing_cycle_anchor": 1698322940,
"billing_thresholds": null,
"cancel_at": null,
"cancel_at_period_end": false,
"canceled_at": null,
"cancellation_details": {
"comment": null,
"feedback": null,
"reason": null
},
"collection_method": "charge_automatically",
"created": 1698322940,
"currency": "eur",
"current_period_end": 1701001340,
"current_period_start": 1698322940,
"customer": "cus_OtF3QA4Ab2HJNn",
"days_until_due": null,
"default_payment_method": "pm_1O5SZrKYINwhn6n4AWSKC8WM",
"default_source": null,
#

Alright I think there it is. Now I would have to take that default payment method and use establish it as defauly payment method of user right, so other subscription will use it too?

oak flume
#

Yep

chilly sigil
#
$checkoutSession = $stripe->checkout->sessions->retrieve(
            'cs_test_b14DllO9WoghxJqsE5UKdpJd8i92aMIFfDSUoUfVmGLJSEZh5m7eMYqEZW',
            ['expand' => ['subscription']]
        );

        $defaultPaymentMethod = $checkoutSession['subscription']['default_payment_method'];

        $stripe->customers->update(
            'cus_Is8yXZukeWcRTO',
            ['invoice_settings' => ['default_payment_method' => $defaultPaymentMethod]]
          );

Like this?

oak flume
#

Yep that looks right to me

#

Give it a test

chilly sigil
#

I will test it, thank you very very much @oak flume !