#itzsky_checkout-event
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1261075326851743844
๐ Have more to share? Add details, code, screenshots, videos, etc. below.
Hi there
Hello, after i complete a charge for a subscription i can see this
evt_1PbUjAB4bznwKBcEfHsMeTQi
WEBHOOK URL
DATE
NEXT RETRY
โ
Failed
https://alonestudio.it/webhook
Jul 11, 11:40 PM
in an hour
Resend
More options
HTTP status code
400 (Bad Request)
Request to your endpoint
{
"id": "evt_1PbUjAB4bznwKBcEfHsMeTQi",
"object": "event",
"api_version": "2024-06-20",
"created": 1720734035,
"data": {
"object": {
"id": "in_1PbUj1B4bznwKBcEfz2Ki7Jx",
"object": "invoice",
"account_country": "AE",
See all 287 lines
Response
Stage 1
Thanks for sharing
Stage 1 it's here on my code
From what I can see, we're making a request to your webhook endpoint with the event payload and your endpiont is replying with a 400 response code and a body of Stage 1
That's the code i have on webhook.php
So invoice.payment_succeeded returns an invoice object, not a charge object
Yes
Which condition is returning the 400 in this case?
How can i know?
You'll need to add some logs after and/or within each if
That's the debug data sent to webhook
Okay, that's a different event from the one you shared earlier
Event evt_1PbUjhB4bznwKBcExf8xDXau was acknowledged by your endpoint. The payload in this case includes a subscription object
No, I don't think that's it. Both events are using the same API version (2024-06-20)
What do you mean by "working on another dashboard"?
On another stripe dashboard
i have same code and it's working fine
invoice.payment_succeeded
Resend
More options
Next retry
in an hour
Response
HTTP status code
400 (Bad Request)
Stage 1 Couldnt get subscription data
That should be the error: Couldnt get subscription data
i Switched on test mode
pi_3PbV0YB4bznwKBcE1eNGHrsJ
Are you still looking at evt_1PbUjAB4bznwKBcEfHsMeTQi or something else
The payment i made now is pi_3PbV0YB4bznwKBcE1eNGHrsJ
Okay, a different event altogether
You're looking at evt_1PbV0cB4bznwKBcE5X6RrXnx now
Did you change your code?
The only mention of "Couldnt get subscription data" in what you shared is a code comment
Okay, so working backwards in your code. You're looking at the event.data.object and attempting to set a value for subscription_id
You'll need to do a lot more debugging here
Can you log the value of $subscription_id?
Sure, let me check how can i log it
itzsky_checkout-event
2024-07-12 00:17:46 - djangy951@gmail.com : sub_1PbVIxB4bznwKBcEGv2ExGb3 : 100
2024-07-12 00:17:46 -
2024-07-12 00:17:46 - djangy951@gmail.com : 100
2024-07-12 00:17:47 - {"error":"Lead not found."}
Okay so with those logs, what do you need help with that isn't working exactly?
Thoose are the errors i am seeing on debug files
Looks like the subscription event is not triggering the webhook correctly
therfore if i cancel a subscription on stripe i can still see it active on my platform and viceversa
That prevents users that cancel subscriptions to rejoin the subscription later since the platform responds with "users is alredy subscribed"
Sure but you write the code as the developer. I'm taking over, I would like you to try and explain exactly what the issue is.
Like what is not happening that you expect to happen?
When i cancel the subscription on stripe it's not cancelling it on my platform
Okay, let's pick an exact Subscription id: how did you cancel it?
I am cancelling it through the stripe dashboard, subscription, cancel subscription
In this case you can see cus_QSQ9UG9bejJrt1
That is a Customer id. Please try and explain clearly what you need exactly so I can help you. It's important to take a few minutes to organize the information in a clear question.
Please share the exact Subscription id that you canceled, what you did in the Dashboard and what you see there. You can also check if the Subscription is canceled or not in the Dashboard.
Once you have all that information please respond in this thread with all the details in one message!
I need that when i cancel the subscription on stripe, this will cancel the subscription on my system.
The subscription id i cancelled it's: sub_1PbVIxB4bznwKBcEGv2ExGb3
As you can see on my database the subscription it's there
Okay so the Subscription is canceled and we (Stripe) created the relevant Event for it and you can view it in your Dashboard to self-serve easily here: https://dashboard.stripe.com/test/events/evt_1PbVTyB4bznwKBcEKk2sjSEQ
Right now your code is not responding to the Event properly. So that's what you need to debug next
Okay, the code that is not working should be on webhook.php?
Because this file is exaclty the same as another dashboard, the older one where i was not using inline charge for the trial fee.
I am trying to log more on webhook response now
Yeah I think that's your next step, add logs at the beginning of your WebhookEndpoint's code to understand if the request even reaches you
Ok let me try
I see the event on my stripe webhook log when i send it on stripe
so it's arriving on my server correctly
This are the logs:
Okay so the Event is received. Then what does your code do? Where is the exact code that handles that specific Event type?
It says that there is no subscription, Could not retrieve subscription data: No such subscription: 'sub_1PbVIxB4bznwKBcEGv2ExGb3'
The subscription is here on database
Perfect so now you have your bug ๐
(I'm looking in parallel)
Okay you are mixing up your API keys I think. The Subscription is created on account A but you are using the API key of a different account to retrieve it. You're even making the request in Live mode
all good, WebhookEndpoints are a pain to debug
I see ๐ฆ
Maybe test mode is not working properly on my platform, i remember my dev always doing tests on live mode before
oh god
you just shared your real API key publicly
Anyone on Discord can view this and use it. You will need to figure out urgently how to change/roll your API key
I deleted the message, but it's easy for anyone to build a bot to listen to all messages on Discord to find API keys like yours
I mean don't blur
Never, ever share API keys with anyone
I don't want to see your keys, even if blurred. I am telling you that you made a request with a Live Secret API key and that's the issue
Ok i made sure now that the keys are correct and in live mode
but they shou;dn't be in Live mode. That Subscription is in Test mode and so is the Event
I am making a new sub in live mode
with new live keys
now they should be all matching
let's see what happens
I mean you absolutely should not be ever doing any of this in Live mode when you are so lost with your code ๐
I know but i doubt at this point that the test mode is working on my platform
since by seeing the code i can tell you that the keys i set were both correct
before and also now
still my advice holds, doing all of this in Live mode is a huge mistake. But it's your own code/company so that's your decision
Can you check pi_3PbWPxB4bznwKBcE1Q1r5DX3?
evt_1PbWQ6B4bznwKBcENRJNstPU
Do you see any mistake now with api keys and webhook?
Because i paid and the webhook request failed
That's a PaymentIntent id and an Invoice Event. I'm sorry you're going way too fast and jumping many steps unfortunately
Your question for the past 2 hours is about Subscription cancelation. You should be able to have clear logs to debug this.
I think i can't cancel the subscription for this reason
if the payment event is not going through correctly on the webhook i will be never be able to cancel the sub correctly
That's why subscription does not exist
we need to understand why this webhook event after payment fails
Sure so next step is to debug that Event really. Add logs to your code and figure out which part fails
I should add logs on the wehbook.php file or on the payment.php file?
and wich logs should i add?
That's up to you. I'm sorry I can't write this all for you
You seem to have code that receives a specific invoice.payment_succeeded Event in your webhook handler's code. That code does "something" (no idea what) and it fails. So you want to add logs to that code to figure out which piece of the code is failing
The logs i added display: Response
Stage 1 Couldnt get subscription data
So the problem happens in this stage, it's not able to receive the data of the subscription, but i don't know how to fix it and why this is happening
What's the exact code for that section?
$subscription_id = $eventobj->subscription;
// is there any trial invoice items??
$trial_x1 = false;
$trial_x2 = false;
// is it 2nd original payment ??
if (isset($eventobj->lines->data[0]->metadata->trial) && isset($eventobj->lines->data[0]->metadata->order_id) && $eventobj->lines->data[0]->metadata->trial == true) {
$trial_x2 = true;
} else if (isset($eventobj->lines->data[0]->metadata->trial) && !isset($eventobj->lines->data[0]->metadata->order_id) && $eventobj->lines->data[0]->metadata->trial == true) {
$trial_x1 = true;
}
//
try {
$subscription = \Stripe\Subscription::retrieve($subscription_id);
} catch (\Exception $e) {
// Couldn't get subscription data
http_response_code(400);
echo "Couldnt get subscription data";
exit;
}
okay so how are you debugging this I don't see any real logs. I see echo but that can never work with WebhookEndpoints, you're not in a browser where you can look at the response.
Most PHP developers would use error_log() or log to a file on their server
I am trying to log all the steps on webhook now on files
okay that would help. So right before that \Stripe\Subscription::retrieve($subscription_id); write to the log/file exactly which Subscription you are retrieving
But I do think that you still have an API key issue but it's hard to say, your code does too much at once for each Event
My logs are displaying: Retrieving subscription with ID: sub_1PbWPxB4bznwKBcEgsDgoHwO
Do you see any problems so far?
Still there?
๐ Catching up here
Okie, can you confirm that you are using the Stripe Account acct_1PaKkBB4bznwKBcE ?
Yes
Please open Stripe Dashboard https://dashboard.stripe.com/test/apikeys and look at the Secret Key (don't share) and compare with the key you are using in your webhook code
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
I am using live keys, not test ones
Oh right, that's correct. And you are retrieving sub_1PbWPxB4bznwKBcEgsDgoHwO but still bumped into 404 not found?
Yes
Can you find that Get request in your request log? https://dashboard.stripe.com/logs?showIP=false&method[0]=get&path=%2Fv1%2Fsubscriptions%2F%3Aid
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.