Skip to content

orca-scan/orca-validation-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

orca-validation-php

Example of how to validate barcode scans in real-time using Php.

Install

First ensure you have Php installed.

# should return 7.1 or higher
php -v

Then execute the following:

# download this example code
git clone https://github.com/orca-scan/orca-validation-php.git

# go into the new directory
cd orca-validation-php

Run

# run php server
php -S 127.0.0.1:8000 server.php

Server will now be running on port 8000.

You can emulate an Orca Scan Validation input using cURL by running the following:

curl --location --request POST 'http://127.0.0.1:8000/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "___orca_sheet_name": "Vehicle Checks",
    "___orca_user_email": "[email protected]",
    "Barcode": "orca-scan-test",
    "Date": "2022-04-19T16:45:02.851Z",
    "Name": "Orca Scan Validation"
}'

Important things to note

  1. Only Orca Scan system fields start with ___
  2. Properties in the JSON payload are an exact match to the field names in your sheet (case and space)

Validation example

This example uses the Laravel framework:

if (preg_match('/$/', $_SERVER["REQUEST_URI"])){
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $data = json_decode(file_get_contents('php://input'), true);

        // NOTE:
        // orca system fields start with ___
        // you can access the value of each field using the field name (data.Name, data.Barcode, data.Location)        $name = $data["Name"];
        $name = $data["Name"];

        // validation example
        if (strlen($name) > 20) {
            // return json error message
            echo json_encode(array(
                "title" => "Invalid Name",
                "message" => "Name cannot contain more than 20 characters"
            ));
            exit;
        }

        //return HTTP Status 200 with no body
        http_response_code(200);
        exit;
    }
}

Test server locally against Orca Cloud

To expose the server securely from localhost and test it easily against the real Orca Cloud environment you can use Secure Tunnels. Take a look at Ngrok or Cloudflare.

ngrok http 8000

Troubleshooting

If you run into any issues not listed here, please open a ticket.

Examples in other langauges

History

For change-log, check releases.

License

© Orca Scan, the Barcode Scanner app for iOS and Android.

About

How to create a validation endpoint for Orca Scan

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages