Skip to content

Creating, Listing and Editing Boarding Passes

pedro ivo edited this page Jul 11, 2016 · 4 revisions
<?php

require 'vendor/autoload.php';

use Passworks\Client;

// Instantiate the Passworks client
$api = new Passworks\Client('your api username', 'your api key');

// upload a asset (background image)
$api->createAsset('background', '/local-path-to-a-image/image.png');
// create a Boarding Pass campaign
$boarding_campaign_args = array(
  'name'              => "createEventTicketCampaign {$time}",
  'icon_id'           => '51838f55-8d40-4554-be22-03ae685a0a32',
  'background_color'  => '#ffffff',
  'text_color'        => '#000000',
  'label_color'       => '#00000' ,
  'transit_type'      => 'air'
);
$boarding_campaign = $api->createBoardingCampaign($boarding_campaign_args);
print_r($boarding_campaign);

// fetching all boarding passes as an array
print_r($api->getBoardingCampaigns()->toArray());

// add an boarding ticket to the the boarding campaign
$boarding_ticket_args = array(
  'back_fields' => array(
    array(
      'value' => 'Marques de Pombal, Portugal',
      'key'   => 'address',
      'label' => 'Addess'
    )
  )
);
$boarding_pass = $api->createBoardingPass($boarding_campaign->id, $boarding_ticket_args);
print_r($boarding_pass);

// fetch a specific boarding pass
print_r($api->getBoardingPass($boarding_campaign->id, $boarding_pass->id));

// boarding pass data to update the pass
$boarding_pass_update_params  = array(
  'back_fields' => array(
    array(
      'value' => 'Av. da Liberdade, 230',
      'key'   => 'address',
      'label' => 'Addess'
    )
  )
);
$extra = array('push' => false);
$updated_boarding_pass = $api->updateEventTicket($boarding_campaign->id, $boarding_pass->id, $boarding_pass_update_params, $extra);
print_r($updated_boarding_pass);


// There are two reports available, a daily and a totalisation report
// for more information, check the API documentation:
// https://github.com/passworks/passworks-api/blob/master/v2/sections/reports.md
//
// Daily usage:
// $report_params = array("start_date" => '2010-10-10', "end_date" => '2016-06-30');
// $daily_report = $api->getBoardingPassDailyReport($campaign_id, $report_params);

// Totalisation
$total_report = $api->getBoardingPassTotalReport($coupon_campaign->id);
$report_data = get_object_vars($total_report->report);

print_r($report_data);
// Array
// (
//     [apple] => stdClass Object
//         (
//             [installs_count] => 0
//             [uninstalls_count] => 0
//         )

//     [android] => stdClass Object
//         (
//             [installs_count] => 2
//             [uninstalls_count] => 0
//         )

//     [installs_count] => 2
//     [uninstalls_count] => 0
//     [redeems_count] => 0
//     [fetches_count] => 0
//     [downloads_count] => 1
//     [views_count] => 0
//     [creates_count] => 3
//     [expires_count] => 0
//     [pushes_count] => 0
//     [updates_count] => 0
//     [webhooks_count] => 0
//     [api_calls_count] => 0
//     [distribution_updates_count] => 0
//     [active_count] => 2
//     [removed_count] => 0
// )