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

85 行
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. Order $order = null,
  27. Invoice $invoice = null
  28. ): Payment
  29. {
  30. $payment = new Payment;
  31. $payment->type = $type;
  32. $payment->amount = round($amount, 2);
  33. $payment->populateProducer($producer);
  34. if($user) {
  35. $payment->populateUser($user);
  36. }
  37. if($userAction) {
  38. $payment->populateUserAction($userAction);
  39. }
  40. if($order) {
  41. $payment->populateOrder($order);
  42. }
  43. if($invoice) {
  44. $payment->populateInvoice($invoice);
  45. }
  46. if($meanPayment) {
  47. $payment->mean_payment = $meanPayment;
  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. Order $order = null,
  59. Invoice $invoice = null
  60. ): ?Payment
  61. {
  62. if ($amount > -0.01 && $amount < 0.01) {
  63. return null;
  64. }
  65. $payment = $this->instanciatePayment($type, $amount, $producer, $user, $userAction, $meanPayment, $order, $invoice);
  66. $payment->setComment($payment->getComment() . $this->orderSolver->getPaymentComment($payment));
  67. $this->create($payment);
  68. return $payment;
  69. }
  70. }