dancecampsPayment.class.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace DANCECAMPS;
  3. include_once 'TOTP.php';
  4. class dancecampsPayment {
  5. private $postdata = array();
  6. private $url = "";
  7. private $response = "";
  8. private $lastError;
  9. public function __construct($CampURL)
  10. {
  11. // Set the URL
  12. $this->url=$CampURL."/payment-receive.php";
  13. }
  14. public function getLastError()
  15. {
  16. return $this->lastError;
  17. }
  18. public function sendPaymentToDanceCamps($BookingID, $APIToken, $Secret, $Result, $Amount, $Fee, $Currency, $TxnID, $Notes, $EmailNotes) {
  19. // Get the token
  20. $token=\TOTP::getOTP($Secret);
  21. if (isset($token['error'])){
  22. $this->setLastError("The secret is not valid");
  23. return false;
  24. }
  25. if (!isset($token['otp']))
  26. {
  27. $this->setLastError("An error occurred getting the TOTP token");
  28. return false;
  29. }
  30. else $token=$token['otp'];
  31. // Set the post data
  32. $this->postdata["BookingID"]=$BookingID;
  33. $this->postdata["APIToken"]=$APIToken;
  34. $this->postdata["Token"]=$token;
  35. $this->postdata["Status"]=$Result;
  36. $this->postdata["Amount"]=$Amount;
  37. $this->postdata["Currency"]=$Currency;
  38. $this->postdata["TxnID"]=$TxnID;
  39. $this->postdata["FeeAmount"]=$Fee;
  40. $this->postdata["Notes"]=$Notes;
  41. $this->postdata["EmailNotes"]=$EmailNotes;
  42. // Send
  43. return $this->sendWithCURL();
  44. }
  45. public function getResponse()
  46. {
  47. return $this->response;
  48. }
  49. private function sendWithCURL() {
  50. $ch = curl_init();
  51. //curl_setopt($ch, CURLOPT_HEADER, true);
  52. curl_setopt($ch, CURLOPT_URL,$this->url);
  53. curl_setopt($ch, CURLOPT_POST, true);
  54. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($this->postdata));
  55. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  56. $this->response = curl_exec($ch);
  57. $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  58. curl_close ($ch);
  59. if ($httpcode!=200) return false;
  60. else {
  61. $arr=json_decode($this->response, true);
  62. if (isset($arr['status']) && $arr['status']==="success") return true;
  63. else return false;
  64. }
  65. }
  66. private function setLastError($msg)
  67. {
  68. $this->lastError=$msg;
  69. }
  70. }
  71. ?>