#ahjaydog-customer-portal

1 messages ยท Page 1 of 1 (latest)

full robin
#

Hello ๐Ÿ‘‹
Give me a moment to catch up and I'll respond as soon as possible ๐Ÿ™‚ thanks

west ember
#

sure no problem

full robin
#

Not seeing a property in the configuration that you can just set
Thinking of workarounds

west ember
#

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

full robin
#

yeah like disable cancellation if there's an invoice past_due or something

west ember
#

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

full robin
#

I believe you can use test clocks to simulate this

west ember
#

meh i could have sworn there was another way to do it i have to check my notes

#

stripe.Invoice.finalize_invoice(
invoice_id
) ???

full robin
#

Not sure what I'm looking at ๐Ÿค”

west ember
#

Programmatically create an open invoice then finalize it

#

Just need to make it past due though

full robin
west ember
#

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) ?

full robin
#

yup

west ember
#

How does it make it past due if you are cancelling it?

full robin
#

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.

west ember
#

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

lean tide
#

Hi there. Taking over here. Give me a moment to catch up on context

west ember
#

np

lean tide
#

Oh if you just want to test a webhook with that event you can use stripe trigger

#

With an invoice.updated event

west ember
#

ok

#

in the updated event i could make the status past_due?

#

I am using ngrok

#

stripe trigger invoice.updated ?

lean tide
#

yup

west ember
#

stripe trigger invoice.updated --override invoice:status.name=past_due ?

#

how do i specify the invoice id to do it on?

lean tide
#

You can't

#

It generates a test event

west ember
#

the test event sent then to a webhook?

lean tide
#

Actually I don't know that for sure. You can try overriding the id

west ember
#

what would the command look like then?

lean tide
#

What do you mean?

west ember
#

with overriding the id

#

stripe trigger invoice.updated --override in_1KPJmIIeTJrsS1reww9QeHgS:status=past_due ?

lean tide
#

--override invoice:id=

#

I believe

#

and --override invoice:status=past_due

#

You can try

west ember
#

ok sure. I never used the stripe command line before. How do I install/use it?

lean tide
west ember
#

stripe trigger invoice.updated --override invoice:id=in_1KPJmIIeTJrsS1reww9QeHgS --override invoice:status=past_due ?

lean tide
#

Yeah

west ember
#

ok i tried that and this happened

#

"Received unknown parameters: status, id"

lean tide
#

What was your command?

west ember
#

same as above

lean tide
#

agh actually I think I know why this isn't working

#

So id and status won't work

west ember
#

hmm ok

#

what if i made the due_date a date in the past?

lean tide
#

You can try. I don't think it will update status though

west ember
#

ok

lean tide
#

I'd recommend using resend

west ember
#

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

lean tide
#

What's your end goal?

#

This is for automated testing?

west ember
#

yes

#

webhook where if an invoice fails or becomes past due, cancel the subscription and change database membership to free

lean tide
#

Oh ok. We discourage calling the stripe api in automated tests. Instead mock/stub data

west ember
#

what is mock/stub data?

#

Why is it discouraged?

lean tide
#

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

west ember
#

ok

#

How about making an unpaid invoice? Is there a way to do that?

silk shoal
#

๐Ÿ‘‹ 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?

west ember
#

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

silk shoal
#

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

west ember
#

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

silk shoal
#

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

west ember
#

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.

silk shoal
#

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

west ember
#

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

silk shoal
#

You have a few options here:

  1. 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)
  2. Create a subscription with a 1 second trial - once the trial is over I believe it'll transition to a past_due state
  3. 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
west ember
#

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

silk shoal
#

Ah, I forgot you'd have to wait for the one hour draft period after renewal... let me think for a minute

west ember
#

ok no worries

lyric panther
#

Hey there ๐Ÿ‘‹ taking over for karbi. Give me a minute to get up to speed

west ember
#

sure thing

lyric panther
#

I think the best move here is to use test-clocks. This is exactly what they were designed for (e.g. #3)

west ember
#

ok

#

how would i set it up for this case?

#

I tried reading the docs but I guess I got stuck

lyric panther
#

Do you have a specific question about something you read in the docs? Are you getting blocked somewhere when you attempt to test?

west ember
#

let me see

#

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

lyric panther
#

You may need to detach the source after the subscription is created

#

so that the invoice doesn't get paid

west ember
#

oh

#

how do i do that

lyric panther
west ember
#

customer under the test clock?

#

deelete payment method?

lyric panther
west ember
#

ok i see how this works now

#

that is useful lol

#

so this detects normal webhooks automatically?

lyric panther
#

It will trigger the associated webhooks as though the time had actually passed. Test Clocks are amazing

west ember
#

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?

lyric panther
#

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

west ember
#

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

lyric panther
#

Those IDs are identical. Did you mean to post a different one?

west ember
#

cus_LE8glJJrVOJ5sV

#

so the test clock makes a new customer id even if you reuse the same email?

lyric panther
#

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

west ember
#

gotcha