Skip to content

Commit

Permalink
Mayor cleanup. Also including the WWDR certificate by default now to …
Browse files Browse the repository at this point in the history
…ease the process.
  • Loading branch information
tschoffelen committed Apr 28, 2017
1 parent c273990 commit 5868cb3
Show file tree
Hide file tree
Showing 9 changed files with 435 additions and 419 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
/vendor
composer.lock
/Certificates.p12
55 changes: 55 additions & 0 deletions README.md
@@ -0,0 +1,55 @@
# PHP Passkit class for iOS Wallet
This class provides the functionality to create a pass for Wallet in Apple's iOS 6 and newer on-the-fly. It creates, signs and packages the Pass as a .pkpass file according to Apple's documentation.

## Requirements
* PHP 5.4 or higher
* PHP [ZIP Support](http://php.net/manual/en/book.zip.php) (may be installed by default)
* Access to filesystem (script must be able to create temporary folders)


## Installation
#### Composer
Run: `$ composer require pkpass/pkpass`

or add to your composer.json: `"pkpass/pkpass": "^1.0.0"`

#### Manual
Require PKPass.php file in your php files `require('src/PKPass.php');`


## Usage
Please take a look at the example.php file for example usage. For more info on the JSON for the pass and how to style it, take a look at the [docs at developers.apple.com](https://developer.apple.com/library/ios/documentation/UserExperience/Reference/PassKit_Bundle/Chapters/Introduction.html).

### Requesting the Pass Certificate
1. Go to the [iOS Provisioning portal](https://developer.apple.com/account/ios/identifier/passTypeId).
2. Create a new Pass Type ID, and write down the Pass ID you choose, you'll need it later.
3. Click the edit button under your newly created Pass Type ID and generate a certificate according to the instructions shown on the page.
4. Download the .cer file and drag it into Keychain Access.
5. Find the certificate you just imported and click the triangle on the left to reveal the private key.
6. Select both the certificate and the private key under it, then right click the certificate in Keychain Access and choose `Export 2 items…`.
6. Choose a password and export the file to a folder.

### Getting the example.php sample to work
1. Request the Pass certificate (`.p12`) as described above and upload it to your server.
2. Set the correct path and password on [line 22](examples/example.php#L22).
3. Change the `passTypeIdentifier` and `teamIndentifier` to the correct values on lines [29](examples/example.php#L29) and [31](examples/example.php#L31) (`teamIndentifier` can be found on the [Developer Portal](https://developer.apple.com/account/#/membership)).

After completing these steps, you should be ready to go. Upload all the files to your server and navigate to the address of the examples/example.php file on your iPhone.


## Included demos
* [Simple example](examples/example.php)
* [Flight ticket example](examples/full_sample/), also [online here](pkpass.dev.scholica.com/examples/full_sample/)
* [Starbucks card example](examples/starbucks_sample/), also [online here](pkpass.dev.scholica.com/examples/starbucks_sample/)


## Debugging passes
If you aren't able to open your pass on an iPhone, plug the iPhone into a Mac and open the 'Console' application. On the left, you can select your iPhone. You will then be able to inspect any errors that occur while adding the pass:

![Console with Passkit error](https://s3-eu-west-1.amazonaws.com/tsfil/Screen-Shot-2017-04-29-01-32-14-SrVhh/Screen-Shot-2017-04-29-01-32-14.png)


## Support & documentation
Please read the instructions above and consult the [Passbook Documentation](https://developer.apple.com/passbook/) before submitting tickets or requesting support. It might also be worth to [check Stackoverflow](http://stackoverflow.com/search?q=%22PHP-PKPass%22), which contains quite a few questions about this library.

Email me at thomas [at] scholica.com or tweet me [@tschoffelen](http://www.twitter.com/tschoffelen).
51 changes: 30 additions & 21 deletions composer.json
@@ -1,23 +1,32 @@
{
"name": "pkpass/pkpass",
"description": "PHP PKPass class for iOS Wallet",
"keywords": ["PHP","apple","ios","iphone","ipad","passbook"],
"homepage": "https://github.com/tschoffelen/PHP-PKPass",
"type": "library",
"authors": [
{
"name": "Tom Schoffelen",
"homepage": "http://www.tomttb.com",
"email": "tom@tomttb.com"
}
],
"require": {
"php": ">=5.4",
"ext-zip": "*"
},
"autoload": {
"psr-4": {
"PKPass\\": ""
}
}
"name": "pkpass/pkpass",
"license": "MIT",
"description": "PHP PKPass class for iOS Wallet",
"keywords": [
"PHP",
"apple",
"ios",
"iphone",
"ipad",
"passbook",
"wallet"
],
"homepage": "https://github.com/tschoffelen/PHP-PKPass",
"type": "library",
"authors": [
{
"name": "Thomas Schoffelen",
"homepage": "http://thomasschoffelen.com/",
"email": "thomas@scholica.com"
}
],
"require": {
"php": ">=5.4",
"ext-zip": "*"
},
"autoload": {
"psr-4": {
"PKPass\\": "src"
}
}
}
92 changes: 44 additions & 48 deletions examples/example.php
@@ -1,89 +1,85 @@
<?php
use PKPass\PKPass;

require('../PKPass.php');
/**
* Copyright (c) 2017, Thomas Schoffelen BV.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/

use PKPass\PKPass;

$pass = new PKPass();
require('../vendor/autoload.php');

$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)
// Replace the parameters below with the path to your .p12 certificate and the certificate password!
$pass = new PKPass('../Certificates.p12', 'password');

// 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', // 4. Set to yours
'serialNumber' => '123456',
'teamIdentifier' => 'AGK5BZEN3E' // 4. Set to yours
];
$associatedAppKeys = [];
$relevanceKeys = [];
$styleKeys = [
// Pass content
$data = [
'description' => 'Demo pass',
'formatVersion' => 1,
'organizationName' => 'Flight Express',
'passTypeIdentifier' => 'pass.com.scholica.flights', // Change this!
'serialNumber' => '12345678',
'teamIdentifier' => 'KN44X8ZLNC', // Change this!
'boardingPass' => [
'primaryFields' => [
'primaryFields' => [
[
'key' => 'origin',
'key' => 'origin',
'label' => 'San Francisco',
'value' => 'SFO',
],
[
'key' => 'destination',
'key' => 'destination',
'label' => 'London',
'value' => 'LHR',
],
],
'secondaryFields' => [
[
'key' => 'gate',
'key' => 'gate',
'label' => 'Gate',
'value' => 'F12',
],
[
'key' => 'date',
'key' => 'date',
'label' => 'Departure date',
'value' => '07/11/2012 10:22',
],
],
'backFields' => [
'backFields' => [
[
'key' => 'passenger-name',
'key' => 'passenger-name',
'label' => 'Passenger',
'value' => 'John Appleseed',
],
],
'transitType' => 'PKTransitTypeAir',
'transitType' => 'PKTransitTypeAir',
],
];
$visualAppearanceKeys = [
'barcode' => [
'format' => 'PKBarcodeFormatQR',
'message' => 'Flight-GateF12-ID6643679AH7B',
'barcode' => [
'format' => 'PKBarcodeFormatQR',
'message' => 'Flight-GateF12-ID6643679AH7B',
'messageEncoding' => 'iso-8859-1',
],
'backgroundColor' => 'rgb(107,156,196)',
'logoText' => 'Flight info',
'backgroundColor' => 'rgb(32,110,247)',
'logoText' => 'Flight info',
'relevantDate' => date('Y-m-d\TH:i:sP')
];
$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));
$pass->setData($data);

// Add files to the PKPass package
// Add files to the pass 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
// Create and output the pass
if(!$pass->create(true)) {
echo 'Error: ' . $pass->getError();
}

0 comments on commit 5868cb3

Please sign in to comment.