SaleDataBuilder.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\AuthorizenetAcceptjs\Gateway\Request;
  8. use Magento\AuthorizenetAcceptjs\Gateway\SubjectReader;
  9. use Magento\AuthorizenetAcceptjs\Model\PassthroughDataObject;
  10. use Magento\Payment\Gateway\Request\BuilderInterface;
  11. use Magento\Sales\Model\Order\Payment;
  12. /**
  13. * Adds the meta transaction information to the request
  14. */
  15. class SaleDataBuilder implements BuilderInterface
  16. {
  17. private const REQUEST_AUTH_AND_CAPTURE = 'authCaptureTransaction';
  18. /**
  19. * @var SubjectReader
  20. */
  21. private $subjectReader;
  22. /**
  23. * @var PassthroughDataObject
  24. */
  25. private $passthroughData;
  26. /**
  27. * @param SubjectReader $subjectReader
  28. * @param PassthroughDataObject $passthroughData
  29. */
  30. public function __construct(
  31. SubjectReader $subjectReader,
  32. PassthroughDataObject $passthroughData
  33. ) {
  34. $this->subjectReader = $subjectReader;
  35. $this->passthroughData = $passthroughData;
  36. }
  37. /**
  38. * @inheritdoc
  39. */
  40. public function build(array $buildSubject): array
  41. {
  42. $paymentDO = $this->subjectReader->readPayment($buildSubject);
  43. $payment = $paymentDO->getPayment();
  44. $data = [];
  45. if ($payment instanceof Payment) {
  46. $data = [
  47. 'transactionRequest' => [
  48. 'transactionType' => self::REQUEST_AUTH_AND_CAPTURE,
  49. ]
  50. ];
  51. $this->passthroughData->setData(
  52. 'transactionType',
  53. $data['transactionRequest']['transactionType']
  54. );
  55. }
  56. return $data;
  57. }
  58. }