| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace DANCECAMPS;
- include_once 'TOTP.php';
- class dancecampsPayment {
- private $postdata = array();
- private $url = "";
- private $response = "";
- private $lastError;
- public function __construct($CampURL)
- {
- // Set the URL
- $this->url=$CampURL."/payment-receive.php";
- }
- public function getLastError()
- {
- return $this->lastError;
- }
- public function sendPaymentToDanceCamps($BookingID, $APIToken, $Secret, $Result, $Amount, $Fee, $Currency, $TxnID, $Notes, $EmailNotes) {
- // Get the token
- $token=\TOTP::getOTP($Secret);
- if (isset($token['error'])){
- $this->setLastError("The secret is not valid");
- return false;
- }
- if (!isset($token['otp']))
- {
- $this->setLastError("An error occurred getting the TOTP token");
- return false;
- }
- else $token=$token['otp'];
-
- // Set the post data
-
- $this->postdata["BookingID"]=$BookingID;
- $this->postdata["APIToken"]=$APIToken;
- $this->postdata["Token"]=$token;
- $this->postdata["Status"]=$Result;
- $this->postdata["Amount"]=$Amount;
- $this->postdata["Currency"]=$Currency;
- $this->postdata["TxnID"]=$TxnID;
- $this->postdata["FeeAmount"]=$Fee;
- $this->postdata["Notes"]=$Notes;
- $this->postdata["EmailNotes"]=$EmailNotes;
- // Send
- return $this->sendWithCURL();
- }
- public function getResponse()
- {
- return $this->response;
- }
- private function sendWithCURL() {
- $ch = curl_init();
- //curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_URL,$this->url);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($this->postdata));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $this->response = curl_exec($ch);
- $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close ($ch);
-
- if ($httpcode!=200) return false;
- else {
- $arr=json_decode($this->response, true);
- if (isset($arr['status']) && $arr['status']==="success") return true;
- else return false;
- }
- }
- private function setLastError($msg)
- {
- $this->lastError=$msg;
- }
- }
- ?>
|