#AlienSoft

1 messages ยท Page 1 of 1 (latest)

abstract streamBOT
white ridge
#

Can you share a screenshot of the error and a code snippet where the error is occurring?

smoky marsh
#

Hi. So I'm creating a deferred payment.
When I'm about to fetch/create a payment intent, I pass certain variables as a JSON (as in the stripe docs)

#

// retrieve JSON from POST body
$jsonStr = file_get_contents('php://input');
$jsonObj = json_decode($jsonStr);

#

but when I populate an intent and want to access the jsonOBJ then it throws an error

#

$paymentIntent = \Stripe\PaymentIntent::create([
"amount" => ($amount) * 100,
"currency" => $jsonObj->currency,

#

$jsonObj->currency | this seems to be the issues ?

#

cos if i mantually type: "currency" => "gbp" payment goes through

white ridge
#

log $jsonObj prior to payment

#

to see what it looks like

smoky marsh
#

i think i just spotted my issue? could it be that the -> should be => ?

#

i do have a log of the json string

white ridge
#

I'm not that familiar with php so syntactically I'm not sure

smoky marsh
#

[
{
"currency": "gbp",
"licno": 1,
"code": "",
"description": "info@ : United Kingdom",
"email1": "info@",
"email2": "",
"email3": "",
"email4": "",
"email5": "",
"vname": "VAT",
"vpc": 20,
"vcountry": "GB"
}
]

white ridge
#

ash so $jsonObj is an array then?

#

Not actually a json object

smoky marsh
#

๐Ÿค”

white ridge
#

That's the result of printing out jsonObj?

smoky marsh
#

does json_decode turn it as an array or obj?

#

the log is from my javascript side, before passing it on to fetch

uneven horizon
#

It's still probably sent as json array, so you either have to send the object literal directly or do this in php

$jsonObj[0]->currency;

smoky marsh
#

hmmm.. let me try that.

#

sadly nope.

#

SyntaxError: Unexpected end of JSON input

uneven horizon
#

Can you try logging the json in the php using something like var_dump($jsonObj) post the results here.

That said since you are able to make it work with using "gbp" The stripe end seems to be working so this is definitely the way yoou are sending/processing the data

Let me know wha the log from php gets you

abstract streamBOT
smoky marsh
#

aaah we're getting somewhere afterll

#

{"error":"Undefined constant "jsonStr""}

#

oh my bad. ignore!

strange imp
#

Hi ๐Ÿ‘‹

I am not very familiar with PHP syntax either but I just wanted to check in and see how things are going here? Is there anything I can help with in regards to using the Stripe APIs?

smoky marsh
#

this is my php debug/output

#

still not been able to resolve this :/

strange imp
#

What API are you trying to use?

smoky marsh
#

using a deferred-payment and I'm trying to initialize the INTENT but keep getting errors with the passed JSON post

#

// retrieve JSON from POST body
$jsonStr = file_get_contents('php://input');
$jsonObj = json_decode($jsonStr);

strange imp
smoky marsh
#

items is an object with options

strange imp
#

Can you share the code that actually attempts to call the API?

smoky marsh
#

const items = [{
currency: xCurrency,
licno: document.querySelector("#cboAmount").selectedIndex + 1,
code: disCode,
description: email[0] + ' : ' + countryName,
email1: email[0],
email2: email[1],
email3: email[2],
email4: email[3],
email5: email[4],
vname: vatName,
vpc: xVatPercent,
vcountry: country
}];

const { clientSecret } = await fetch("create.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ items }),
}).then((r) => r.json());

#

JSON.stringify({ items }) is passing the items obj

strange imp
#

Wait this is occurring client side. Is the error being thrown before it passes the data back the create.php?

smoky marsh
#

the error is created within the create.php

strange imp
#

Okay so what is happening in create.php?

smoky marsh
#

the issue isnt' really STRIPE related.. it's the way I'm trying to access the ITEMS parameters in the create.php

strange imp
#

Gotcha. Well I have served as a rubber duck before, so what's happening in create.php?

smoky marsh
#

for example when i hard code the payment intent currency with
"currency" => "eur", then no problem.

#

but when i try and set it with the json obj
"currency" => $jsonObj>currency,

#

then when it's failing

strange imp
#

Don't you need to use -> to access object properties in PHP?

smoky marsh
#

yh that was a typo here ๐Ÿ™‚

#

"currency" => $jsonObj->currency,

#

i even tried: "currency" => $jsonObj["currency"],

#

to see if it's an array but to no avail

strange imp
#

Hmmm ๐Ÿค”

Could you try assigning the values you are trying to access to variables and log them prior to making a request to Stripe?

smoky marsh
#

but that's the whole problem. for some reason it's NOT accessing any of the variables from the OBJ ๐Ÿ™‚

strange imp
#

Okay and what happens when you try to log the $jsonObj in create.php? Is that where you get the output you shared above?

smoky marsh
#

here is my log. so i don't understand why i can't be accessing the parameters as all examples online show the same thing :/

strange imp
#

What is the Type of the $jsonObj?

smoky marsh
#

im trying to do a small test

strange imp
#

Interesting

smoky marsh
#

oh ๐Ÿ˜ฎ

#

just got one field logged

#

wtf. it's working all of a sudden!

strange imp
#

And was it the 4th field?

smoky marsh
#

they're all returning now :/

#

hold on just doing some more tests

strange imp
#

๐ŸŽ‰

smoky marsh
#

aaaaaaaaaaaaand

#

voila! ๐Ÿฅณ

#

i can't believe i spent 3hrs on this thing

#

๐Ÿ˜„

strange imp
#

๐Ÿ™Œ