authorize('customerBelongsToService', $customer); return $this->handleArcadiaMail($request, ArcadiaMailType::default(), $customer, $service); } public function outgoingMailGame(SendArchadiaGameMailRequest $request, Customer $customer, Service $service) { $this->authorize('customerBelongsToService', $customer); return $this->handleArcadiaMail($request, ArcadiaMailType::game(), $customer, $service); } private function handleArcadiaMail( BaseApiRequest $request, ArcadiaMailType $type, Customer $customer, Service $service ) { $request = $request->merge([ 'order_number' => str_pad(\intval($request->order_number), 9, '0', STR_PAD_LEFT) ]); $xml = 'none'; try { /** @var \App\Models\CustomerInfo $customerInfo */ $customerInfo = $customer->info($service->brand, Customer::FIRST_OR_FAIL); $orderType = ArcadiaOrderType::make(intval($request->state_order)); $xml = $this->makeXml($request, $type, $orderType, $customer, $customerInfo); // Format xml $doc = new DOMDocument('1.0', 'utf-8'); $doc->preserveWhiteSpace = true; $doc->formatOutput = true; $doc->loadXML($xml); $xml = $doc->saveXML(); Storage::disk('arcadia')->put(date("Ymd_His") . ".xml", $xml); return response()->json(); } catch (\Exception $e) { Log::critical("ARCADIA XML CREATION FAILED : " . $e->getMessage()); if (!config('app.debug')) { dispatch(function () use ($xml, $e) { Mail::to(config('mail.MAIL_ADMIN'))->send(new CourrierArcadiaError( "ARCADIA XML CREATION FAILED", "Une erreur est survenue lors de la création du fichier XML : " . $e->getMessage(), $xml )); })->afterResponse(); } else { throw $e; } throw new CrmException('Failed to create the arcadia xml file', 0, $e); } } /** * render Arcadia xml for order * * @param SendArchadiaMailRequest $request * @param ArcadiaMailType $type * @param ArcadiaOrderType $orderType * @param Customer $customer * @param CustomerInfo $customerInfo * @return string */ private function makeXml( BaseApiRequest $request, ArcadiaMailType $type, ArcadiaOrderType $orderType, Customer $customer, CustomerInfo $customerInfo ): string { return view( 'mail.arcadiaOrders.default', [ 'request' => $request, 'type' => $type, 'orderType' => $orderType, 'customer' => $customer, 'customerInfo' => $customerInfo ] )->render(); } }