+ 'promotedProduct' => $product,
+ 'buttons' => $buttons,
+
+ 'stouyapi' => [
+ 'internet-archive' => $iaUrl,
+ 'developer-url' => $game->developer->website ?? null,
+ ]
+ ];
+
+ if ($linkDeveloperPage) {
+ $data['developer']['url'] = 'ouya://launcher/discover/dev--'
+ . categoryPath($game->developer->uuid);
+ }
+
+ return $data;
+}
+
+function buildDeveloperCurrentGamer()
+{
+ return [
+ 'gamer' => [
+ 'uuid' => '00702342-0000-1111-2222-c3e1500cafe2',
+ 'username' => 'stouyapi',
+ ],
+ ];
+}
+
+/**
+ * For /api/v1/developers/xxx/products/?only=yyy
+ */
+function buildDeveloperProductOnly($product, $developer)
+{
+ return [
+ 'developerName' => $developer->name,
+ 'currency' => $product->currency,
+ 'products' => [
+ buildProduct($product),
+ ],
+ ];
+}
+
+/**
+ * For /api/v1/developers/xxx/products/
+ */
+function buildDeveloperProducts($products, $developer)
+{
+ //remove duplicates
+ $products = array_values(array_column($products, null, 'identifier'));
+
+ $jsonProducts = [];
+ foreach ($products as $product) {
+ $jsonProducts[] = buildProduct($product);
+ }
+ return [
+ 'developerName' => $developer->name,
+ 'currency' => $products[0]->currency ?? 'EUR',
+ 'products' => $jsonProducts,
+ ];
+}
+
+function buildPurchases($game)
+{
+ $purchasesData = [
+ 'purchases' => [],
+ ];
+ $promotedProduct = getPromotedProduct($game);
+ if ($promotedProduct) {
+ $purchasesData['purchases'][] = [
+ 'purchaseDate' => time() * 1000,
+ 'generateDate' => time() * 1000,
+ 'identifier' => $promotedProduct->identifier,
+ 'gamer' => '00702342-0000-1111-2222-c3e1500cafe2',//gamer uuid
+ 'uuid' => '00702342-0000-1111-2222-c3e1500beef3',//transaction ID
+ 'priceInCents' => $promotedProduct->originalPrice * 100,
+ 'localPrice' => $promotedProduct->localPrice,
+ 'currency' => $promotedProduct->currency,
+ ];
+ }
+
+ $encryptedOnce = dummyEncrypt($purchasesData);
+ $encryptedTwice = dummyEncrypt($encryptedOnce);
+ return $encryptedTwice;
+}
+
+function buildSearch($games)
+{
+ $games = sortByTitle($games);
+ $results = [];
+ foreach ($games as $game) {
+ $results[] = [
+ 'title' => $game->title,
+ 'url' => 'ouya://launcher/details?app=' . $game->packageName,
+ 'contentRating' => $game->contentRating,
+ ];
+ }
+ return [
+ 'count' => count($results),
+ 'results' => $results,
+ ];
+}
+
+function dummyEncrypt($data)
+{
+ return [
+ 'key' => base64_encode('0123456789abcdef'),
+ 'iv' => 't3jir1LHpICunvhlM76edQ==',//random bytes
+ 'blob' => base64_encode(
+ json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
+ ),