AmazonAuthorizationDetails.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. namespace Amazon\Payment\Domain\Details;
  17. use Amazon\Payment\Domain\AmazonAuthorizationStatus;
  18. use Amazon\Payment\Domain\AmazonAuthorizationStatusFactory;
  19. class AmazonAuthorizationDetails
  20. {
  21. /**
  22. * @var AmazonAuthorizationStatus
  23. */
  24. private $status;
  25. /**
  26. * @var string|null
  27. */
  28. private $captureTransactionId;
  29. /**
  30. * @var string|null
  31. */
  32. private $authorizeTransactionId;
  33. /**
  34. * @var bool
  35. */
  36. private $captureNow = false;
  37. /**
  38. * AmazonAuthorizationDetails constructor.
  39. *
  40. * @param AmazonAuthorizationStatusFactory $amazonAuthorizationStatusFactory
  41. * @param array $details
  42. */
  43. public function __construct(AmazonAuthorizationStatusFactory $amazonAuthorizationStatusFactory, array $details)
  44. {
  45. $status = $details['AuthorizationStatus'];
  46. $this->status = $amazonAuthorizationStatusFactory->create([
  47. 'state' => $status['State'],
  48. 'reasonCode' => (isset($status['ReasonCode']) ? $status['ReasonCode'] : null)
  49. ]);
  50. if (isset($details['IdList']['member'])) {
  51. $this->captureTransactionId = $details['IdList']['member'];
  52. }
  53. if (isset($details['AmazonAuthorizationId'])) {
  54. $this->authorizeTransactionId = $details['AmazonAuthorizationId'];
  55. }
  56. if (isset($details['CaptureNow'])) {
  57. $this->captureNow = ('true' === $details['CaptureNow']);
  58. }
  59. }
  60. /**
  61. * Get status
  62. *
  63. * @return AmazonAuthorizationStatus
  64. */
  65. public function getStatus()
  66. {
  67. return $this->status;
  68. }
  69. /**
  70. * Get authorize transaction id
  71. *
  72. * @return string|null
  73. */
  74. public function getAuthorizeTransactionId()
  75. {
  76. return $this->authorizeTransactionId;
  77. }
  78. /**
  79. * Get capture transaction id
  80. *
  81. * @return string|null
  82. */
  83. public function getCaptureTransactionId()
  84. {
  85. return $this->captureTransactionId;
  86. }
  87. /**
  88. * Has capture
  89. *
  90. * @return bool
  91. */
  92. public function hasCapture()
  93. {
  94. return $this->captureNow;
  95. }
  96. /**
  97. * Is pending
  98. *
  99. * @return bool
  100. */
  101. public function isPending()
  102. {
  103. return (AmazonAuthorizationStatus::STATE_PENDING === $this->getStatus()->getState());
  104. }
  105. }