-
-
Notifications
You must be signed in to change notification settings - Fork 187
/
index.php
171 lines (150 loc) · 4.89 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?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;
require('../../vendor/autoload.php');
if(isset($_POST['name'])) {
// User has filled in the card info, so create the pass now
setlocale(LC_MONETARY, 'en_US');
// 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
// Set the path to your Pass Certificate (.p12 file)
$pass = new PKPass('../../Certificates.p12', 'password');
$pass->setData('{
"passTypeIdentifier": "pass.com.scholica.flights",
"formatVersion": 1,
"organizationName": "Starbucks",
"teamIdentifier": "KN44X8ZLNC",
"serialNumber": "' . $id . '",
"backgroundColor": "rgb(240,240,240)",
"logoText": "Starbucks",
"description": "Demo pass",
"storeCard": {
"secondaryFields": [
{
"key": "balance",
"label": "BALANCE",
"value": "' . $balance . '"
},
{
"key": "name",
"label": "NICKNAME",
"value": "' . $name . '"
}
],
"backFields": [
{
"key": "id",
"label": "Card Number",
"value": "' . $id . '"
}
]
},
"barcode": {
"format": "PKBarcodeFormatPDF417",
"message": "' . $id . '",
"messageEncoding": "iso-8859-1",
"altText": "' . $id . '"
}
}');
// add files to the PKPass package
$pass->addFile('icon.png');
$pass->addFile('[email protected]');
$pass->addFile('logo.png');
$pass->addFile('background.png', 'strip.png');
// Create and output the PKPass
$pass->create(true);
exit;
} else {
// User lands here, there are no $_POST variables set
?>
<html>
<head>
<title>Starbucks pass creator - PHP class demo</title>
<meta name="viewport" content="width=device-width; user-scalable=no"/>
<style>
body {
font-family: Helvetica, sans-serif;
}
.header {
background-color: #CCC;
padding-top: 30px;
padding-bottom: 30px;
margin-bottom: 32px;
text-align: center;
}
.logo {
width: 84px;
height: 84px;
margin-bottom: 20px;
}
.title {
color: black;
font-size: 22px;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.1);
font-weight: bold;
display: block;
text-align: center;
}
.userinfo {
margin: 0 auto;
padding-bottom: 32px;
width: 280px;
}
form.form-stacked {
padding: 0;
}
legend {
text-align: center;
padding-bottom: 25px;
border-bottom: none;
clear: both;
}
input.xlarge {
width: 280px;
height: 26px;
line-height: 26px;
}
</style>
</head>
<body>
<div class="header">
<img class="logo" src="logo_web.png"/>
<span class="title">Starbucks</span>
</div>
<div class="userinfo">
<form action="index.php" method="post" class="form-stacked">
<fieldset>
<legend style="padding-left: 0;">Please enter your info</legend>
<div class="clearfix">
<label style="text-align:left" for="name">Nickname</label>
<div class="input">
<input class="xlarge"
name="name"
id="name"
type="text"
value="Johnny's card"/>
</div>
</div>
<br/><br/>
<center><input type="submit" class="btn primary" value=" Create pass > "/></center>
</fieldset>
</form>
</div>
</body>
</html>
<?php } ?>