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.

87 rindas
2.3KB

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