Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

85 rindas
2.2KB

  1. <?php
  2. namespace common\logic\Payment\Service;
  3. use common\logic\AbstractBuilder;
  4. use common\logic\Document\Invoice\Model\Invoice;
  5. use common\logic\Order\Order\Model\Order;
  6. use common\logic\Order\Order\Service\OrderSolver;
  7. use common\logic\Payment\Model\Payment;
  8. use common\logic\Producer\Producer\Model\Producer;
  9. use common\logic\User\User\Model\User;
  10. class PaymentBuilder extends AbstractBuilder
  11. {
  12. protected PaymentSolver $paymentSolver;
  13. protected OrderSolver $orderSolver;
  14. public function loadDependencies(): void
  15. {
  16. $this->paymentSolver = $this->loadService(PaymentSolver::class);
  17. $this->orderSolver = $this->loadService(OrderSolver::class);
  18. }
  19. public function instanciatePayment(
  20. string $type,
  21. float $amount,
  22. Producer $producer,
  23. User $user = null,
  24. User $userAction = null,
  25. string $meanPayment = null,
  26. string $comment = null,
  27. Order $order = null,
  28. Invoice $invoice = null
  29. ): Payment
  30. {
  31. $payment = new Payment;
  32. $payment->type = $type;
  33. $payment->amount = round($amount, 2);
  34. $payment->populateProducer($producer);
  35. $payment->setMeanPayment($meanPayment);
  36. $payment->setComment($comment);
  37. if($user) {
  38. $payment->populateUser($user);
  39. }
  40. if($userAction) {
  41. $payment->populateUserAction($userAction);
  42. }
  43. if($order) {
  44. $payment->populateOrder($order);
  45. }
  46. if($invoice) {
  47. $payment->populateInvoice($invoice);
  48. }
  49. return $payment;
  50. }
  51. public function createPayment(
  52. string $type,
  53. float $amount,
  54. Producer $producer,
  55. User $user = null,
  56. User $userAction = null,
  57. string $meanPayment = null,
  58. string $comment = null,
  59. Order $order = null,
  60. Invoice $invoice = null
  61. ): ?Payment
  62. {
  63. if ($amount > -0.01 && $amount < 0.01) {
  64. return null;
  65. }
  66. $payment = $this->instanciatePayment($type, $amount, $producer, $user, $userAction, $meanPayment, $comment, $order, $invoice);
  67. $payment->setSummary($this->orderSolver->getPaymentComment($payment));
  68. $this->create($payment);
  69. return $payment;
  70. }
  71. }