-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
346 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vendor/* | ||
composer.lock | ||
composer.phar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Form Campaign DEMO | ||
|
||
This is a *simple* project aimed to show how to use the Passworks PHP SDK | ||
|
||
## Configure | ||
|
||
First of all you sould have a Passworks Account and get yours `API credentials` | ||
Then set it to the `config.php` | ||
|
||
``` | ||
$API_USER = 'username'; | ||
$API_KEY = 'api_key'; | ||
``` | ||
|
||
Then go to the example folder, install the composer and and load the API, | ||
|
||
``` | ||
# cd examples/form-demo | ||
# curl -sS https://getcomposer.org/installer | php | ||
# php composer.phar install | ||
... | ||
Loading composer repositories with package information | ||
Updating dependencies (including require-dev) | ||
- Installing passworks/passworks-php (v2.0.1) | ||
Downloading: 100% | ||
Writing lock file | ||
Generating autoload files | ||
``` | ||
|
||
## Create a campaign | ||
|
||
The `generate_campaign.php` script generates a new coupon campaign and you can change it placing | ||
your campaign's information. | ||
|
||
> The campaign structure is documentented in this file | ||
``` | ||
# php generate_campaign.php | ||
``` | ||
|
||
This campaign was created with 2 CSV fields (name, email) that are supposed to be filled during | ||
the pass creation. | ||
|
||
## Running a basic server | ||
|
||
For this test, you can run the basic PHP server. | ||
|
||
``` | ||
# php -S localhost:8080 | ||
PHP 7.0.7 Development Server started at Wed Jun 1 11:14:14 2016 | ||
Listening on http://localhost:8080 | ||
Document root is /Users/pedroivo/Documents/passworks/passworks-php/examples/form-demo | ||
Press Ctrl-C to quit. | ||
``` | ||
|
||
Then navigate to `http://localhost:8080` and see the campaigns and create some passes | ||
|
||
## Create passes | ||
|
||
After create the campaign, navigate to the `http://localhost:8080` page and chose your campaign. | ||
Then just fill the fields and create a new pass. | ||
|
||
Note that there is a list os the passes already created with the links to each format of distribution. | ||
|
||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
require 'config.php'; | ||
$campaign_id = $_GET["id"]; | ||
$campaign = $api->getCouponInfo($campaign_id); | ||
$passes = $api->listCouponPasses($campaign_id); | ||
|
||
?> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<title>Testing Creation Passes</title> | ||
<link rel="stylesheet" href=""> | ||
<style> | ||
|
||
form label { | ||
display: block; | ||
} | ||
|
||
</style> | ||
</head> | ||
<body> | ||
|
||
<h2>Create your pass for the campaign "<?= $campaign->name ?>"</h2> | ||
<form action="generate_pass.php" method="post"> | ||
<input type="hidden" name="id" value="<?= $campaign_id ?>"> | ||
<label for=""> | ||
Name | ||
<input type="text" name="name" placeholder="Whats is your name"> | ||
</label> | ||
<label for=""> | ||
<input type="email" name="email" placeholder="What is your email?"> | ||
</label> | ||
<input type="submit" value="Generate"> | ||
</form> | ||
|
||
<?php if (sizeof($passes) > 0) { ?> | ||
<section> | ||
<h2>Existing passes</h2> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Pass ID</th> | ||
<th>Created</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<?php foreach ($passes as $key => $value) { ?> | ||
<tr> | ||
<td><?= $value->id ?></td> | ||
<td><?= $value->created_at ?></td> | ||
<td> | ||
<a href="<?= $value->page_url ?>" title="">Page</a> | ||
<a href="<?= $value->pkpass_url ?>" title="">Download</a> | ||
<a href="<?= $value->page_url ?>.qrcode" title="">QR Code</a> | ||
</td> | ||
</tr> | ||
<?php } ?> | ||
</tbody> | ||
</table> | ||
</section> | ||
<?php } ?> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
require 'config.php'; | ||
|
||
?> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<title>Testing Creation Passes</title> | ||
<link rel="stylesheet" href=""> | ||
</head> | ||
<body> | ||
|
||
<section> | ||
<h2>New Campaign</h2> | ||
<form action="campaign_new.php" method="post"> | ||
<label for=""> | ||
Name | ||
<input type="text" name="name" placeholder="Whats is your name"> | ||
</label> | ||
</section> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"require": { | ||
"passworks/passworks-php": "2.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
$API_USER = 'asd'; | ||
$API_KEY = 'ROV2zGLvXzP0DmFtBmDNLQ'; | ||
|
||
|
||
// Instantiate the Passworks client | ||
|
||
$api = new Passworks\Client($API_USER, $API_KEY); | ||
$api->setEndpoint('http://api.passworks.git:3000'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
require 'config.php'; | ||
|
||
// upload a asset (background image) | ||
$icon = $api->createAsset('icon', 'assets/climb-gym.png'); | ||
|
||
// As any other object in the API it returns a stdClass with the object's properties | ||
// print_r($icon); | ||
// stdClass Object | ||
// ( | ||
// [id] => d5a32073-2ded-481b-838f-58d29f9e11ca | ||
// [asset_type] => icon | ||
// [created_at] => 2016-05-31T15:18:21Z | ||
// ) | ||
|
||
$coupon_campaign_args = array( | ||
'name' => "50% Off for Climbers", | ||
'icon_id' => $icon->id, | ||
'secondary_fields' => array( | ||
array( | ||
'key' => "Name", // This key is going to be used when matching the pass information | ||
'value' => "Your Name", | ||
'label' => "Name" | ||
), | ||
array( | ||
'key' => "Email", // This key is going to be used when matching the pass information | ||
'value' => "Your email", | ||
'label' => "Email" | ||
) | ||
), | ||
'back_fields' => array( | ||
array( | ||
'key' => "contact", | ||
'value' => "Call us anytime: +351 915 652 071", | ||
'label' => "Our contact" | ||
) | ||
), | ||
'barcode' => array( | ||
'format' => "qrcode", | ||
'message' => "", | ||
'alt_text' => "", | ||
'alt_text_type' => "mirror" | ||
) | ||
); | ||
|
||
$coupon_campaign = $api->createCouponCampaign($coupon_campaign_args); | ||
|
||
// print_r($coupon_campaign); | ||
// | ||
// stdClass Object ( | ||
// [id] => 9f28f63e-823b-43b0-8c53-30c7ed596ff5 | ||
// [name] => 20% Off for Climbers | ||
// [template_id] => 62a4341e-4499-4b27-b6bc-32a9ee42af94 | ||
// [organization_name] => asd | ||
// [barcode] => stdClass Object ( | ||
// [format] => none | ||
// [message] => | ||
// [alt_text] => | ||
// [alt_text_type] => mirror | ||
// ) | ||
// [barcodes] => Array() | ||
// [allow_multiple_redeems] => | ||
// [header_fields] => Array() | ||
// [primary_fields] => Array() | ||
// [secondary_fields] => Array() | ||
// [auxiliary_fields] => Array() | ||
// [back_fields] => Array() | ||
// [locations] => Array() | ||
// [beacons] => Array() | ||
// [created_at] => 2016-05-31T15:19:56Z | ||
// [updated_at] => 2016-05-31T15:19:56Z | ||
// [distributions] => Array ( | ||
// [0] => stdClass Object ( | ||
// [id] => 98497cb0-e798-4b02-a0d5-c04034c9ce05 | ||
// [distribution_type] => downloadPage | ||
// [state] => published | ||
// [page_url] => http://192.168.1.79.xip.io:3000/p/s8K7vPi9vQ | ||
// [pkpass_url] => http://192.168.1.79.xip.io:3000/p/s8K7vPi9vQ.pkpass | ||
// [preview_url] => http://192.168.1.79.xip.io:3000/p/s8K7vPi9vQ.png | ||
// [created_at] => 2016-05-31T15:19:56.696Z | ||
// [updated_at] => 2016-05-31T15:19:56.769Z | ||
// [published_at] => 2016-05-31T15:19:56.776Z | ||
// ) | ||
// ) | ||
// ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
require 'config.php'; | ||
|
||
$campaign_id = $_POST["id"]; | ||
$name = $_POST["name"]; | ||
$email = $_POST["email"]; | ||
|
||
if (strlen($name) <= 0 || strlen($email) <= 0) { | ||
// TODO send a message | ||
header("Location: index.php"); | ||
} | ||
|
||
$params = array( | ||
'secondary_fields' => array( | ||
array( | ||
'value' => $name, | ||
'key' => 'Name', // key matching the campaign field | ||
'label' => 'Name' | ||
), | ||
array( | ||
'value' => $email, | ||
'key' => 'Email', // key matching the campaign field | ||
'label' => 'Email' | ||
) | ||
) | ||
); | ||
|
||
$api->createCoupon($campaign_id, $params); | ||
header("Location: campaign.php?id=$campaign_id"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
require 'config.php'; | ||
|
||
$campaigns = $api->getCouponCampaigns(); | ||
|
||
?> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<title>Testing Creation Passes</title> | ||
<link rel="stylesheet" href=""> | ||
</head> | ||
<body> | ||
|
||
<section> | ||
<h2>Campaigns</h2> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Campaign</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<?php foreach ($campaigns as $key => $value) { ?> | ||
<tr> | ||
<td> | ||
<img src="<?= $value->distributions[0]->preview_url ?>" alt=""> | ||
<a href="campaign.php?id=<?= $value->id ?>" title=""><?= $value->name ?></a> | ||
</td> | ||
<td> | ||
<a href="<?= $value->distributions[0]->page_url ?>" title="">Page</a> | ||
<a href="<?= $value->distributions[0]->pkpass_url ?>" title="">Download</a> | ||
<a href="<?= $value->distributions[0]->page_url ?>.qrcode" title="">QR Code</a> | ||
</td> | ||
</tr> | ||
<?php } ?> | ||
</tbody> | ||
</table> | ||
</section> | ||
|
||
</body> | ||
</html> |
Empty file.