#xfechx - payment link update

1 messages · Page 1 of 1 (latest)

hollow hemlock
#

Hello. What error/issue are you seeing exactly?

tribal coral
#

Hello:

#

req_qaThLAnEtV7sET

hollow hemlock
#

That link shows all available fields you can update with

#

If you need to set that application fee, you will have to create a new payment link

tribal coral
#

hmmm

#

but if I created the original payment link with an application fee? I cannot just update it? I have to create a new one? So if a link has a wrong amount, and user wants to update the amount, the link has to be different (if using connect/application fees) ??

hollow hemlock
#

Unfortunately you will have to generate a new link

tribal coral
#

Can I still update it if I don't pass an application fee?

#

I think generating a new link is not convenient, my question is about updating

#

not creating

#

will the application fee stay the same?

hollow hemlock
#

Yeah it would stay the same

tribal coral
#

ok

#

now I get this:

#

req_0h4VOQCrZRbYdR

tribal coral
#

ok, I am confused with this. Where do I get the id of the line item?

#

The ID of an existing line item on the payment link

#

I am re-creating price and product in order to update an existing payment link

vocal lance
#

1/ Retrieve the PaymentLink and expand the line items
2/ Update the Payment Link, switch over the line item(s) to the right Price(s) by setting the id and its state

tribal coral
#

can you explain it with an example? Sorry..
How can I expand the line items?

vocal lance
#

What have you tried?

#

Sorry to push a bit but it's importnat that you try things yourself first and share exact issues with the exact code you have tried

tribal coral
#

I don't know how to "switch over the line item(s) to the right Price(s) by setting the id and its state"

I have the line_items now

vocal lance
#

What have you tried?

tribal coral
#

well, I need to pass a new price

vocal lance
#

I know what you are trying to do, I've shown you the exact thing missing earlier

#

Now what I'm asking is to see what you tried exactly

#

Share your exact code, what you got back, what's blocking you. I can't just give you the answer since that won't really help you internalize how to self-serve most of the questions you're asking

tribal coral
#

I had this on creating a payment link:

#

'line_items' => [['price' => $price->id, 'quantity' => 1]]

#

now I have $line_items (but not sure why I would need this for updating the payment_link)

vocal lance
#

where do you have $line_items? What's in it? Did you print this and look at the exact output?
Did you carefully read the docs for the Update API? Specifically the exact link I gave you which tells you exactly what you are missing in the code?

#

I'm happy to help further I'm just trying to nudge you to try things first, but if you're stuck let me know

tribal coral
#

Sure..

#

So, basically I am trying to update a payment link. I originally thought that I had to re-create the price and product again, to be able to pass this ones to the new payment link.

#

But I received an error about missing the line_items id

#

I am able to 1\ retrieve the payment link using expand

#

but then I don't know how to update the price on the payment link

#

do I need to update the price in the line items?

vocal lance
#

1/ Retrieve the PaymentLink and get the line items
2/ Fine the id of the line item you want to update
3/ Call the Update PaymentLink API and pass the new price and the id of the existing line item to move it to the new price.

tribal coral
#

2/ Fine the id of the line item you want to update:
How?

vocal lance
#

😅

#

Can you share your exact code at this point? I'm sorry, I don't understand what you don't see and I want to see your code as I've explained it twice earlier and it's not clicking

tribal coral
#

$stripe_payment_link = $stripe->paymentLinks->retrieve([
'id' => $payment_link_id,
'expand' =>['line_items'],
]);
$line_items = $stripe_payment_link->line_items;

#

$stripe_payment_link = $stripe->paymentLinks->update($payment_link_id,
[
'line_items' => $line_items,
'allow_promotion_codes' => true,
'metadata' => array(
'Invoice'=>$post_id,
'Customer'=>$user->user_firstname . ' ' . $user->user_lastname,
'CustomerID'=>$user->id,
'Link'=>$permalink,
'Reference'=>get_the_title($post_id),
'Interval'=>$interval,
'Notes'=>$notes,
'Vendor' => $vendor_email,
'VendorID' => $author_id,
'Timestamp'=>$timestamp,
'API'=>$API,
'Affiliate'=>$affiliate_email,
'Tickets'=>$tickets,
'Test'=>$test_mode,
'CFDI'=>$facturapi
),
'after_completion' => [
'type' => 'redirect',
'redirect' => ['url' => get_bloginfo('url') . '/stripe/payment-successful/'],
],
],
$connected_account
);

vocal lance
#

you can wrap your code in three ` to make it readable

#
var_dump($line_items);```
Can you try ^ and see if you can't see the line item id I was referring to?
tribal coral
#

$stripe_payment_link = $stripe->paymentLinks->retrieve([ 'id' => $payment_link_id, 'expand' =>['line_items'], ]); $line_items = $stripe_payment_link->line_items; $stripe_payment_link = $stripe->paymentLinks->update($payment_link_id, [ 'line_items' => $line_items, 'allow_promotion_codes' => true, 'metadata' => array( 'Invoice'=>$post_id, 'Customer'=>$user->user_firstname . ' ' . $user->user_lastname, 'CustomerID'=>$user->id, 'Link'=>$permalink, 'Reference'=>get_the_title($post_id), 'Interval'=>$interval, 'Notes'=>$notes, 'Vendor' => $vendor_email, 'VendorID' => $author_id, 'Timestamp'=>$timestamp, 'API'=>$API, 'Affiliate'=>$affiliate_email, 'Tickets'=>$tickets, 'Test'=>$test_mode, 'CFDI'=>$facturapi ), 'after_completion' => [ 'type' => 'redirect', 'redirect' => ['url' => get_bloginfo('url') . '/stripe/payment-successful/'], ], ], $connected_account );

#

So

vocal lance
#

yu neeayou need three ` on both sides. But I'd already read the code, try what I just said

tribal coral
#

I don't know where to pass the new price

vocal lance
#

I understand, but right now you're just rushing too fast

#

you're taking the line items and then for some reason re-passing it again, which doesn't really make sense

#

so try what I said, share the results here

tribal coral
#

I know, my code is incomplete

#

I can't test that yet, I know it is wrong. That is why I am asking where to pass again the new amount for the updated payment link

#

I was told before, price and product are not updateable

vocal lance
#

I can't test that yet
Why can't you test that?

tribal coral
#

Because I know it is incomplete and exactly the same thing you are mentioning. that i am re passing the line item

#

the one just retrived

vocal lance
#

Sure sure, but try what I just told you

tribal coral
#

what?

#

I see

#

sorry

#

one sec

vocal lance
#

no rush!

vocal lance
#

@tribal coral let me know if I can still help

tribal coral
#

ah, sorry the image was not been sent

vocal lance
#

I'm sorry thst means ~nothing though

#

that's just your code crashing, all I'm asking is to retrieve the link and expand the line item

#

looks like you didn't even pass a payment link id to the retrieve call, just an empty string

tribal coral
#

So definitely getting some error

#

and unable to retrieve line items

#

      $stripe_payment_link = $stripe->paymentLinks->retrieve([
        'id' => 'plink_1Kfp4AGZgYEIO0k5QXHccRsh',
        'expand' =>['line_items'],
      ]);
      $line_items = $stripe_payment_link->line_items;

      wp_mail($email , 'line items', 'line items are: ' . $line_items);```
#

I am getting the first email, but not the second one

#

the errors I see are those ones I sent from screenshot, only

pearl sedge
#

Hey @tribal coral! Stepping in for @vocal lance here. Give me a moment to catch up

vocal lance
#

I'll keep

#

You're using it wrong :p

#

You want $stripe_payment_link = $stripe->paymentLinks->retrieve( 'plink_1Kfp4AGZgYEIO0k5QXHccRsh', [ 'expand' =>['line_items'], ] ); $line_items = $stripe_payment_link->line_items;

tribal coral
#

still no luck

vocal lance
#

please help me help you, share information not just "doesn't work" and "no luck"

#

you're the developer here, this is your own code, you wrote

tribal coral
#

I am not getting an email response after that

vocal lance
#

what is "an email response"

#

it's PHP, why would you get an email?

tribal coral
#

      $stripe_payment_link = $stripe->paymentLinks->retrieve(
        'plink_1Kfp4AGZgYEIO0k5QXHccRsh',
        [
          'expand' =>['line_items'],
        ]
      );
      $line_items = $stripe_payment_link->line_items;

      wp_mail('xfechx@gmail.com', 'line items', 'line items are: ' . $line_items);```
vocal lance
#

oh boy why an email

#

Why not print to the console or the browser like you would for any code?

tribal coral
#

that is another story you don't need to know those details

vocal lance
#

I do, since you're not going to make progress that way

#

you're not catching any error, logging them properly to help you debug, that's not a viable path forward

tribal coral
#

so, i print it for an email because it is the easiest at the moment

#

in this side

#

I know it is not ideal

vocal lance
#

it's less than ideal, you really should pause for a few minutes, move away from your Wordpress environment, and write simple standalone PHP that you can debug by hand in seconds

#

Ultimately: that code can't work because you created the Payment Link on a completely different account because you use Direct Charges apparently

tribal coral
#

yes, it is through a connected account

#

ok

#

i get the error

#

i am not passing connected account to retrieve it

vocal lance
#

correct

#

once you do you should get line items, assuming the code is correct

tribal coral
#

OK so I can obtain the price and the id

#

through line_item

#

so I need to pass price and id from line_item ?

#

to update the payment link?

#

and how do i update the price to that same line_item?

#

line_items **

vocal lance
#

what have you tried?

#

Sorry to sound like a broken record, but this is really simple once you do try. Earlier you were stuck getting the id, now you have it

tribal coral
#

I am wanting to pass a new price to be able to update payment_link... when I pass the new price, it gives me the error: parameter_unknown - line_items[0][price]

#

i asked here, and told that I need to pass the line items' id. Now I have the id, but how do I update the price to the new one I am creating, so that I can update the payment link with a new amount?

vocal lance
#

I still understand your question, I'm just trying to teach you

#

the docs are pretty clear

#
  'plink_123',
  [
    'line_items' => [
      'id' => 'li_123',
      'price' => 'price_NEW',
      'quantity' => 1,
    ],
  ],
  'expand' =>['line_items'],
]);```
#

this is how you update an existing Payment Link and move from an old Price to price_NEW

tribal coral
#

thanks

vocal lance
#

does it work?

tribal coral
#

i am onto it, one sec

tribal coral
#

I am getting a php error, not sure if I am passing it correctly, I think the expand part ..

#
            [
              'line_items' => [
                'id' => $line_items->id,
                'price' => $price->id,
                'quantity' => 1,
              ],
              'allow_promotion_codes' => true,
              'metadata' => array(
                'Invoice'=>$post_id, 
                'Customer'=>$user->user_firstname . ' ' . $user->user_lastname, 
                'CustomerID'=>$user->id, 
                'Link'=>$permalink, 
                'Reference'=>get_the_title($post_id), 
                'Interval'=>$interval,
                'Notes'=>$notes, 
                'Vendor' => $vendor_email, 
                'VendorID' => $author_id, 
                'Timestamp'=>$timestamp, 
                'API'=>$API, 
                'Affiliate'=>$affiliate_email, 
                'Tickets'=>$tickets,
                'Test'=>$test_mode,
                'CFDI'=>$facturapi
              ),
              'after_completion' => [
                'type' => 'redirect',
                'redirect' => ['url' => get_bloginfo('url') . '/stripe/payment-successful/'],
              ],
            ], 
            ['expand' => ['line_items']],
            $connected_account
          );```
halcyon vortex
#

What is the error that you are getting?

tribal coral
#

Stripe\Exception\InvalidArgumentException::getJsonBody(), but that is an error when try , catch .

#

and in stripe

halcyon vortex
#

There should be a message along with that exception. Can you print that out and send it to be?

#

The expansion part of that code looks correct and I am not immediately sure what else might be causing that code to error out

tribal coral
#

not sure why, these are my catches:

    error_messages($e);
  } catch(\Stripe\Error\InvalidRequest $e){
      error_messages($e);
  } catch (\Stripe\Error\Card $e){
      error_messages($e);
  } catch (Exception $e){
      error_messages($e);
  } ``` I never get errors on those error_messages($e) functions
vocal lance
#

There's no reason to expand on the update

#

you passed an array in the middle of the array for params which wouldn't work

#

also try simpler code really, you're making this so hard for yourself. You don't need metadata for now, you can always add this later, you're just debugging a basic update to a payment link, try making the simplest call possible with hardcoded values and slowly work your way up to your real use-case

tribal coral
#

Ok, so now I do not get an error, but the price is not being updated

#

sorry , i am getting error, one second

#

I am getting that error on the catch..

#
            [
              'line_items' => [
                'id' => $line_items[0]->id,
                'price' => $price->id,
                'quantity' => 1,
              ],
              'allow_promotion_codes' => true,
              'after_completion' => [
                'type' => 'redirect',
                'redirect' => ['url' => get_bloginfo('url') . '/stripe/payment-successful/'],
              ],
            ], 
            $connected_account
          );```
vocal lance
#

you say "that error" and not sharing the error

#

there's also no reason to pass any of the other stuff, you don't need to set allow_promotion_codes and such

#

just try to purely update the line item and nothing else to start

tribal coral
#

so still getting the exception error: Uncaught Error: Call to undefined method Stripe\Exception\InvalidArgumentException::getJsonBody()

#

when using this:

#
        'plink_1Kfp4AGZgYEIO0k5QXHccRsh',
        [
          'expand' =>['line_items'],
        ], 
        $connected_account
      );
      $line_items = $stripe_payment_link->line_items;```
vocal lance
#

it's unlikely this is the call failing

#

and you confirmed earlier this worked totally fine for you

#

I'm sorry, it's quite hard to help you based on how complex your environment is, I will reiterate that as a PHP developer you'd be better off trying your code locally on your machine, with PHP installed, first

tribal coral
#

thanks for the tip

vocal lance
#

How did you confirm this call is the one failing?

#

what's $connected_account exactly? Is it a string? An array? Something else? Can you try hardcoding the right things too instead of using a variable?

tribal coral
#

that is convenient for you, yes, I can do that and paste the code here, but I am 100% certain $connected_account works, otherwise I wont be using it.

$connected_account = array('stripe_account' => $connect);
$connect = the stripe user id of the connected account.

#

I am actually debugging in the test mode logs/events from the connected account

#

you are treating this as if the error was elsewhere

#

I confirm the error comes from here:

#
        'plink_1Kfp4AGZgYEIO0k5QXHccRsh',
        [
          'expand' =>['line_items'],
        ], 
        $connected_account
      );
      $line_items = $stripe_payment_link->line_items;```
#

I can hardcode the $connected account too, if you prefer.

#

but I am not exactly sure, why I cannot catch the error, as I am getting an error on my catches, that usually work well with like the other hundred stripe function calls that I use in my code

vocal lance
#

I'm fairly confident this call works already

#

And that you're mixing the calls up and think it's the one crashing when it's not

#

If you send an email before/after that log line you should get both emails

#
  'plink_1Kfp4AGZgYEIO0k5QXHccRsh',
  [
    'expand' =>['line_items'],
  ], 
  [
    'stripe_account' => 'acct_123'
  ]
);``` this exact code will run as long as you pass the right account id
tribal coral
#

You are right

#

Further debugging, I got until here:

#
            [
              'line_items' => [
                'id' => $line_items[0]->id,
                'price' => $price->id,
                'quantity' => 1,
              ],
              'allow_promotion_codes' => true,
              'after_completion' => [
                'type' => 'redirect',
                'redirect' => ['url' => get_bloginfo('url') . '/stripe/payment-successful/'],
              ],
            ], 
            $connected_account
          );```
vocal lance
#

cool so try what I said:
1/ hardcode everything and stop with the $connect_account
2/ remove allow_promotion_codes and after_completion entirely
3/ log information

#

like basically $line_items[0]->id won't work that just is invalid PHP

#

if you had logged it before which I recommended you'd know, and if you had hardcoded the exact id like I also recommend you'd have quickly confirmed

#

$line_items is a Stripe List and data is an array that has the item. You want $line_items->data[0]->id instead

tribal coral
vocal lance
#

hence why printing the content was crucial

#

I don't push to be annoying, I'm trying to teach you to fish, all of that can be debugged in a few minutes at best if you add the right logs at each step

tribal coral
#

req_8NpcLtjJGad0La

#

I am now getting :

invalid_request_error - line_items
Invalid array
Was this useful?

Yes

No
{
  "line_items": {
    "id": "li_LMYATKdbL50BlC",
    "price": "price_1KfrFiGZgYEIO0k5M4cL2QZJ",
    "quantity": "1"
  },```
vocal lance
#

ah that's my bad sorry

#

it's an array of arrays

#
  'plink_123',
  [
    'line_items' => [ // list of line items
      [ // the first line item
        'id' => 'li_123',
        'price' => 'price_NEW',
        'quantity' => 1,
      ],
    ],
  ],
  'expand' =>['line_items'],
]);```
tribal coral
#

I now get this:
req_6ppdrfcD352sC7

#

using the new array of arrays you sent

#
Received unknown parameter: line_items[0][price]
Was this useful?

Yes

No
{
  "line_items": {
    "0": {
      "id": "li_LMYATKdbL50BlC",
      "price": "price_1KfrKbGZgYEIO0k5p9xFfezY",
      "quantity": "1"
    }
  },```
vocal lance
#

hum that one is strange

#

let me look at the code

#

duh I'm so sorry 😦

#

We don't support updating the price at all 🤦

#

Like right now the only thing you can do is changing the quantity you have to create a new link instead

tribal coral
#

ok, so payment links are super limited

vocal lance
#

I'm sorry

tribal coral
#

you cannot code for updating a payment link's amount

#

no worries, not your fault

vocal lance
#

well not "support limited" but they have limitations yes

tribal coral
#

I think that is pretty limiting, if the payment_links are supposed to be easy to use, it means customers won't see any different amount in a payment link already sent

#

it would be nice to request this feature

#

how can i workaround this? I mean I can continuosly create new payment links, but the problem is that a customer that already has a link, they will ONLY ever see that same amount on the payment link..

vocal lance
#

you can't really work around it for now, other than making it inactive and creating a new one

tribal coral
#

Thanks a lot for your help today