承接 nikapps/bazaar-api-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nikapps/bazaar-api-php

Composer 安装命令:

composer require nikapps/bazaar-api-php

包简介

A PHP API wrapper for CafeBazaar Rest Api v2

README 文档

README

A PHP API wrapper for Cafebazaar REST API (v2).

If you are looking for version 1.x, please visit branch v1.

CafeBazaar Logo

Table of Contents

Installation

If you don't have Composer, first you should install it on your system:

https://getcomposer.org

Now run this command to install the package:

composer require nikapps/bazaar-api-php
  • Notice: if you don't know anything about composer, please read this article.

Configuration

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)

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

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=<REDIRECT_URI>&client_id=<CLIENT_ID>

Don't forget to change <REDIRECT_URI> and <CLIENT_ID>.

  • After clicking on accept/confirm button, you will be redirected to: <REDIRECT_URI>?code=<CODE>

  • <REDIRECT_URI> is url of this file:

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

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

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

Here is the full example: authorization.php

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

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

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

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

Customization

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

See: https://github.com/nikapps/bazaar-api-php/blob/master/examples/

Dependencies

Testing

Run:

phpunit

Official Documentation

Contribute

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

License

This project released under the MIT License.

/*
 * 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

Donate via Paypal

nikapps/bazaar-api-php 适用场景与选型建议

nikapps/bazaar-api-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 467 次下载、GitHub Stars 达 4, 最近一次更新时间为 2015 年 03 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「wrapper」 「CafeBazaar」 「Cafebazaar Api」 「In App Purchase」 「iap」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nikapps/bazaar-api-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nikapps/bazaar-api-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 nikapps/bazaar-api-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 467
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 25
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-17