3 days free on activation | চালু করলেই ৩দিন ফ্রি | Help WhatsApp:
+8801715881168
Account
Home
About Us
Demo
Pricing
Developer Docs
For call: +8801715881168
Documentation
Android api access
Download
WordPress Plugin
Download
WHMCS Module
Download
Web API
Copy to clipboard
Copy
//Route Route::get('/callback', [PayController::class, 'callback'])->name('url-callback'); //env TOUCH_PAY_APP_KEY = xxxxxxxxxxx class PayController extends Controller { private $appKey; private $url; public function __construct() { $this->appKey = env('TOUCH_PAY_APP_KEY'); $this->url = 'https://pay.touchsitbd.com'; } function payment() { $env = random_int(100000, 999999); $params = [ 'invoiceid'=>$env, 'currency'=>'BDT', 'amount'=>10,//Amount 'clientdetails'=>[ 'firstname'=>"example ", 'email'=>"example@gmail.com" ] ]; //dd($params['amount']); // Initialize a variable to hold the payment status message $paymentStatusMessage = ''; // Construct the data to send to the API $invoiceId = $params['invoiceid']; $hostUrl = (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST']; $successUrl = $hostUrl . '/callback?order_id=' . $invoiceId; $paymentCurrency = $params['currency']; $postData = array( 'cus_name' => $params['clientdetails']['firstname'], 'cus_email' => $params['clientdetails']['email'], 'amount' => $params['amount'], 'conversion' => $paymentCurrency, 'success_url' => $successUrl, 'metadata' => json_encode(array('invoice_id' => $invoiceId)) ); // Set up the cURL session $ch = curl_init($this->url. '/api/checkout-v1'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData)); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'app-key: ' . $this->appKey )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Execute the cURL session $response = curl_exec($ch); // Check for errors if ($response === false) { $paymentStatusMessage = 'cURL error: ' . curl_error($ch); } else { // Parse the API response $responseData = json_decode($response, true); // Check if the API response contains the 'hosted_url' if (isset($responseData['host_url'])) { // Payment was successful, you can display a success message here $paymentStatusMessage = 'Payment Successful! Redirecting...'; // Redirect the user to the hosted_url header('Location: ' . $responseData['host_url']); exit; } else { // Handle the case where 'hosted_url' is not present in the response $paymentStatusMessage = 'Error: Unable to retrieve hosted_url from the API response.'; } } // Close the cURL session curl_close($ch); } public function callback(Request $request){ //dd($request->all()); if ($request->order_id && $request->invoice_id) { $postData = array( 'invoice_id' => $request->invoice_id ); // Use WHMCS localAPI to update the invoice status to 'Unpaid' // Set up the cURL session for verification $ch = curl_init($this->url . '/api/verify-payment'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData)); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'app-key:' .$this->appKey, // Add your app key here )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Execute the cURL session $response = curl_exec($ch); if ($response === false) { // Handle cURL errors return curl_error($ch); } // Parse the API response $responseData = json_decode($response, true); if (!is_array($responseData)) { // Handle invalid JSON response echo 'Invalid JSON response from the API'; } // Check if the payment status is present in the API response if (!isset($responseData['status'])) { echo 'API response missing status'; } $metadataInvoiceID = isset($responseData['metadata']['invoice_id']) ? $responseData['metadata']['invoice_id'] : null; //echo 'Error updating invoice status: ' . $metadataInvoiceID.'
'; if ($responseData['status'] == 1) { if(session('student')!==null){ $tution = new TutionPaymentController; return $tution->TutionSuccess($responseData); } elseif(session('donner')!==null){ $tution = new DonnerPayController; return $tution->paymentComplete($responseData); }else{ $applicationview = new InstitituteAdmissionController; return $applicationview->ApplicationView($responseData); } }else { return $responseData; } } else { echo 'Invalid or missing order ID or invoice ID'; } } }