get('default_stock_status') === 1; $auto_invoice = (int)$csm->get('auto_invoice_and_credit_note') === 1; try { dbTransaction($pdo2, function($pdo) use ($id, $company_id, $logging, $uuid, $auto_approve, $auto_invoice) { $order = new OrderManager($pdo, $company_id); $order->confirmOrder($id, $uuid, $logging, $auto_approve); if ($auto_invoice) { $invMgmt = new InvoiceManager($pdo, $company_id); $invMgmt->createFromOrder($id, $logging); } }); $answer['success'] = 1; $answer['message'] = 'Order confirmed.'; $answer['auto_approved'] = $auto_approve; $answer['auto_invoice'] = $auto_invoice; notify_node('order_updated', [], $company_id); if ($auto_invoice) { (new UsageGuard($pdo1, $company_id, $packages))->increment(); notify_node('invoice_updated', [], $company_id); } } catch (PDOException $e) { $answer['message'] = 'Database error, please try again.'; http_response_code(500); } catch (Exception $e) { $answer['message'] = $e->getMessage(); http_response_code(400); } exit(json_encode($answer)); ?>