token = $token; } public function createVoucher($coin, $amount) { $url = 'https://api.uwallet.biz/v1/voucher'; $data = [ 'coin' => $coin, 'amount' => $amount ]; return $this->sendRequest('POST', $url, $data); } public function redeemVoucher($coin, $voucherCode) { $url = 'https://api.uwallet.biz/v1/voucher/use'; $data = [ 'coin' => $coin, 'code' => $voucherCode ]; return $this->sendRequest('POST', $url, $data); } public function getBalance() { $url = 'https://api.uwallet.biz/v1/wallet'; return $this->sendRequest('GET', $url); } public function checkVoucherStatus($transactionId) { $url = 'https://api.uwallet.biz/v1/transaction'; $data = ['id' => $transactionId]; $response = $this->sendRequest('GET', $url, $data); return $response; } private function sendRequest($method, $url, $data = []) { $headers = [ 'Authorization: ' . $this->token, 'Content-Type: application/json' ]; $ch = curl_init(); if ($method == 'POST') { curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); } else { curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); } curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); $err = curl_error($ch); curl_close($ch); if ($err) { return "cURL Error: " . $err; } else { return json_decode($response); } } } $uVoucher = new uVoucher($uvoucherToken);