PHP7 SDK for Suretly Lender API
The recommended way to install LenderAPI SDK is through Composer.
# Install Composer
curl -sS https://getcomposer.org/installer | php
Next, run the Composer command to install the latest stable version of LenderAPI SDK:
php composer.phar require suretly/lender-api-sdk
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
After installing, you need to create a new Suretly\LenderApi\LenderManager
.
Include LenderManager class
use Suretly\LenderApi\LenderManager;
You can create SDK from static method:
$sdk = LenderManager::create('id', 'token', 'server'):
Or you can create a configuration for your connection and create a LenderManager:
$config = [
'id' => '<your_id>',
'token' => '<your_token>',
'server' => '<server_name>'
];
$sdk = new LenderManager($config);
$options = $sdk->getOptions();
Get orders with parameter $limit
and optional parameter $skip
.
The limit parameter must be set in the range from 0 to 25.
$orders = $sdk->getOrders($limit, $skip);
For a create a new order, you must create a new Suretly\LenderApi\Model\NewOrder
object.
/** @var Suretly\LenderApi\Model\NewOrder $newOrder */
$newOrder = new NewOrder()
// ...
// set data
// ..
After, you can add new order on Suretly server with method postNewOrder
:
/** @var string $orderID */
$orderID = $sdk->postNewOrder($newOrder)->id;
Method postNewOrder
return object with 2 fields
/** @var object $response */
$response = $sdk->postNewOrder($newOrder);
$orderID = $response->id;
$feeAmount = $response->fee_amount;
For example, json data
{
"id": "string"
}
To get the status of the order, run method getOrderStatus
, which return Suretly\LenderApi\Model\OrderStatus object:
$orderStatus = $sdk->getOrderStatus($orderID);
For example, json data
{
"id": "string",
"public": true,
"sum": 0,
"cost": 0,
"bids_count": 0,
"stop_time": 0,
"fee_total": 0,
"fee_paid": 0,
"payment_link": "string"
}
To get a order, you must call method getOrder
with parameter $orderID
:
/** @var \Suretly\LenderApi\Model\Order $order */
$order = $sdk->getOrder($orderID);
For example, json data for Borrower with russian passport:
{
"id": "string",
"uid": "string",
"status": "string",
"borrower": {
"name": {
"first": "string",
"middle": "string",
"last": "string",
"maiden": "string"
},
"gender": "string",
"birth": {
"date": "string",
"place": "string"
},
"email": "string",
"phone": "string",
"profile_url": "string",
"photo_url": "string",
"city": "string",
"identity_document_type": "passport_rf",
"identity_document": {
"series": "string",
"number": "string",
"issue_date": "string",
"issue_place": "string",
"issue_code": "string",
"registration": {
"country": "string",
"zip": "string",
"area": "string",
"city": "string",
"street": "string",
"house": "string",
"building": "string",
"flat": "string",
"address_line_1": "string",
"address_line_2": "string"
},
"iin": "string",
"expire_date": "string",
"ssn": "string",
"authority": "string"
},
"residential": {
"country": "string",
"zip": "string",
"area": "string",
"city": "string",
"street": "string",
"house": "string",
"building": "string",
"flat": "string",
"address_line_1": "string",
"address_line_2": "string"
}
},
"user_credit_score": 0,
"cost": "string",
"loan_sum": "string",
"loan_term": "string",
"loan_rate": 0,
"currency_code": "string",
"max_wait_time": "string",
"created_at": "string",
"modify_at": "string",
"closed_at": "string",
"bids_count": "string",
"bids_sum": "string",
"callback": "string"
}
For a cancel the order, you must call method postOrderStop
with parameter $orderID
:
$sdk->postOrderStop($orderID);
To get a contract for a Borrower, you must call method getContract
with parameter $orderID
:
/** @var string $contractHTML */
$contractHTML = $sdk->getContract($orderID);
Method getContract
return HTML code:
'<html><head>Contract</head>...</html>'
To confirm that contract is signed by borrower:
$sdk->postContractAccept($orderID);
To confirm that order is paid and issued:
$sdk->postOrderIssued($orderID);
To confirm that order is paid:
$sdk->postOrderPaid($orderID);
To confirm that order is partial paid:
$sdk->postOrderPartialPaid($orderID, $sum);
To get fee_amount prolong order, you must run method getOrderProlong
with parameter $orderID
and parameter $days
, which return float value:
/** @var float $feeAmount */
$feeAmount = $sdk->getOrderProlong($orderID, $days);
For example, json data
{
"fee_amount": 0
}
To prolong order, you must call method postOrderUnpaid
$sdk->postOrderProlong($orderID, $days);
To upload a borrower image, you must call method postUploadImageOrder
with parameter $orderID
, parameter $realPathToFile
, which is realpath to file, and optional parameter $filename
:
$sdk->postUploadImageOrder($orderID, $realPathToFile, $filename);
Mark loan as overdue:
$sdk->postOrderUnpaid($orderID, $sum);
/** @var \Suretly\LenderApi\Model\Currency[] $currencies */
$currencies = $sdk->getCurrencies();
For example, json data
[
{
"code": "DE",
"name": "Germany"
},
{
"code": "FR",
"name": "France"
},
{
"code": "US",
"name": "United States of America"
},
{
"code": "RU",
"name": "Russia"
},
{
"code": "KZ",
"name": "Казахстан"
}
]
/** @var \Suretly\LenderApi\Model\Country[] $countries */
$countries = $sdk->getCountries();
For example, json data
[
{
"code": "DE",
"name": "Germany",
"currency_code": "EUR"
},
{
"code": "FR",
"name": "France",
"currency_code": "EUR"
},
{
"code": "US",
"name": "United States of America",
"currency_code": "USD"
},
{
"code": "SWE",
"name": "Sweden",
"currency_code": "BTC"
},
{
"code": "RU",
"name": "Russia",
"currency_code": "RUB"
},
{
"code": "KZ",
"name": "Казахстан",
"currency_code": "KZT"
}
]
All SDK methods should use try/catch. For example:
try {
$sdk->postOrderUnpaid($orderID, $sum);
} catch (\Exception $exception) {
echo $exception->getMessage();
}
All SDK methods call ResponseErrorException when an error occurs on the server.
You can see all errors in class - SuretlySDK\Type\ResponseErrorStatusType
.
try {
$sdk->postOrderUnpaid($orderID, $sum);
} catch (\SuretlySDK\Type\ResponseErrorStatusType $exception) {
echo $exception->getCode() . ': ' . $exception->getMessage();
}
Now, you should use LenderManager instead Suretly.
use Suretly\LenderApi\LenderManager;
// create sdk
$sdk = LenderManager::create('id', 'token');
Also, all field on Model is private and you should use getters and setters.
// create sdk
/** @var Order $order */
$orderId = $order->getId();
That's all.
For run examples test in root project directory run commands
cd examples
php example.php
For run unit tests in root project directory run command in console
/vendor/bin/phpunit
For Windows
/vendor/bin/phpunit.bat