Response.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * This file is part of the Klarna KP module
  4. *
  5. * (c) Klarna Bank AB (publ)
  6. *
  7. * For the full copyright and license information, please view the NOTICE
  8. * and LICENSE files that were distributed with this source code.
  9. */
  10. namespace Klarna\Kp\Model\Api;
  11. use Klarna\Kp\Api\Data\ResponseInterface;
  12. /**
  13. * Class Response
  14. *
  15. * @package Klarna\Kp\Model\Api
  16. */
  17. class Response implements ResponseInterface
  18. {
  19. use Export;
  20. /**
  21. * @var string
  22. */
  23. private $session_id;
  24. /**
  25. * @var string
  26. */
  27. private $client_token;
  28. /**
  29. * @var int
  30. */
  31. private $fraud_status;
  32. /**
  33. * @var string
  34. */
  35. private $redirect_url;
  36. /**
  37. * @var string
  38. */
  39. private $order_id;
  40. /**
  41. * @var int
  42. */
  43. private $response_code = 418;
  44. /**
  45. * @var string
  46. */
  47. private $message;
  48. /**
  49. * @var array
  50. */
  51. private $payment_method_categories = [];
  52. /**
  53. * Response constructor.
  54. *
  55. * @param array $data
  56. */
  57. public function __construct($data = [])
  58. {
  59. foreach ($data as $key => $value) {
  60. if (property_exists($this, $key)) {
  61. $this->$key = $value;
  62. $this->exports[] = $key;
  63. }
  64. }
  65. }
  66. /**
  67. * @return string
  68. */
  69. public function getSessionId()
  70. {
  71. return $this->session_id;
  72. }
  73. /**
  74. * @return string
  75. */
  76. public function getClientToken()
  77. {
  78. return $this->client_token;
  79. }
  80. /**
  81. * @return int
  82. */
  83. public function getResponseCode()
  84. {
  85. return $this->response_code;
  86. }
  87. /**
  88. * @return string
  89. */
  90. public function getOrderId()
  91. {
  92. return $this->order_id;
  93. }
  94. /**
  95. * @return string
  96. */
  97. public function getRedirectUrl()
  98. {
  99. return $this->redirect_url;
  100. }
  101. /**
  102. * @return array
  103. */
  104. public function getPaymentMethodCategories()
  105. {
  106. return $this->payment_method_categories;
  107. }
  108. /**
  109. * @return int
  110. */
  111. public function getFraudStatus()
  112. {
  113. return $this->fraud_status;
  114. }
  115. /**
  116. * @return bool
  117. */
  118. public function isSuccessfull()
  119. {
  120. return in_array($this->response_code, [200, 201, 204], false);
  121. }
  122. /**
  123. * @return string
  124. */
  125. public function getMessage()
  126. {
  127. return $this->message;
  128. }
  129. }