|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
-
- namespace common\logic\Payment\Service;
-
- use common\logic\AbstractBuilder;
- use common\logic\Document\Invoice\Model\Invoice;
- use common\logic\Order\Order\Model\Order;
- use common\logic\Order\Order\Service\OrderSolver;
- use common\logic\Payment\Model\Payment;
- use common\logic\Producer\Producer\Model\Producer;
- use common\logic\User\User\Model\User;
-
- class PaymentBuilder extends AbstractBuilder
- {
- protected PaymentSolver $paymentSolver;
- protected OrderSolver $orderSolver;
-
- public function loadDependencies(): void
- {
- $this->paymentSolver = $this->loadService(PaymentSolver::class);
- $this->orderSolver = $this->loadService(OrderSolver::class);
- }
-
- public function instanciatePayment(
- string $type,
- float $amount,
- Producer $producer,
- User $user = null,
- User $userAction = null,
- string $meanPayment = null,
- Order $order = null,
- Invoice $invoice = null
- ): Payment
- {
- $payment = new Payment;
-
- $payment->type = $type;
- $payment->amount = round($amount, 2);
- $payment->populateProducer($producer);
-
- if($user) {
- $payment->populateUser($user);
- }
-
- if($userAction) {
- $payment->populateUserAction($userAction);
- }
-
- if($order) {
- $payment->populateOrder($order);
- }
-
- if($invoice) {
- $payment->populateInvoice($invoice);
- }
-
- if($meanPayment) {
- $payment->mean_payment = $meanPayment;
- }
-
- return $payment;
- }
-
- public function createPayment(
- string $type,
- float $amount,
- Producer $producer,
- User $user = null,
- User $userAction = null,
- string $meanPayment = null,
- Order $order = null,
- Invoice $invoice = null
- ): ?Payment
- {
- if ($amount > -0.01 && $amount < 0.01) {
- return null;
- }
-
- $payment = $this->instanciatePayment($type, $amount, $producer, $user, $userAction, $meanPayment, $order, $invoice);
- $payment->setComment($payment->getComment() . $this->orderSolver->getPaymentComment($payment));
- $this->create($payment);
-
- return $payment;
- }
- }
|