#itzsky_checkout-event

1 messages ยท Page 1 of 1 (latest)

obtuse shuttleBOT
#

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

glossy peak
#

Hi there

turbid wharf
#

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

glossy peak
#

Thanks for sharing

turbid wharf
#

Stage 1 it's here on my code

glossy peak
#

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

turbid wharf
glossy peak
#

So invoice.payment_succeeded returns an invoice object, not a charge object

turbid wharf
#

Yes

glossy peak
#

Which condition is returning the 400 in this case?

turbid wharf
#

How can i know?

glossy peak
#

You'll need to add some logs after and/or within each if

turbid wharf
glossy peak
#

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

turbid wharf
#

Maybe it's the api version?

#

Because same code was working on another dashboard

glossy peak
#

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

turbid wharf
#

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

glossy peak
#

Are you still looking at evt_1PbUjAB4bznwKBcEfHsMeTQi or something else

turbid wharf
#

The payment i made now is pi_3PbV0YB4bznwKBcE1eNGHrsJ

glossy peak
#

Okay, a different event altogether

#

You're looking at evt_1PbV0cB4bznwKBcE5X6RrXnx now

turbid wharf
#

evt_1PbV0cB4bznwKBcE5X6RrXnx

#

yes

glossy peak
#

Did you change your code?

#

The only mention of "Couldnt get subscription data" in what you shared is a code comment

turbid wharf
#

Yes i added the echo logs on the errors

glossy peak
#

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?

turbid wharf
#

Sure, let me check how can i log it

obtuse shuttleBOT
verbal nacelle
#

itzsky_checkout-event

turbid wharf
#

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."}

verbal nacelle
#

Okay so with those logs, what do you need help with that isn't working exactly?

turbid wharf
#

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"

verbal nacelle
#

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?

turbid wharf
#

When i cancel the subscription on stripe it's not cancelling it on my platform

verbal nacelle
#

Okay, let's pick an exact Subscription id: how did you cancel it?

turbid wharf
#

I am cancelling it through the stripe dashboard, subscription, cancel subscription

#

In this case you can see cus_QSQ9UG9bejJrt1

verbal nacelle
#

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!

turbid wharf
#

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

verbal nacelle
turbid wharf
#

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

verbal nacelle
#

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

turbid wharf
#

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:

verbal nacelle
#

Okay so the Event is received. Then what does your code do? Where is the exact code that handles that specific Event type?

turbid wharf
#

It says that there is no subscription, Could not retrieve subscription data: No such subscription: 'sub_1PbVIxB4bznwKBcEGv2ExGb3'

#

The subscription is here on database

verbal nacelle
#

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

turbid wharf
#

Mmm

#

Let me check the config file, i am sure i checked that initally

verbal nacelle
#

all good, WebhookEndpoints are a pain to debug

turbid wharf
#

I see ๐Ÿ˜ฆ

#

Maybe test mode is not working properly on my platform, i remember my dev always doing tests on live mode before

verbal nacelle
#

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

turbid wharf
#

Let me roll it, i was sure i edited them

#

Done

#

Let me blur them

verbal nacelle
#

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

turbid wharf
#

Ok i made sure now that the keys are correct and in live mode

verbal nacelle
#

but they shou;dn't be in Live mode. That Subscription is in Test mode and so is the Event

turbid wharf
#

I am making a new sub in live mode

#

with new live keys

#

now they should be all matching

#

let's see what happens

verbal nacelle
#

I mean you absolutely should not be ever doing any of this in Live mode when you are so lost with your code ๐Ÿ˜…

turbid wharf
#

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

verbal nacelle
#

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

turbid wharf
#

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

verbal nacelle
#

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.

turbid wharf
#

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

verbal nacelle
#

Sure so next step is to debug that Event really. Add logs to your code and figure out which part fails

turbid wharf
#

I should add logs on the wehbook.php file or on the payment.php file?

#

and wich logs should i add?

verbal nacelle
#

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

turbid wharf
#

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

verbal nacelle
#

What's the exact code for that section?

turbid wharf
#

$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;
    }
verbal nacelle
#

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

turbid wharf
#

I am trying to log all the steps on webhook now on files

verbal nacelle
#

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

alpine mirageBOT
turbid wharf
#

My logs are displaying: Retrieving subscription with ID: sub_1PbWPxB4bznwKBcEgsDgoHwO

#

Do you see any problems so far?

#

Still there?

clear dragon
#

๐Ÿ‘‹ Catching up here

clear dragon
#

Okie, can you confirm that you are using the Stripe Account acct_1PaKkBB4bznwKBcE ?

turbid wharf
#

Yes

clear dragon
turbid wharf
clear dragon
#

Oh right, that's correct. And you are retrieving sub_1PbWPxB4bznwKBcEgsDgoHwO but still bumped into 404 not found?

turbid wharf
#

Yes

clear dragon