#Vinz - Webhook

1 messages ยท Page 1 of 1 (latest)

worldly basin
#

Hi ๐Ÿ‘‹

#

What I do is stripe trigger customer.subscription.updated --override subscription:customer=cus_M1M --override subscription:items.data.price.product=prod_Ki1

#

Quoting to keep this all together

dull rose
#

to simulate a downgrade

worldly basin
#

Okay

#

So what are you experiencing when you do this?

#

sorry last time I've spoke to your teams was on irc channel
Yeah we find threading makes conversations easier to follow

dull rose
#
Setting up fixture for: customer
Running fixture for: customer
Setting up fixture for: plan
Running fixture for: plan
Setting up fixture for: subscription
Running fixture for: subscription
Trigger failed: Request failed, status=400, body={
  "error": {
    "message": "You cannot combine currencies on a single customer. This customer has had a subscription, coupon, or invoice item with currency eur",
    "type": "invalid_request_error"
  }
}
#

What I'd like is to fire the correct event in the webhook locally

worldly basin
#

Okay os it seems like the is a currency cross between the Sub, Product, and the Customer.

#

What is the currency of the product you are downgrading to?

dull rose
#

all is in euros

#

eur

worldly basin
#

Weird. Do you have the Subscription ID so I could review it?

dull rose
#

sub_1LJJY4IP6C7BiREFadNYLWbA

worldly basin
#

Thanks, looking

#

Okay and you are providing the actual customer ID when you make the call to stripe trigger?

dull rose
#

yep. Safe to write it down here ?

worldly basin
#

Yeah, without your account keys no one can mess with them

dull rose
#

stripe trigger customer.subscription.updated --override subscription:customer=cus_M1MGAAjga37ItL --override subscription:items.data.price.product=prod_Ki1ltkozyFPugI

#

up ๐Ÿ™‚

worldly basin
#

up ?

dull rose
#

my bad sorry

worldly basin
#

Okay so one thing that jumps out at me. You cannot change the Customer on a subscription.update

#

Subscriptions are Customer record specific

#

The customer currently associated with the Subscription ID you provided does not match the customer ID you just shared

dull rose
#

OK so I can override the id? Otherwise how can the cli know which subs I want to update

worldly basin
#

Yes, you can specify the the subscription ID

worldly basin
#

I see Sub: sub_1LJJY4IP6C7BiREFadNYLWbA, is associated with Customer cu_1LJJY4IP6C7BiREFke7ZJQit

dull rose
#

sub_1LJJY4IP6C7BiREFadNYLWbA is for customer cus_M1MGAAjga37ItL on test mode of course

dull rose
#

weird: diff between cu_ and cus_ ?

worldly basin
#

Hmmm...just different tokens

dull rose
#

anyway the CLI is not happy:

Trigger failed: Request failed, status=404, body={
  "error": {
    "code": "resource_missing",
    "doc_url": "https://stripe.com/docs/error-codes/resource-missing",
    "message": "No such customer: 'cu_1LJJY4IP6C7BiREFke7ZJQit'",
    "param": "customer",
    "type": "invalid_request_error"
  }
}
dull rose
worldly basin
#

It's a lot sometimes.

#

So yeah, sorry the cu_ token is internal. I apologize for the confusion.

#

Okay, wait a sec. What if you use the stripe trigger command and use the --add flag to specify customer ID? Rather than subscirption.customer?

dull rose
#

seems it worked! are you able to explain why?

worldly basin
#

Yeah, the point of reference for the event triggered is the Customer object. So when you trigger it creates a new customer unless you specify which one to use.

#

The CLI starts with the customer, then creates a subscription, then performs the update.

#

So you first provide the customer ID, then the subscription, and finally the price you want to update the subscription with

dull rose
#

Well now the CLI gives no error but my webhook can not find the customer:
company = User.objects.get(email=customer_email).company

#

with customer_email = event['data']['object']['email']

#

where can I find the doc for --add flag?

worldly basin
dull rose
#

well for a elif event_type == 'customer.created': object is a customer isn't it?

worldly basin
#

For customer.discount.created the object is a discount

dull rose
#

So what can I do. I don't want to wait for one month to simulate my downgrade and check that all is OK

worldly basin
#

well you just said the CLI works now. Or did I misunderstand you?

#

Your webhook listener code needs to identify the different event types and be prepared to handle the different records that will be returned in the data.object parameter

dull rose
#

not a misunderstanding but my webhook doesnt answer well. I don't understand what the CLI did. In dev mode it works, in production as well but I'm coding new features and whant to test

#

customer: cus_M1MGAAjga37ItL
subs: sub_1LJJY4IP6C7BiREFadNYLWbA
price: price_1K2bhiIP6C7BiREFaFzDgTr5

want to simulate a renewal of this price in a month

worldly basin
#

Okay so you are not changing the price, you just want to simulate the recurring invoice for this subscription?

dull rose
#

well for now yes.

#

Despite I trigger

stripe trigger customer.subscription.updated --add subscription:customer=cus_M1MGAAjga37ItL 
#

when I print(f"customer_id {customer_id}") in my webhook

#

it print

customer_id cus_M1NZotLzDq3NN4````
#

which is why it does not work

#

cannot understand properly the trigger and add. Sorry...

worldly basin
#

No worries.

dull rose
#

returns :

Trigger failed: Request failed, status=400, body={
  "error": {
    "code": "parameter_unknown",
    "doc_url": "https://stripe.com/docs/error-codes/parameter-unknown",
    "message": "Received unknown parameter: id",
    "param": "id",
    "type": "invalid_request_error"
  }
}
worldly basin
#

Okay so my first thought is this. The subscription you are providing already has a customer associated with it. So you should not be specifying the customer if you are specifying the subscription

dull rose
#

OKAY. how to specify the subs?

worldly basin
#

You did already, --add subscrption:id=sub_1LJJY4IP6C7BiREFadNYLWbA

dull rose
#

gives an error
Trigger failed: Request failed, status=400, body={
"error": {
"code": "parameter_unknown",
"doc_url": "https://stripe.com/docs/error-codes/parameter-unknown",
"message": "Received unknown parameter: id",
"param": "id",
"type": "invalid_request_error"
}
}

#

stripe trigger customer.subscription.updated --add subscription:id=sub_1LJJY4IP6C7BiREFadNYLWbA

worldly basin
#

Try using --override

dull rose
#

idem

#

stripe trigger customer.subscription.updated --override subscription:id=sub_1LJJY4IP6C7BiREFadNYLWbA

worldly basin
#

And you get the same response?

dull rose
#

yep

worldly basin
#

Okay. I know this is kind of grasping at straws but what if you specified customer.subscripition=sub_1LJJY4IP6C7BiREFadNYLWbA or even just subscription=sub_1LJJY4IP6C7BiREFadNYLWbA?

dull rose
#

Yep, I've tried it. gives :

goroutine 1 [running]:
github.com/stripe/stripe-cli/pkg/fixtures.buildRewrites({0xc0002af7c0, 0x1, 0x132d59e}, 0x0)
        /Users/runner/work/stripe-cli/stripe-cli/pkg/fixtures/fixtures.go:377 +0x5ab
github.com/stripe/stripe-cli/pkg/fixtures.(*Fixture).Add(0xc000142630, {0xc0002af7c0, 0x1, 0x1})
        /Users/runner/work/stripe-cli/stripe-cli/pkg/fixtures/fixtures.go:168 +0x7e
github.com/stripe/stripe-cli/pkg/fixtures.NewFixtureFromFile({0x1b09e60, 0x20d8540}, {0xc000965200, 0x6b}, {0x0, 0x0}, {0x1920a07, 0x16}, {0x1937fdc, 0x2b}, ...)
        /Users/runner/work/stripe-cli/stripe-cli/pkg/fixtures/fixtures.go:103 +0x2d2
github.com/stripe/stripe-cli/pkg/fixtures.BuildFromFixtureFile({0x1b09e60, 0x20d8540}, {0xc000965200, 0xc000965200}, {0x0, 0xc0001436b0}, {0x1920a07, 0xa}, {0x1937fdc, 0x2b}, ...)
        /Users/runner/work/stripe-cli/stripe-cli/pkg/fixtures/triggers.go:76 +0x108
github.com/stripe/stripe-cli/pkg/fixtures.Trigger({0x1af5140, 0xc0008061e0}, {0x206724117, 0x1}, {0x0, 0x0}, {0x1920a07, 0x16}, {0xc000965200, 0x6b}, ...)
        /Users/runner/work/stripe-cli/stripe-cli/pkg/fixtures/triggers.go:139 +0x2c5
#

for the second option

#

maybe I need to update my CLI

#

upddate in progress. Hope I've not bother you with an old CLI

worldly basin
#

I've got to step away but my colleague @snow whale will be able to provide additional support from here.
๐Ÿคž the update resolves the issue

snow whale
#

๐Ÿ‘‹

dull rose
#

hi

snow whale
#

To summarize, you want to trigger a customer.subscription.updated event and replace the customer/sub/price?

dull rose
#

yep

#

with existing customer to avoid waiting one month to see the result

snow whale
#

Gotcha. Have you looked into using test clocks? That is the other route here. These CLI fixtures are a bit tricky for how to handle this exactly. Give me a moment to check on how to do this.

dull rose
#

stripe trigger customer.subscription.updated --add subscription:customer.id=cus_M1MGAAjga37ItL gives no error but wy webhook print the client id : customer_id cus_M1Nv1ZKP7MSvPe

#

๐Ÿ˜ญ

#

I've had a look a clocks but it does not offer to test with existing test customers

snow whale
#

Okay let's start with stripe trigger customer.subscription.updated --override subscription:customer=cus_M1MGAAjga37ItL

#

That should work

#

Wait

#

Wrong

#

Let me edit

#

No ID

#

There edited

#

Try that

dull rose
#

yep, result:

Setting up fixture for: customer
Running fixture for: customer
Setting up fixture for: plan
Running fixture for: plan
Setting up fixture for: subscription
Running fixture for: subscription
Trigger failed: Request failed, status=400, body={
  "error": {
    "message": "You cannot combine currencies on a single customer. This customer has had a subscription, coupon, or invoice item with currency eur",
    "type": "invalid_request_error"
  }
}
snow whale
#

Okay progress, but ugh!

#

How to override that currency....

#

One sec

dull rose
#

stripe trigger customer.subscription.updated --override subscription:customer=cus_M1MGAAjga37ItL --override subscription:items.data[0].price.currency='eur'

#

?

#

nope

snow whale
#

No I think you need to override the currency on the customer itself

dull rose
#

wooof you're right!!

#

but still

#

my webhook print customer_id cus_M1O4VIvepxmLLi after trigerring stripe trigger customer.subscription.updated --override subscription:customer=cus_M1MGAAjga37ItL --override subscription:customer.currency="eur"

#

and when I test locally, my dev mode webhooks on my server is flooded with requests. Bit of anoying but it's an other matter

snow whale
#

Did the above work?

dull rose
#

from the cli point of view yes.

#

from the webhook nope

dull rose
#

I've been on it for about 2.5 hours

snow whale
#

You triggered the event you desired, right?

dull rose
#

the customer_id receved is not the one specified in the event triggered

snow whale
#

Oh okay so it didn't work

#

The above didn't actually override the customer ID at all?

#

Huh you are right

dull rose
#

doesn't seem so since I print in my webhook the customer_id = subscription['customer']

snow whale
#

I just tested on mine

#

And it doesn't override.

#

Weird

#

Let me look further

dull rose
#

I'm having a walk away from computer but still waiting for your answer

#

thank you so much

dull rose
#

any idea @snow whale ?

snow whale
#

Sorry still digging with some colleagues

#

Okay so the consensus is actually that the subscription.update API doesn't accept a Customer ID as a parameter, so it follows that you can't trigger a Subscription update using a Customer on your account. We believe we should be throwing an error here when you attempt to do this but we aren't.

#

But overall it seems like this isn't possible. I'm going to file a ticket internally to get this looked at further

#

To see if we can add this functionality or at least improve the experience around it (we should be providing a clear error if it isn't possible).

dull rose
#

thank you

#

too bad

#

and with the clock? is it possible to fix an existing customer?

snow whale
#

No, you would recreate your customer/sub to use test clocks

#

Can't add a test clock to an existing customer

#

But that still is the best way to test this imo

#

Assuming you already saw that but figured I would re-link

dull rose
#

brrraaa it works very well!

#

Simple question @snow whale I use a datefield in my db to offer a subscription higher than the one the user pay for.

#

maybe all that is userless and there is a stripe feature to do so

#

in the dashboard

#

offer a product for a certain period of time

snow whale
#

Glad that worked. I need to step away. @worthy dome will be able to help you further!

worthy dome
#

Hey there ๐Ÿ‘‹ , catching up on this thread...

dull rose
#

Hi.

#

I have 3 plans. 1, 2, 3.

#

I want to offer a plan 3 to a customer each month

#

he pays for plan 2.

#

I have added a datefield attr in db: plan_offered_until

#

and in webhook, if today is before plan_offered_until do nothing

#

if today is after plan_offered_until : change plan accordingly to stripe webhook received event

#

is there an easier way to cope with in stripe dashboard ?

#

I'm a bit confused with coupon. I don't really understand how they work

worthy dome
#

Unfortunately I don't think we do scheduled product availability like that. You will need you own custom code like you already have for this.

#

To clarify, which webhook event are you listening to where you check plan_offered_until?

dull rose
worthy dome
#

Ah I see, a billing block event. Glad you got it working!

#

Anything you are still trying to figure out with this flow?

dull rose
#

Nope. I'm all set.

#

Thanks

worthy dome
#

Nice! Have a good weekend and all that