PHPackages                             nikapps/bazaar-api-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. nikapps/bazaar-api-php

ActiveLibrary[API Development](/categories/api)

nikapps/bazaar-api-php
======================

A PHP API wrapper for CafeBazaar Rest Api v2

2.0.1(10y ago)546621MITPHPPHP &gt;=5.5.9

Since Mar 17Pushed 10y ago2 watchersCompare

[ Source](https://github.com/nikapps/bazaar-api-php)[ Packagist](https://packagist.org/packages/nikapps/bazaar-api-php)[ RSS](/packages/nikapps-bazaar-api-php/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (6)Dependencies (2)Versions (9)Used By (1)

Bazaar-Api-PHP (BazaarApi for PHP)
==================================

[](#bazaar-api-php-bazaarapi-for-php)

A PHP API wrapper for [Cafebazaar REST API (v2)](https://cafebazaar.ir/developers/docs/developer-api/v2/introduction/?l=fa).

**If you are looking for version 1.x, please visit [branch v1](https://github.com/nikapps/bazaar-api-php/tree/v1/).**

[![CafeBazaar Logo](https://camo.githubusercontent.com/99c3454ec04c11cecf93c103b931ac841d42c70a63f3f78f2709bd23566259d2/68747470733a2f2f646c2e64726f70626f7875736572636f6e74656e742e636f6d2f752f32393134313139392f62617a6161722d6c6f676f2d616e642d6c6f676f747970652e706e673f7261773d31)](https://camo.githubusercontent.com/99c3454ec04c11cecf93c103b931ac841d42c70a63f3f78f2709bd23566259d2/68747470733a2f2f646c2e64726f70626f7875736572636f6e74656e742e636f6d2f752f32393134313139392f62617a6161722d6c6f676f2d616e642d6c6f676f747970652e706e673f7261773d31)

Table of Contents
-----------------

[](#table-of-contents)

- [Bazaar-Api-PHP (BazaarApi for PHP)](#bazaar-api-php-bazaarapi-for-php)
    - [Table of Contents](#table-of-contents)
    - [Installation](#installation)
    - [Configuration](#configuration)
        - [Create a client](#create-a-client)
        - [Getting refresh token](#getting-refresh-token)
        - [Setting up config](#setting-up-config)
    - [Usage](#usage)
        - [Purchase](#purchase)
        - [Subscription](#subscription)
        - [Cancel Subscription (Unsubscribe)](#cancel-subscription-unsubscribe)
    - [Customization](#customization)
        - [Custom Token Storage](#custom-token-storage)
    - [Examples](#examples)
    - [Dependencies](#dependencies)
    - [Testing](#testing)
    - [Official Documentation](#official-documentation)
    - [Contribute](#contribute)
    - [License](#license)
    - [Donation](#donation)

Installation
------------

[](#installation)

If you don't have [Composer](https://getcomposer.org), first you should install it on your system:

```
https://getcomposer.org

```

Now run this command to install [the package](https://packagist.org/packages/nikapps/bazaar-api-php):

```
composer require nikapps/bazaar-api-php

```

- **Notice:** if you don't know anything about **composer**, please read this [article](https://scotch.io/tutorials/a-beginners-guide-to-composer).

Configuration
-------------

[](#configuration)

### Create a client

[](#create-a-client)

First, you should go to your cafebazaar panel and create a client.

- Login to your panel and go to this url: `https://pardakht.cafebazaar.ir/panel/developer-api/?l=fa&nd=False`
- Click on `new client` and enter your redirect uri (it is needed for getting returned `code` and `refresh_token`. see the [next section](#getting-refresh-token))

now you have your `client-id` and `client-secret`.

### Getting refresh token

[](#getting-refresh-token)

- Open this url in your browser:

```
https://pardakht.cafebazaar.ir/devapi/v2/auth/authorize/?response_type=code&access_type=offline&redirect_uri=&client_id=

```

**Don't forget to change `` and ``.**

- After clicking on accept/confirm button, you will be redirected to: `?code=`
- `` is url of this file:

```
$bazaar = new Bazaar(new Config([
    'client-secret' => 'your-client-secret',
    'client-id' => 'your-client-id'
]));

$token = $bazaar->token('');

echo "Refresh Token: " . $token->refreshToken();
```

**Here is the full example: [authorization.php](https://github.com/nikapps/bazaar-api-php/blob/master/examples/authorization.php)**

### Setting up config

[](#setting-up-config)

As you can see in previous section, we create a `Config` instance and set `client-id` and `client-secret`.

For other api calls, we also should set `refresh-token` and `storage`.

```
$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')
]));
```

The `storage` handles storing and retrieving `access_token`. in this package we have two different storages:

- `FileTokenStorage` which store token in a file.
- `MemoryTokenStorage` which does not persist the token and you can only use it in current request.

Usage
-----

[](#usage)

### Purchase

[](#purchase)

Here is the example of getting state of a purchase:

```
$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();
}
```

**Full Example: [purchase.php](https://github.com/nikapps/bazaar-api-php/blob/master/examples/purchase.php)**

### Subscription

[](#subscription)

Here is the example of getting state of a subscription:

```
$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();
}
```

**Full Example: [subscription.php](https://github.com/nikapps/bazaar-api-php/blob/master/examples/subscription.php)**

### Cancel Subscription (Unsubscribe)

[](#cancel-subscription-unsubscribe)

Here is the example of how you can cancel a subscription:

```
$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();
}
```

**Full Example: [unsubscribe.php](https://github.com/nikapps/bazaar-api-php/blob/master/examples/unsubscribe.php)**

Customization
-------------

[](#customization)

### Custom Token Storage

[](#custom-token-storage)

If you want to store the token somewhere else (maybe database or redis?!), you can implement the `TokenStorageInterface`

```
class CustomTokenStorage implements TokenStorageInterface
{

    public function save(Token $token)
    {
    	// store access token
    }

    public function retrieve()
    {
    	// return access token
    }

    public function expired()
    {
    	// is token expired?
    }

}
```

Examples
--------

[](#examples)

See:

Dependencies
------------

[](#dependencies)

- [GuzzleHttp (~5.3|~6.1)](https://packagist.org/packages/guzzlehttp/guzzle)

Testing
-------

[](#testing)

Run:

```
phpunit

```

Official Documentation
----------------------

[](#official-documentation)

- [Developer API (Persian/Farsi)](https://cafebazaar.ir/developers/docs/developer-api/v2/getting-started/?l=fa)
- [Developer API (English)](https://cafebazaar.ir/developers/docs/developer-api/v2/getting-started/?l=en)

Contribute
----------

[](#contribute)

Wanna contribute? simply fork this project and make a pull request!

License
-------

[](#license)

This project released under the [MIT License](http://opensource.org/licenses/mit-license.php).

```
/*
 * Copyright (C) 2015-2016 NikApps Team.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * 1- The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * 2- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

```

Donation
--------

[](#donation)

[![Donate via Paypal](https://camo.githubusercontent.com/e1ff554a09e8e92bef25abc553ff05b88f45afd695877cf12f3a46558ef65b2e/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e61746543435f4c472e676966)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=G3WRCRDXJD6A8)

###  Health Score

32

—

LowBetter than 70% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 97.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~58 days

Recently: every ~87 days

Total

7

Last Release

3753d ago

Major Versions

v1.x-dev → 2.0.02016-02-28

PHP version history (2 changes)1.0.0PHP &gt;=5.4.0

2.0.0PHP &gt;=5.5.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/9f76490bba7e578cb08504eafaa582eaf0b07ab01345f9b8fb50e435f7aa2002?d=identicon)[nikapps](/maintainers/nikapps)

![](https://www.gravatar.com/avatar/94f199381138539812836796c76244cdbe6e5d5167961e0f1f8b7d2665ba8b73?d=identicon)[alibo](/maintainers/alibo)

---

Top Contributors

[![alibo](https://avatars.githubusercontent.com/u/5338482?v=4)](https://github.com/alibo "alibo (35 commits)")[![moradgholi](https://avatars.githubusercontent.com/u/6699138?v=4)](https://github.com/moradgholi "moradgholi (1 commits)")

---

Tags

apiwrapperCafeBazaarCafebazaar ApiIn App PurchaseiapBazaar

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nikapps-bazaar-api-php/health.svg)

```
[![Health](https://phpackages.com/badges/nikapps-bazaar-api-php/health.svg)](https://phpackages.com/packages/nikapps-bazaar-api-php)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3751.2M45](/packages/tencentcloud-tencentcloud-sdk-php)[gabrielbull/ups-api

PHP UPS API

4642.4M10](/packages/gabrielbull-ups-api)[files.com/files-php-sdk

Files.com PHP SDK

2478.1k](/packages/filescom-files-php-sdk)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

232.5k](/packages/eslazarev-wildberries-sdk)[dariusiii/tmdb-laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.

1821.1k](/packages/dariusiii-tmdb-laravel)[walle89/swedbank-json

Unofficial API client for the Swedbank's and Sparbanken's mobile apps in Sweden.

772.5k](/packages/walle89-swedbank-json)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
