#ahjaydog-customer-portal
1 messages ยท Page 1 of 1 (latest)
Hello ๐
Give me a moment to catch up and I'll respond as soon as possible ๐ thanks
sure no problem
Not seeing a property in the configuration that you can just set
Thinking of workarounds
ok
What if you listened to if event.type == 'invoice.payment_failed':
#if failed invoice event
#if statement for open invoice
#expand invoice on subscriptions
#if subscription status past_due
#delete / cancel subscription id
to sort of prevent an outstanding past due from being created
Otherwise my work around is not using the customer portal to cancel unless they pay their outstanding balance. But I'd rather just use the portal to do it if possible
I might be able to do something if they click the customer portal link.. deny them access unless they pay their outstanding balance links that I show on their profile page
But still.. I would love if you built this into portal as a setting or something
yeah like disable cancellation if there's an invoice past_due or something
yea exactly
it forces customers to pay and actually helps them not get a bigger outstanding balance over time
You want to cancel, then pay what you owe us first
Because the behavior now is they can just cancel while still having an outstanding balance then disappear forever while still having the outstanding balance
Hopefully you can submit that as an idea or something. Is there a way I could test for past due on the dashboard or programmatically?
When creating that commented webhook if that makes sense
I believe you can use test clocks to simulate this
meh i could have sworn there was another way to do it i have to check my notes
stripe.Invoice.finalize_invoice(
invoice_id
) ???
Not sure what I'm looking at ๐ค
Programmatically create an open invoice then finalize it
Just need to make it past due though
You could rather mark it for cancellation and handle cancellation using webhooks
by setting invoice_now property server-side
https://stripe.com/docs/api/subscriptions/cancel#cancel_subscription-invoice_now
wow sounds crazy but i am still confused by that. The names seem to trip me up
so update the subscription invoice_now stripe.Subscription.delete("sub_Et7Dzxz3Vs2zhg", invoice_now=True) ?
yup
How does it make it past due if you are cancelling it?
My bad for the confusion! I was suggesting a workaround. Instead of creating a past_due invoice, you could cancel the sub and prepare a final invoice.
hmm
hi codename_duchess
I don't know if I really like that workaround
All I want to do is create a past due invoice somehow programmatically or on the dashboard to test a webhook
Hi there. Taking over here. Give me a moment to catch up on context
np
Oh if you just want to test a webhook with that event you can use stripe trigger
With an invoice.updated event
ok
in the updated event i could make the status past_due?
I am using ngrok
stripe trigger invoice.updated ?
stripe trigger invoice.updated --override invoice:status.name=past_due ?
how do i specify the invoice id to do it on?
the test event sent then to a webhook?
Actually I don't know that for sure. You can try overriding the id
what would the command look like then?
What do you mean?
with overriding the id
stripe trigger invoice.updated --override in_1KPJmIIeTJrsS1reww9QeHgS:status=past_due ?
--override invoice:id=
I believe
and --override invoice:status=past_due
You can try
ok sure. I never used the stripe command line before. How do I install/use it?
stripe trigger invoice.updated --override invoice:id=in_1KPJmIIeTJrsS1reww9QeHgS --override invoice:status=past_due ?
Yeah
What was your command?
same as above
agh actually I think I know why this isn't working
I believe you can only override params that you can update: https://stripe.com/docs/api/invoices/update
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So id and status won't work
If you already have a past event id that was an invoice.updated event where the status was past_due, you can use the stripe resend command: https://stripe.com/docs/cli/events/resend
You can try. I don't think it will update status though
ok
I'd recommend using resend
i would have to look for an event id then
but what if i void the invoice later in a webhook for that event id?
This seems to use what already happened in the past and I might run out of them
I need a reliable way to make them
yes
webhook where if an invoice fails or becomes past due, cancel the subscription and change database membership to free
Oh ok. We discourage calling the stripe api in automated tests. Instead mock/stub data
Because it runs up unnecessary calls to the stripe api and contributes to rate limiting
For automated testing it's best practice to just mock data
Not make api calls
๐ Hopping in since @lean tide had to head out - can you be more specific? Are you just trying to create an invoice in test mode that's unpaid?
yes
or maybe it is the subscription unpaid, but the invoice past due i forget which one but i'd like to create both whatever the behavior is
Is there a reason you can't stub all this out like they suggested earlier? If you stub this all out you have complete control over what it looks like
with the command line?
they said to use the resend command line
but if my webhook cancels the resent event id subscription I have to somehow make another past due thing again
I need an easy way to make subs/invoices past due/unpaid
No, if you were stubbing out these events you wouldn't use resend/the command line - you write tests on your end that send a "mocked" version of the event to your endpoint
ok i really don'
don't understand this concept of mock and stub
guess ill go watch a youtube video or something
write tests, what kind of tests? That is what I am trying to do is somehow make this unpaid/past due through python or something
mocked meaning fake? I want to see the end result though as if I am cancelling the subscription on the dashboard but do it programmatically.
Let's back up - are you just trying to do a one-time test to make sure everything is working correctly or are you doing automated testing? Earlier you mentioned you wanted some automated testing, which is why we recommended stubbing/mocking out the events
I have this cron job where in the past I somehow did it
I don't remember how the heck I made the unpaid/past due or whatever to test each time i ran this cron job but somehow back then i asked here and it worked
I need a reliable to way recreate the past due/unpaid to test this cron job
but now instead of a cron job i want to use a webhook below with that pseudocode
I can write the webhook the same sort of way like the cron job but I don't want to wait days for something to become past due/unpaid
Like this code here is what I would do to make a new open invoice but to make it past due/unpaid is what I want to know
That second dpaste is like my starting point to make the bad invoices/subscriptions to then use for the cron job
You have a few options here:
- Mock out what the event should be and send that to your webhook for testing (This really is what we recommend if you're doing automated testing)
- Create a subscription with a 1 second trial - once the trial is over I believe it'll transition to a past_due state
- Use test clocks (https://stripe.com/docs/billing/testing/test-clocks) to simulate the what the transition to past_due will look like and get the subscription to the correct state
ooh i like #2
nice and easy let me try it
remind me of how an invoice and subscription becomes past due or unpaid? I just want to be sure what the flow looks like
so subs become past due and invoices become unpaid? Is that right? If so how do they get that way?
So with #2 I did this:
stripe.Subscription.create(
customer="cus_LE8glJJrVOJ5sV",
trial_end="1655832338",
items=[
{"price": "price_1HIoAVIeTJrsS1redUjVLESh"},
],
)
Subscription is now active after the trial and see a draft invoice
Do i finalize it?
It changed to open if I do
Ah, I forgot you'd have to wait for the one hour draft period after renewal... let me think for a minute
ok no worries
Hey there ๐ taking over for karbi. Give me a minute to get up to speed
sure thing
I think the best move here is to use test-clocks. This is exactly what they were designed for (e.g. #3)
ok
how would i set it up for this case?
I tried reading the docs but I guess I got stuck
Do you have a specific question about something you read in the docs? Are you getting blocked somewhere when you attempt to test?
let me see
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
So I set one up
Added a customer
started a subscription
Couldn't create subscriptionThe customer is missing a chargeable source
add 424242 as the source, created the sub
I see that I could advance the time
You may need to detach the source after the subscription is created
so that the invoice doesn't get paid
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Ah, sorry. Delete the card is better: https://stripe.com/docs/api/cards/delete
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
ok i see how this works now
that is useful lol
so this detects normal webhooks automatically?
It will trigger the associated webhooks as though the time had actually passed. Test Clocks are amazing
I got it to become past due which is awesome
so the customer id is different than the actual customer id?
and the retrying also applies to my billing settings like try every day or whatever with the smart retries?
so the customer id is different than the actual customer id?
I'm not sure what you're asking here. The Customer ID should remain the same throughout the Test Clock simulation
and the retrying also applies to my billing settings like try every day or whatever with the smart retries?
Correct
I have cus_Lv1Zquf85rMBke and cus_Lv1Zquf85rMBke
the first one is the test clock one. I reused the same email
That is really cool i like the test clocks a lot
Those IDs are identical. Did you mean to post a different one?
cus_LE8glJJrVOJ5sV
so the test clock makes a new customer id even if you reuse the same email?
You can have multiple customer objects with the same email.
I believe right now you have to create a new customer in order for the test clock to function. You cannot use an existing customer as far as I can tell
gotcha