PassthroughDataBuilder.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\Model\PassthroughDataObject;
  9. use Magento\Payment\Gateway\Request\BuilderInterface;
  10. /**
  11. * Adds data to the request that can be used in the response
  12. */
  13. class PassthroughDataBuilder implements BuilderInterface
  14. {
  15. /**
  16. * @var PassthroughDataObject
  17. */
  18. private $passthroughData;
  19. /**
  20. * @param PassthroughDataObject $passthroughData
  21. */
  22. public function __construct(PassthroughDataObject $passthroughData)
  23. {
  24. $this->passthroughData = $passthroughData;
  25. }
  26. /**
  27. * @inheritdoc
  28. */
  29. public function build(array $buildSubject): array
  30. {
  31. $fields = [];
  32. foreach ($this->passthroughData->getData() as $key => $value) {
  33. $fields[] = [
  34. 'name' => $key,
  35. 'value' => $value
  36. ];
  37. }
  38. if (!empty($fields)) {
  39. return [
  40. 'transactionRequest' => [
  41. 'userFields' => [
  42. 'userField' => $fields
  43. ]
  44. ]
  45. ];
  46. }
  47. return [];
  48. }
  49. }