AbstractAmazonAuthorizationResponse.php 1.9 KB

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