Download the PHP package nikapps/bazaar-api-laravel without Composer
On this page you can find all versions of the php package nikapps/bazaar-api-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nikapps/bazaar-api-laravel
More information about nikapps/bazaar-api-laravel
Files in nikapps/bazaar-api-laravel
Package bazaar-api-laravel
Short Description An API wrapper for cafebazaar based on popular Laravel Framework
License MIT
Informations about the package bazaar-api-laravel
Bazaar-Api-Laravel (BazaarApi for Laravel)
An Easy-To-Use CafeBazaar API helper package for Laravel Framework (Laravel 4.2.x)
Version 2.x is based on Bazaar-Api-PHP.
Installation
Simply run command:
Or you can add this package dependency to your Laravel's composer.json :
{
"require": {
"nikapps/bazaar-api-laravel": "2.*"
}
}
Then update composer:
-
Add this package provider in your providers array [app/config/app.php]
:
'Nikapps\BazaarApiLaravel\BazaarApiLaravelServiceProvider',
Next you need to publish configuration file. Run this command:
Run :
If you see a bazaar:refresh-token
command, you are all set to go !
Configuration
Create a client
First of all, you should go to your cafebazaar panel and get client id
and client secret
.
-
Login to your panel and go to this url: (Developer API section)
http://pardakht.cafebazaar.ir/panel/developer-api/?l=fa
-
Click on
new client
and enter your redirect uri (you have to set it for gettingcode
andrefresh_token
from cafebazaar) - Change your configuration file and set your
client_id
,client_secret
andredirect_uri
.
Get refresh token
- Open this url in your browser:
- don't forget to change <REDIRECT_URI>
and <CLIENT_ID>
.
- After clicking on accept/confirm button, you'll go to :
<REDIRECT_URI>?code=<CODE>
- copy <CODE>
- Run this command:
- replace <CODE>
with the copied data.
- Copy
refresh_token
and save in your configuration file. (app/config/packages/nikapps/bazaar-api-laravel/config.php)
Done!
Usage
Purchase
$purchase = BazaarApi::purchase('com.package.name', 'product_id', 'purchase_token');
//or you can pass an array
$purchase = BazaarApi::purchase([
'package' => 'com.package.name',
'product_id' => 'product_id',
'purchase_token' => 'purchase_token'
]);
echo "Developer Payload: " . $purchase->getDeveloperPayload();
echo "PurchaseTime: " . $purchase->getPurchaseTime(); //instance of Carbon
echo "Consumption State: " . $purchase->getConsumptionState();
echo "Purchase State: " . $purchase->getPurchaseState();
echo "Kind: " . $purchase->getKind();
Subscription
$subscription = BazaarApi::subscription('com.package.name', 'subscription_id', 'purchase_token');
//or you can pass an array
$subscription = BazaarApi::subscription([
'package' => 'com.package.name',
'subscription_id' => 'subscription_id',
'purchase_token' => 'purchase_token'
]);
echo "Initiation Time: " . $subscription->getInitiationTime(); // instance of Carbon
echo "Expiration Time: " . $subscription->getExpirationTime(); // instance of Carbon
echo "Auto Renewing: " . $subscription->isAutoRenewing(); // boolean
echo "Kind: " . $subscription->getKind();
Cancel Subscription
$cancelSubscription = BazaarApi::cancelSubscription('com.package.name', 'subscription_id', 'purchase_token');
//or you can pass an array
$cancelSubscription = BazaarApi::cancelSubscription([
'package' => 'com.package.name',
'subscription_id' => 'subscription_id',
'purchase_token' => 'purchase_token'
]);
echo "Cancel Subscription: " . $cancelSubscription->isCancelled(); // bool
Refresh Token (Manually)
This packages refreshes token when it's necessary, but if you want you can do it manually.
$token = BazaarApi::refreshToken();
echo 'Access Token: ' . $token->getAccessToken();
echo 'Scope: ' . $token->getScope();
echo 'Expire In: ' . $token->getExpireIn();
echo 'Token Type: ' . $token->getTokenType();
Clear Cache
Run this command to clean your cache, this command also invalidates your token.
Dependencies
Contribute
Wanna contribute? simply fork this project and make a pull request!
License
This project released under the MIT License.