<?php // 1. Create a client in your developer panel // 2. Go to https://pardakht.cafebazaar.ir/devapi/v2/auth/authorize/?response_type=code&access_type=offline&redirect_uri=<REDIRECT_URI>&client_id=<CLIENT_ID> // (<redirect url> is url of this script). // 3. Store the refresh token use Nikapps\BazaarApi\Bazaar; use Nikapps\BazaarApi\Config; require_once __DIR__ . '/../vendor/autoload.php'; $bazaar = new Bazaar(new Config(['client-secret' => 'your-client-secret', 'client-id' => 'your-client-id'])); $redirectUrl = 'http://example.com/callback'; $token = $bazaar->token($redirectUrl); if ($token->failed()) { echo $token->errorDescription(); } else { echo "Refresh Token: " . $token->refreshToken(); }
<?php use Nikapps\BazaarApi\Bazaar; use Nikapps\BazaarApi\Config; use Nikapps\BazaarApi\Storage\FileTokenStorage; require_once __DIR__ . '/../vendor/autoload.php'; // We need a file to store access token. keep it in private! $bazaar = new Bazaar(new Config(['client-secret' => 'your-client-secret', 'client-id' => 'your-client-id', 'refresh-token' => 'refresh-token-123456', 'storage' => new FileTokenStorage(__DIR__ . '/token.json')])); // Which subscription do you want to unsubscribe/cancel? // it also automatically refreshes token if needed $unsubscribe = $bazaar->unsubscribe('com.example.app', 'subscription-id (sku)', 'purchase-token'); if ($unsubscribe->successful()) { echo "The subscription has been successfully cancelled!"; } else { echo $unsubscribe->errorDescription(); }
<?php use Nikapps\BazaarApi\Bazaar; use Nikapps\BazaarApi\Config; use Nikapps\BazaarApi\Storage\FileTokenStorage; require_once __DIR__ . '/../vendor/autoload.php'; // We need a file to store access token. keep it in private! $bazaar = new Bazaar(new Config(['client-secret' => 'your-client-secret', 'client-id' => 'your-client-id', 'refresh-token' => 'refresh-token-123456', 'storage' => new FileTokenStorage(__DIR__ . '/token.json')])); // Set your purchase info (package name, product id (SKU) and purchase token) // it also automatically refreshes token if needed $purchase = $bazaar->purchase('com.example.app', 'product-id (sku)', 'purchase-token'); if ($purchase->failed()) { echo $purchase->errorDescription(); } else { echo "Purchased: " . $purchase->purchased(); echo "Consumed: " . $purchase->consumed(); echo "Developer Payload: " . $purchase->developerPayload(); echo "Purchase Time (Timestamp in ms): " . $purchase->time(); }
<?php use Nikapps\BazaarApi\Bazaar; use Nikapps\BazaarApi\Config; use Nikapps\BazaarApi\Storage\FileTokenStorage; require_once __DIR__ . '/../vendor/autoload.php'; // We need a file to store access token. keep it in private! $bazaar = new Bazaar(new Config(['client-secret' => 'your-client-secret', 'client-id' => 'your-client-id', 'refresh-token' => 'refresh-token-123456', 'storage' => new FileTokenStorage(__DIR__ . '/token.json')])); // Set your subscription info (package name, subscription id (SKU) and purchase token) // it also automatically refreshes token if needed $subscription = $bazaar->subscription('com.example.app', 'subscription-id (sku)', 'purchase-token'); if ($subscription->failed()) { echo $subscription->errorDescription(); } else { echo "Start Time (Timestamp in ms): " . $subscription->startTime(); // initiationTime() echo "End Time (Timestamp in ms): " . $subscription->endTime(); // expirationTime(), nextTime() echo "Is auto renewing? " . $subscription->autoRenewing(); echo "Is expired? (end time is past) " . $subscription->expired(); }