Advertisement
stixlink

api1

Oct 30th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Created by stixlink.
  5. * E-mail: stixlink@gmail.com
  6. * Skype: stixlink
  7. * Date: 24.10.14
  8. * Time: 13:29
  9. */
  10. Yii::import('application.extensions.xcoin.SCurl');
  11.  
  12. /**
  13. * Class XCoin
  14. *
  15. * @property SCurl $_curl
  16. */
  17. class XCoinProcessor {
  18.  
  19. protected $apikey = '1ca8bd81a7e2dca83d5566fcc9f31a3c';
  20. protected $urlapi = 'https://xpay.pro/api';
  21. private $_curl;
  22. private $_data = array();
  23.  
  24. public function __construct() {
  25.  
  26. $this->_curl = new SCurl($this->urlapi);
  27. $this->_data = array('API_KEY' => $this->apikey);
  28. }
  29.  
  30.  
  31. /**
  32. * @param $data
  33. */
  34. public function setData(Array $data) {
  35.  
  36. $this->_data = CMap::mergeArray($this->_data, $data);
  37. }
  38.  
  39. public function unsetData() {
  40.  
  41. $this->_data = array('API_KEY' => $this->apikey);
  42. }
  43.  
  44. /**
  45. * @return string
  46. */
  47. public function getData() {
  48.  
  49. return CJSON::encode($this->_data);
  50. }
  51.  
  52. /**
  53. * @param $type
  54. *
  55. * @return mixed
  56. * @throws CException
  57. */
  58. public function execute($type, Array $data = array()) {
  59.  
  60. if (!empty($data)) {
  61. $this->setData($data);
  62. }
  63. $this->setData(array('type' => $type));
  64. $sendData = $this->getData();
  65. $response = $this->_curl->execute($sendData);
  66.  
  67. if ($response && !($response instanceof Exception)) {
  68.  
  69. return CJSON::decode($response);
  70. } elseif ($response instanceof Exception) {
  71.  
  72. throw new CException($response->getMessage());
  73. } else {
  74.  
  75. return $response;
  76. }
  77.  
  78.  
  79. }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement