-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDemoPage.php
More file actions
274 lines (248 loc) · 9.47 KB
/
DemoPage.php
File metadata and controls
274 lines (248 loc) · 9.47 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Unity Publisher API for PHP demo</title>
<style>
table {
border-collapse: collapse;
}
td, th {
border: 1px gray solid;
padding: 5px;
}
th {
background: #EEE;
}
.changelog_cell{
position: relative;
}
.changelog_cell:hover .changelog_body {
display: block;
}
.changelog_body {
display: none;
top: 0;
right: 100%;
width: 500px;
position: absolute;
padding: 5px;
background: white;
border: 2px solid gray;
z-index: 1000;
overflow: auto;
}
</style>
</head>
<body>
<?php
require 'AssetStorePublisherClient.class.php'; // Include the class
// Create the client instance
$store = new AssetStore\Client();
// Login with your credentials. Return value of this call is the login token that can be used with LoginWithToken method
$store->Login('your@publisher.email.com', 'password');
// Or, if you don't want to keep your credentials in the code, use the token (returned by Login() method or retrieved from your browser cookies)
// $store->LoginWithToken('put your token here');
?>
<form method="post" id="asForm">
<h2>Publisher info</h2>
<ul>
<?php
$publisherInfo = $store->GetPublisherInfo();
?>
<li>Id: <?php echo $publisherInfo->GetId(); ?></li>
<li>Name: <?php echo $publisherInfo->GetName(); ?></li>
<li>Description: <?php echo $publisherInfo->GetDescription(); ?></li>
<li>Rating: <?php echo $publisherInfo->GetRating(); ?> (from <?php echo $publisherInfo->GetRatingCount(); ?> votes)</li>
<li>Payout cut: <?php echo $publisherInfo->GetPayoutCut() * 100; ?>%</li>
<li>Publisher URL (short): <?php echo $publisherInfo->GetPublisherShortUrl(); ?></li>
<li>URL: <?php echo $publisherInfo->GetSiteUrl(); ?></li>
<li>Support URL: <?php echo $publisherInfo->GetSupportUrl(); ?></li>
<li>Support email: <?php echo $publisherInfo->GetSupportEmail(); ?></li>
</ul>
<?php
$salesPeriods = $store->FetchSalesPeriods();
$salesYear = reset($salesPeriods)->GetYear();
$salesMonth = reset($salesPeriods)->GetMonth();
if (isset($_POST['selectedPeriod'])) {
$periodArray = explode('-', $_POST['selectedPeriod']);
$salesYear = $periodArray[0];
$salesMonth = $periodArray[1];
}
$sales = $store->FetchSales($salesYear, $salesMonth);
$downloads = $store->FetchDownloads($salesYear, $salesMonth);
?>
<h2>Sales periods</h2>
<ul>
<?php
foreach ($salesPeriods as $value) {
echo sprintf('<li>Month: %d, year: %d, formatted: %s</li>',
$value->GetMonth(),
$value->GetYear(),
date('F Y', $value->GetDate()));
}
?>
</ul>
<h2>Sales and downloads</h2>
Period: <select name="selectedPeriod" onChange="document.forms['asForm'].submit();">
<?php
foreach ($salesPeriods as $value) {
echo sprintf('<option value="%s" %s>%s</option>',
$value->GetYear() . '-' . $value->GetMonth(),
($value->GetYear() == $salesYear && $value->GetMonth() == $salesMonth) ? 'selected' : '',
date('F Y', $value->GetDate())
);
}
?>
</select>
<h3>Sales</h3>
<h4>Gross: $<?php echo $sales->GetRevenueGross(); ?>, net: $<?php echo $sales->GetRevenueNet(); ?> (<?php echo $sales->GetPayoutCut() * 100; ?>%)</h4>
<table>
<tr><th>Package name</th><th>Price ($)</th><th>Qty</th><th>Refunds</th><th>Chargebacks</th><th>Gross ($)</th><th>First</th><th>Last</th></tr>
<?php
foreach ($sales->GetPackageSales() as $value) {
echo sprintf('<tr><td><a href="%s">%s</a></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
$value->GetShortUrl(),
$value->GetPackageName(),
$value->GetPrice(),
$value->GetQuantity(),
$value->GetRefunds(),
$value->GetChargebacks(),
$value->GetGross() == 0 ? null : $value->GetGross(),
$value->GetFirstPurchaseDate() == null ? null : date('d F Y', $value->GetFirstPurchaseDate()),
$value->GetLastPurchaseDate() == null ? null : date('d F Y', $value->GetLastPurchaseDate())
);
}
?>
</table>
<h3>Free Downloads</h3>
<table>
<tr><th>Package name</th><th>Qty</th><th>First</th><th>Last</th></tr>
<?php
foreach ($downloads->GetPackageDownloads() as $value) {
echo sprintf('<tr><td><a href="%s">%s</a></td><td>%s</td><td>%s</td><td>%s</td></tr>',
$value->GetShortUrl(),
$value->GetPackageName(),
$value->GetQuantity(),
$value->GetFirstDownloadDate() == null ? null : date('d F Y', $value->GetFirstDownloadDate()),
$value->GetLastDownloadDate() == null ? null : date('d F Y', $value->GetLastDownloadDate())
);
}
?>
</table>
<h2>Revenue</h2>
<table>
<tr><th>Date</th><th>Type</th><th>Description</th><th>Debet ($)</th><th>Credit ($)</th><th>Balance ($)</th></tr>
<?php
$revenue = $store->FetchRevenue();
foreach ($revenue as $value) {
switch ($value->GetInfoType()) {
case AssetStore\RevenueInfo::TypeRevenue:
$infoType = 'Revenue';
break;
case AssetStore\RevenueInfo::TypePayout:
$infoType = 'Payout';
break;
default:
$infoType = 'Unknown';
break;
}
echo sprintf('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
date('d F Y', $value->GetDate()),
$infoType,
$value->GetDescription(),
$value->GetDebet(),
$value->GetCredit(),
$value->GetBalance() == 0 ? null : $value->GetBalance()
);
}
?>
</table>
<h2>Packages</h2>
<table>
<tr><th>Package</th><th>Status</th><th>Version</th><th>Price ($)</th><th>Size</th><th>Created</th><th>Published</th><th>Modified</th><th>Id</th><th>Changelog</th></tr>
<?php
$packages = $store->FetchPackages();
foreach ($packages as $package) {
$versions = $package->GetVersions();
echo "<tr>";
foreach ($versions as $version) {
switch ($version->GetStatus()) {
case AssetStore\PackageVersionInfo::StatusPublished:
$infoType = 'Published';
break;
case AssetStore\PackageVersionInfo::StatusDraft:
$infoType = 'Draft';
break;
case AssetStore\PackageVersionInfo::StatusPending:
$infoType = 'Pending';
break;
case AssetStore\PackageVersionInfo::StatusDeclined:
$infoType = 'Declined';
break;
case AssetStore\PackageVersionInfo::StatusError:
$infoType = 'Error';
break;
default:
$infoType = 'Unknown';
break;
}
$size = $version->GetSize();
echo sprintf('<td><a href="%s">%s</a></td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s kB</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td class="changelog_cell"><i>Hover to see</i><div class="changelog_body">%s</div></td>',
$package->GetShortUrl(),
$version->GetName(),
$infoType,
$version->GetVersion(),
$version->GetPrice(),
$size / 1000,
date('d F Y H:i:s', $version->GetCreatedDate()),
date('d F Y H:i:s', $version->GetPublishedDate()),
date('d F Y H:i:s', $version->GetModifiedDate()),
$package->GetId(),
htmlspecialchars($version->GetReleaseNotes())
);
}
echo "</tr>";
}
?>
</table>
<h2>Verify invoice</h2>
<?php
$invoiceNumbers = '';
if (isset($_POST['invoiceNumbers']) && !empty($_POST['invoiceNumbers'])) {
$invoiceNumbers = $_POST['invoiceNumbers'];
$invoiceNumbersArray = explode(',', $invoiceNumbers);
$invoiceNumbersInfo = $store->VerifyInvoice($invoiceNumbersArray);
}
?>
Enter comma separated invoice numbers:
<input type="text" name="invoiceNumbers" value="<?php echo $invoiceNumbers; ?>" size="13">
<button onclick="document.forms['asForm'].submit();">Verify</button>
<br>
<br>
<table>
<tr><th>Invoice #</th><th>Package</th><th>Purchase</th><th>Refunded?</th></tr>
<?php
if (isset($invoiceNumbersInfo)) {
foreach ($invoiceNumbersInfo as $value) {
echo sprintf('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
$value->GetInvoiceNumber(),
$value->GetPackageName(),
date('d F Y', $value->GetPurchaseDate()),
$value->IsRefunded() ? 'Yes' : 'No'
);
}
}
?>
</table>
</form>
</body>
</html>