Sozlamalar
Barcha misollar muhitdan ikkita qiymatni o'qiydi:
export PARTNER_API_URL="https://partner.goxost.net/api/v1"
export PARTNER_API_KEY="gxp_xxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Kichik mijoz
<?php
// PHP 8+, no packages needed.
function partner(string $method, string $path, ?array $body = null): array
{
$ch = curl_init(getenv('PARTNER_API_URL') . $path);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('PARTNER_API_KEY'),
'Content-Type: application/json',
'Accept: application/json',
],
]);
if ($body !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
}
$json = json_decode((string) curl_exec($ch), true) ?? [];
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($status >= 400) {
throw new RuntimeException(($json['error']['code'] ?? 'HTTP_' . $status) . ': ' . ($json['error']['message'] ?? ''));
}
return $json['data'];
}
// Node.js 18+ (built-in fetch).
async function partner(method, path, body) {
const res = await fetch(process.env.PARTNER_API_URL + path, {
method,
headers: {
Authorization: `Bearer ${process.env.PARTNER_API_KEY}`,
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: body ? JSON.stringify(body) : undefined,
});
const json = await res.json();
if (!res.ok) throw new Error(`${json.error?.code}: ${json.error?.message}`);
return json.data;
}
# Python 3.9+, pip install requests
import os, requests
def partner(method, path, body=None):
res = requests.request(
method,
os.environ["PARTNER_API_URL"] + path,
json=body,
headers={"Authorization": "Bearer " + os.environ["PARTNER_API_KEY"], "Accept": "application/json"},
timeout=30,
)
data = res.json()
if res.status_code >= 400:
raise RuntimeError(f"{data['error']['code']}: {data['error']['message']}")
return data["data"]
Taklifdan natijagacha
<?php
$offers = partner('GET', '/offers?search=PUBG');
$offer = $offers[0];
$check = partner('POST', "/offers/{$offer['id']}/check", ['fields' => ['player_id' => '5123456789']]);
if ($check['checked'] && ! $check['valid']) {
exit('Wrong player ID: ' . $check['reason']);
}
// Your own order number makes retries safe.
$order = partner('POST', '/orders', [
'transaction_id' => 'shop-88121',
'offer_id' => $offer['id'],
'fields' => ['player_id' => '5123456789'],
'max_price' => $offer['price'],
]);
echo $order['status'], PHP_EOL; // completed, or pending/processing — wait for the webhook
const offers = await partner('GET', '/offers?search=PUBG');
const offer = offers[0];
const check = await partner('POST', `/offers/${offer.id}/check`, { fields: { player_id: '5123456789' } });
if (check.checked && !check.valid) throw new Error(`Wrong player ID: ${check.reason}`);
// Your own order number makes retries safe.
const order = await partner('POST', '/orders', {
transaction_id: 'shop-88121',
offer_id: offer.id,
fields: { player_id: '5123456789' },
max_price: offer.price,
});
console.log(order.status); // completed, or pending/processing — wait for the webhook
offers = partner("GET", "/offers?search=PUBG")
offer = offers[0]
check = partner("POST", f"/offers/{offer['id']}/check", {"fields": {"player_id": "5123456789"}})
if check["checked"] and not check["valid"]:
raise SystemExit("Wrong player ID: " + str(check["reason"]))
# Your own order number makes retries safe.
order = partner("POST", "/orders", {
"transaction_id": "shop-88121",
"offer_id": offer["id"],
"fields": {"player_id": "5123456789"},
"max_price": offer["price"],
})
print(order["status"]) # completed, or pending/processing — wait for the webhook
Natijani keyinroq o'qish
Webhook kelmagan bo'lsa, buyurtmani o'zingizning ID ingiz bo'yicha so'rang:
curl https://partner.goxost.net/api/v1/orders/shop-88121 \
-H "Authorization: Bearer $PARTNER_API_KEY"
Eslatma
max_price — butun buyurtma uchun umumiy summa. quantity 1 dan katta bo'lsa, bir dona narxini miqdorga ko'paytirib yuboring.