Repositories | Polyback | Log in to see private repositories


polyback-website / 1229fe4649cb3ec2444c7fef95f4bc3c95be66fc / api/games/product-info.php

1,885 bytes | parent directory

<?php require $_SERVER['DOCUMENT_ROOT'].'/api/private/core.php';

// MarketplaceService:GetProductInfo(id) and PlayerOwnsAsset(player, id). Anybody may look.
//   ?id=1 (&type=Product) -> the table the API returns   ?id=1&owner=5 -> {"success":true,"owns":true}

use pizzaboxer\ProjectPolygon\Database;
use pizzaboxer\ProjectPolygon\Catalog;

header("content-type: application/json");
function fail($message) { die(json_encode(["success" => false, "message" => $message])); }
$id = (int) ($_GET["id"] ?? 0);

if (isset($_GET["owner"])) die(json_encode(["success" => true, "owns" => (bool) Catalog::OwnsAsset((int) $_GET["owner"], $id)]));

if (($_GET["type"] ?? "") === "Product")
{
	$p = Database::singleton()->run(
		"SELECT p.*, a.creator, u.username FROM PlaceProducts p JOIN assets a ON a.id = p.PlaceID JOIN users u ON u.id = a.creator WHERE p.ID = :id", [":id" => $id]
	)->fetch(PDO::FETCH_OBJ);
	if (!$p) fail("There's no product with that id");
	die(json_encode(["success" => true, "info" => ["ProductId" => (int) $p->ID, "AssetId" => 0, "Name" => $p->Name, "Description" => $p->Description,
		"PriceInRobux" => (int) $p->Price, "IsForSale" => (bool) $p->Active, "Sales" => (int) $p->Sales, "AssetTypeId" => 0,
		"Creator" => ["Id" => (int) $p->creator, "Name" => $p->username, "CreatorType" => "User", "CreatorTargetId" => (int) $p->creator]]]));
}

$a = Catalog::GetAssetInfo($id);
if (!$a) fail("There's no item with that id");
die(json_encode(["success" => true, "info" => ["AssetId" => (int) $a->id, "ProductId" => 0, "Name" => $a->name, "Description" => (string) $a->description,
	"PriceInRobux" => $a->sale ? (int) $a->price : null, "IsForSale" => (bool) $a->sale, "Sales" => (int) ($a->Sales ?? 0), "AssetTypeId" => (int) $a->type,
	"Creator" => ["Id" => (int) $a->creator, "Name" => $a->username, "CreatorType" => "User", "CreatorTargetId" => (int) $a->creator]]]));