#Vinz - Webhook
1 messages ยท Page 1 of 1 (latest)
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
to simulate a downgrade
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
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
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?
Weird. Do you have the Subscription ID so I could review it?
sub_1LJJY4IP6C7BiREFadNYLWbA
Thanks, looking
Okay and you are providing the actual customer ID when you make the call to stripe trigger?
yep. Safe to write it down here ?
Yeah, without your account keys no one can mess with them
stripe trigger customer.subscription.updated --override subscription:customer=cus_M1MGAAjga37ItL --override subscription:items.data.price.product=prod_Ki1ltkozyFPugI
up ๐
up ?
my bad sorry
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
OK so I can override the id? Otherwise how can the cli know which subs I want to update
Yes, you can specify the the subscription ID
how?
On my dashboard it does
I see Sub: sub_1LJJY4IP6C7BiREFadNYLWbA, is associated with Customer cu_1LJJY4IP6C7BiREFke7ZJQit
sub_1LJJY4IP6C7BiREFadNYLWbA is for customer cus_M1MGAAjga37ItL on test mode of course
but you're right cu_1LJJY4IP6C7BiREFke7ZJQit gives the same customer.
weird: diff between cu_ and cus_ ?
Hmmm...just different tokens
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"
}
}
so many thread to answer you guys are octopuss
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?
seems it worked! are you able to explain why?
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
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?
The object is a subscription, not a customer
https://stripe.com/docs/api/events/types#event_types-customer.subscription.updated
well for a elif event_type == 'customer.created': object is a customer isn't it?
Yes. We list what the object is for every one of the events in our API reference doc
https://stripe.com/docs/api/events/types#event_types-customer.created
For customer.discount.created the object is a discount
So what can I do. I don't want to wait for one month to simulate my downgrade and check that all is OK
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
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
Okay so you are not changing the price, you just want to simulate the recurring invoice for this subscription?
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...
No worries.
stripe trigger customer.subscription.updated --add subscription:customer=cus_M1MGAAjga37ItL --add subscription:id=sub_1LJJY4IP6C7BiREFadNYLWbA
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"
}
}
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
OKAY. how to specify the subs?
You did already, --add subscrption:id=sub_1LJJY4IP6C7BiREFadNYLWbA
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
Try using --override
idem
stripe trigger customer.subscription.updated --override subscription:id=sub_1LJJY4IP6C7BiREFadNYLWbA
And you get the same response?
yep
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"
}
}
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?
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
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
๐
hi
To summarize, you want to trigger a customer.subscription.updated event and replace the customer/sub/price?
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.
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
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
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"
}
}
stripe trigger customer.subscription.updated --override subscription:customer=cus_M1MGAAjga37ItL --override subscription:items.data[0].price.currency='eur'
?
nope
No I think you need to override the currency on the customer itself
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
Did the above work?
see here
I've been on it for about 2.5 hours
What doesn't work for the webhook?
You triggered the event you desired, right?
the customer_id receved is not the one specified in the event triggered
Oh okay so it didn't work
The above didn't actually override the customer ID at all?
Huh you are right
doesn't seem so since I print in my webhook the customer_id = subscription['customer']
I'm having a walk away from computer but still waiting for your answer
thank you so much
any idea @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).
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
Details on test clocks here: https://stripe.com/docs/billing/testing/test-clocks
Assuming you already saw that but figured I would re-link
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
Glad that worked. I need to step away. @worthy dome will be able to help you further!
Hey there ๐ , catching up on this thread...
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
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?
Well it worked with the clock and my custom code:
if plan < company.plan:
webhook_timestamp = subscription['current_period_start']
if settings.DEBUG:
today = datetime.datetime.fromtimestamp(webhook_timestamp).date()
print(today)
else:
today = datetime.date.today()
I've added today = datetime.datetime.fromtimestamp(webhook_timestamp).date() to deal with the clock time
Ah I see, a billing block event. Glad you got it working!
Anything you are still trying to figure out with this flow?
Nice! Have a good weekend and all that