apiKey = $apiKey; $this->secKey = $secKey; } public function createVouchers($amount, $worthValue, $invoiceID) { $curl = curl_init(); $securityHash = hash_hmac('sha512', $this->apiKey . ":" . $this->secKey . ":" . $amount . ":" . $invoiceID . ":" . $worthValue, $this->secKey); $baseUrl = "https://www.premiumvouchers.com/api/vouchers/CreateVouchers?"; $params = "ApiKey=" . $this->apiKey . "&Amount=" . $amount . "&WorthValue=" . $worthValue . "&InvoiceID=" . $invoiceID . "&SecurityHash=" . $securityHash; curl_setopt_array($curl, array( CURLOPT_URL => $baseUrl . $params, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "", CURLOPT_HTTPHEADER => array( "cache-control: no-cache" ) )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { return "cURL Error #:" . $err; } else { return json_decode($response); } } public function redeemVouchers($voucherCode, $worthValue, $invoiceID) { $curl = curl_init(); $securityHash = hash_hmac('sha512', $this->apiKey . ":" . $this->secKey . ":" . $voucherCode . ":" . $invoiceID . ":" . $worthValue, $this->secKey); $baseUrl = "https://www.premiumvouchers.com/api/vouchers/ReturnVouchers?"; $params = "ApiKey=" . $this->apiKey . "&VoucherCode=" . $voucherCode . "&WorthValue=" . $worthValue . "&InvoiceID=" . $invoiceID . "&SecurityHash=" . $securityHash; curl_setopt_array($curl, array( CURLOPT_URL => $baseUrl . $params, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "", CURLOPT_HTTPHEADER => array( "cache-control: no-cache" ) )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { return "cURL Error #:" . $err; } else { return json_decode($response); } } public function getBalance() { $curl = curl_init(); $baseUrl = "https://www.premiumvouchers.com/api/vouchers/GetBalance?"; $params = "ApiKey=" . $this->apiKey; curl_setopt_array($curl, array( CURLOPT_URL => $baseUrl . $params, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "", CURLOPT_HTTPHEADER => array( "cache-control: no-cache" ) )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { return "cURL Error #:" . $err; } else { return json_decode($response); } } } $psVoucher = new VoucherAPI($permium_apiKey, $permium_secKey);