fosbury/fosbury

This package is abandoned and no longer maintained. No replacement package was suggested.

Fosbury is an PHP API Client for Fosbury (http://fosbury.co)

0.9.3 2014-01-15 11:00 UTC

This package is not auto-updated.

Last update: 2015-12-06 08:03:10 UTC


README

A PHP Client for Fosbury (http://fosbury.co). Fosbury is a platform to create Passbook templates, campaigns and passes.

Wraps around the Fosbury API. See the documentation at Apiary.io.

License

Apache 2.0

Installation

The PHP library comes as a Composer package Fosbury PHP Client at Packagist

To install PHP Client with Composer just add the following to your composer.json file:

// composer.json
{
    // ...
    require: {
        // ...
        "fosbury/fosbury": "dev-master"
    }
}

Then, update

# install
$ php composer.phar install
# update
$ php composer.phar update 

And include the bootstrap file

# Require the bootstrap file
require_once 'vendor/autoload.php';

Happy passing!

Usage

Authorization

To authorize, set the API key. Please send a mail to api@fosbury.co to obtain the API key of your Fosbury account.

$fosbury = new Fosbury\Client("your_api_key");

Generating campaigns

In order to generate passes, you need to generate a template (a pass layout) and a campaign (a collection of passes). For more information on parameters and options, see the API Documentation

// Basic coupon campaign generation example
// Create a basic template
$template = $fosbury->createTemplate('My template', 
                                     'coupon',
                                     array('primary_label' => '20%',
                                           'primary_value' => 'Discount')
                                    );

// Create a campaign with 10 passes
// Because the barcode_type is set to 'single', 
$campaign = $fosbury->createCampaign($template['id'],
                                     array('quantity' => 10,
                                           'barcode' => '12345',
                                           'barcode_type' => 'single')
                                           );

// Distribute the campaign, the passes will be rendered.
// The returned JSON provides information about the generic url to download passes (live_url).
$fosbury->distributeCampaign($campaign['id']);

Generating single passes

When generating seperate passes, create a template and campaign first. After that, passes can be created with the createPass function. For more information on parameters and options, see the API Documentation

// Create a basic template
$template = $fosbury->createTemplate('My template',
                                     'coupon',
                                     array('primary_label' => '20%',
                                           'primary_value' => 'Discount')
                                    );

// Create a campaign with quantity 1 (more passes can be created later)
// Barcode is ommited, this will provided on pass creation level
$campaign = $fosbury->createCampaign($template['id'], array('quantity' => 1));

// Distribute the campaign to make it public and render the first pass
$fosbury->distributeCampaign($campaign['id']);

// Create a backfield for the pass
$fosbury->createCampaignBackfield($campaign['id'],
                                  "Backfield title",
                                  "Backfield description");

// Add a geofenced location to the pass
$fosbury->createCampaignLocation($campaign['id'],
                                 54.33,
                                 4.44,
                                 "Starbucks Coffee");

// Create 2 passes with the campaign above.
// The returned JSON contains information on the location of the passes (live_url).
$pass1 = $fosbury->createPass($campaign,
                              array('barcode' => '11111',
                                    'secondary_label' => 'John',
                                    'secondary_label' => 'Doe')
                              );

$pass2 = $fosbury->createPass($campaign,
                              array('barcode' => '22222',
                                    'secondary_label' => 'Jane',
                                    'secondary_label' => 'Doe')
                              );

Pushing updates

Note: A pass holder will only receive a push update if one of the field values is changed. For more information about field names, take a look at our API Documentation.

Fosbury allows push notifications to be sent to passes. To achieve this, first update a pass and send a push notification afterwards.

// Update a pass. 
// Note: the updatePass accepts a pass serial number or an id as identifier.
$fosbury->updatePass('FSBABC123', array('secondary_value' => '50% off!'));

// Send the push notification to the pass
$fosbury->pushPass('FSBABC123', array('secondary_change_message' => '50% off!'));