nikapps / bazaar-api-laravel
基于流行 Laravel 框架的 cafebazaar API 包装器
Requires
- php: >=5.4.0
- illuminate/support: 4.2.*
- nikapps/bazaar-api-php: 1.*
This package is not auto-updated.
Last update: 2024-09-14 17:06:04 UTC
README
为 Laravel 框架(Laravel 4.2.x)提供易用的 CafeBazaar API 辅助包
2.x 版本基于 Bazaar-Api-PHP。
安装
只需运行以下命令
composer require nikapps/bazaar-api-laravel
或者您可以将此 包 依赖添加到 Laravel 的 composer.json 文件中
{ "require": { "nikapps/bazaar-api-laravel": "2.*" } }
然后更新 composer
composer update
在您的 providers 数组中添加此包提供者 [app/config/app.php]
'Nikapps\BazaarApiLaravel\BazaarApiLaravelServiceProvider',
接下来,您需要发布配置文件。运行以下命令
php artisan config:publish nikapps/bazaar-api-laravel
运行
php artisan
如果您看到 bazaar:refresh-token
命令,那么您就可以开始使用了!
配置
创建客户端
首先,您应该前往您的 cafebazaar 控制面板并获取 客户端 ID
和 客户端密钥
。
-
登录到您的面板并访问此 URL: (开发者 API 部分)
http://pardakht.cafebazaar.ir/panel/developer-api/?l=fa
-
点击
新建客户端
并输入您的重定向 URI(您必须设置它以从 cafebazaar 获取code
和refresh_token
) -
更改您的配置文件并设置您的
client_id
、client_secret
和redirect_uri
。
获取刷新令牌
- 在浏览器中打开此 URL
https://pardakht.cafebazaar.ir/auth/authorize/?response_type=code&access_type=offline&redirect_uri=<REDIRECT_URI>&client_id=<CLIENT_ID>
- 不要忘记更改 <REDIRECT_URI>
和 <CLIENT_ID>
。
- 点击接受/确认按钮后,您将转到:
<REDIRECT_URI>?code=<CODE>
- 复制 <CODE>
- 运行以下命令
php artisan bazaar:refresh-token <CODE>
- 将 <CODE>
替换为复制的数据。
- 复制
refresh_token
并将其保存到您的配置文件中。 (app/config/packages/nikapps/bazaar-api-laravel/config.php)
完成!
用法
购买
$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 = 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();
取消订阅
$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
刷新令牌(手动)
此包在需要时刷新令牌,但您也可以手动进行。
$token = BazaarApi::refreshToken(); echo 'Access Token: ' . $token->getAccessToken(); echo 'Scope: ' . $token->getScope(); echo 'Expire In: ' . $token->getExpireIn(); echo 'Token Type: ' . $token->getTokenType();
清除缓存
运行此命令以清理您的缓存,此命令还会使您的令牌失效。
php artisan bazaar:clear-cache
依赖项
贡献
想要贡献?只需将此项目分支出来并创建一个 pull request!
许可证
本项目根据 MIT 许可证 发布。
/*
* Copyright (C) 2015 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.
*/