#xfechx_api

1 messages ยท Page 1 of 1 (latest)

rain heronBOT
#

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

๐Ÿ“ Have more to share? Add details, code, screenshots, videos, etc. below.

uncut sandal
#

hi!

I just do not understand why in some cases works and some other does not.
what's the current status of your inestigation into that, what have you found?

#

I also do not know what "described properly, while others are described poorly" means

oak halo
#

this is related to development

#

not stripe support

#

what I mean is the descriptions in the dashboard, I have to programatically change them to be more descriptive

#

It already works - but not in all cases, so I want to know why

#

I also have another issue, with balance transactions (through API) not coming back with Account details (name, address) while it was before

uncut sandal
#

makes sense I guess, so what is the code that does that, what API call does it make, what happens/does not happen in the cases where it doesn't work?

oak halo
#

where it doesn't work it just displays "invoice-473843F09-009" or whatever the stripe invoice default format looks like

#

rather than the format that I have in the description of the subscription's charge

#

take a look here

#

if you see the top payment, it says "invoice 83108..." instead of it's description, all of these charges use the exact same code

#

they are subscription charges, and through webhook, the payment intent description gets written to use the charge description

#

so not sure why it is not consistent

uncut sandal
#

sorry you didn't answer anything I asked

#

so what is the code that does that, what API call does it make, what happens/does not happen in the cases where it doesn't work?

rain heronBOT
oak halo
#

so, on the following events:

invoice.payment succeded, invoice.payment_failed,
charge.succeded, charge.failed
checkout.session.completed

I have a function call, update_payment_intent($payent_intent)

#

which has the following content

analog haven
#

Which URL is that screenshot from?

oak halo
#

from the dashboard

#

I also have another question regarding connected accounts and account details not displaying anymore (using same code, different result)

#

should I open a new thread?

analog haven
#

Let's figure out the first issue first please

#

Is this the ID of a payment with an unexpected description? pi_3PXm8iHlZBj3A1TO19Z3zBNM

oak halo
#

yes

analog haven
#

I don't see any requests to update that intent like your code implies?

oak halo
#

can you see it in the other ones?

#

like this one:

#

pi_3PX0t1HlZBj3A1TO1IXZhCl2

#

or this one, from the day before:
pi_3PXLgVHlZBj3A1TO0adBdid7

analog haven
#
#

But that request was never sent for pi_3PXm8iHlZBj3A1TO19Z3zBNM

oak halo
#

why was it not sent?
If I haven't changed anything related to webhooks

#

from one day to the next one

analog haven
#

That's only something you can answer I'm afraid

oak halo
#

sorry?

#

I am asking you - why is my webhook if it has responded properly, hasn't updated on subscription charge, and the other one yes.

analog haven
#

You're asking me why the API request sent from your integration to update a Payment Intent wasn't sent. The answer is I don't know โ€“ are there any logs in your server indicative of an error around that time?

#

This is something you will need to debug I'm afraid. There's no evidence of even an attempted/failed update request

#

My guess is this intent doesn't fulfil any of your if/conditional logic so it just skipped the update request

oak halo
#

ah ok, So I can see that in charge.succedded, for the one that did not work the error was:

There was a problem with your transaction<br>No such notification: 'evt_3PXm8iHlZBj3A1TO1mr5cpqD'```
analog haven
#

Where in the code you've shared is that thrown?

oak halo
#

Ok, I identified the error

analog haven
#

And if your webhook code does error, then you shouldn't be returning a 2xx response really as this will prevent automated retry logic

oak halo
#

it is because that subscription did not have metadata filled

analog haven
#

Great!

oak halo
#

ahh sorry

#

what is more current, or better

#

plan or price?

#

to get metadata, in case it was not defined in the subscription

#

specifically to subscriptions

analog haven
#

Plan API/resource is deprecated, use price_xxx

oak halo
#

using this:

#
//if it is an invoice:
if($event_json->data->object->object === 'invoice'){
    if($event_json->data->object->lines->data[0]->price->type == 'one_time'){ //it is a one time invoice charge:
        $metadata = $event_json->data->object->metadata;
        if(empty($metadata)){
            $metadata = $event_json->data->object->lines->data[0]->metadata;
        }
    } 
    else if ($event_json->data->object->object === 'subscription') { //a subscripiton
        $metadata = $event_json->data->object->lines->data[0]->metadata;
        if(empty($metadata)){
            $metadata = $event_json->data->object->lines->data[0]->price->metadata;
        }
    }
}```
viral oxide
#

hi! I'm taking over this thread.

#

what's your question?

oak halo
#

cannot find metadata under invoice.payment succeded using that code, but I can see it in the event json

viral oxide
#

where is the metadata stored exactly? on the Subscription, Invoice, Price, somewhere else?

oak halo
#
    if($event_json->data->object->lines->data[0]->price->type == 'one_time'){ //it is a one time invoice charge:
        $metadata = $event_json->data->object->metadata;
        if(empty($metadata)){
            $metadata = $event_json->data->object->lines->data[0]->metadata;
        }
    } 
    else { //a subscripiton
        $metadata = $event_json->data->object->metadata;
        if(empty($metadata)){
            $metadata = $event_json->data->object->lines->data[0]->metadata;
            if(empty($metadata)){
                $metadata = $event_json->data->object->lines->data[0]->price->metadata;
            }
        }
    }
}```
#

Sometimes it might be stored in subscription + price, sometimes it might only be on price (i.e when using dashboard to make the subscription, rather than the API)

viral oxide
#

do you get an error with the above code?

oak halo
#

no

#

my webhook simply doesn't retrieve the API metadata parameter, which is needed to continue

viral oxide
#

can you share a specific Evenet ID (evt_xxx) where your code didn't find any metadata?

oak halo
#

evt_1PXm8nHlZBj3A1TOiigYMhCg

#

this is the snippet:

#
//if it is an invoice:
if($event_json->data->object->object === 'invoice'){
    if($event_json->data->object->lines->data[0]->price->type == 'one_time'){ //it is a one time invoice charge:
        $metadata = $event_json->data->object->metadata;
        if(empty($metadata)){
            $metadata = $event_json->data->object->lines->data[0]->metadata;
        }
    } 
    else { //a subscripiton
        $metadata = $event_json->data->object->metadata;
        if(empty($metadata)){
            $metadata = $event_json->data->object->lines->data[0]->metadata;
            if(empty($metadata)){
                $metadata = $event_json->data->object->lines->data[0]->price->metadata;
            }
        }
    }
}

//when it is a charge, usually metadata is on the event root
if($event_json->data->object->object === 'charge'){
    $metadata = $event_json->data->object->metadata;
}

$API = $metadata->API;```
#

This line should find it if(empty($metadata)){ $metadata = $event_json->data->object->lines->data[0]->price->metadata;

viral oxide
#

in this event I do see metadata on the Price. it is in object->lines->data[0]->price

oak halo
#

yes

#

so this is the code, but I cannot retrieve it.

#
//if it is an invoice:
if($event_json->data->object->object === 'invoice'){
    if($event_json->data->object->lines->data[0]->price->type == 'one_time'){ //it is a one time invoice charge:
        $metadata = $event_json->data->object->metadata;
        if(empty($metadata)){
            $metadata = $event_json->data->object->lines->data[0]->metadata;
        }
    } 
    else if($event_json->data->object->lines->data[0]->price->type == 'subscription'){ //a subscripiton
        $metadata = $event_json->data->object->metadata;
        if(empty($metadata)){
            $metadata = $event_json->data->object->lines->data[0]->metadata;
            if(empty($metadata)){
                $metadata = $event_json->data->object->lines->data[0]->price->metadata;
            }
        }
    }
}```
viral oxide
#

no there are mistakes. for example you wrote $metadata = $event_json->data->object->metadata; so it's missing the [0]

#

it should be something like $metadata = $event_json->object->lines->data[0]->price I think (you'll need to double check).

#

I recommend doing this step-by-step with logs. like print $event_json->object and check its value, then print $event_json->object->lines, and so on.

oak halo
#

It works with data->object->metadata
for other scenarios, where the metadata is directly under the subscription

#

Or if you tell me I should omit the data part then I can change it but I don't want to break more things

#

So how should I use it when metadata is on the price and not on the subscription directly

viral oxide
#

something like this

if (metadata is on the subscription) {
  $metadata = $event_json->object->metadata;
} else if (metadata is on the price) {
  $metadata = $event_json->object->lines->data[0]->price->metadata;
}
oak halo
#

why are you omitting the data part?

#

I don't think we should omit that

viral oxide
#

I don't understand your question, sorry.

#

oh, you mean my code?

#

there's proabbly mistakes in it, I wrote it quickly just to give you an idea

oak halo
#

yes

#

hmmm

#

I am looking for something without mistakes, because on other scenarios it works

viral oxide
#

like I said, try this step-by-step with some logs until you are sure you get the correct values.

#

the code I wrote above should work when you receive a Subscription payload. you can write somethign similar for when it's an Invoice payload.

oak halo
#

hmmm, that doesn't really help me

#

because it works on MANY other scenarios

#

I need someone that can help me please

#

can you put me someone that works with PHP and knows the API ?

viral oxide
#

because it works on MANY other scenarios
can you calrify this? your webhook code processing events should handle different types of events using if. something like this:

if (the event is `invoice.payment_failed`) {
   // process the event
}
else if (the event is `customer.subscription.created`) {
   // process the event differently
}

so changing one part of the code shouldn't break anything else

oak halo
#

ahh I am getting frustrated, I have been working with the API for like 10 years.

#

and you are talking to me like I started working with it yesterday. I need specific help

#

so with this:

#
//if it is an invoice:
if($event_json->data->object->object === 'invoice'){
    echo '--- it is an invoice object ---';
    if($event_json->data->object->lines->data[0]->price->type == 'one_time'){ //it is a one time invoice charge:
        $metadata = $event_json->data->object->metadata;
        if(empty($metadata)){
            $metadata = $event_json->data->object->lines->data[0]->metadata;
        }
    } 
    else if($event_json->object->lines->data[0]->price->type == 'subscription'){ //a subscripiton
        echo '--- filling metadata for subscription ---';
        $metadata = $event_json->object->metadata;
        if(empty($metadata)){
            $metadata = $event_json->object->lines->data[0]->metadata;
            if(empty($metadata)){
                $metadata = $event_json->object->lines->data[0]->price->metadata;
            }
        }
    }
}```
#

i get this:

--- filling metadata now ------ it is an invoice object ------ API being used is: ------

#

so it is not even entering the subscription else if

viral oxide
#

you're making it difficult to help you. can you be more precise in your question?
like, which event exactly is not entering in the else if? a invoice.payment_succeeded, or something else?

oak halo
#

ok, fixed it - I have a specific question

#

will a price ALWAYS exist on a subscription?

rain heronBOT
viral oxide
#

yes

oak halo
#

ok, thanks a lot, I have resolved this issue.

#

I have another question

#

regarding connected accounts, retrieving business data

warm verge
#

I can take that next question, soma needs to step away

oak halo
#

hello, thank you

#

So with the same code, now it cannot seem to retrieve account name and address:

#

this worked for a while

#
warm verge
#

"Now" compared to when? Are you suggesting something changed in the results without you making a change? Reading the backscroll above, I don't see how this is related to what you've been speaking about so far today

#

And to put a sharper focus on the issue, is the problem that the retrieval is failing or that the response object does not contain the information you expect it to?