您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

88 行
2.4KB

  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. string $dateTransaction = null,
  28. Order $order = null,
  29. Invoice $invoice = null
  30. ): Payment
  31. {
  32. $payment = new Payment;
  33. $payment->type = $type;
  34. $payment->amount = round($amount, 2);
  35. $payment->populateProducer($producer);
  36. $payment->setMeanPayment($meanPayment);
  37. $payment->setComment($comment);
  38. $payment->setDateTransaction($dateTransaction);
  39. if($user) {
  40. $payment->populateUser($user);
  41. }
  42. if($userAction) {
  43. $payment->populateUserAction($userAction);
  44. }
  45. if($order) {
  46. $payment->populateOrder($order);
  47. }
  48. if($invoice) {
  49. $payment->populateInvoice($invoice);
  50. }
  51. return $payment;
  52. }
  53. public function createPayment(
  54. string $type,
  55. float $amount,
  56. Producer $producer,
  57. User $user = null,
  58. User $userAction = null,
  59. string $meanPayment = null,
  60. string $comment = null,
  61. string $dateTransaction = null,
  62. Order $order = null,
  63. Invoice $invoice = null
  64. ): ?Payment
  65. {
  66. if ($amount > -0.01 && $amount < 0.01) {
  67. return null;
  68. }
  69. $payment = $this->instanciatePayment($type, $amount, $producer, $user, $userAction, $meanPayment, $comment, $dateTransaction, $order, $invoice);
  70. $payment->setSummary($this->orderSolver->getPaymentComment($payment));
  71. $this->create($payment);
  72. return $payment;
  73. }
  74. }