Download the PHP package itaccfarm/reseller-api-sdk without Composer
On this page you can find all versions of the php package itaccfarm/reseller-api-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download itaccfarm/reseller-api-sdk
More information about itaccfarm/reseller-api-sdk
Files in itaccfarm/reseller-api-sdk
Package reseller-api-sdk
Short Description SDK for accfarm reseller api
License
Homepage https://github.com/ITAccfarm/reseller-api-sdk
Informations about the package reseller-api-sdk
Markdown output:
Accfarm SDK
This is an official Accfarm Reseller SDK. Out of the box it covers all endpoints and has the functionality to fully interact with API. This SDK can be used for development as it is, or serve as reference for you own SDK.
Table of contents
- Installation
- Getting started
- Order Statuses
- Methods
- Authentication
- Authenticate
- Refresh
- Invalidate
- Object
- Get Token
- Get Secret
- Set Token
- Set Secret
- Data
- Offers
- Offer
- Categories
- Orders
- Order
- User
- Buy
- Callback
Installation
Installation via composer:
composer require itaccfarm/reseller-api-sdk
Manual installation:
- Download archive
- Unpack and add ResellerSDK to your project
- Remove ITAccfarm from namespace and path to where you put ResellerSDK folder and add your namespace
Getting started
There are only 4 files in this SDK:
- src/ResellerSDK/ResellerSDK.php - Contains all core code and logic
- index.php - File used for demonstration (you can delete it)
- callback_example.php - File used for demonstration (you can delete it)
Let's start with our first and only ResellerSDK
class.
-
First of all, we need to create new object.
-
Then authenticate with email and password, check if our credentials are correct, and then store token and user secret from auth data to your DB, file, config, etc.
-
Then we can make API requests with this object! You can see the list of all methods in Methods section.
- Next time you create an object of that class you can simply pass bearer token and user secret into the construct method.
Order statuses
- 1: new:
- 2: in_progress
- 3: complete
- 4: canceled
- 5: pending
- 6: refunded
- 7: mispaid
Methods
List of all methods:
$api->auth(string $email, string $password): ?array
$api->refresh(): ?string
-
$api->invalidate(): bool
$api->uesr(): array
$api->categories(): array
$api->offers(array $filters): array
$api->orders(): array
-
$api->order(string $orderNumber): array
-
$api->buy(string $type, array $data)
$api->getToken(): string
$api->getSecret(): string
$api->setToken(string $token): $this
$api->setSecret(string $secret): $this
Authentication
Authenticate
Endpoint: https://accfarm.com/api/v1/user/login
Method: $api->auth(string $email, string $password)
Params: string $email, string $password
Returns: ?array ['bearerToken' => 'token', 'userSecret' => 'secret']
or null
This method:
- Attempts authentication on 'user/login' endpoint.
- Stores bearer token to an object.
It is strongly suggested to store your token to the database, file or some other way and not to use this method every time when making requests.
Refresh
Endpoint: https://accfarm.com/api/v1/user/refresh
Method: $api->refresh();
Returns: string (new token) or null
This method:
- Refreshes token.
- Replaces old token with a new one in an object.
Invalidate
Endpoint: https://accfarm.com/api/v1/user/invalidate
Method: $api->refresh();
Returns: bool (invalidation successful or not)
This method:
- Invalidates and deletes token from an object.
Object
Construct
Params: string $bearerToken = '', string $userSecret = ''
Get Token
Method: $api->getToken()
Returns: string (token from an object)
This method:
- Returns bearer token from an object.
Get Secret
Method: $api->getSecret()
Returns: string (secret from an object)
This method:
- Returns user secret from an object.
Set Token
Method: $api->setToken(string $token)
Params: string $token
Returns: $this
This method:
- Sets bearer token to an object.
Set Secret
Method: $api->setSecret(string $secret)
Params: string $secret
Returns: $this
This method:
- Sets user secret to an object.
Data
User
Endpoint: https://accfarm.com/api/v1/user
Method: $api->user();
Returns: array (current user)
This method:
- Returns current user.
Offers
Endpoint: https://accfarm.com/api/v1/offers
Method: $api->offers(array $data);
Params: Optional: [category_id => int, product_id => int, discount => bool]
Returns: array (offers)
This method:
- Return offers with filters.
Offer
Endpoint: https://accfarm.com/api/v1/offer
Method: $api->offer(int $id);
Params: int $id
Returns: array (offer)
This method:
- Return offer by its id.
Categories
Endpoint: https://accfarm.com/api/v1/categories
Method: $api->categories();
Returns: array (all categories)
This method:
- Returns all categories.
Orders
Endpoint: https://accfarm.com/api/v1/orders
Method: $api->orders();
Returns: array (user orders)
This method:
- Return all user orders.
Order
Endpoint: https://accfarm.com/api/v1/order
Method: $api->order(string $orderNumber);
Params: string $orderNumber
Returns: array (user order)
This method:
- Return order by it's 'order_number'.
Buy
Endpoint: https://accfarm.com/api/v1/buy
Method: $api->buy(string $type, array $data);
Returns: array (user order)
This method:
- Creates order and does everything a simple order creation on website would do.
Params for types:
$type
options:
'offer'
'review'
'install'
'offer'
type $data
params:
- quantity: required|int
- offer_id: required|int
- callback_url: optional|string
- sandbox: optional|bool
'review'
type $data
params:
- quantity: required|int
- offer_id: required|int
- url: required|string
- reviews_array: optional|array
- reviews: optional|string
- file: optional|types:txt,doc,csv|max_size:6020
- callback_url: optional|string
- sandbox: optional|bool
'install'
type $data
params:
- quantity: required|int
- offer_id: required|int
- app_link: required|string
- app_id: required
- days: required|int
- country: required|array
- reviews: optional|string
- file: optional|types:txt,doc,csv|max_size:6020
- callback_url: optional|string
- sandbox: optional|bool
If 'file'
, 'reviews'
or 'reviews_array'
is empty, then reviews will be autogenerated.
It is recommended to write your on reviews.
Params in $data
explained:
'file'
: send reviews in file. They will be reviewed manually. Example:$data['file'] = realpath('') . '\' . 'test_data.txt;
'reviews'
: reviews should be divided by \n. Example:$data['reviews'] = 'review1 \n review2 \n review3';
'reviews_array'
: each review in new index. Example:$data['reviews_array'] = ['review1', 'review2', ...]
'url'
: url to place where to write reviews'app_link'
: url to place where to make installs'days'
: spread installations in this span of days'country'
: ISO country code (US, RU, UA, etc.)'sandbox'
: sandbox mode to make test orders.$data['sandbox'] = 1;
for test orders.-
'callback_url'
: your url endpoint to send order data to.
Callback
If you provide callback_url in buy method, Accfarm will send you order data on order updates.
Call to you endpoint (your callbackurl) will always have Signature_ header. This will allow you to be sure call is coming from Accfarm. To check if it's valid you're going to need to:
-
Hash request data with your user secret with the following code:
- And then to check resulting hash against Signature header:
All versions of reseller-api-sdk with dependencies
ext-json Version *
ext-curl Version *
ext-fileinfo Version *