|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
-
- namespace common\logic\Payment\Service;
-
- use common\helpers\MeanPayment;
- use common\logic\AbstractService;
- use common\logic\Order\Order\Model\Order;
- use common\logic\Payment\Model\Payment;
- use common\logic\SolverInterface;
-
- class PaymentSolver extends AbstractService implements SolverInterface
- {
- public function isTypeDebit(Payment $payment): bool
- {
- return in_array($payment->getType(), [
- Payment::TYPE_DEBIT,
- Payment::TYPE_PAYMENT,
- ]);
- }
-
- public function isTypeCredit(Payment $payment): bool
- {
- return in_array($payment->getType(), [
- Payment::TYPE_CREDIT,
- Payment::TYPE_INITIAL_CREDIT,
- Payment::TYPE_REFUND
- ]);
- }
-
- public function sumAmountPaid(Payment $payment, float $amount = 0)
- {
- if($this->isTypeDebit($payment)) {
- $amount += $payment->amount;
- }
- else {
- $amount -= $payment->amount;
- }
-
- return $amount;
- }
-
- public function getAmount(Payment $payment, bool $format = false): string
- {
- if ($format) {
- return number_format($payment->getAmount(), 2) . ' €';
- } else {
- return $payment->getAmount();
- }
- }
-
- /**
- * Retourne le libellé du CreditHistory informant de son type et
- * éventuellement de la date de sa commande associée.
- *
- */
- public function getStrWording(Payment $payment, Order $order = null): string
- {
- $str = '';
- $type = $payment->getType();
-
- if (Payment::TYPE_INITIAL_CREDIT == $type) {
- $str = 'Crédit initial';
- } elseif (Payment::TYPE_CREDIT == $type) {
- $str = 'Crédit';
- } elseif (Payment::TYPE_PAYMENT == $type) {
- $str = 'Débit';
- } elseif (Payment::TYPE_REFUND == $type) {
- $str = 'Recrédit';
- } elseif (Payment::TYPE_DEBIT == $type) {
- $str = 'Débit';
- }
-
- if (Payment::TYPE_PAYMENT == $type || Payment::TYPE_REFUND == $type) {
-
- // Optimisation
- if(!$order) {
- $order = $payment->order;
- }
-
- if ($order && $order->distribution) {
- $str .= '<br />Commande : ' . date('d/m/Y', strtotime($order->distribution->date));
- } else {
- $str .= '<br />Commande supprimée';
- }
- }
-
- return $str;
- }
-
- public function getDate(Payment $payment, bool $format = false): string
- {
- $date = $payment->getDate();
-
- if ($format) {
- return date('d/m/Y à H:i:s', strtotime($date));
- } else {
- return $date;
- }
- }
-
- public function isMeanPaymentCredit(Payment $payment): bool
- {
- return $payment->mean_payment == MeanPayment::CREDIT;
- }
-
- public function getStrMeanPayment(Payment $payment): string
- {
- return MeanPayment::getStrBy($payment->getMeanPayment());
- }
-
- public function getStrType(Payment $payment): string
- {
- switch($payment->type) {
- case Payment::TYPE_PAYMENT:
- return 'Paiement';
- case Payment::TYPE_DEBIT:
- return 'Débit';
- case Payment::TYPE_CREDIT:
- return 'Crédit';
- case Payment::TYPE_REFUND:
- return 'Remboursement';
- case Payment::TYPE_INITIAL_CREDIT:
- return 'Crédit initial';
- }
-
- return 'Type de paiement inconnu';
- }
-
- public function getStrUserAction(Payment $payment): string
- {
- $userAction = $payment->getUserActionObject();
-
- if ($userAction) {
- return $userAction->getName() . ' ' . $userAction->getlastname();
- } else {
- return 'Système';
- }
- }
- }
|