AddressDataBuilder.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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\Payment\Gateway\Request\BuilderInterface;
  10. /**
  11. * Adds the basic payment information to the request
  12. */
  13. class AddressDataBuilder implements BuilderInterface
  14. {
  15. /**
  16. * @var SubjectReader
  17. */
  18. private $subjectReader;
  19. /**
  20. * @param SubjectReader $subjectReader
  21. */
  22. public function __construct(SubjectReader $subjectReader)
  23. {
  24. $this->subjectReader = $subjectReader;
  25. }
  26. /**
  27. * @inheritdoc
  28. */
  29. public function build(array $buildSubject): array
  30. {
  31. $paymentDO = $this->subjectReader->readPayment($buildSubject);
  32. $order = $paymentDO->getOrder();
  33. $billingAddress = $order->getBillingAddress();
  34. $shippingAddress = $order->getShippingAddress();
  35. $result = [
  36. 'transactionRequest' => []
  37. ];
  38. if ($billingAddress) {
  39. $result['transactionRequest']['billTo'] = [
  40. 'firstName' => $billingAddress->getFirstname(),
  41. 'lastName' => $billingAddress->getLastname(),
  42. 'company' => $billingAddress->getCompany() ?? '',
  43. 'address' => $billingAddress->getStreetLine1(),
  44. 'city' => $billingAddress->getCity(),
  45. 'state' => $billingAddress->getRegionCode(),
  46. 'zip' => $billingAddress->getPostcode(),
  47. 'country' => $billingAddress->getCountryId()
  48. ];
  49. }
  50. if ($shippingAddress) {
  51. $result['transactionRequest']['shipTo'] = [
  52. 'firstName' => $shippingAddress->getFirstname(),
  53. 'lastName' => $shippingAddress->getLastname(),
  54. 'company' => $shippingAddress->getCompany() ?? '',
  55. 'address' => $shippingAddress->getStreetLine1(),
  56. 'city' => $shippingAddress->getCity(),
  57. 'state' => $shippingAddress->getRegionCode(),
  58. 'zip' => $shippingAddress->getPostcode(),
  59. 'country' => $shippingAddress->getCountryId()
  60. ];
  61. }
  62. if ($order->getRemoteIp()) {
  63. $result['transactionRequest']['customerIP'] = $order->getRemoteIp();
  64. }
  65. return $result;
  66. }
  67. }