handleArcadiaMail($request, ArcadiaMailType::default()); } /** * Send arcadia game mail (games) * * @param \App\Http\Requests\Api\V2\SendArchadiaGameMailRequest $request * @return \Illuminate\Http\JsonResponse */ public function outgoingMailGame(SendArchadiaGameMailRequest $request): JsonResponse { return $this->handleArcadiaMail($request, ArcadiaMailType::game()); } /** * Form xml message and save it in the apropriate storage location * to be picked up by the arcadia job * * @param \App\Http\Requests\Api\V2\BaseApiRequest $request * @param \App\Enums\ArcadiaMailType $type * @return \Illuminate\Http\JsonResponse * @throws \Exception If an error occurs while generating and saving the xml file. */ private function handleArcadiaMail(BaseApiRequest $request, ArcadiaMailType $type): JsonResponse { $request = $request->merge([ 'order_num' => str_pad(\intval($request->order_num), 9, '0', STR_PAD_LEFT) ]); $xml = 'none'; try { $customerInfo = \array_intersect_key($request->all()['deliver'], [ 'email' => '', 'firstname' => '', 'lastname' => '', 'address' => '', 'address2' => '', 'city' => '', 'postcode' => '', 'phone' => '' ]); $orderType = ArcadiaOrderType::make(intval($request->state_order)); $xml = $this->makeXml($request, $type, $orderType, $customerInfo); // * Format xml. $doc = new DOMDocument('1.0', 'utf-8'); $doc->xmlStandalone = true; $doc->preserveWhiteSpace = false; $doc->formatOutput = true; $doc->loadXML($xml); $xml = $doc->saveXML(); Storage::disk('arcadia')->put(Str::slug(sprintf( 'v2_order_%s_%s_%s%s', $request->order_num, $type->label, date('Ymd_His'), \microtime(true) )) . '.xml', $xml); return response()->json(); // @codeCoverageIgnoreStart } catch (\Exception $e) { Log::critical("ARCADIA XML CREATION FAILED FOR $request->order_num : " . $e->getMessage()); if (!config('app.debug')) { dispatch(function () use ($xml, $e, $request) { Mail::to(config('mail.MAIL_ADMIN'))->send(new CourrierArcadiaError( "ARCADIA XML CREATION FAILED FOR $request->order_num", "Une erreur est survenue lors de la création du fichier XML : " . $e->getMessage(), $xml ?: '' )); })->afterResponse(); } throw $e; // @codeCoverageIgnoreEnd }//end try } /** * render Arcadia xml for order * * @param \App\Http\Requests\Api\V2\BaseApiRequest $request * @param \App\Enums\ArcadiaMailType $type * @param \App\Enums\ArcadiaOrderType $orderType * @param array $customerInfo * @return string */ private function makeXml( BaseApiRequest $request, ArcadiaMailType $type, ArcadiaOrderType $orderType, array $customerInfo ): string { $arcadiaMailType = $type->equals(ArcadiaMailType::default()) ? 'mail.arcadiaOrders.default' : 'mail.arcadiaOrders.game'; return view($arcadiaMailType, [ 'request' => $request, 'type' => $type, 'orderType' => $orderType, 'customerInfo' => $customerInfo ])->render(); } }