From 94aeac4892d215bdf67ce1308776ca9e7cfd0895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Fri, 15 Oct 2021 16:48:27 +0200 Subject: [PATCH 1/3] client v2 update --- clients/V2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/V2 b/clients/V2 index 639e6ea..93950cd 160000 --- a/clients/V2 +++ b/clients/V2 @@ -1 +1 @@ -Subproject commit 639e6eacebdf4dfa9140429c49db9053052093bc +Subproject commit 93950cd75e168e2c274762ecfaca13eada1ce077 From c70d8bd376520b7e529b0cafa15ccf403faacb2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Fri, 15 Oct 2021 18:36:02 +0200 Subject: [PATCH 2/3] Try to prevent overlaping on job setServiceStat --- app/Jobs/SetServiceStats.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Jobs/SetServiceStats.php b/app/Jobs/SetServiceStats.php index 2522c66..94df567 100644 --- a/app/Jobs/SetServiceStats.php +++ b/app/Jobs/SetServiceStats.php @@ -8,6 +8,7 @@ use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; +use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Queue\SerializesModels; class SetServiceStats implements ShouldQueue @@ -17,6 +18,9 @@ class SetServiceStats implements ShouldQueue use Queueable; use SerializesModels; + /** Used to prevent overlaping */ + private const JOBKEY = 95563222; + /** @var \App\Models\Service */ protected $service; @@ -45,4 +49,9 @@ class SetServiceStats implements ShouldQueue $serviceStat->nb_calls += 1; $serviceStat->saveOrFail(); } + + public function middleware() + { + return [(new WithoutOverlapping(self::JOBKEY))->releaseAfter(30)]; + } } From 923e566ee768242c3987317e2da572c43aada298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Mon, 18 Oct 2021 09:03:00 +0200 Subject: [PATCH 3/3] Changed Arcadia mails, add customer parameters for these calls Updated Client bump to 2.2.0 --- .../Controllers/Api/V2/ArcadiaController.php | 37 +++++++++---------- .../Api/V2/SendArchadiaDefaultMailRequest.php | 17 +++++++++ .../Api/V2/SendArchadiaGameMailRequest.php | 21 ++++++++++- .../Requests/Api/V2/StoreCustomerRequest.php | 2 +- clients/V2 | 2 +- composer.json | 2 +- .../mail/arcadiaOrders/default.blade.php | 16 ++++---- routes/api.php | 4 +- tests/Feature/ApiV2/ArcadiaTest.php | 24 ++++++++++-- tests/Unit/CrmClientV2ArcadiaTest.php | 19 +++++++++- 10 files changed, 106 insertions(+), 38 deletions(-) diff --git a/app/Http/Controllers/Api/V2/ArcadiaController.php b/app/Http/Controllers/Api/V2/ArcadiaController.php index ca3c0bd..e6897f2 100644 --- a/app/Http/Controllers/Api/V2/ArcadiaController.php +++ b/app/Http/Controllers/Api/V2/ArcadiaController.php @@ -10,8 +10,6 @@ use App\Http\Requests\Api\V2\BaseApiRequest; use App\Http\Requests\Api\V2\SendArchadiaDefaultMailRequest; use App\Http\Requests\Api\V2\SendArchadiaGameMailRequest; use App\Mail\CourrierArcadiaError; -use App\Models\Customer; -use App\Models\CustomerInfo; use App\Models\Service; use DOMDocument; use Illuminate\Support\Facades\Log; @@ -30,33 +28,37 @@ use Illuminate\Support\Facades\Storage; */ class ArcadiaController extends Controller { - public function outgoingMailDefault(SendArchadiaDefaultMailRequest $request, Customer $customer, Service $service) + public function outgoingMailDefault(SendArchadiaDefaultMailRequest $request, Service $service) { - $this->authorize('customerBelongsToService', $customer); - return $this->handleArcadiaMail($request, ArcadiaMailType::default(), $customer, $service); + return $this->handleArcadiaMail($request, ArcadiaMailType::default(), $service); } - public function outgoingMailGame(SendArchadiaGameMailRequest $request, Customer $customer, Service $service) + public function outgoingMailGame(SendArchadiaGameMailRequest $request, Service $service) { - $this->authorize('customerBelongsToService', $customer); - return $this->handleArcadiaMail($request, ArcadiaMailType::game(), $customer, $service); + return $this->handleArcadiaMail($request, ArcadiaMailType::game(), $service); } private function handleArcadiaMail( BaseApiRequest $request, - ArcadiaMailType $type, - Customer $customer, - Service $service + ArcadiaMailType $type ) { $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); + $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, $customer, $customerInfo); + $xml = $this->makeXml($request, $type, $orderType, $customerInfo); // Format xml $doc = new DOMDocument('1.0', 'utf-8'); @@ -90,16 +92,14 @@ class ArcadiaController extends Controller * @param SendArchadiaMailRequest $request * @param ArcadiaMailType $type * @param ArcadiaOrderType $orderType - * @param Customer $customer - * @param CustomerInfo $customerInfo + * @param array $customerInfo * @return string */ private function makeXml( BaseApiRequest $request, ArcadiaMailType $type, ArcadiaOrderType $orderType, - Customer $customer, - CustomerInfo $customerInfo + array $customerInfo ): string { return view( 'mail.arcadiaOrders.default', @@ -107,7 +107,6 @@ class ArcadiaController extends Controller 'request' => $request, 'type' => $type, 'orderType' => $orderType, - 'customer' => $customer, 'customerInfo' => $customerInfo ] )->render(); diff --git a/app/Http/Requests/Api/V2/SendArchadiaDefaultMailRequest.php b/app/Http/Requests/Api/V2/SendArchadiaDefaultMailRequest.php index d554900..510e8c4 100644 --- a/app/Http/Requests/Api/V2/SendArchadiaDefaultMailRequest.php +++ b/app/Http/Requests/Api/V2/SendArchadiaDefaultMailRequest.php @@ -19,6 +19,14 @@ class SendArchadiaDefaultMailRequest extends BaseApiRequest 'order_num' => RemoveNonNumeric::class, 'package_unit_weight' => RemoveNonNumeric::class, 'support_code' => Trim::class, + 'deliver.firstname' => Trim::class, + 'deliver.lastname' => Trim::class, + 'deliver.email' => Trim::class, + 'deliver.address' => Trim::class, + 'deliver.address2' => Trim::class, + 'deliver.city' => Trim::class, + 'deliver.postcode' => Trim::class, + 'deliver.phone' => Trim::class ]; /** @@ -39,6 +47,15 @@ class SendArchadiaDefaultMailRequest extends BaseApiRequest new EnumIsValidRule(ArcadiaOrderType::class) ], 'support_code' => 'required|int', + 'deliver' => 'required|array', + 'deliver.firstname' => 'required|string|min:2', + 'deliver.lastname' => 'required|string|min:2', + 'deliver.email' => 'required|email:rfc,dns,spoof,filter', + 'deliver.address' => 'required|string|min:2', + 'deliver.address2' => 'sometimes|string|min:2', + 'deliver.city' => 'required|string|min:2', + 'deliver.postcode' => 'required|string|min:5', + 'deliver.phone' => 'required|string', ]; } } diff --git a/app/Http/Requests/Api/V2/SendArchadiaGameMailRequest.php b/app/Http/Requests/Api/V2/SendArchadiaGameMailRequest.php index 901c48a..c30c71c 100644 --- a/app/Http/Requests/Api/V2/SendArchadiaGameMailRequest.php +++ b/app/Http/Requests/Api/V2/SendArchadiaGameMailRequest.php @@ -16,7 +16,15 @@ class SendArchadiaGameMailRequest extends BaseApiRequest 'operation' => Trim::class, 'order_date' => Trim::class, 'support_code' => Trim::class, - 'type' => Trim::class + 'type' => Trim::class, + 'deliver.firstname' => Trim::class, + 'deliver.lastname' => Trim::class, + 'deliver.email' => Trim::class, + 'deliver.address' => Trim::class, + 'deliver.address2' => Trim::class, + 'deliver.city' => Trim::class, + 'deliver.postcode' => Trim::class, + 'deliver.phone' => Trim::class ]; /** @@ -32,7 +40,16 @@ class SendArchadiaGameMailRequest extends BaseApiRequest 'label_type_support' => 'required|string', 'operation' => 'required|int', 'order_date' => 'required|date', - 'support_code' => 'required|int' + 'support_code' => 'required|int', + 'deliver' => 'required|array', + 'deliver.firstname' => 'required|string|min:2', + 'deliver.lastname' => 'required|string|min:2', + 'deliver.email' => 'required|email:rfc,dns,spoof,filter', + 'deliver.address' => 'required|string|min:2', + 'deliver.address2' => 'sometimes|string|min:2', + 'deliver.city' => 'required|string|min:2', + 'deliver.postcode' => 'required|digits:5', + 'deliver.phone' => 'required|string', ]; } } diff --git a/app/Http/Requests/Api/V2/StoreCustomerRequest.php b/app/Http/Requests/Api/V2/StoreCustomerRequest.php index a3f7f6d..5ff3268 100644 --- a/app/Http/Requests/Api/V2/StoreCustomerRequest.php +++ b/app/Http/Requests/Api/V2/StoreCustomerRequest.php @@ -28,7 +28,7 @@ class StoreCustomerRequest extends BaseApiRequest ->uncompromised() ], 'birth_date' => 'required|date_format:Y-m-d', - 'address' => 'sometimes|string', + 'address' => 'sometimes|required_with:address2|string', 'address2' => 'sometimes|string', 'phone' => 'sometimes|string', 'country' => [ diff --git a/clients/V2 b/clients/V2 index 93950cd..c957231 160000 --- a/clients/V2 +++ b/clients/V2 @@ -1 +1 @@ -Subproject commit 93950cd75e168e2c274762ecfaca13eada1ce077 +Subproject commit c9572314aac3819994e8fd81b918a2075fac1ac7 diff --git a/composer.json b/composer.json index c977808..d8d1aad 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "ldc/ldccrmv2client", "type": "project", - "version": "2.1.8", + "version": "2.2.0", "description": "LDC CRM V2", "authors": [ { diff --git a/resources/views/mail/arcadiaOrders/default.blade.php b/resources/views/mail/arcadiaOrders/default.blade.php index 5b55cbe..cdbaabe 100644 --- a/resources/views/mail/arcadiaOrders/default.blade.php +++ b/resources/views/mail/arcadiaOrders/default.blade.php @@ -1,15 +1,15 @@ - email }}]]> + - lastname }}]]> - firstname }}]]> - address }}]]> - address2 }}]]> - postcode }}]]> - city }}]]> - phone }}]]> + + + + + + + @if($type->equals(ArcadiaMailType::default())) @if($orderType->equals(ArcadiaOrderType::cb())) 1 diff --git a/routes/api.php b/routes/api.php index ed014ca..ad5d783 100644 --- a/routes/api.php +++ b/routes/api.php @@ -55,9 +55,9 @@ Route::prefix('v2')->name('apiV2.')->group(function () { }); }); Route::prefix('arcadia')->name('arcadia.')->group(function () { - Route::post('/outgoing-mail/{customer}/default', [V2ArcadiaController::class, 'outgoingMailDefault']) + Route::post('/outgoing-mail/default', [V2ArcadiaController::class, 'outgoingMailDefault']) ->name('outgoingMailDefault'); - Route::post('/outgoing-mail/{customer}/game', [V2ArcadiaController::class, 'outgoingMailGame']) + Route::post('/outgoing-mail/game', [V2ArcadiaController::class, 'outgoingMailGame']) ->name('outgoingMailGame'); }); Route::apiResource('questions', V2QuestionController::class)->only(['index']); diff --git a/tests/Feature/ApiV2/ArcadiaTest.php b/tests/Feature/ApiV2/ArcadiaTest.php index e3aa138..cec79c1 100644 --- a/tests/Feature/ApiV2/ArcadiaTest.php +++ b/tests/Feature/ApiV2/ArcadiaTest.php @@ -20,6 +20,16 @@ class ArcadiaTest extends ApiBase { extract($this->getCustomer()); $data = [ + 'deliver' => [ + 'email' => $customer->email, + 'firstname' => $info->firstname, + 'lastname' => $info->lastname, + 'phone' => $info->phone, + 'address' => $info->address, + 'address2' => $info->address2, + 'city' => $info->city, + 'postcode' => $info->postcode, + ], 'operation' => 16, 'label_type_support' => 'Send Departaimants', 'order_date' => \date('Y/m/d H:i:s'), @@ -30,8 +40,7 @@ class ArcadiaTest extends ApiBase 'package_unit_weight' => 200, ]; $response = $this->callApiWithToken($service, 'post', route( - 'apiV2.arcadia.outgoingMailDefault', - compact('customer') + 'apiV2.arcadia.outgoingMailDefault' ), $data); $json = $response->decodeResponseJson(); @@ -42,6 +51,16 @@ class ArcadiaTest extends ApiBase { extract($this->getCustomer()); $data = [ + 'deliver' => [ + 'email' => $customer->email, + 'firstname' => $info->firstname, + 'lastname' => $info->lastname, + 'phone' => $info->phone, + 'address' => $info->address, + 'address2' => $info->address2, + 'city' => $info->city, + 'postcode' => $info->postcode, + ], 'operation' => 16, 'order_date' => date('Y/m/d H:i:s'), 'support_code' => 32, @@ -51,7 +70,6 @@ class ArcadiaTest extends ApiBase ]; $response = $this->callApiWithToken($service, 'post', route( 'apiV2.arcadia.outgoingMailGame', - compact('customer') ), $data); $json = $response->decodeResponseJson(); diff --git a/tests/Unit/CrmClientV2ArcadiaTest.php b/tests/Unit/CrmClientV2ArcadiaTest.php index f87a21c..10cf626 100644 --- a/tests/Unit/CrmClientV2ArcadiaTest.php +++ b/tests/Unit/CrmClientV2ArcadiaTest.php @@ -14,8 +14,16 @@ class CrmClientV2ArcadiaTest extends CrmClientTester { $api = new CrmApiV2(); $customer = $api->getCustomerOrNew(static::$info->hashcode); - + dump(static::$info->postcode); $arcadiaOrderMail = new ArcadiaMailDefault([ + 'email' => static::$customer->email, + 'firstname' => static::$info->firstname, + 'lastname' => static::$info->lastname, + 'phone' => static::$info->phone, + 'address' => static::$info->address, + 'address2' => static::$info->address2, + 'city' => static::$info->city, + 'postcode' => static::$info->postcode, 'operation' => 16, 'label_type_support' => 'Send Departaimants', 'order_date' => \date('Y/m/d H:i:s'), @@ -32,7 +40,16 @@ class CrmClientV2ArcadiaTest extends CrmClientTester { $api = new CrmApiV2(); $customer = $api->getCustomerOrNew(static::$info->hashcode); + dump(static::$info->postcode); $arcadiaOrderMail = new ArcadiaMailGame([ + 'email' => static::$customer->email, + 'firstname' => static::$info->firstname, + 'lastname' => static::$info->lastname, + 'phone' => static::$info->phone, + 'address' => static::$info->address, + 'address2' => static::$info->address2, + 'city' => static::$info->city, + 'postcode' => static::$info->postcode, 'operation' => 16, 'order_date' => date('Y/m/d H:i:s'), 'support_code' => 32,