#KarlMeyer

1 messages · Page 1 of 1 (latest)

solemn galeBOT
craggy trench
#

Hello. Unfortunately we can only support users in English in here

blissful surge
#

I also speack English

#

could you give me a hand?

craggy trench
#

Ok cool. What can I help you with?

blissful surge
#

I am trying to call this variable {{summe}}, nbut it gives me an error in symfony:
this is the code:

$session = Session::create([

'line_items' => [[
  'price_data' => [
    'currency' => 'usd',
    'product_data' => [
      'name' => 'T-shirt',
    ],
    //'unit_amount' => 2000,
    'unit_amount' => '{{summe}}',
  ],
  'quantity' => 1,
]],
'mode' => 'payment',
craggy trench
#

There's also a possibility the error occurred before the request reached our servers, so there may not be a request id. What was the error message?

blissful surge
#

I believe ist this one: req_5rIp8E3nnMxpHe

#

invalid integer: {{summe}}

#

thats the error message

craggy trench
#

Ah yeah you're just passing a string with braces around the word summe

#

If summe is set to an integer, just pass the variable without quotes or braces around it

blissful surge
#

when I don't use the quotes i get: syntax error, unexpected token "{"

craggy trench
#

Yeah remove the braces too. I'm not a PHP programmer, but I think it should be: 'unit_amount' => summe

blissful surge
#

in the html I have:
{% set summe = summe + bestellung.preis %}
{{summe}}

craggy trench
#

Ok but you create the checkout session on the backend

blissful surge
#

without the braces I get: Undefined constant "App\Controller\summe"

craggy trench
#

So what you have in html isn't relevant here

#

Or at least you should be creating the checkout session on the backend. Is that what you're doing?

blissful surge
#

I created an html page, where I call diferent values from the server. the added values are returned in the variable {{summe}} in the same html. I just wanted to pass this variable to the payment form

craggy trench
#

Yes I understand, but unless the summe variable exists in that scope on the server (not in your html) you can't reference it

#

and you'd need to reference it like 'unit_amount' => summe

#

Because it's server side code, nothing is being templatized or filled in like your html is

blissful surge
#

so I have to create a checkout session where the variable is included

#

reference

craggy trench
#

Somewhere in that function you'd set $summe = summe + bestellung.preis or whatever the proper syntax for that in PHP is. then reference it in the session creation with 'unit_amount' => summe

#

Or if you have summe set in your javascript code on the front-end, you can pass that to your backend to create the checkout session

#

But 'unit_amount' => '{{summe}}', is not how you reference a variable in the backend

blissful surge
#

I understand. Thank you for your help. I will try and reference that variable in a session🙏