SubjectReader.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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;
  8. use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
  9. use Magento\Payment\Gateway\Helper;
  10. /**
  11. * Helper for extracting information from the payment data structure
  12. */
  13. class SubjectReader
  14. {
  15. /**
  16. * Reads payment from subject
  17. *
  18. * @param array $subject
  19. * @return PaymentDataObjectInterface
  20. */
  21. public function readPayment(array $subject): PaymentDataObjectInterface
  22. {
  23. return Helper\SubjectReader::readPayment($subject);
  24. }
  25. /**
  26. * Reads store's ID, otherwise returns null.
  27. *
  28. * @param array $subject
  29. * @return int|null
  30. */
  31. public function readStoreId(array $subject): ?int
  32. {
  33. $storeId = $subject['store_id'] ?? null;
  34. if (empty($storeId)) {
  35. try {
  36. $storeId = (int)$this->readPayment($subject)
  37. ->getOrder()
  38. ->getStoreId();
  39. } catch (\InvalidArgumentException $e) {
  40. // No store id is current set
  41. }
  42. }
  43. return $storeId ? (int)$storeId : null;
  44. }
  45. /**
  46. * Reads amount from subject
  47. *
  48. * @param array $subject
  49. * @return string
  50. */
  51. public function readAmount(array $subject): string
  52. {
  53. return (string)Helper\SubjectReader::readAmount($subject);
  54. }
  55. /**
  56. * Reads response from subject
  57. *
  58. * @param array $subject
  59. * @return array
  60. */
  61. public function readResponse(array $subject): ?array
  62. {
  63. return Helper\SubjectReader::readResponse($subject);
  64. }
  65. /**
  66. * Reads login id from subject
  67. *
  68. * @param array $subject
  69. * @return string|null
  70. */
  71. public function readLoginId(array $subject): ?string
  72. {
  73. return $subject['merchantAuthentication']['name'] ?? null;
  74. }
  75. /**
  76. * Reads transaction key from subject
  77. *
  78. * @param array $subject
  79. * @return string|null
  80. */
  81. public function readTransactionKey(array $subject): ?string
  82. {
  83. return $subject['merchantAuthentication']['transactionKey'] ?? null;
  84. }
  85. }