Loyalty
extends AbstractApiResourceGroup
in package
Class Loyalty
Tags
Table of Contents
Methods
- accountActivate() : LoyaltyAccountActivateResponse
- Makes POST "/api/v5/loyalty/account/{id}/activate" request.
- accountBonusCharge() : LoyaltyBonusCreditResponse
- Makes POST "/api/v5/loyalty/account/{id}/bonus/charge" request.
- accountBonusCredit() : LoyaltyBonusCreditResponse
- Makes POST "/api/v5/loyalty/account/{id}/bonus/credit" request.
- accountBonusOperations() : LoyaltyBonusOperationsResponse
- Makes GET "/api/v5/loyalty/account/{id}/bonus/operations" request.
- accountCreate() : LoyaltyAccountCreateResponse
- Makes POST "/api/v5/loyalty/account/create" request.
- accountEdit() : LoyaltyAccountCreateResponse
- Makes POST "/api/v5/loyalty/account/{id}/edit" request.
- accountGet() : LoyaltyAccountResponse
- Makes GET "/api/v5/loyalty/account/{id}" request.
- accounts() : LoyaltyAccountsResponse
- Makes GET "/api/v5/loyalty/accounts" request.
- bonusOperations() : AllBonusOperationsResponse
- Makes GET "/api/v5/loyalty/bonus/operations" request.
- calculate() : LoyaltyCalculateResponse
- Makes POST "/api/v5/loyalty/calculate" request.
- get() : LoyaltyResponse
- Makes GET "/api/v5/loyalty/loyalties/{id}" request.
- getBonusAccountDetails() : BonusAccountDetailsResponse
- Makes GET "/api/v5/loyalty/account/{$id}/bonus/{$status}/details" request.
- loyalties() : LoyaltiesResponse
- Makes GET "/api/v5/loyalty/loyalties" request.
Methods
accountActivate()
Makes POST "/api/v5/loyalty/account/{id}/activate" request.
public
accountActivate(int $id) : LoyaltyAccountActivateResponse
Example:
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
try {
$response = $client->loyalty->accountActivate(159);
} catch (ApiExceptionInterface $exception) {
echo sprintf(
'Error from RetailCRM API (status code: %d): %s',
$exception->getStatusCode(),
$exception->getMessage()
);
if (count($exception->getErrorResponse()->errors) > 0) {
echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
}
return;
}
echo 'Activated loyalty account: ' . print_r($response->loyaltyAccount, true);
Parameters
- $id : int
Tags
Return values
LoyaltyAccountActivateResponseaccountBonusCharge()
Makes POST "/api/v5/loyalty/account/{id}/bonus/charge" request.
public
accountBonusCharge(int $id, LoyaltyBonusChargeRequest $request) : LoyaltyBonusCreditResponse
Example:
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyBonusChargeRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new LoyaltyBonusChargeRequest();
$request->amount = 100;
$request->comment = 'Payment for the goods.';
try {
$response = $client->loyalty->accountBonusCharge(159, $request);
} catch (ApiExceptionInterface $exception) {
echo sprintf(
'Error from RetailCRM API (status code: %d): %s',
$exception->getStatusCode(),
$exception->getMessage()
);
if (count($exception->getErrorResponse()->errors) > 0) {
echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
}
return;
}
echo 'Status: ' . var_export($response->success, true);
Parameters
- $id : int
- $request : LoyaltyBonusChargeRequest
Tags
Return values
LoyaltyBonusCreditResponseaccountBonusCredit()
Makes POST "/api/v5/loyalty/account/{id}/bonus/credit" request.
public
accountBonusCredit(int $id, LoyaltyBonusCreditRequest $request) : LoyaltyBonusCreditResponse
Example:
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyBonusCreditRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new LoyaltyBonusCreditRequest();
$request->amount = 100;
$request->activationDate = new DateTime();
$request->expireDate = (new DateTime())->add(new DateInterval('P14D'));
$request->comment = 'Monthly membership bonuses.';
try {
$response = $client->loyalty->accountBonusCredit(159, $request);
} catch (ApiExceptionInterface $exception) {
echo sprintf(
'Error from RetailCRM API (status code: %d): %s',
$exception->getStatusCode(),
$exception->getMessage()
);
if (count($exception->getErrorResponse()->errors) > 0) {
echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
}
return;
}
echo 'Credited bonuses for account: ' . print_r($response->loyaltyBonus, true);
Parameters
- $id : int
- $request : LoyaltyBonusCreditRequest
Tags
Return values
LoyaltyBonusCreditResponseaccountBonusOperations()
Makes GET "/api/v5/loyalty/account/{id}/bonus/operations" request.
public
accountBonusOperations(int $id[, LoyaltyBonusOperationsRequest|null $request = null ]) : LoyaltyBonusOperationsResponse
Example:
use RetailCrm\Api\Component\Transformer\DateTimeTransformer;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Filter\Loyalty\LoyaltyAccountBonusOperationsApiFilterType;
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyBonusOperationsRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new LoyaltyBonusOperationsRequest();
$request->filter = new LoyaltyAccountBonusOperationsApiFilterType();
$request->filter->createdAtFrom = DateTimeTransformer::create('2020-01-01 00:00:00');
$request->filter->createdAtTo = DateTimeTransformer::create('2021-08-01 00:00:00');
try {
$response = $client->loyalty->accountBonusOperations(159, $request);
} catch (ApiExceptionInterface $exception) {
echo sprintf(
'Error from RetailCRM API (status code: %d): %s',
$exception->getStatusCode(),
$exception->getMessage()
);
if (count($exception->getErrorResponse()->errors) > 0) {
echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
}
return;
}
echo 'Account operations: ' . print_r($response->bonusOperations, true);
Parameters
- $id : int
- $request : LoyaltyBonusOperationsRequest|null = null
Tags
Return values
LoyaltyBonusOperationsResponseaccountCreate()
Makes POST "/api/v5/loyalty/account/create" request.
public
accountCreate(LoyaltyAccountCreateRequest $request) : LoyaltyAccountCreateResponse
Example:
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\CustomersCorporate\SerializedEntityCustomer;
use RetailCrm\Api\Model\Entity\Loyalty\SerializedCreateLoyaltyAccount;
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyAccountCreateRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new LoyaltyAccountCreateRequest();
$account = new SerializedCreateLoyaltyAccount();
$account->customer = new SerializedEntityCustomer();
$account->customer->id = 4787;
$account->cardNumber = '2222 3333 4444 5555';
$account->phoneNumber = '88005553125';
$request->site = 'bitrix-test';
$request->loyaltyAccount = $account;
try {
$response = $client->loyalty->accountCreate($request);
} catch (ApiExceptionInterface $exception) {
echo sprintf(
'Error from RetailCRM API (status code: %d): %s',
$exception->getStatusCode(),
$exception->getMessage()
);
if (count($exception->getErrorResponse()->errors) > 0) {
echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
}
return;
}
echo 'Created loyalty account: ' . print_r($response->loyaltyAccount, true);
Parameters
- $request : LoyaltyAccountCreateRequest
Tags
Return values
LoyaltyAccountCreateResponseaccountEdit()
Makes POST "/api/v5/loyalty/account/{id}/edit" request.
public
accountEdit(int $id, LoyaltyAccountEditRequest $request) : LoyaltyAccountCreateResponse
Example:
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\Loyalty\LoyaltyAccount;
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyAccountEditRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$account = new LoyaltyAccount();
$account->cardNumber = '4444 5555 6666 7777';
$account->phoneNumber = '88005553000';
try {
$response = $client->loyalty->accountEdit(159, new LoyaltyAccountEditRequest($account));
} catch (ApiExceptionInterface $exception) {
echo sprintf(
'Error from RetailCRM API (status code: %d): %s',
$exception->getStatusCode(),
$exception->getMessage()
);
if (count($exception->getErrorResponse()->errors) > 0) {
echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
}
return;
}
echo 'Response: ' . print_r($response, true);
Parameters
- $id : int
- $request : LoyaltyAccountEditRequest
Tags
Return values
LoyaltyAccountCreateResponseaccountGet()
Makes GET "/api/v5/loyalty/account/{id}" request.
public
accountGet(int $id) : LoyaltyAccountResponse
Example:
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
try {
$response = $client->loyalty->accountGet(1);
} catch (ApiExceptionInterface $exception) {
echo sprintf(
'Error from RetailCRM API (status code: %d): %s',
$exception->getStatusCode(),
$exception->getMessage()
);
if (count($exception->getErrorResponse()->errors) > 0) {
echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
}
return;
}
echo 'Current loyalty account balance: ' . $response->loyaltyAccount->amount . ' bonuses.';
Parameters
- $id : int
Tags
Return values
LoyaltyAccountResponseaccounts()
Makes GET "/api/v5/loyalty/accounts" request.
public
accounts(LoyaltyAccountsRequest $request) : LoyaltyAccountsResponse
Example:
use RetailCrm\Api\Enum\Loyalty\AccountStatus;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Filter\Loyalty\LoyaltyAccountApiFilterType;
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyAccountsRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new LoyaltyAccountsRequest();
$request->filter = new LoyaltyAccountApiFilterType();
$request->filter->status = AccountStatus::ACTIVATED;
try {
$response = $client->loyalty->accounts($request);
} catch (ApiExceptionInterface $exception) {
echo sprintf(
'Error from RetailCRM API (status code: %d): %s',
$exception->getStatusCode(),
$exception->getMessage()
);
if (count($exception->getErrorResponse()->errors) > 0) {
echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
}
return;
}
echo 'Accounts: ' . print_r($response->loyaltyAccounts, true);
Parameters
- $request : LoyaltyAccountsRequest
Tags
Return values
LoyaltyAccountsResponsebonusOperations()
Makes GET "/api/v5/loyalty/bonus/operations" request.
public
bonusOperations([AllBonusOperationsRequest|null $request = null ]) : AllBonusOperationsResponse
Example:
use RetailCrm\Api\Enum\PaginationLimit;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Filter\Loyalty\LoyaltyBonusOperationsApiFilterType;
use RetailCrm\Api\Model\Request\Loyalty\AllBonusOperationsRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new AllBonusOperationsRequest();
$request->limit = PaginationLimit::LIMIT_20;
$request->cursor = '12345';
$request->filter = new LoyaltyBonusOperationsApiFilterType([1, 2, 3]);
try {
$response = $client->loyalty->bonusOperations($request);
} catch (ApiExceptionInterface $exception) {
echo sprintf(
'Error from RetailCRM API (status code: %d): %s',
$exception->getStatusCode(),
$exception->getMessage()
);
if (count($exception->getErrorResponse()->errors) > 0) {
echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
}
return;
}
echo 'All bonus operations: ' . print_r($response->bonusOperations, true);
Parameters
- $request : AllBonusOperationsRequest|null = null
Tags
Return values
AllBonusOperationsResponsecalculate()
Makes POST "/api/v5/loyalty/calculate" request.
public
calculate(LoyaltyCalculateRequest $request) : LoyaltyCalculateResponse
Example:
use RetailCrm\Api\Enum\Loyalty\PrivilegeType;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Entity\CustomersCorporate\SerializedRelationAbstractCustomer;
use RetailCrm\Api\Model\Entity\Loyalty\SerializedOrder;
use RetailCrm\Api\Model\Entity\Loyalty\SerializedOrderDelivery;
use RetailCrm\Api\Model\Entity\Loyalty\SerializedOrderProduct;
use RetailCrm\Api\Model\Entity\Loyalty\SerializedOrderProductOffer;
use RetailCrm\Api\Model\Request\Loyalty\LoyaltyCalculateRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$item = new SerializedOrderProduct();
$item->offer = SerializedOrderProductOffer::withId(1);
$item->quantity = 10;
$order = new SerializedOrder();
$order->customer = SerializedRelationAbstractCustomer::withExternalId(
'47876750',
'bitrix-test'
);
$order->items = [$item];
$order->delivery = new SerializedOrderDelivery(100);
$order->privilegeType = PrivilegeType::NONE;
$request = new LoyaltyCalculateRequest();
$request->site = 'bitrix-test';
$request->bonuses = 5;
$request->order = $order;
try {
$response = $client->loyalty->calculate($request);
} catch (ApiExceptionInterface $exception) {
echo sprintf(
'Error from RetailCRM API (status code: %d): %s',
$exception->getStatusCode(),
$exception->getMessage()
);
if (count($exception->getErrorResponse()->errors) > 0) {
echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
}
return;
}
echo 'Response: ' . print_r($response, true);
Parameters
- $request : LoyaltyCalculateRequest
Tags
Return values
LoyaltyCalculateResponseget()
Makes GET "/api/v5/loyalty/loyalties/{id}" request.
public
get(int $id) : LoyaltyResponse
Example:
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
try {
$response = $client->loyalty->get(1);
} catch (ApiExceptionInterface $exception) {
echo sprintf(
'Error from RetailCRM API (status code: %d): %s',
$exception->getStatusCode(),
$exception->getMessage()
);
if (count($exception->getErrorResponse()->errors) > 0) {
echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
}
return;
}
echo 'Loyalty program name: ' . $response->loyalty->name;
Parameters
- $id : int
Tags
Return values
LoyaltyResponsegetBonusAccountDetails()
Makes GET "/api/v5/loyalty/account/{$id}/bonus/{$status}/details" request.
public
getBonusAccountDetails(int $id, string $status, BonusAccountDetailsRequest $request) : BonusAccountDetailsResponse
Example:
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Filter\Loyalty\LoyaltyAccountBonusApiFilterType;
use RetailCrm\Api\Model\Request\Loyalty\BonusAccountDetailsRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
try {
$request = new BonusAccountDetailsRequest();
$request->status = 'bonus_status';
$request->id = 1;
$request->limit = 2;
$request->page = 1;
$request->filter = new LoyaltyAccountBonusApiFilterType();
$request->filter->date = new DateTime();
$response = $client->loyalty->getBonusAccountDetails(
$request->status,
$request->id,
$request
);
} catch (ApiExceptionInterface $exception) {
echo sprintf(
'Error from RetailCRM API (status code: %d): %s',
$exception->getStatusCode(),
$exception->getMessage()
);
if (count($exception->getErrorResponse()->errors) > 0) {
echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
}
return;
}
echo 'Total bonus amount: ' . $response->statistic->totalAmount;
Parameters
- $id : int
- $status : string
- $request : BonusAccountDetailsRequest
Tags
Return values
BonusAccountDetailsResponseloyalties()
Makes GET "/api/v5/loyalty/loyalties" request.
public
loyalties(LoyaltiesRequest $request) : LoyaltiesResponse
Example:
use RetailCrm\Api\Enum\NumericBoolean;
use RetailCrm\Api\Factory\SimpleClientFactory;
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
use RetailCrm\Api\Model\Filter\Loyalty\LoyaltyApiFilterType;
use RetailCrm\Api\Model\Request\Loyalty\LoyaltiesRequest;
$client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
$request = new LoyaltiesRequest();
$request->filter = new LoyaltyApiFilterType();
$request->filter->active = NumericBoolean::TRUE;
$request->filter->blocked = NumericBoolean::FALSE;
try {
$response = $client->loyalty->loyalties($request);
} catch (ApiExceptionInterface $exception) {
echo sprintf(
'Error from RetailCRM API (status code: %d): %s',
$exception->getStatusCode(),
$exception->getMessage()
);
if (count($exception->getErrorResponse()->errors) > 0) {
echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
}
return;
}
echo 'Loyalties: ' . print_r($response->loyalties, true);
Parameters
- $request : LoyaltiesRequest