#xfechx - prices and plans

1 messages ยท Page 1 of 1 (latest)

covert bison
#

Hello, what is your question?

viscid tangle
#

For naming a failed subscription payment (for an email notification)...

I am looking for the name inside the subscription.

What would be the best name to choose?

From the price, or from the plan?

covert bison
#

That is up to you, whichever you think is clearer for your customers. In API terms, either one should work, prices are the more recent API but they are backwards compatible with plans.

Also I believe that when both are present, they should have the same name. Are you seeing somewhere where they are different?

viscid tangle
#

hmm

#

so I can use plans, for simplicity?

#

they have the same name

#

in which cases they would not be both present?

covert bison
#

Use prices, if only one is going to be present, it would be the price. If I remember correctly, both price and plan will exist if you set the subscription up with a plan but just price will exist if you use price objects

viscid tangle
#

So how can I best retrieve a failed subscription payment name?

#

$invoice->lines->data[0]->price->nickname???

#

or $subscription->items->data[0]->price->nickname ?

#

I can't find the property name in price

covert bison
#

Do you have the ID of a price or subscription that you are looking at here?

viscid tangle
#

my question would be:

#

doesn't name necessarily appear?
Is name the same as nickname in price?

#

req_R2yTgEEgcrYsAM

#

my issue is which one should I choose?

#

for a notification for a subscription payment?

covert bison
#

Nickname on the price is the most modern way to check for this value. These fields all should be the same, so it would probably be easiest to pick that one.

viscid tangle
#

ok

#

another question

#

how can I know in a subscription which payment method was used?

covert bison
#

What event are you listening to for failed payments like this?

viscid tangle
#

invoice.payment_failed

#

also

#

how can I enable this:

#

Customers can update their payment information on a secure, Stripe-hosted page that you can customise with your brand colours and logo

covert bison
#

Looking in to the easiest way to see the payment method and will get back to you

#

For that event, you can check the default_payment_method field on the Invoice. That will have the payment method if the user used one, though keep in mind that these events can sometimes happen because of a lack of payment method

viscid tangle
#

But if it is a subscription, how can it lack a default payment method?

#

also, in this case, there is a default_payment_method: null

covert bison
#

If you don't set a payment method on the customer or subscription, there won't be a default payment method.

viscid tangle
#

with the stripe invoice hosted url

#

can I then get a payment from customer and save as a default payment method, for further charges?

#

Another question:

#

I would like to re-send this event to my server, how can I do this?

#

I know I can do this via the dashboard, but can I use the stripe terminal to do this, or can I do it with cURL

covert bison
#

Yes, it is possible to collect payment methods like that. How are you currently collecting them for your subscriptions?

#

You can use any of those three as long as the event was from less than 30 days ago

viscid tangle
#

Many different ways, but - can customers update their payment method on file by using a stripe hosted invoice url ?

covert bison
#

I don't think that that happens automatically. I am a bit too busy to test this myself at the moment, can you try making a payment like this and see if anything updates?

viscid tangle
#

I would like to know how to do it actually

#

So if they pay with a different card, will this card be saved as default, or how do I then set it as default?

solemn arrow
#

๐Ÿ‘‹ hopping in since @covert bison has to head out soon

#

With the hosted invoice page if they pay with a different card, it is NOT automatically set as the default - you'd have to listen for the payment_method.attached to know that a new payment method was added to the customer, and then write code to set it as invoice_settings.default_payment_method on the customer

viscid tangle
#

ok

#

if I try $subscription->lines->data[0]->price->nickname; and it is an 'older' invoice that only has $subscription->plan->name What will happen?

solemn arrow
#

Can you be more specific here? I'm not fully understanding your question

viscid tangle
#

sorry, coming back to payment_method.attached

#

what do you mean by invoice_settings.default_payment_method

#

do I need to retrieve the invoice from payment_method.attached?

#

I can see that payment_method object doesn't have many options, how can I listen to that and update that specific subscription/invoice to use that new payment method?

solemn arrow
#

You asked how to change the default payment method on the customer, which is set at invoice_settings.default_payment_method (https://stripe.com/docs/api/customers/create#create_customer-invoice_settings-default_payment_method). When a new Payment Method has been created and attached to the customer through the hosted invoice page (which you'd listen for through the payment_method.attached webhook event) you'd take the Payment Method ID from there and set it to invoice_settings.default_payment_method

#

If you want to set the default on the Subscription instead of the Customer that's a different story - is that what you want?

viscid tangle
#

I want to set it on a subscription specifically

solemn arrow
#

Gotcha, then instead you'd probably have to listen for the invoice.paid webhook event, retrieve Payment Intent associated with the Invoice to get the Payment Method that was used to pay it, and then update the Subscription to set default_payment_method

viscid tangle
#

ok, will try this

#

can I instead use invoice.payment_succeded?

solemn arrow
#

Yes, if you want to that would also be an option

viscid tangle
#

so then it would be:

#

$payment_method = $payment_intent->payment_method

#

if I am taking it from an invoice.payment_succeded then it will ALWAYS have a payment_method, right?

solemn arrow
#

Not necessarily - $0 invoices will still trigger an invoice.payment_succeeded event, but won't have a payment method

viscid tangle
#

I see

#

how can I set the default payment method on the subscription

#

is it through a method? or like this:

#

$subscription->default_payment_method = $payment_method;

solemn arrow
viscid tangle
#

can it be made like this?

#

$subscription_default_payment_method = \Stripe\Subscription::update($subscription_id, ['default_payment_method' => $payment_intent_payment_method], $connected_account);

solemn arrow
viscid tangle
#

I use it like that in many many stripe calls

#

it contains:

#

$connected_account = array('stripe_account' => $event_json->account);

solemn arrow
#

Ah, so $connected_account is itself an array - I assumed that was just a string with an account ID

#

then it looks fine

viscid tangle
#

yes? even if it is the 'older' way to call stripe functions?

#

rather than:

#

$stripe = new \Stripe\StripeClient($secret_key, $connected_account);

#

then

solemn arrow
#

Why don't you go ahead and try it out?

viscid tangle
#

$subscription_default_payment_method = $stripe->subscriptions->update($subscription_id, ['default_payment_method' => $payment_intent_payment_method], $connected_account);

solemn arrow
#

Right now you're at a point where you understand everything your code needs to do, and you have code written to do it - so next best thing to do is just try running the code and see if it works ๐Ÿ™‚

#

You'll have way more luck debugging things just by running through things (we can spot check, but it's always possible for us to miss something and we don't know what your integration relies on)

viscid tangle
#

ok, how can I trigger a invoice.payment_failed so that I can update the invoice payment?

#

can it be made from a checkout session (subscription) with a card that fails right afterwards?