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; } }