AbstractAmazonRefundResponse.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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;
  17. use Amazon\Core\Exception\AmazonServiceUnavailableException;
  18. use Amazon\Payment\Domain\Details\AmazonRefundDetails;
  19. use Amazon\Payment\Domain\Details\AmazonRefundDetailsFactory;
  20. use AmazonPay\ResponseInterface;
  21. abstract class AbstractAmazonRefundResponse
  22. {
  23. /**
  24. * @var AmazonRefundDetails
  25. */
  26. protected $details;
  27. /**
  28. * AbstractAmazonRefundResponse constructor.
  29. *
  30. * @param ResponseInterface $response
  31. * @param AmazonRefundDetailsFactory $amazonRefundDetailsFactory
  32. */
  33. public function __construct(
  34. ResponseInterface $response,
  35. AmazonRefundDetailsFactory $amazonRefundDetailsFactory
  36. ) {
  37. $data = $response->toArray();
  38. if (200 != $data['ResponseStatus']) {
  39. throw new AmazonServiceUnavailableException();
  40. }
  41. $this->details = $amazonRefundDetailsFactory->create([
  42. 'details' => $data[$this->getResultKey()]['RefundDetails']
  43. ]);
  44. }
  45. /**
  46. * @return AmazonRefundDetails
  47. */
  48. public function getDetails()
  49. {
  50. return $this->details;
  51. }
  52. /**
  53. * Get result key
  54. *
  55. * @return string
  56. */
  57. abstract protected function getResultKey();
  58. }