AmazonRefundDetails.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\AmazonRefundStatus;
  18. use Amazon\Payment\Domain\AmazonRefundStatusFactory;
  19. class AmazonRefundDetails
  20. {
  21. /**
  22. * @var AmazonRefundStatus
  23. */
  24. private $refundStatus;
  25. /**
  26. * @var string|null
  27. */
  28. private $refundId;
  29. /**
  30. * @param AmazonRefundStatusFactory $amazonRefundStatusFactory
  31. * @param array $details
  32. */
  33. public function __construct(
  34. AmazonRefundStatusFactory $amazonRefundStatusFactory,
  35. array $details
  36. ) {
  37. $statusData = $details['RefundStatus'];
  38. $this->refundStatus = $amazonRefundStatusFactory->create([
  39. 'state' => $statusData['State'],
  40. 'reasonCode' => isset($statusData['ReasonCode']) ? $statusData['ReasonCode'] : null
  41. ]);
  42. if (isset($details['AmazonRefundId'])) {
  43. $this->refundId = $details['AmazonRefundId'];
  44. }
  45. }
  46. /**
  47. * @return AmazonRefundStatus
  48. */
  49. public function getRefundStatus()
  50. {
  51. return $this->refundStatus;
  52. }
  53. /**
  54. * @return string|null
  55. */
  56. public function getRefundId()
  57. {
  58. return $this->refundId;
  59. }
  60. /**
  61. * @return bool
  62. */
  63. public function isRefundPending()
  64. {
  65. return $this->refundStatus->getState() === AmazonRefundStatus::STATE_PENDING;
  66. }
  67. /**
  68. * @return bool
  69. */
  70. public function isRefundCompleted()
  71. {
  72. return $this->refundStatus->getState() === AmazonRefundStatus::STATE_COMPLETED;
  73. }
  74. /**
  75. * @return bool
  76. */
  77. public function isRefundDeclined()
  78. {
  79. return $this->refundStatus->getState() === AmazonRefundStatus::STATE_DECLINED;
  80. }
  81. }