Class: Square::Loyalty::Rewards::Client
- Inherits:
-
Object
- Object
- Square::Loyalty::Rewards::Client
- Defined in:
- lib/square/loyalty/rewards/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Square::Types::CreateLoyaltyRewardResponse
Creates a loyalty reward.
-
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteLoyaltyRewardResponse
Deletes a loyalty reward by doing the following:.
-
#get(request_options: {}, **params) ⇒ Square::Types::GetLoyaltyRewardResponse
Retrieves a loyalty reward.
- #initialize(client:) ⇒ Square::Loyalty::Rewards::Client constructor
-
#redeem(request_options: {}, **params) ⇒ Square::Types::RedeemLoyaltyRewardResponse
Redeems a loyalty reward.
-
#search(request_options: {}, **params) ⇒ Square::Types::SearchLoyaltyRewardsResponse
Searches for loyalty rewards.
Constructor Details
#initialize(client:) ⇒ Square::Loyalty::Rewards::Client
8 9 10 |
# File 'lib/square/loyalty/rewards/client.rb', line 8 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Square::Types::CreateLoyaltyRewardResponse
Creates a loyalty reward. In the process, the endpoint does following:
-
Uses the ‘reward_tier_id` in 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.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/square/loyalty/rewards/client.rb', line 22 def create(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/loyalty/rewards", body: params ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::CreateLoyaltyRewardResponse.load(_response.body) end raise _response.body end |
#delete(request_options: {}, **params) ⇒ Square::Types::DeleteLoyaltyRewardResponse
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](api-endpoint:Loyalty-CreateLoyaltyReward)), it updates the order by removing the reward and related discounts.
You cannot delete a reward that has reached the terminal state (REDEEMED).
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/square/loyalty/rewards/client.rb', line 89 def delete(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "DELETE", path: "v2/loyalty/rewards/#{params[:reward_id]}" ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::DeleteLoyaltyRewardResponse.load(_response.body) end raise _response.body end |
#get(request_options: {}, **params) ⇒ Square::Types::GetLoyaltyRewardResponse
Retrieves a loyalty reward.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/square/loyalty/rewards/client.rb', line 64 def get(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "GET", path: "v2/loyalty/rewards/#{params[:reward_id]}" ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::GetLoyaltyRewardResponse.load(_response.body) end raise _response.body end |
#redeem(request_options: {}, **params) ⇒ Square::Types::RedeemLoyaltyRewardResponse
Redeems a loyalty reward.
The endpoint sets the reward to the ‘REDEEMED` terminal state.
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.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/square/loyalty/rewards/client.rb', line 116 def redeem(request_options: {}, **params) _path_param_names = ["reward_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/loyalty/rewards/#{params[:reward_id]}/redeem", body: params.except(*_path_param_names) ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::RedeemLoyaltyRewardResponse.load(_response.body) end raise _response.body end |
#search(request_options: {}, **params) ⇒ Square::Types::SearchLoyaltyRewardsResponse
Searches for loyalty rewards. This endpoint accepts a request with no query filters and returns results for all loyalty accounts. If you include a ‘query` object, `loyalty_account_id` is required and `status` is optional.
If you know a reward ID, use the [RetrieveLoyaltyReward](api-endpoint:Loyalty-RetrieveLoyaltyReward) endpoint.
Search results are sorted by ‘updated_at` in descending order.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/square/loyalty/rewards/client.rb', line 46 def search(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/loyalty/rewards/search", body: params ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::SearchLoyaltyRewardsResponse.load(_response.body) end raise _response.body end |