#hanis03
1 messages · Page 1 of 1 (latest)
Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- hanis03, 6 hours ago, 9 messages
- hanis-paymentelement-email, 10 hours ago, 25 messages
What's your question?
In create.php i reciving this json error:
{
error: "calculateOrderAmount(): Argument #1 ($items) must be of type array, null given, called in /data/web/virtuals/314556/virtual/www/subdom/admin/admin/novyshop/platby/create.php on line 26"
}
Can you help me?
What do you need help with exactly? The error is telling you the issue: Argument #1 ($items) must be of type array, null given
Yeah but before when I´m using something like authenticate with Link email, it´s working. But I want using own email form
So I don´t know how describe my problem, but if you want, I will send you code
Start here:
error: "calculateOrderAmount(): Argument #1 ($items) must be of type array, null given, called in /data/web/virtuals/314556/virtual/www/subdom/admin/admin/novyshop/platby/create.php on line 26"
}```
Go to line 26
Figure out why you're passing null to argument 1
Use print statements or a debugger to do this
We can help with stripe api questions in here, but you really need to debug this code yourself
If you ask specific questions, I'm happy to help, but I can't debug your code for you
try {
$jsonStr = file_get_contents('php://input');
$jsonObj = json_decode($jsonStr);
$paymentIntent = $stripe->paymentIntents->create([
'amount' => calculateOrderAmount($jsonObj->items),
'currency' => 'czk',
'setup_future_usage' => 'off_session',
'payment_method_types' => ['card'],
/*'automatic_payment_methods' => [
'enabled' => true,
],*/
]);
$paymentIntent->confirmation_method = 'manual';
$output = [
'clientSecret' => $paymentIntent->client_secret,
];
echo json_encode($output);
$_SESSION['output'] = $output;
} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
but I before don´t use some $items
I don´t have idea how to fix that.
😦
You still haven't asked a specific question
I don't know what to do with the above code
Use print statements or a debugger to debug
I don´t know how to fix that
We can help integrate the stripe api, but I can't teach you basic debugging skills in here
That's something fundamental you need to learn
I understand that, but yesterday I was texting with your colleague and he wanted to help me solve it together. I don't use $items in any way and I don't know what they have to be there for
What is line 26?
I just don't have enough info here
And you haven't asked a specific question yet
You just asked me to fix it
'amount' => calculateOrderAmount($jsonObj->items),
This is on line 26
Sorry, I'm using a translator.
Yeah so what the error means then is $jsonObj->items is null when it should be an array.
Argument #1 ($items) must be of type array, null given
So you need to trace your code back using print statements or a debugger to find out why that is
However, I don't use $items.
Yeah but I copy from your site: https://stripe.com/docs/payments/quickstart?lang=php
Where is in default
But look at checkout.js
Items are passed there
So in your code, you aren't passing items correctly somewhere
// This is a public sample test API key.
// Don’t submit any personally identifiable information in requests made with this key.
// Sign in to see your own test API key embedded in code samples.
const stripe = Stripe("--own--stripe--code--");
// The items the customer wants to buy
const items = [{ id: "xl-tshirt" }];
let elements;
initialize();
checkStatus();
document
.querySelector("#payment-form")
.addEventListener("submit", handleSubmit);
// Fetches a payment intent and captures the client secret
async function initialize() {
const { clientSecret } = await fetch("create.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ items }),
}).then((r) => r.json());
elements = stripe.elements({ clientSecret });
const paymentElementOptions = {
layout: "accordion",
};
const paymentElement = elements.create("payment", paymentElementOptions);
paymentElement.mount("#payment-element");
}
async function handleSubmit(e) {
e.preventDefault();
setLoading(true);
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
return_url: "--return--url--",
},
});
if (error.type === "card_error" || error.type === "validation_error") {
errShowMessage(error.message);
console.log(error.message);
} else {
showMessage("Vyskytla se neočekávaná chyba.");
}
setLoading(false);
}
async function checkStatus() {
const clientSecret = new URLSearchParams(window.location.search).get(
"payment_intent_client_secret"
);
if (!clientSecret) {
return;
}
const { paymentIntent } = await stripe.retrievePaymentIntent(clientSecret);
switch (paymentIntent.status) {
case "succeeded":
showMessage("Zaplaceno!");
break;
case "processing":
showMessage("Platba je v procesu.");
break;
case "requires_payment_method":
showMessage("Vaše platba nebyla úspěšná, zkuste to prosím znovu.");
break;
default:
showMessage("Vyskytla se chyba.");
break;
}
}
function showMessage(messageText) {
const messageContainer = document.querySelector("#payment-message");
messageContainer.classList.remove("hidden");
messageContainer.textContent = messageText;
/*
setTimeout(function () {
messageContainer.classList.add("hidden");
messageContainer.textContent = "";
}, 5000);*/
}
function errShowMessage(messageText) {
const messageContainer = document.querySelector("#warnings");
const containerBox = document.querySelector(".payment-message-err");
containerBox.classList.remove("hidden");
messageContainer.textContent = messageText;
}
function setLoading(isLoading) {
if (isLoading) {
document.querySelector("#submit").disabled = true;
document.querySelector("#spinner").classList.remove("hidden");
document.querySelector("#button-text").classList.add("hidden");
} else {
document.querySelector("#submit").disabled = false;
document.querySelector("#spinner").classList.add("hidden");
document.querySelector("#button-text").classList.remove("hidden");
}
}
But I don´t know what I must to do with items here, because before I don´t used and it works
Previous code, but this not. I used before this code still but i use also "Link", but now I want use without that
So you're saying you haven't changed our sample code at all?
And the sample you downloaded is failing without any modifications?
Something yes, but what was connected to the Link service
I don´t know
What do you mean?
Have you changed the sample code in any way?
Or you just downloaded it and ran it?
Download and then change, but I left what was there, only added it
do you want me to send the code?
Yeah. Was it a lot that you changed? If not, just send the part you changed
But again, this is something you need to debug yourself
These are fundamental debugging skills you need to learn
If you ask specific questions I can help
But I'm not going to download your code and debug your entire integration myself
I understand
There will be more, but before that it didn't ask me for $items and I didn't do anything with them.
Ok send me your client side code then so I can take a look
php like where is html code?
or js
Sorry. For some reason I can't get to Cloudflare so they can't delete the old data. So I can't find the error.
CODE:
// This is a public sample test API key.
// Don’t submit any personally identifiable information in requests made with this key.
// Sign in to see your own test API key embedded in code samples.
const stripe = Stripe("--stripe--");
// The items the customer wants to buy
const items = [{ id: "xl-tshirt" }];
let elements;
initialize();
checkStatus();
document
.querySelector("#payment-form")
.addEventListener("submit", handleSubmit);
// Fetches a payment intent and captures the client secret
async function initialize() {
const { clientSecret } = await fetch("create.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ items }),
}).then((r) => r.json());
elements = stripe.elements({ clientSecret });
const paymentElementOptions = {
layout: "accordion",
};
const paymentElement = elements.create("payment", paymentElementOptions);
paymentElement.mount("#payment-element");
}
async function handleSubmit(e) {
e.preventDefault();
setLoading(true);
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
return_url: "--return--",
},
});
if (error.type === "card_error" || error.type === "validation_error") {
errShowMessage(error.message);
console.log(error.message);
} else {
showMessage("Vyskytla se neočekávaná chyba.");
}
setLoading(false);
}
async function checkStatus() {
const clientSecret = new URLSearchParams(window.location.search).get(
"payment_intent_client_secret"
);
if (!clientSecret) {
return;
}
const { paymentIntent } = await stripe.retrievePaymentIntent(clientSecret);
switch (paymentIntent.status) {
case "succeeded":
showMessage("Zaplaceno!");
break;
case "processing":
showMessage("Platba je v procesu.");
break;
case "requires_payment_method":
showMessage("Vaše platba nebyla úspěšná, zkuste to prosím znovu.");
break;
default:
showMessage("Vyskytla se chyba.");
break;
}
}
function showMessage(messageText) {
const messageContainer = document.querySelector("#payment-message");
messageContainer.classList.remove("hidden");
messageContainer.textContent = messageText;
/*
setTimeout(function () {
messageContainer.classList.add("hidden");
messageContainer.textContent = "";
}, 5000);*/
}
function errShowMessage(messageText) {
const messageContainer = document.querySelector("#warnings");
const containerBox = document.querySelector(".payment-message-err");
containerBox.classList.remove("hidden");
messageContainer.textContent = messageText;
}
function setLoading(isLoading) {
if (isLoading) {
document.querySelector("#submit").disabled = true;
document.querySelector("#spinner").classList.remove("hidden");
document.querySelector("#button-text").classList.add("hidden");
} else {
document.querySelector("#submit").disabled = false;
document.querySelector("#spinner").classList.add("hidden");
document.querySelector("#button-text").classList.remove("hidden");
}
}
In cloudflare error 500 - error on server
Can I disable this like $items?
What do you mean?
If you don't use items, just remove all references of it in the code
Are you a developer?
Junior developer
Yeah if you're not using it, just remove it
I was afraid it wouldn't work without it 😄
But I'm not sure what I'm going to send to create.php
Nothing?
Or then how to call it
It's your integration
I don't know your requirements
Does the payment intent amount vary based on user selection in the fronte-end? Or do you know ahead of time?
This is all up to you...
Okay I will try it something, otherwise I will contact you