#xfechx-paymentlink

1 messages ยท Page 1 of 1 (latest)

prime tusk
#

Hi! You are creating the PaymentLink with the API, and you would like to set the metadata of all the charge objects for that PaymentLink?

exotic harness
#

yes

#

so that my webhook process the charge.succeded like with other methods of payments

#

using metadata

#

?

prime tusk
#

That's not possible unfortunately.

#

But if you have the Charge ID, it might be possible to figure out the PaymentLink associated with it. Would that solve your issue?

exotic harness
#

Yes

#

how can I do it, because I need to retrieve the metadata

#

related to the payment link

#

through a charge.succeded

prime tusk
#

Give me a few minutes to look into this.

exotic harness
#

Also, with a checkout session, how can I tell that it is coming from a payment link?

#

another question, can I update a payment link with a description, afterwards?

#

sorry a a payment intent from a payment link

floral wraith
#

HI there ๐Ÿ‘‹ stepping in.

#

From the Charge object you can check the payment_intent field to find the related Payment Intent. Once you have the Payment Intent you can use it to retrieve the associated Checkout Session:
https://stripe.com/docs/api/checkout/sessions/list#list_checkout_sessions-payment_intent

You can then check the payment_link field on the Checkout Session to find it's related Payment Link.

#

And yes, you can update a Payment Intent.

exotic harness
#

THANKS

#

can you specify how can I retrieve the checkout session from the payment intent?

#

I only one the one related to the charge

floral wraith
#

Sure, you'd use the List Checkout Sessions function that I linked above, and use the Payment Intent ID as your filter criteria.

exotic harness
#

thanks

#

a question

#

can I use this? I am getting an error, I think it is because it is not getting the connected account. But I am passing it, maybe my syntaxis is wrong:

#

$payment_intent_object = \Stripe\PaymentIntent::retrieve($payment_intent, [], $connected_account);

floral wraith
#

What's the error?

exotic harness
#

We are sorry</h4><p><strong>There was a problem with your transaction<br>No such payment_intent: 'pi_3KgplQGZgYEIO0k51TiPLsjD'

#

Ahhh I think it is because it is trying to pull it on live mode

floral wraith
#

Ah that could do it.

exotic harness
#

the problem is that my metadata always includes a test flag

#

but these charges coming from payment links dont have metadata, very frustrating

floral wraith
#

Ah gotcha. Every object also has a livemode parameter to help identify what mode they belong to.

exotic harness
#

can you please check if this one was trying to use live or test?

#

evt_3KgplQGZgYEIO0k51ivd1DDZ

floral wraith
#

Test

exotic harness
#

so not sure why is that not being retrieved?

floral wraith
#

Usually that error is seen when the object is on the connected account but you're checking the platform, or vice versa

exotic harness
#

OK, so I am on the platform (under live mode) under a webhook for a connected account

#

because on platforms, I have to use this to check the webhooks even if they are in test mode

floral wraith
#

Can you share the ID of a failed request?

exotic harness
floral wraith
#

Wait, are you not trying to retrieve an object anymore? What is it you're trying to accomplish?

exotic harness
#

I am trying to process charge.succeded

#

I am trying to get the "Link" parameter from metadata, but my charge doesn't have metadata, so I am trying to pull the metadata from the checkout, so I need to use the payment_intent first.

#

in order for me to pull the payment_intent, I need the Link from the metadata, so that it tells my code where the request is comming from and so that it matches the destination (i.e where the webhook is hosted)

#

this is a filter, so that events from other connected accounts do not interfere.

floral wraith
#

Okay, and which part of the process is running into a problem, the request to list the Checkout Sessions?

exotic harness
#

the request to list the payment intent

#

$payment_intent_object = \Stripe\PaymentIntent::retrieve($payment_intent, [], $connected_account);

#

I can confirm that connected account is a valid array with the connected account id

#

[stripe_account => acct_xyz]

thin idol
#

Hello. Stepping in for toby here as they have to step out. Give me a bit to catch up

exotic harness
#

ok

thin idol
#

So the question still is why you are getting a no such payment intent error?

exotic harness
#

I don't know

#

that is my question

thin idol
#

Yeah was just confirming what you want to know

#

Can you share the request id for that request?

#

As well as the payment intent id and connected account that you are passing in

exotic harness
thin idol
#

That is just a screenshot of a charge event

#

I mean for the request that is failing

exotic harness
#

where do i find it? I am on that screen

#

Also, I need to follow up re SEPA and other payment methods not appearing on checkout for connected account

thin idol
#

Ok one thing at a time

#

Can you find that request id that is failing and share it?

#

Also providing the paymentintent id and connected account id you are using?

exotic harness
#

I think is this one:

#

req_u0HFnRHjVb6T5I

#

acct_1K3kZZGZgYEIO0k5

#

pi_3KgplQGZgYEIO0k51TiPLsjD

thin idol
exotic harness
#

huh?

#

I use this in ALL my code

#

all the time...

#

what is wrong with this call:

#

$payment_intent_object = \Stripe\PaymentIntent::retrieve($payment_intent, [], $connected_account);

#

to start with, are the parameters ok?

#

I can confirm (AGAIN) that $connected_account is a properly built array with 'stripe_account' => acct__xyz

#

that variable $connected_account, is used ALL over my code, it works no problem, why would it be different here? I also just printed it and it prints the array for the connected account.

#

I just printed it testing and it is fine... so why do you say that I am using it incorrectly?

#

acct_1K3kZZGZgYEIO0k5

thin idol
#

Ah I see. I didn't see the first message where you said connected_account pointed to that array

#

Let me take a look into this again

exotic harness
#

ok

#

OK i am able to retrieve it now

#

the problem was that I didn't need that middle empty array.

#

the API never shows calls with connected accounts, so it is usually confusing

#

anyway, the payment intent doesn't have metadata?

#

it is empty... so I really don't know how to retrieve the metadata from a payment link

thin idol
#

Can you share the request for how you are setting the metadata?

#

From there I can determine the exact object that metadata is set on

exotic harness
#

Yeah, the payment intent object doesn't contain any metadata

#
wicked sonnet
#

Hi @exotic harness! Stepping in for @thin idol. You are setting metadata on the PaymentLink itself, yes?

exotic harness
#

I am trying to retrieve it

#

when it is a charge.succeded

#

so that I can pull the "Link" element from it

#

metadata->Link

wicked sonnet
#

Let's back up a sec.

#

Where are you passing metadata originally.

exotic harness
#

on the payment link

#

This issue is about payment links' charge not inheriting payment link metadata

#

or payment intent metadata

wicked sonnet
#

Okay so that is where the metadata will live. It will not exist on the PaymentIntent as it doesn't get carried down afaik.

#

So are you asking how to get back to your PaymentLink ID to then retrieve the metadata?

exotic harness
#

ok, i am updating the payment intent anyway on the checkout.completed

#

so I could do this?

#
                $payment_intent_object = \Stripe\PaymentIntent::update(
                    $payment_intent, 
                    [
                        'description' => 'Payment Link No. '.$metadata->Invoice. ' ['.$metadata->Reference.']',
                        'metadata' => $metadata
                    ],
                    $connected_account
                );
            }```
#

$metadata is the metadata from the checkout session

wicked sonnet
#

Yep that looks right to me.

exotic harness
#

I am getting an error, i think it doesn't accept the metadata array

#

just like that. Do you know how I can just pass it directly?

#

without having to re-write each element from the associative array?

wicked sonnet
#

Ah I didn't realize that $metadata wasn't already an object

exotic harness
#

it is been pulled like this:

#

$metadata = $event_json->data->object->metadata;

#

it is an object

#
  ["Invoice"]=>
  string(4) "4572"
  ["Customer"]=>
  string(12) "Luna Escobar"
  ["CustomerID"]=>
  string(3) "197"
  ["Link"]=>
  string(46) "https://app.lunaescobar.com/payment-link/test/"
  ["Reference"]=>
  string(4) "Test"
  ["Notes"]=>
  string(0) ""
  ["Vendor"]=>
  string(23) "lunaescobar18@gmail.com"
  ["VendorID"]=>
  string(3) "197"
  ["Timestamp"]=>
  string(14) "20220324122702"
  ["API"]=>
  string(0) ""
  ["Affiliate"]=>
  string(0) ""
  ["Tickets"]=>
  string(0) ""
  ["Test"]=>
  string(4) "true"
  ["CFDI"]=>
  string(0) ""
}```
#

that's a var_dump

#

how do I update the payment intent with that metadata object

#

it is stored in $metadata

wicked sonnet
#

Huh, that does seem fine to me. Can you provide the request ID where you hit the error above when you tried to pass that?

exotic harness
#

I have the event ID:

#

evt_1Kgu3gGZgYEIO0k5PNpqFiOl

#

I get a 500 error

#

so it is difficult for me to track where, but without that line, it works.

#

so it must be that

wicked sonnet
#

Huh weird. What is the error message on your server?

exotic harness
#

{"code":"internal_server_error","message":"<p>There has been a critical error on this website.<\/p><p><a href=\"https:\/\/wordpress.org\/support\/article\/faq-troubleshooting\/\">Learn more about troubleshooting WordPress.<\/a><\/p>","data":{"status":500},"additional_errors":[]}

#

I see that in the std out from the webhook response

#

but yeah, if I comment the line, and I resend the webhook, all good

#

so it is that

#
                    $payment_intent, 
                    [
                        'description' => 'Payment Link No. '.$metadata->Invoice. ' ['.$metadata->Reference.']',
                        'metadata' => $metadata
                    ],
                    $connected_account
                );```
wicked sonnet
#

If you wrap $metadata in [] does that change anything?

#

Sorry, I'm not super familiar syntactically with PHP

exotic harness
#

no

#

same errror

wicked sonnet
#

Okay let me grab a colleague

exotic harness
#

thanks

vagrant shard
#

Hi ๐Ÿ‘‹

exotic harness
#

hi

vagrant shard
#

That syntax looks kind of strange to me. metadata needs to be an associative array of key => value pairs.

exotic harness
#

it is an object

#
  ["Invoice"]=>
  string(4) "4572"
  ["Customer"]=>
  string(12) "Luna Escobar"
  ["CustomerID"]=>
  string(3) "197"
  ["Link"]=>
  string(46) "https://app.lunaescobar.com/payment-link/test/"
  ["Reference"]=>
  string(4) "Test"
  ["Notes"]=>
  string(0) ""
  ["Vendor"]=>
  string(23) "lunaescobar18@gmail.com"
  ["VendorID"]=>
  string(3) "197"
  ["Timestamp"]=>
  string(14) "20220324122702"
  ["API"]=>
  string(0) ""
  ["Affiliate"]=>
  string(0) ""
  ["Tickets"]=>
  string(0) ""
  ["Test"]=>
  string(4) "true"
  ["CFDI"]=>
  string(0) ""
}```
#

How can I convert it , so that I can just pass it like this:

#

metadata => $metadata

vagrant shard
#

First question, if you remove the line metadata => $metadata does the Update call work?

exotic harness
#

yes, like mentioned above ๐Ÿ™‚

vagrant shard
#

Sorry I'm just hopping in

exotic harness
#

sure no worries

#

thanks

#

so yes, it works without that line

#

the $metadata contains an object, taken from the event

vagrant shard
#

Do you have a Request ID for one of the failed requests?

exotic harness
#

hmmmm I have a event id

vagrant shard
exotic harness
#

evt_1Kgu3gGZgYEIO0k5PNpqFiOl

#

No, but I am resending the webhook only

#

You can find it with the event id , no?

vagrant shard
#

I'm talking about the request to Update the payment intent

#

that is a separate API request

exotic harness
#

are you a php developer? Do you know how can I pass the object $metadata to the new metadata for payment intent?

#

ok

vagrant shard
#

This is likely specific to our PHP library and how it transforms the arguments you provide into a POST request. It helps me to see the data payload of that POST request, which I can do with the request ID

exotic harness
#

req_2QtcZYU9FtaAgy

#

not sure if it is that one

vagrant shard
#

Perfect, thank you

#

Okay no, try looking for one that failed

#

This is a successful request

exotic harness
#

where do I look for it, for a connected account?

#

that is the last one I see

#

req_2QtcZYU9FtaAgy

#

for payment intents

#

OK

#

got it

#

i needed to convert the php object to associative array

#

with (array)$metadata

vagrant shard
#

Okay, so since you are passing in the Stripe Account header the request will exist on the Connected Account.

#

So you can look in their activity logs to find the request.

exotic harness
#

OK, how can I get the charge from the payment intent? So that I can update the charge's description

#

because also charges from payment link don't have descriptions

vagrant shard
exotic harness
#

I am using payment links

#

I do that for checkout sessions, but I am at the moment implementing payment links

vagrant shard
#

Ooooohhhh.....yeah that makes sense

exotic harness
#

so I also need to fill in a description for the charge

#

I already filled in the metadata for the payment intent

#

so that helps with charge.succeded , I can at least obtain the metadata from that event

vagrant shard
#

Do you make an API call to retrieve the Payment Intent?

exotic harness
#

yes why

vagrant shard
#

Okay well you should receive the charges list on that Payment Intent. You can examine those charges and update them with the description already on the Payment Intent.

exotic harness
#
                    $payment_intent, 
                    [
                        'description' => 'Payment Link No. '.$metadata->Invoice. ' ['.$metadata->Reference.']',
                        'metadata' => (array)$metadata
                    ],
                    $connected_account
                );

                $charge_object = \Stripe\Charge::update($payment_intent_object->charges->data[0]->id, 
                [
                    'description' => $payment_intent_object->description
                ],
                $connected_account);```
vagrant shard
#

You cannot update the charge within the payment intent. That needs to be a separate API call

exotic harness
#

yeah there are two api calls there, no

#

?

#

$charge_object = \Stripe\Charge::update($payment_intent_object->charges->data[0]->id,
[
'description' => $payment_intent_object->description
],
$connected_account);

#
                [
                    'description' => $payment_intent_object->description
                ],
                $connected_account);```
vagrant shard
#

Sorry, the indentation threw me off. I mostly develop in Python so those have special meaning for me ๐Ÿ™‚

#

Those calls look good to me.

exotic harness
#

ahh,

#

I have a problem

#

charge.succeeded comes BEFORE checkout.sessioncompleted

#

I am updating the payment intent in the checkout.session

vagrant shard
#

Okay. So what is the particular problem? You want to add the description before the Charge succeeds?

exotic harness
#

yes, because my code sends notification emails when charge.succeeded

#

and it uses the charge's description

#

sno not sure how to obtain a description from a charge.succeded (that comes from a payment-link)

#

?

#

do you know how to?

vagrant shard
#

Hmmm...in that case the best option I could see would be to delay the sending of the email by a few seconds until the checkout session is also returned.

exotic harness
#

hmm

#

better option

#

to retrieve payment intent, and copy the metadata and description to the charge's

vagrant shard
#

True!

#

Good point. You can go backwards by finding the PI

exotic harness
#

and how can I update the charge description?

#

can I use:

#
$charge->description = 'xxyyzz';
$charge->save();
#

?

vagrant shard
#

honestly I haven't used the PHP library enough to be sure. I'd probably make a $strip->charges->update(['description' => $payment_intent->description]) call.

exotic harness
#

Done

#

all good!

#

Thanks a lot for all the help today guys