Class: Square::Loyalty::Accounts::Client
- Inherits:
-
Object
- Object
- Square::Loyalty::Accounts::Client
- Defined in:
- lib/square/loyalty/accounts/client.rb
Instance Method Summary collapse
-
#accumulate_points(request_options: {}, **params) ⇒ Square::Types::AccumulateLoyaltyPointsResponse
Adds points earned from a purchase to a [loyalty account](entity:LoyaltyAccount).
-
#adjust(request_options: {}, **params) ⇒ Square::Types::AdjustLoyaltyPointsResponse
Adds points to or subtracts points from a buyer’s account.
-
#create(request_options: {}, **params) ⇒ Square::Types::CreateLoyaltyAccountResponse
Creates a loyalty account.
-
#get(request_options: {}, **params) ⇒ Square::Types::GetLoyaltyAccountResponse
Retrieves a loyalty account.
- #initialize(client:) ⇒ void constructor
-
#search(request_options: {}, **params) ⇒ Square::Types::SearchLoyaltyAccountsResponse
Searches for loyalty accounts in a loyalty program.
Constructor Details
#initialize(client:) ⇒ void
10 11 12 |
# File 'lib/square/loyalty/accounts/client.rb', line 10 def initialize(client:) @client = client end |
Instance Method Details
#accumulate_points(request_options: {}, **params) ⇒ Square::Types::AccumulateLoyaltyPointsResponse
Adds points earned from a purchase to a [loyalty account](entity:LoyaltyAccount).
-
If you are using the Orders API to manage orders, provide the ‘order_id`. Square reads the order
to compute the points earned from both the base loyalty program and an associated [loyalty promotion](entity:LoyaltyPromotion). For purchases that qualify for multiple accrual rules, Square computes points based on the accrual rule that grants the most points. For purchases that qualify for multiple promotions, Square computes points based on the most recently created promotion. A purchase must first qualify for program points to be eligible for promotion points.
-
If you are not using the Orders API to manage orders, provide ‘points` with the number of points to add.
You must first perform a client-side computation of the points earned from the loyalty program and loyalty promotion. For spend-based and visit-based programs, you can call [CalculateLoyaltyPoints](api-endpoint:Loyalty-CalculateLoyaltyPoints) to compute the points earned from the base loyalty program. For information about computing points earned from a loyalty promotion, see [Calculating promotion points](developer.squareup.com/docs/loyalty-api/loyalty-promotions#calculate-promotion-points).
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/square/loyalty/accounts/client.rb', line 151 def accumulate_points(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request_data = Square::Loyalty::Accounts::Types::AccumulateLoyaltyPointsRequest.new(params).to_h non_body_param_names = ["account_id"] body = request_data.except(*non_body_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/loyalty/accounts/#{params[:account_id]}/accumulate", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::AccumulateLoyaltyPointsResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#adjust(request_options: {}, **params) ⇒ Square::Types::AdjustLoyaltyPointsResponse
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](api-endpoint:Loyalty-AccumulateLoyaltyPoints) to add points when a buyer pays for the purchase.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/square/loyalty/accounts/client.rb', line 194 def adjust(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request_data = Square::Loyalty::Accounts::Types::AdjustLoyaltyPointsRequest.new(params).to_h non_body_param_names = ["account_id"] body = request_data.except(*non_body_param_names) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/loyalty/accounts/#{params[:account_id]}/adjust", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::AdjustLoyaltyPointsResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#create(request_options: {}, **params) ⇒ Square::Types::CreateLoyaltyAccountResponse
Creates a loyalty account. To create a loyalty account, you must provide the ‘program_id` and a `mapping` with the `phone_number` of the buyer.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/square/loyalty/accounts/client.rb', line 26 def create(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/loyalty/accounts", body: Square::Loyalty::Accounts::Types::CreateLoyaltyAccountRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::CreateLoyaltyAccountResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#get(request_options: {}, **params) ⇒ Square::Types::GetLoyaltyAccountResponse
Retrieves a loyalty account.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/square/loyalty/accounts/client.rb', line 100 def get(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/loyalty/accounts/#{params[:account_id]}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::GetLoyaltyAccountResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#search(request_options: {}, **params) ⇒ Square::Types::SearchLoyaltyAccountsResponse
Searches for loyalty accounts in a loyalty program.
You can search for a loyalty account using the phone number or customer ID associated with the account. To return all loyalty accounts, specify an empty ‘query` object or omit it entirely.
Search results are sorted by ‘created_at` in ascending order.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/square/loyalty/accounts/client.rb', line 65 def search(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/loyalty/accounts/search", body: Square::Loyalty::Accounts::Types::SearchLoyaltyAccountsRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Square::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Square::Types::SearchLoyaltyAccountsResponse.load(response.body) else error_class = Square::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |