#AlienSoft
1 messages ยท Page 1 of 1 (latest)
Can you share a screenshot of the error and a code snippet where the error is occurring?
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
i think i just spotted my issue? could it be that the -> should be => ?
i do have a log of the json string
I'm not that familiar with php so syntactically I'm not sure
[
{
"currency": "gbp",
"licno": 1,
"code": "",
"description": "info@ : United Kingdom",
"email1": "info@",
"email2": "",
"email3": "",
"email4": "",
"email5": "",
"vname": "VAT",
"vpc": 20,
"vcountry": "GB"
}
]
๐ค
That's the result of printing out jsonObj?
does json_decode turn it as an array or obj?
the log is from my javascript side, before passing it on to fetch
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;
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
aaah we're getting somewhere afterll
{"error":"Undefined constant "jsonStr""}
oh my bad. ignore!
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?
{"items":[{"currency":"gbp","licno":1,"code":"","description":"info@test.com : United Kingdom","email1":"info@test.com","email2":"","email3":"","email4":"","email5":"","vname":"VAT","vpc":20,"vcountry":"GB"}]}
this is my php debug/output
still not been able to resolve this :/
What API are you trying to use?
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);
Okay so you are trying to create a Paymnet Intent. Why are you passing items? It's not a valid parameter: https://stripe.com/docs/api/payment_intents/create
items is an object with options
Can you share the code that actually attempts to call the API?
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
Wait this is occurring client side. Is the error being thrown before it passes the data back the create.php?
the error is created within the create.php
Okay so what is happening in create.php?
the issue isnt' really STRIPE related.. it's the way I'm trying to access the ITEMS parameters in the create.php
Gotcha. Well I have served as a rubber duck before, so what's happening in create.php?
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
Don't you need to use -> to access object properties in PHP?
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
Hmmm ๐ค
Could you try assigning the values you are trying to access to variables and log them prior to making a request to Stripe?
but that's the whole problem. for some reason it's NOT accessing any of the variables from the OBJ ๐
Okay and what happens when you try to log the $jsonObj in create.php? Is that where you get the output you shared above?
{"currency":"gbp","licno":1,"code":"","description":"info@test.com : United Kingdom","email1":"info@test.com","email2":"","email3":"","email4":"","email5":"","vname":"VAT","vpc":20,"vcountry":"GB"}
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 :/
What is the Type of the $jsonObj?
im trying to do a small test
$jsonStr = '{"currency":"gbp","licno":1,"code":"","description":"info@test.com : United Kingdom","email1":"info@test.com","email2":"","email3":"","email4":"","email5":"","vname":"VAT","vpc":20,"vcountry":"GB"}
';
$jsonObj = json_decode($jsonStr);
echo $jsonObj>[3];
exit;
Interesting
And was it the 4th field?
๐
๐