From 5e5493ff8221f7d760affdc43c42bb8280f274e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Tue, 16 May 2023 08:33:17 +0200 Subject: [PATCH] More Fixes --- README.md | 3 ++ .../SystempayCreditTransactionUpdate.php | 4 +- app/Models/Shop/Order.php | 38 +++++-------------- 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 8e58233..1ff49ee 100644 --- a/README.md +++ b/README.md @@ -72,3 +72,6 @@ php artisan cashier:webhook # TODO - Allow changing e-mail quand ca sera supporté sur CRM (use soundsystem mechanism) + +# FIXME + Envoi d’un mail de remboursement avec l’avoir en pièce jointe : l’avoir est vide diff --git a/app/Jobs/Payment/SystempayCreditTransactionUpdate.php b/app/Jobs/Payment/SystempayCreditTransactionUpdate.php index bbb935a..d4855b0 100644 --- a/app/Jobs/Payment/SystempayCreditTransactionUpdate.php +++ b/app/Jobs/Payment/SystempayCreditTransactionUpdate.php @@ -107,7 +107,7 @@ class SystempayCreditTransactionUpdate return ResponseType::expiredPayment(); case \in_array($transStatus, ['SUSPENDED']): return ResponseType::suspendedPayment(); - case $this->isCancelledPayment($transStatus) or + case $this->isCanceledPayment($transStatus) or \in_array($transStatus, ['CANCELLED']): return ResponseType::canceledPayment(); case $this->isPendingPayment($transStatus): @@ -165,7 +165,7 @@ class SystempayCreditTransactionUpdate * @param string $transStatus * @return boolean */ - private function isCancelledPayment(string $transStatus): bool + private function isCanceledPayment(string $transStatus): bool { $canceled_statuses = [ 'NOT_CREATED', diff --git a/app/Models/Shop/Order.php b/app/Models/Shop/Order.php index 45ebca0..abac0de 100644 --- a/app/Models/Shop/Order.php +++ b/app/Models/Shop/Order.php @@ -131,7 +131,6 @@ class Order extends Model static::updating(function (self $model) { static::assertValidateStatus($model); static::assertCancelStatus($model); - static::assertDeliveryStatusCanBeChanged($model); if ($model->validation_status->equals(ValidationStatus::validated())) { OrderIsValidated::dispatchUnless($model->mail_sent, $model); @@ -285,12 +284,15 @@ class Order extends Model * * @return boolean */ - public function getCanBeCancelledAttribute(): bool + public function getCanBeCanceledAttribute(): bool { // * Si le status de validation n'est pas annulé return $this->getOriginal('validation_status') !== ValidationStatus::canceled()->value && // * Si le statut de livraison n'est pas récupéré - $this->getOriginal('delivery_status') !== DeliveryStatus::recovered()->value; + !\in_array($this->getOriginal('delivery_status'), [ + DeliveryStatus::recovered()->value, + DeliveryStatus::canceled()->value, + ]); } /** @@ -304,7 +306,10 @@ class Order extends Model public function getCanBeRefundAttribute(): bool { return $this->total_ttc > $this->total_refund and - !$this->delivery_status->equals(DeliveryStatus::recovered()); + !\in_array($this->getOriginal('delivery_status'), [ + DeliveryStatus::recovered()->value, + DeliveryStatus::canceled()->value, + ]); } /** @@ -581,31 +586,6 @@ class Order extends Model } } - /** - * Check if delivery status can be changed. - * - * @param self $model - * @return void - * @throws \Illuminate\Validation\ValidationException If the order is canceled while it cannot be. - */ - public static function assertDeliveryStatusCanBeChanged(self $model) - { - $deliveryStatusHasChanged = $model->getOriginal('delivery_status') !== $model->delivery_status->value; - if ($deliveryStatusHasChanged and !$model->validation_status->equals(ValidationStatus::validated())) { - throw ValidationException::withMessages([ - 'messages' => - // phpcs:ignore Generic.Files.LineLength.TooLong - "L'état de livraison de la commande ne peut être modifié car la commande '{$model->id}' n'est pas validée" - ]); - } - if ($model->getOriginal('validation_status') === ValidationStatus::canceled()->value) { - throw ValidationException::withMessages([ - 'messages' => - "L'état de livraison de la commande ne peut être modifié car la commande '{$model->id}' est annulée" - ]); - } - } - /** * Get updated current session order *