Hi @tobiasfabian,
Hi Forum,
I have a problem in my completePaytment:after hook.
I do a few things like creating a PDF, sending it via email and sending the data to a shipping platform for further operations and saving some IDs.
The Problem I face, that Kirby blocks completely also for other visitors on the website until all things are done. Which is too long. We are talking about 3-5 seconds. For someone ordering and paying I think it is ok, but for someone on the website at the same time, just browsing, it is way too long.
Do you have any ideas how I can solve this?
'ww.merx.completePayment:after' => function (OrderPage $orderPage) {
// Stock updates
if (option('debug') !== true) {
foreach($orderPage->cart() as $cartItem) {
$productPage = page($cartItem['id']);
if ($productPage && $productPage->stock()->isNotEmpty()) {
$stock = $productPage->stock()->toFloat();
$productPage->update([
'stock' => $stock - (float)$cartItem['quantity'],
]);
}
}
}
// Creates PDF ans sends an email to the customer
createPDF($orderPage, 'email');
//adds the user to Mailchimp if user checked with the required data
$mailchimp = kirby()->session()->get('mailchimp', 'string');
if($mailchimp == 'accepted'){
$uuid = $orderPage->uuid();
mailchimp($uuid);
}
//Facebook Coversion API
$uuid = $orderPage->uuid();
fb_capi($uuid, 'Purchase', kirby()->session()->get('event_id'));
//Send Data to the Shipping Platform and receiving ID, storing it with the order
kirby()->impersonate('kirby');
if ($orderPage->paymentComplete()->toBool()) {
$uuid = $orderPage->uuid();
$data = parcel($uuid);
$orderPage = $orderPage->update([
'parcel_id' => $data
]);
}
//Add user ID, if user is logged in
kirby()->impersonate();
if( kirby()->user() ){
$orderPage = $orderPage->update([
'userID' => kirby()->user()->id(),
]);
}
},
Everything else works great. Just the delay for all users gives me a headache.
Thanks,
Simon