Processor.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model\Order\Payment;
  7. use Magento\Sales\Api\Data\InvoiceInterface;
  8. use Magento\Sales\Api\Data\OrderPaymentInterface;
  9. use Magento\Sales\Model\Order\Invoice;
  10. use Magento\Sales\Model\Order\Payment;
  11. use Magento\Sales\Model\Order\Payment\Operations\AuthorizeOperation;
  12. use Magento\Sales\Model\Order\Payment\Operations\CaptureOperation;
  13. use Magento\Sales\Model\Order\Payment\Operations\OrderOperation as OrderOperation;
  14. use Magento\Sales\Model\Order\Payment\Operations\RegisterCaptureNotificationOperation;
  15. /**
  16. * Class Processor using for process payment
  17. */
  18. class Processor
  19. {
  20. /**
  21. * @var AuthorizeOperation
  22. */
  23. protected $authorizeOperation;
  24. /**
  25. * @var CaptureOperation
  26. */
  27. protected $captureOperation;
  28. /**
  29. * @var OrderOperation
  30. */
  31. protected $orderOperation;
  32. /**
  33. * @var RegisterCaptureNotificationOperation
  34. */
  35. protected $registerCaptureNotification;
  36. /**
  37. * Set operations
  38. *
  39. * @param AuthorizeOperation $authorizeOperation
  40. * @param CaptureOperation $captureOperation
  41. * @param OrderOperation $orderOperation
  42. * @param RegisterCaptureNotificationOperation $registerCaptureNotification
  43. */
  44. public function __construct(
  45. AuthorizeOperation $authorizeOperation,
  46. CaptureOperation $captureOperation,
  47. OrderOperation $orderOperation,
  48. RegisterCaptureNotificationOperation $registerCaptureNotification
  49. ) {
  50. $this->authorizeOperation = $authorizeOperation;
  51. $this->captureOperation = $captureOperation;
  52. $this->orderOperation = $orderOperation;
  53. $this->registerCaptureNotification = $registerCaptureNotification;
  54. }
  55. /**
  56. * Process authorize operation
  57. *
  58. * @param OrderPaymentInterface $payment
  59. * @param bool $isOnline
  60. * @param float $amount
  61. * @return OrderPaymentInterface|Payment
  62. */
  63. public function authorize(OrderPaymentInterface $payment, $isOnline, $amount)
  64. {
  65. return $this->authorizeOperation->authorize($payment, $isOnline, $amount);
  66. }
  67. /**
  68. * Process capture operation
  69. *
  70. * @param OrderPaymentInterface $payment
  71. * @param InvoiceInterface $invoice
  72. * @return OrderPaymentInterface|Payment
  73. * @throws \Magento\Framework\Exception\LocalizedException
  74. */
  75. public function capture(OrderPaymentInterface $payment, $invoice)
  76. {
  77. return $this->captureOperation->capture($payment, $invoice);
  78. }
  79. /**
  80. * Process order operation
  81. *
  82. * @param OrderPaymentInterface $payment
  83. * @param float $amount
  84. * @return OrderPaymentInterface|Payment
  85. */
  86. public function order(OrderPaymentInterface $payment, $amount)
  87. {
  88. return $this->orderOperation->order($payment, $amount);
  89. }
  90. /**
  91. * Registers capture notification.
  92. *
  93. * @param OrderPaymentInterface $payment
  94. * @param string|float $amount
  95. * @param bool|int $skipFraudDetection
  96. * @return OrderPaymentInterface
  97. */
  98. public function registerCaptureNotification(
  99. OrderPaymentInterface $payment,
  100. $amount,
  101. $skipFraudDetection = false
  102. ) {
  103. return $this->registerCaptureNotification->registerCaptureNotification($payment, $amount, $skipFraudDetection);
  104. }
  105. }