// Predefined data
 $labels = ['SFO' => 'San Francisco', 'LAX' => 'Los Angeles', 'LHR' => 'London'];
 $gates = ['F12', 'G43', 'A2', 'C5', 'K9'];
 // User-set vars
 $passenger = addslashes($_POST['passenger']);
 $origin = $_POST['origin'];
 $origin_label = $labels[$origin];
 $destination = $_POST['destination'];
 $destination_label = $labels[$destination];
 $gate = $gates[array_rand($gates)];
 // Yup, pick a random gate
 $date = date('m/d/Y H:i', $_POST['date']);
 // Convert date to string
 // Create pass
 //Set certifivate and path in the constructor
 $pass = new PKPass('../../Certificate.p12', 'test123');
 // Add the WWDR certificate
 $pass->setWWDRcertPath('../AppleWWDR.pem');
 //Check if an error occured within the constructor
 if ($pass->checkError($error) == true) {
     exit('An error occured: ' . $error);
 }
 //Or do it manually outside of the constructor
 /*
 	// Set the path to your Pass Certificate (.p12 file)
 	if($pass->setCertificate('../../Certificate.p12') == false) {
 		echo 'An error occured';
 		if($pass->checkError($error) == true) {
 			echo ': '.$error;
 		}
 		exit('.');
<?php
use PKPass\PKPass;

if (isset($_POST['name'])) {
    // User has filled in the card info, so create the pass now

    setlocale(LC_MONETARY, 'en_US');
    require('../../PKPass.php');

    // Variables
    $id      = rand(100000, 999999) . '-' . rand(100, 999) . '-' . rand(100, 999); // Every card should have a unique serialNumber
    $balance = '$' . rand(0, 30) . '.' . rand(10, 99); // Create random balance
    $name    = stripslashes($_POST['name']);

    // Create pass
    $pass = new PKPass();

    $pass->setCertificate('../../../Certificate.p12'); // Set the path to your Pass Certificate (.p12 file)
    $pass->setCertificatePassword('test123'); // Set password for certificate
    $pass->setWWDRcertPath('../../../AppleWWDR.pem');
    $pass->setJSON('{
	"passTypeIdentifier": "pass.com.apple.test",
	"formatVersion": 1,
	"organizationName": "Starbucks",
	"teamIdentifier": "AGK5BZEN3E",
	"serialNumber": "' . $id . '",
    "backgroundColor": "rgb(240,240,240)",
	"logoText": "Starbucks",
	"description": "Demo pass",
	"storeCard": {
        "secondaryFields": [
<?php

use PKPass\PKPass;
require '../PKPass.php';
$pass = new PKPass();
$pass->setCertificate('../Certificate.p12');
// 1. Set the path to your Pass Certificate (.p12 file)
$pass->setCertificatePassword('test123');
// 2. Set password for certificate
$pass->setWWDRcertPath('../AppleWWDRCA.pem');
// 3. Set the path to your WWDR Intermediate certificate (.pem file)
// Top-Level Keys http://developer.apple.com/library/ios/#documentation/userexperience/Reference/PassKit_Bundle/Chapters/TopLevel.html
$standardKeys = ['description' => 'Demo pass', 'formatVersion' => 1, 'organizationName' => 'Flight Express', 'passTypeIdentifier' => 'pass.com.apple.test', 'serialNumber' => '123456', 'teamIdentifier' => 'AGK5BZEN3E'];
$associatedAppKeys = [];
$relevanceKeys = [];
$styleKeys = ['boardingPass' => ['primaryFields' => [['key' => 'origin', 'label' => 'San Francisco', 'value' => 'SFO'], ['key' => 'destination', 'label' => 'London', 'value' => 'LHR']], 'secondaryFields' => [['key' => 'gate', 'label' => 'Gate', 'value' => 'F12'], ['key' => 'date', 'label' => 'Departure date', 'value' => '07/11/2012 10:22']], 'backFields' => [['key' => 'passenger-name', 'label' => 'Passenger', 'value' => 'John Appleseed']], 'transitType' => 'PKTransitTypeAir']];
$visualAppearanceKeys = ['barcode' => ['format' => 'PKBarcodeFormatQR', 'message' => 'Flight-GateF12-ID6643679AH7B', 'messageEncoding' => 'iso-8859-1'], 'backgroundColor' => 'rgb(107,156,196)', 'logoText' => 'Flight info'];
$webServiceKeys = [];
// Merge all pass data and set JSON for $pass object
$passData = array_merge($standardKeys, $associatedAppKeys, $relevanceKeys, $styleKeys, $visualAppearanceKeys, $webServiceKeys);
$pass->setJSON(json_encode($passData));
// Add files to the PKPass package
$pass->addFile('images/icon.png');
$pass->addFile('images/icon@2x.png');
$pass->addFile('images/logo.png');
if (!$pass->create(true)) {
    // Create and output the PKPass
    echo 'Error: ' . $pass->getError();
}