Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. <?php
  2.  
  3. class Skrillapi {
  4.  
  5. private static $version = "1.0.0";
  6. * Initializes the request parameter
  7. *
  8. * @param string $user_email The Skrill username
  9. * @param string $secret_word The secret word used in developer settings
  10. * @param string $merchant_id The account id
  11. * @param string $mqi The MQI password
  12. */
  13. public function __construct($user_email, $secret_word=false, $merchant_id=false, $mqi=false) {
  14.  
  15. //Set authorization parameters user email required for each request
  16. $this->user_email = $user_email;
  17. $this->secret_word = $secret_word;
  18. $this->merchant_id = $merchant_id ? $merchant_id : '';
  19. $this->mqi = $mqi ? $mqi : '';
  20. // The url to send payment requests
  21. $this->url = "https://www.moneybookers.com/app/payment.pl" ;
  22. $this->refund_url = "https://www.moneybookers.com/app/refund.pl";
  23. }
  24.  
  25. public function getResponse() {
  26. return $this->response;
  27. }
  28.  
  29. public function getError() {
  30. return $this->error;
  31. }
  32. /**
  33. * Used for creating the redirection URL for making payments
  34. *
  35. * @param array $args The parameters to be send to Skrill
  36. * @param string $request_type The type of request charge / refund
  37. * @param string $sid The session id
  38. *
  39. */
  40. public function prepareRequest($args = false, $request_type = null, $sid = null){
  41.  
  42. $url = $this->url;
  43. //Set parameters for refund
  44. if($request_type == "refund"){
  45. $params['action'] = 'prepare';
  46. $params['email'] = $this->user_email;
  47. $params['password'] = md5($this->mqi);
  48. $url = $this->refund_url;
  49. $args = array_merge($params,$args);
  50. }
  51. //Used for executing refund request
  52. if($sid){
  53. unset($args);
  54. $args = array('action' => "refund",'sid'=>$sid);
  55. $url = $this->refund_url;
  56. }
  57. $fields = http_build_query($args);
  58. $curl = curl_init($url);
  59. curl_setopt($curl, CURLOPT_POST, 1);
  60. curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
  61. curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
  62. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  63. // For refund the response is an xml string
  64. if($request_type == "refund"){
  65. $this->parseXml(curl_exec($curl),"refund");
  66. }
  67. else{
  68. $this->response = curl_exec($curl);
  69. $this->error = curl_error($curl);
  70. }
  71. curl_close($curl);
  72. }
  73. /**
  74. * Parse the response from gateway
  75. *
  76. * @param array $fields The post parameters from gateway
  77. *
  78. * @return boolean true/false
  79. */
  80. public function validateResponse($fields){
  81. // Validate the Skrill signature
  82. $concatFields = $fields['merchant_id']
  83. .$fields['transaction_id']
  84. .strtoupper(md5($this->secret_word))
  85. .$fields['mb_amount'].$fields['mb_currency']
  86. .$fields['status'];
  87. if (strtoupper(md5($concatFields)) == $fields['md5sig'] && $fields['pay_to_email'] == $this->user_email)
  88. return true;
  89. else
  90. return false;
  91. }
  92. /**
  93. * Validate the parameters from return url
  94. *
  95. * @param array $fields The get parameters in url
  96. *
  97. * @return boolean true/false
  98. */
  99. public function validateReturnUrl($fields){
  100. // Validate the Moneybookers signature
  101. $concatFields = $this->merchant_id
  102. .$fields['transaction_id']
  103. .strtoupper(md5($this->secret_word));
  104. if (strtoupper(md5($concatFields)) == $fields['msid'])
  105. return true;
  106. else
  107. return false;
  108. }
  109. /**
  110. * Parse the response from gateway
  111. *
  112. * @param string $response The xml response
  113. * @param string $type The type of action - refund
  114. *
  115. */
  116. public function parseXml($xml,$type){
  117.  
  118. $parsed = simplexml_load_string($xml);
  119. if(isset($parsed)){
  120. if(isset($parsed->error)){
  121. $this->error = $parsed->error->error_msg;
  122. }
  123. if($type == "refund")
  124. $this->refund_response = json_decode(json_encode($parsed),TRUE);
  125. else
  126. $this->response = json_decode(json_encode($parsed),TRUE);
  127. }
  128. }
  129. }
  130. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement