$loyaltyApi = $client->getLoyaltyApi();LoyaltyApi
- Create Loyalty Account
- Search Loyalty Accounts
- Retrieve Loyalty Account
- Accumulate Loyalty Points
- Adjust Loyalty Points
- Search Loyalty Events
- List Loyalty Programs
- Calculate Loyalty Points
- Create Loyalty Reward
- Search Loyalty Rewards
- Delete Loyalty Reward
- Retrieve Loyalty Reward
- Redeem Loyalty Reward
Creates a loyalty account. For more information, see Create a loyalty account.
function createLoyaltyAccount(CreateLoyaltyAccountRequest $body): ApiResponse| Parameter | Type | Tags | Description |
|---|---|---|---|
body |
CreateLoyaltyAccountRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type CreateLoyaltyAccountResponse.
$body_loyaltyAccount_mappings = [];
$body_loyaltyAccount_mappings_0_type = 'PHONE';
$body_loyaltyAccount_mappings_0_value = '+14155551234';
$body_loyaltyAccount_mappings[0] = new Models\LoyaltyAccountMapping(
$body_loyaltyAccount_mappings_0_type,
$body_loyaltyAccount_mappings_0_value
);
$body_loyaltyAccount_mappings[0]->setId('id0');
$body_loyaltyAccount_mappings[0]->setCreatedAt('created_at8');
$body_loyaltyAccount_programId = 'd619f755-2d17-41f3-990d-c04ecedd64dd';
$body_loyaltyAccount = new Models\LoyaltyAccount(
$body_loyaltyAccount_mappings,
$body_loyaltyAccount_programId
);
$body_loyaltyAccount->setId('id2');
$body_loyaltyAccount->setBalance(14);
$body_loyaltyAccount->setLifetimePoints(38);
$body_loyaltyAccount->setCustomerId('customer_id0');
$body_loyaltyAccount->setEnrolledAt('enrolled_at2');
$body_idempotencyKey = 'ec78c477-b1c3-4899-a209-a4e71337c996';
$body = new Models\CreateLoyaltyAccountRequest(
$body_loyaltyAccount,
$body_idempotencyKey
);
$apiResponse = $loyaltyApi->createLoyaltyAccount($body);
if ($apiResponse->isSuccess()) {
$createLoyaltyAccountResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Get more response info...
// $statusCode = $apiResponse->getStatusCode();
// $headers = $apiResponse->getHeaders();Searches for loyalty accounts. In the current implementation, you can search for a loyalty account using the phone number associated with the account. If no phone number is provided, all loyalty accounts are returned.
function searchLoyaltyAccounts(SearchLoyaltyAccountsRequest $body): ApiResponse| Parameter | Type | Tags | Description |
|---|---|---|---|
body |
SearchLoyaltyAccountsRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type SearchLoyaltyAccountsResponse.
$body = new Models\SearchLoyaltyAccountsRequest;
$body->setQuery(new Models\SearchLoyaltyAccountsRequestLoyaltyAccountQuery);
$body_query_mappings = [];
$body_query_mappings_0_type = 'PHONE';
$body_query_mappings_0_value = '+14155551234';
$body_query_mappings[0] = new Models\LoyaltyAccountMapping(
$body_query_mappings_0_type,
$body_query_mappings_0_value
);
$body_query_mappings[0]->setId('id4');
$body_query_mappings[0]->setCreatedAt('created_at8');
$body->getQuery()->setMappings($body_query_mappings);
$body->setLimit(10);
$body->setCursor('cursor0');
$apiResponse = $loyaltyApi->searchLoyaltyAccounts($body);
if ($apiResponse->isSuccess()) {
$searchLoyaltyAccountsResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Get more response info...
// $statusCode = $apiResponse->getStatusCode();
// $headers = $apiResponse->getHeaders();Retrieves a loyalty account.
function retrieveLoyaltyAccount(string $accountId): ApiResponse| Parameter | Type | Tags | Description |
|---|---|---|---|
accountId |
string |
Template, Required | The ID of the loyalty account to retrieve. |
This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type RetrieveLoyaltyAccountResponse.
$accountId = 'account_id2';
$apiResponse = $loyaltyApi->retrieveLoyaltyAccount($accountId);
if ($apiResponse->isSuccess()) {
$retrieveLoyaltyAccountResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Get more response info...
// $statusCode = $apiResponse->getStatusCode();
// $headers = $apiResponse->getHeaders();Adds points to a loyalty account.
- If you are using the Orders API to manage orders, you only provide the
order_id. The endpoint reads the order to compute points to add to the buyer's account. - If you are not using the Orders API to manage orders,
you first perform a client-side computation to compute the points.
For spend-based and visit-based programs, you can callCalculateLoyaltyPointsto compute the points. For more information, see Loyalty Program Overview. You then provide the points in a request to this endpoint.
For more information, see Accumulate points.
function accumulateLoyaltyPoints(string $accountId, AccumulateLoyaltyPointsRequest $body): ApiResponse| Parameter | Type | Tags | Description |
|---|---|---|---|
accountId |
string |
Template, Required | The loyalty account ID to which to add the points. |
body |
AccumulateLoyaltyPointsRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type AccumulateLoyaltyPointsResponse.
$accountId = 'account_id2';
$body_accumulatePoints = new Models\LoyaltyEventAccumulatePoints;
$body_accumulatePoints->setLoyaltyProgramId('loyalty_program_id8');
$body_accumulatePoints->setPoints(90);
$body_accumulatePoints->setOrderId('RFZfrdtm3mhO1oGzf5Cx7fEMsmGZY');
$body_idempotencyKey = '58b90739-c3e8-4b11-85f7-e636d48d72cb';
$body_locationId = 'P034NEENMD09F';
$body = new Models\AccumulateLoyaltyPointsRequest(
$body_accumulatePoints,
$body_idempotencyKey,
$body_locationId
);
$apiResponse = $loyaltyApi->accumulateLoyaltyPoints($accountId, $body);
if ($apiResponse->isSuccess()) {
$accumulateLoyaltyPointsResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Get more response info...
// $statusCode = $apiResponse->getStatusCode();
// $headers = $apiResponse->getHeaders();Adds points to or subtracts points from a buyer's account.
Use this endpoint only when you need to manually adjust points. Otherwise, in your application flow, you call AccumulateLoyaltyPoints to add points when a buyer pays for the purchase.
function adjustLoyaltyPoints(string $accountId, AdjustLoyaltyPointsRequest $body): ApiResponse| Parameter | Type | Tags | Description |
|---|---|---|---|
accountId |
string |
Template, Required | The ID of the loyalty account in which to adjust the points. |
body |
AdjustLoyaltyPointsRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type AdjustLoyaltyPointsResponse.
$accountId = 'account_id2';
$body_idempotencyKey = 'idempotency_key2';
$body_adjustPoints_points = 112;
$body_adjustPoints = new Models\LoyaltyEventAdjustPoints(
$body_adjustPoints_points
);
$body_adjustPoints->setLoyaltyProgramId('loyalty_program_id4');
$body_adjustPoints->setReason('reason0');
$body = new Models\AdjustLoyaltyPointsRequest(
$body_idempotencyKey,
$body_adjustPoints
);
$apiResponse = $loyaltyApi->adjustLoyaltyPoints($accountId, $body);
if ($apiResponse->isSuccess()) {
$adjustLoyaltyPointsResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Get more response info...
// $statusCode = $apiResponse->getStatusCode();
// $headers = $apiResponse->getHeaders();Searches for loyalty events.
A Square loyalty program maintains a ledger of events that occur during the lifetime of a buyer's loyalty account. Each change in the point balance (for example, points earned, points redeemed, and points expired) is recorded in the ledger. Using this endpoint, you can search the ledger for events. For more information, see Loyalty events.
function searchLoyaltyEvents(SearchLoyaltyEventsRequest $body): ApiResponse| Parameter | Type | Tags | Description |
|---|---|---|---|
body |
SearchLoyaltyEventsRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type SearchLoyaltyEventsResponse.
$body = new Models\SearchLoyaltyEventsRequest;
$body->setQuery(new Models\LoyaltyEventQuery);
$body->getQuery()->setFilter(new Models\LoyaltyEventFilter);
$body_query_filter_loyaltyAccountFilter_loyaltyAccountId = 'loyalty_account_id6';
$body->getQuery()->getFilter()->setLoyaltyAccountFilter(new Models\LoyaltyEventLoyaltyAccountFilter(
$body_query_filter_loyaltyAccountFilter_loyaltyAccountId
));
$body_query_filter_typeFilter_types = [Models\LoyaltyEventType::DELETE_REWARD, Models\LoyaltyEventType::ADJUST_POINTS, Models\LoyaltyEventType::EXPIRE_POINTS];
$body->getQuery()->getFilter()->setTypeFilter(new Models\LoyaltyEventTypeFilter(
$body_query_filter_typeFilter_types
));
$body_query_filter_dateTimeFilter_createdAt = new Models\TimeRange;
$body_query_filter_dateTimeFilter_createdAt->setStartAt('start_at8');
$body_query_filter_dateTimeFilter_createdAt->setEndAt('end_at4');
$body->getQuery()->getFilter()->setDateTimeFilter(new Models\LoyaltyEventDateTimeFilter(
$body_query_filter_dateTimeFilter_createdAt
));
$body_query_filter_locationFilter_locationIds = ['location_ids2', 'location_ids3', 'location_ids4'];
$body->getQuery()->getFilter()->setLocationFilter(new Models\LoyaltyEventLocationFilter(
$body_query_filter_locationFilter_locationIds
));
$body_query_filter_orderFilter_orderId = 'PyATxhYLfsMqpVkcKJITPydgEYfZY';
$body->getQuery()->getFilter()->setOrderFilter(new Models\LoyaltyEventOrderFilter(
$body_query_filter_orderFilter_orderId
));
$body->setLimit(30);
$body->setCursor('cursor0');
$apiResponse = $loyaltyApi->searchLoyaltyEvents($body);
if ($apiResponse->isSuccess()) {
$searchLoyaltyEventsResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Get more response info...
// $statusCode = $apiResponse->getStatusCode();
// $headers = $apiResponse->getHeaders();Returns a list of loyalty programs in the seller's account. Currently, a seller can only have one loyalty program. For more information, see Loyalty Overview. .
function listLoyaltyPrograms(): ApiResponseThis method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type ListLoyaltyProgramsResponse.
$apiResponse = $loyaltyApi->listLoyaltyPrograms();
if ($apiResponse->isSuccess()) {
$listLoyaltyProgramsResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Get more response info...
// $statusCode = $apiResponse->getStatusCode();
// $headers = $apiResponse->getHeaders();Calculates the points a purchase earns.
- If you are using the Orders API to manage orders, you provide
order_idin the request. The endpoint calculates the points by reading the order. - If you are not using the Orders API to manage orders, you provide the purchase amount in the request for the endpoint to calculate the points.
An application might call this endpoint to show the points that a buyer can earn with the specific purchase.
function calculateLoyaltyPoints(string $programId, CalculateLoyaltyPointsRequest $body): ApiResponse| Parameter | Type | Tags | Description |
|---|---|---|---|
programId |
string |
Template, Required | The loyalty program ID, which defines the rules for accruing points. |
body |
CalculateLoyaltyPointsRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type CalculateLoyaltyPointsResponse.
$programId = 'program_id0';
$body = new Models\CalculateLoyaltyPointsRequest;
$body->setOrderId('RFZfrdtm3mhO1oGzf5Cx7fEMsmGZY');
$body->setTransactionAmountMoney(new Models\Money);
$body->getTransactionAmountMoney()->setAmount(72);
$body->getTransactionAmountMoney()->setCurrency(Models\Currency::UZS);
$apiResponse = $loyaltyApi->calculateLoyaltyPoints($programId, $body);
if ($apiResponse->isSuccess()) {
$calculateLoyaltyPointsResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Get more response info...
// $statusCode = $apiResponse->getStatusCode();
// $headers = $apiResponse->getHeaders();Creates a loyalty reward. In the process, the endpoint does following:
- Uses the
reward_tier_idin the request to determine the number of points to lock for this reward. - If the request includes
order_id, it adds the reward and related discount to the order.
After a reward is created, the points are locked and not available for the buyer to redeem another reward. For more information, see Loyalty rewards.
function createLoyaltyReward(CreateLoyaltyRewardRequest $body): ApiResponse| Parameter | Type | Tags | Description |
|---|---|---|---|
body |
CreateLoyaltyRewardRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type CreateLoyaltyRewardResponse.
$body_reward_loyaltyAccountId = '5adcb100-07f1-4ee7-b8c6-6bb9ebc474bd';
$body_reward_rewardTierId = 'e1b39225-9da5-43d1-a5db-782cdd8ad94f';
$body_reward = new Models\LoyaltyReward(
$body_reward_loyaltyAccountId,
$body_reward_rewardTierId
);
$body_reward->setId('id4');
$body_reward->setStatus(Models\LoyaltyRewardStatus::REDEEMED);
$body_reward->setPoints(230);
$body_reward->setOrderId('RFZfrdtm3mhO1oGzf5Cx7fEMsmGZY');
$body_reward->setCreatedAt('created_at2');
$body_idempotencyKey = '18c2e5ea-a620-4b1f-ad60-7b167285e451';
$body = new Models\CreateLoyaltyRewardRequest(
$body_reward,
$body_idempotencyKey
);
$apiResponse = $loyaltyApi->createLoyaltyReward($body);
if ($apiResponse->isSuccess()) {
$createLoyaltyRewardResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Get more response info...
// $statusCode = $apiResponse->getStatusCode();
// $headers = $apiResponse->getHeaders();Searches for loyalty rewards in a loyalty account.
In the current implementation, the endpoint supports search by the reward status.
If you know a reward ID, use the RetrieveLoyaltyReward endpoint.
For more information about loyalty rewards, see Loyalty Rewards.
function searchLoyaltyRewards(SearchLoyaltyRewardsRequest $body): ApiResponse| Parameter | Type | Tags | Description |
|---|---|---|---|
body |
SearchLoyaltyRewardsRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type SearchLoyaltyRewardsResponse.
$body = new Models\SearchLoyaltyRewardsRequest;
$body_query_loyaltyAccountId = '5adcb100-07f1-4ee7-b8c6-6bb9ebc474bd';
$body->setQuery(new Models\SearchLoyaltyRewardsRequestLoyaltyRewardQuery(
$body_query_loyaltyAccountId
));
$body->getQuery()->setStatus(Models\LoyaltyRewardStatus::REDEEMED);
$body->setLimit(10);
$body->setCursor('cursor0');
$apiResponse = $loyaltyApi->searchLoyaltyRewards($body);
if ($apiResponse->isSuccess()) {
$searchLoyaltyRewardsResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Get more response info...
// $statusCode = $apiResponse->getStatusCode();
// $headers = $apiResponse->getHeaders();Deletes a loyalty reward by doing the following:
- Returns the loyalty points back to the loyalty account.
- If an order ID was specified when the reward was created (see CreateLoyaltyReward), it updates the order by removing the reward and related discounts.
You cannot delete a reward that has reached the terminal state (REDEEMED). For more information, see Loyalty rewards.
function deleteLoyaltyReward(string $rewardId): ApiResponse| Parameter | Type | Tags | Description |
|---|---|---|---|
rewardId |
string |
Template, Required | The ID of the loyalty reward to delete. |
This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type DeleteLoyaltyRewardResponse.
$rewardId = 'reward_id4';
$apiResponse = $loyaltyApi->deleteLoyaltyReward($rewardId);
if ($apiResponse->isSuccess()) {
$deleteLoyaltyRewardResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Get more response info...
// $statusCode = $apiResponse->getStatusCode();
// $headers = $apiResponse->getHeaders();Retrieves a loyalty reward.
function retrieveLoyaltyReward(string $rewardId): ApiResponse| Parameter | Type | Tags | Description |
|---|---|---|---|
rewardId |
string |
Template, Required | The ID of the loyalty reward to retrieve. |
This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type RetrieveLoyaltyRewardResponse.
$rewardId = 'reward_id4';
$apiResponse = $loyaltyApi->retrieveLoyaltyReward($rewardId);
if ($apiResponse->isSuccess()) {
$retrieveLoyaltyRewardResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Get more response info...
// $statusCode = $apiResponse->getStatusCode();
// $headers = $apiResponse->getHeaders();Redeems a loyalty reward.
The endpoint sets the reward to the terminal state (REDEEMED).
If you are using your own order processing system (not using the Orders API), you call this endpoint after the buyer paid for the purchase.
After the reward reaches the terminal state, it cannot be deleted. In other words, points used for the reward cannot be returned to the account.
For more information, see Loyalty rewards.
function redeemLoyaltyReward(string $rewardId, RedeemLoyaltyRewardRequest $body): ApiResponse| Parameter | Type | Tags | Description |
|---|---|---|---|
rewardId |
string |
Template, Required | The ID of the loyalty reward to redeem. |
body |
RedeemLoyaltyRewardRequest |
Body, Required | An object containing the fields to POST for the request. See the corresponding object definition for field details. |
This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type RedeemLoyaltyRewardResponse.
$rewardId = 'reward_id4';
$body_idempotencyKey = '98adc7f7-6963-473b-b29c-f3c9cdd7d994';
$body_locationId = 'P034NEENMD09F';
$body = new Models\RedeemLoyaltyRewardRequest(
$body_idempotencyKey,
$body_locationId
);
$apiResponse = $loyaltyApi->redeemLoyaltyReward($rewardId, $body);
if ($apiResponse->isSuccess()) {
$redeemLoyaltyRewardResponse = $apiResponse->getResult();
} else {
$errors = $apiResponse->getErrors();
}
// Get more response info...
// $statusCode = $apiResponse->getStatusCode();
// $headers = $apiResponse->getHeaders();