Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. <?php
  2.  
  3. class SimPay
  4. {
  5. protected $auth = array();
  6. protected $api = '1';
  7.  
  8. protected $response = array();
  9. protected $call = array();
  10.  
  11. public function __construct($key = '', $secret = '', $api = false)
  12. {
  13. if(isset($api) and !empty($api)) {
  14. $this->api = $api;
  15. }
  16.  
  17. $this->auth = array(
  18. "auth" => array(
  19. "key" => $key,
  20. "secret" => $secret,
  21. )
  22. );
  23. }
  24.  
  25. public function url($value, $params = array())
  26. {
  27. $data = json_encode(array('params'=>array_merge($this->auth, $params)));
  28. $this->call = $this->request($data, "https://simpay.pl/api/".$api."/".$value);
  29. return $this->call;
  30. }
  31.  
  32. public function getStatus($params)
  33. {
  34. $this->response = $this->url('status', $params);
  35. return $this->response;
  36. }
  37.  
  38. public function check()
  39. {
  40. if(isset($this->response) and is_array($this->response)) {
  41. if(isset($this->response['respond']['status']) and $this->response['respond']['status']=='OK') {
  42. return true;
  43. } else if(isset($this->response['error']) and is_array($this->response['error'])) {
  44. return false;
  45. }
  46. } else {
  47. throw new Exception('Brak informacji na temat ostatniego zapytania');
  48. }
  49. }
  50.  
  51. public function error()
  52. {
  53. if(isset($this->response['error']) and is_array($this->response['error'])) {
  54. return true;
  55. } else {
  56. return false;
  57. }
  58. }
  59.  
  60. public function showError()
  61. {
  62. if(isset($this->response['error']) and is_array($this->response['error'])) {
  63. return $this->response['error'];
  64. } else {
  65. throw new Exception('Brak bledu do pokazania');
  66. }
  67. }
  68.  
  69. private function request($data, $url)
  70. {
  71. $curl = curl_init();
  72. curl_setopt($curl, CURLOPT_URL, $url);
  73. curl_setopt($curl, CURLOPT_POST, 1);
  74. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  75. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  76. curl_setopt($curl, CURLOPT_FAILONERROR, 1);
  77. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // developer only
  78. $call = curl_exec($curl);
  79. $response = json_decode($call, true);
  80. $error = curl_errno($curl);
  81. curl_close($curl);
  82.  
  83. if ($error > 0) {
  84. throw new RuntimeException('CURL ERROR Code:'.$error);
  85. }
  86. return $response;
  87. }
  88.  
  89. public function response() {
  90. return $this->response;
  91. }
  92. }
  93.  
  94. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement