codeswholesale/sdk
Composer 安装命令:
composer require codeswholesale/sdk
包简介
A PHP wrapper for CodesWholesale's API
README 文档
README
CodesWholesale.com is an API-driven wholesale platform for digital game distribution. This is the CodesWholesale SDK for PHP that will enable developers to easily integrate API with any PHP-based application.
Installation
You can install codeswholesale-sdk-php via Composer or by downloading the source.
Via Composer:
codeswholesale-sdk-php is available on Packagist as the codeswholesale/sdk package.
Install Composer on your project root
curl -sS https://getcomposer.org/installer | php
Or download it from official page: https://getcomposer.org/download/
Configure the codeswholesale/sdk dependency in your 'composer.json' file:
"require": {
"codeswholesale/sdk": "2.1"
}
Install the latest SDK with its dependencies on your project root
php composer.phar install
Create your CodesWholesale account
If you don’t have an account yet, sign up at CodesWholesale and set up your API credentials:
- Create a CodesWholesale account and create your API keys in WEB API tab, under your profile name link. Save your keys in safe place. Your API password is visible only once.
Getting Started
-
Require the CodesWholesale PHP SDK via the composer auto loader
require 'vendor/autoload.php';
-
Configure the client using the API keys
$params = [ /** * API Keys * These are test api keys that can be used for testing your integration: */ 'cw.client_id' => 'ff72ce315d1259e822f47d87d02d261e', 'cw.client_secret' => '$2a$10$E2jVWDADFA5gh6zlRVcrlOOX01Q/HJoT6hXuDMJxek.YEo.lkO2T6', /** * CodesWholesale ENDPOINT */ 'cw.endpoint_uri' => \CodesWholesale\CodesWholesale::SANDBOX_ENDPOINT, /** * Due to security reasons, you should use SessionStorage only while testing. * In order to go live, you should change it to database storage. */ 'cw.token_storage' => new \CodesWholesale\Storage\TokenSessionStorage() ]; $clientBuilder = new \CodesWholesale\ClientBuilder($params); $client = $clientBuilder->build();
For production release, please remember to switch from SANDBOX endpoint to LIVE endpoint.
-
List all available platforms, regions, languages on the CodesWholesale platform
$platforms = $client->getPlatforms() $regions = $client->getRegions(); $languages = $client->getLanguages();
-
List all products from the price list
$products = $client->getProducts(); foreach($products as $product) { $product->getName(); // the name of product $product->getStockQuantity(); // current stock quantity $product->getImageUrl(ImageType::SMALL) // product image url }
-
List all products from price list by language/platform/region
$products = $client->getProducts([ "language" => [ "Multilanguage", "fr" ], "platform" => [ "Steam" ], "region" => [ "WORLDWIDE" ] ]); foreach($products as $product) { $product->getName(); // the name of product $product->getStockQuantity(); // current stock quantity $product->getImageUrl(ImageType::SMALL) // product image url }
-
List all products from price list from the last 60 days
$products = $client->getProducts([ "inStockDaysAgo" => 60 ]); foreach($products as $product) { $product->getName(); // the name of product $product->getStockQuantity(); // current stock quantity $product->getImageUrl(ImageType::SMALL) // product image url }
-
Fetch invoice for your order
$orderInvoice = Invoice::get($createdOrder->getOrderId()); $invoicePath = Base64Writer::writeInvoice($orderInvoice, "./invoices");
-
Screen your customer before completing order
$securityInformation = Security::check( "devteam@codeswholesale.com", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.7.12 (KHTML, like Gecko) Version/8.0.7 Safari/600.7.12", "devteam-payment@codeswholesale.com", "81.90.190.200" ); $ipBlacklisted = $security->isIpBlacklisted(); $torIp = $security->isTorIp(); $domainBlackListed = $security->isDomainBlacklisted(); $subdomain = $security->isSubDomain();
-
Check your order history
$orders = Order::getHistory("2017-12-11", "2017-12-12"); foreach ($orderList as $order) { $order->getOrderId(); $order->getClientOrderId(); $order->getTotalPrice() ; $order->getStatus(); $order->getCreatedOn(); }
-
Single product details
```php
$product = \CodesWholesale\Resource\Product::get($productHref);
```
- Retrieve product description
```php
$productDescription = \CodesWholesale\Resource\ProductDescription::get($product->getDescriptionHref());
$productDescription->getLocalizedTitles(); // localized titles
$productDescription->getPegiRating(); // pegi rating
$productDescription->getPlatform(); // platform such as PC/Mac
$productDescription->getFactSheets(); // description in different langauges
$productDescription->getReleases(); // release dates
$productDescription->getEditions(); // editions
$productDescription->getDeveloperHomepage(); // game developer homepage
$productDescription->getKeywords(); // keywords
$productDescription->getGameLanguages(); // languages
$productDescription->getOfficialTitle(); // official title
$productDescription->getDeveloperName(); // game developer name
$productDescription->getEanCodes(); // EAN codes
$productDescription->getLastUpdate(); // last game update
$productDescription->getCategory(); // category of game
$productDescription->getPhotos(); // urls photo
$productDescription->getExtensionPacks(); // extension packs
$productDescription->getVideos(); // urls video
$productDescription->getProductId(); // product id
```
- Retrieve account details, balance value and available credit
```php
$account = $client->getAccount();
$account->getFullName(); // name of account
$account->getEmail(); // email
$account->getTotalToUse(); // total money to use, balance + credit
$account->getCurrentBalance(); // current balance value
$account->getCurrentCredit(); // current credit value
```
- Create order
```php
$createdOrder = Order::createOrder(
[
[
"productId" => "6313677f-5219-47e4-a067-7401f55c5a3a",
"quantity" => "2",
],
], null);
foreach ($createdOrder->getProducts() as $product) {
$product->getProductId();
$product->getUnitPrice();
foreach ($product->getCodes() as $code) {
$code->getCodeId();
if ($code->isPreOrder()) {
echo "<b>Code has been pre-ordered!</b>" . " <br>";
}
if ($code->isText()) {
echo "Text code to use: <b>" . $code->getCode() . "</b><br>";
}
if ($code->isImage()) {
$fullPath = \CodesWholesale\Util\Base64Writer::writeImageCode($code, "./my-codes");
echo "Product has been saved in <b>" . $fullPath . "</b><br>";
}
}
}
```
-
Receive notifications about product changes via Codeswholesale postback request
To receive notifications from CodesWholesale, first you have to configure your postback URL that will be responsible for handling CodesWholesale requests. In order to do that, follow these steps:
- Sign in to [CodesWholesale](https://app.codeswholesale.com/)
- Go to API tab
- Configure and test your post back url
If the URL has been successfully configured, you should be able to handle CodesWholesale requests as follow
```php
$client->registerStockAndPriceChangeHandler(function (array $stockAndPriceChanges) {
foreach ($stockAndPriceChanges as $stockAndPriceChange) {
/**
* Here you can save changes to your database
*
* @var StockAndPriceChange $stockAndPriceChange
*/
echo $stockAndPriceChange->getProductId();
echo $stockAndPriceChange->getQuantity();
$prices = $stockAndPriceChange->getPrices();
foreach ($prices as $price) {
/**
* @var Price $price
*/
echo $price->getRange();
echo $price->getValue();
}
echo "<hr>";
}
});
$client->registerHidingProductHandler(function (Notification $notification) {
/**
* Here you can request for product which was hidden or just hide it
* using provided productId
*/
echo $notification->getProductId();
});
$client->registerPreOrderAssignedHandler(function (AssignedPreOrder $notification) {
/**
* Here you can request for ordered product using productId
*/
echo $notification->getOrderId();
});
$client->registerUpdateProductHandler(function (Notification $notification) {
/**
* Here you can request product which was updated.
* It can be image, name or other product parameter.
*/
echo $notification->getProductId();
});
$client->registerNewProductHandler(function(Notification $notification) {
/**
* Here you can request product which was updated.
* It can be image, name or other product parameter.
*/
echo $notification->getProductId();
});
$client->handle(SIGNATURE);
```
If you send test request from the API tab and your script is configured to work with sandbox environment, it will download ten fake images.
You can check "examples" directory for more samples and details.
Copyright & Licensing
Copyright © 2014 Codeswholesale
This project is licensed under the Apache 2.0 Open Source License.
For additional information, please see:
- fkooman OAuth2 client: https://github.com/fkooman/php-oauth-client
codeswholesale/sdk 适用场景与选型建议
codeswholesale/sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 50.28k 次下载、GitHub Stars 达 35, 最近一次更新时间为 2014 年 04 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「api」 「cloud」 「games」 「codeswholesale」 「cd-keys」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 codeswholesale/sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 codeswholesale/sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 codeswholesale/sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
UCloud Resource (Cloud) Storage SDK for PHP
The flysystem adapter for yandex disk rest api.
Provide a way to secure accesses to all routes of an symfony application.
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
统计信息
- 总下载量: 50.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 36
- 点击次数: 10
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-only
- 更新时间: 2014-04-30