PHP Example

Version 1.7 (อัพเดทล่าสุด 26 มีนาคม 2024)

File Example

				
					<?php


  $branchId = <YOUR_BRANCH_ID>;
  $apiKey = '<YOUR_API_KEY>';
  $file = '<YOUR_IMAGE_FILE>';


  $url = 'https://api.slipok.com/api/line/apikey/' . $branchId;


  $headers = [
    'Content-Type: multipart/form-data',
    'x-authorization: ' . $apiKey
  ];


  $fields = [
    'files' => new CURLFile($file),
    'log' => true,
    // 'amount' => amount, // Add this to check with amount of the slip
  ];


  $curl = curl_init();


  curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => $fields,
    CURLOPT_HTTPHEADER => $headers,
  ));


  $response = curl_exec($curl);


  curl_close($curl);


  if($response){
    $json_response = json_decode($response);
    $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
   
    if($http_code === 200 && $json_response->{'success'} === true) {
      // Handle correct slip
      echo(json_encode($json_response->{'data'})); // Slip data
    } else {
      // Handle incorrect slip
      echo 'code: '.$json_response->{'code'}; // Error code
      echo '<br/>';
      echo 'message: '.$json_response->{'message'}; // Error message
    }
  } else {
    echo curl_errno($curl); // Curl error no
    echo curl_error($curl); // Curl error message
  }

				
			

Data Example

				
					  <?php


  $branchId = <YOUR_BRANCH_ID>;
  $apiKey = '<YOUR_API_KEY>';
  $data = '<YOUR_QR_DATA>';


  $url = 'https://api.slipok.com/api/line/apikey/' . $branchId;


  $headers = [
    'Content-Type: multipart/form-data',
    'x-authorization: ' . $apiKey
  ];


  $fields = [
    'data' => $data,
    'log' => true,
    // 'amount' => amount, // Add this to check with amount of the slip
  ];


  $curl = curl_init();


  curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => $fields,
    CURLOPT_HTTPHEADER => $headers,
  ));


  $response = curl_exec($curl);


  curl_close($curl);


  if($response){
    $json_response = json_decode($response);
    $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
   
    if($http_code === 200 && $json_response->{'success'} === true) {
      // Handle correct slip
      echo(json_encode($json_response->{'data'})); // Slip data
    } else {
      // Handle incorrect slip
      echo 'code: '.$json_response->{'code'}; // Error code
      echo '<br/>';
      echo 'message: '.$json_response->{'message'}; // Error message
    }
  } else {
    echo curl_errno($curl); // Curl error no
    echo curl_error($curl); // Curl error message
  }

				
			

Url Example

				
					<?php


  $branchId = <YOUR_BRANCH_ID>;
  $apiKey = '<YOUR_API_KEY>';
  $imageUrl = '<YOUR_IMAGE_URL>';


  $url = 'https://api.slipok.com/api/line/apikey/' . $branchId;


  $headers = [
    'Content-Type: multipart/form-data',
    'x-authorization: ' . $apiKey
  ];


  $fields = [
    'url' => $imageUrl,
    'log' => true,
    // 'amount' => amount, // Add this to check with amount of the slip
  ];


  $curl = curl_init();


  curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => $fields,
    CURLOPT_HTTPHEADER => $headers,
  ));


  $response = curl_exec($curl);


  curl_close($curl);


  if($response){
    $json_response = json_decode($response);
    $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
   
    if($http_code === 200 && $json_response->{'success'} === true) {
      // Handle correct slip
      echo(json_encode($json_response->{'data'})); // Slip data
    } else {
      // Handle incorrect slip
      echo 'code: '.$json_response->{'code'}; // Error code
      echo '<br/>';
      echo 'message: '.$json_response->{'message'}; // Error message
    }
  } else {
    echo curl_errno($curl); // Curl error no
    echo curl_error($curl); // Curl error message
  }