I get the following error message when I want to do a checkout in the store:
I don’t understand why this function throws this error and why it is displayed as dump() in the UI.
Array
(
[paymentmethod] => Array
(
[label] => Payment Method
[message] => Array
(
[required] => Bitte gib etwas ein
)
)
)
Dump from my OrderPage Object:
OrderPage Object
(
[children] => Kirby\Cms\Pages Object
(
)
[content] => Kirby\Cms\Content Object
(
[name] => Max MM Mustermann
[email] => max@mustermann.de
[street] => Musterstraße 16
[zip] => 12345
[city] => Musterhausen
[country] => Deutschland
[paymentmethod] => stripe-simple
[legal] => on
[items] => -
id: shop/xxx-2022-edition
quantity: "1"
key: >
shop/xxx-2022-edition-weiss-ral9010
color: weiß (RAL9010)
title: 'xxx - 2022 Edition'
price: 395
taxRate: 19
template: product
uid: xxx-2022-edition
tax: '63.067226890756'
sum: 395
sumTax: '63.067226890756'
-
id: shop/versandkosten
key: shop/versandkosten
quantity: 1
title: Versandkosten
price: 12
taxRate: 19
template: product
uid: versandkosten
tax: '1.9159663865546'
sum: 12
sumTax: '1.9159663865546'
)
[files] => Kirby\Cms\Files Object
(
)
[id] => i5mmdvUX2nthsNEJ
[mediaUrl] => https://xxx/media/shop/pages/i5mmdvUX2nthsNEJ
[mediaRoot] => /Users/timo/projects/xxx/website/media/shop/pages/i5mmdvUX2nthsNEJ
[num] =>
[parent] =>
[slug] => i5mmdvUX2nthsNEJ
[template] => Kirby\Cms\Template Object
(
[name:protected] => order
[type:protected] => html
[defaultType:protected] => html
)
[translations] => Kirby\Cms\Collection Object
(
[0] => de
)
[uid] => i5mmdvUX2nthsNEJ
[uri] => i5mmdvUX2nthsNEJ
[url] => https://xxx/i5mmdvUX2nthsNEJ
[siblings] => Kirby\Cms\Pages Object
(
[0] => home
[1] => shop
[2] => agb
[3] => checkout
[4] => datenschutzerklaerung
[5] => error
[6] => impressum
[7] => orders
[8] => success
[9] => widerrufsbelehrung
)
)
Settings:
'ww.merx.gateways' => [
'pre-order' => [
'completePayment' => function (OrderPage $virtualOrderPage, array $data): OrderPage {
// update order page
$virtualOrderPage->content()->update([
'paymentComplete' => false,
]);
return $virtualOrderPage;
}
],
'stripe-simple' => [
'initializePayment' => function (OrderPage $virtualOrderPage): OrderPage {
setStripeApiKey();
$items = [];
foreach ($virtualOrderPage->cart() as $item) {
$p = site()->find($item['id']);
$title = ($p && $p->parent() && $p->parent()->intendedTemplate() == 'product') ? $p->parent()->title() . ' (' . $item['title'] . ')' : $item['title'];
if (isset($item['color']))
$title .= ' - ' . $item['color'];
$items[] = [
'price_data' => [
'currency' => option('ww.merx.currency', 'EUR'),
'product_data' => [
'name' => $title,
],
'unit_amount' => floatval($item['sum']) * 100,
],
'quantity' => $item['quantity'],
];
}
$session = \Stripe\Checkout\Session::create([
'customer_email' => $virtualOrderPage->email(),
'line_items' => $items,
'mode' => 'payment',
'success_url' => url(option('ww.merx.successPage') . '?session_id={CHECKOUT_SESSION_ID}'),
'cancel_url' => url('checkout'), // todo error Page?!
]);
$virtualOrderPage->content()->update([
'sessionId' => $session->id,
'session' => $session,
'redirect' => $session->url,
]);
return $virtualOrderPage;
},
'completePayment' => function (OrderPage $virtualOrderPage, array $data): OrderPage {
setStripeApiKey();
$session = null;
$customer = null;
// get session and customer data
if ($virtualOrderPage->sessionId()->toString() === $data['session_id']) {
$session = \Stripe\Checkout\Session::retrieve($data['session_id']);
$customer = \Stripe\Customer::retrieve($session->customer);
}
// check if user canceled payment
if ($session === null || $session['payment_status'] !== 'paid' || $session['status'] !== 'complete') {
// throw new Exception([
// 'key' => 'merx.paymentCanceled',
// 'httpCode' => 400,
// ]);
}
// update order page
$virtualOrderPage->content()->update([
'paymentDetails' => $session,
'customer' => $customer,
'paymentComplete' => true,
'payedDate' => date('c'),
]);
return $virtualOrderPage;
}
],
],
PHP 7.4.33 and PHP 8.1, Kirby 3.7.5.1