#xfechx - prices and plans
1 messages ยท Page 1 of 1 (latest)
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?
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?
hmm
so I can use plans, for simplicity?
they have the same name
in which cases they would not be both present?
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
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
Do you have the ID of a price or subscription that you are looking at here?
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?
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.
ok
another question
how can I know in a subscription which payment method was used?
What event are you listening to for failed payments like this?
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
Here is the doc on how to integrate with that customer portal https://stripe.com/docs/billing/subscriptions/integrating-customer-portal
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
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
If you don't set a payment method on the customer or subscription, there won't be a default payment method.
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
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
Many different ways, but - can customers update their payment method on file by using a stripe hosted invoice url ?
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?
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?
๐ 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
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?
Can you be more specific here? I'm not fully understanding your question
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?
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?
I want to set it on a subscription specifically
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
Yes, if you want to that would also be an option
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?
Not necessarily - $0 invoices will still trigger an invoice.payment_succeeded event, but won't have a payment method
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;
That's not how you make an update request with the PHP library - Do you see the same here (https://stripe.com/docs/api/subscriptions/update?lang=php) ? You'd modify that and pass in 'default_payment_method' => $payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
can it be made like this?
$subscription_default_payment_method = \Stripe\Subscription::update($subscription_id, ['default_payment_method' => $payment_intent_payment_method], $connected_account);
The way you're setting $connected_account is wrong - have you taken a look at https://stripe.com/docs/connect/authentication#stripe-account-header
I use it like that in many many stripe calls
it contains:
$connected_account = array('stripe_account' => $event_json->account);
Ah, so $connected_account is itself an array - I assumed that was just a string with an account ID
then it looks fine
yes? even if it is the 'older' way to call stripe functions?
rather than:
$stripe = new \Stripe\StripeClient($secret_key, $connected_account);
then
Why don't you go ahead and try it out?
$subscription_default_payment_method = $stripe->subscriptions->update($subscription_id, ['default_payment_method' => $payment_intent_payment_method], $connected_account);
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)