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:) ⇒ Square::Loyalty::Accounts::Client constructor
-
#search(request_options: {}, **params) ⇒ Square::Types::SearchLoyaltyAccountsResponse
Searches for loyalty accounts in a loyalty program.
Constructor Details
#initialize(client:) ⇒ Square::Loyalty::Accounts::Client
8 9 10 |
# File 'lib/square/loyalty/accounts/client.rb', line 8 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).
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/square/loyalty/accounts/client.rb', line 85 def accumulate_points(request_options: {}, **params) _path_param_names = ["account_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/loyalty/accounts/#{params[:account_id]}/accumulate", body: params.except(*_path_param_names) ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::AccumulateLoyaltyPointsResponse.load(_response.body) end raise _response.body 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.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/square/loyalty/accounts/client.rb', line 109 def adjust(request_options: {}, **params) _path_param_names = ["account_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/loyalty/accounts/#{params[:account_id]}/adjust", body: params.except(*_path_param_names) ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::AdjustLoyaltyPointsResponse.load(_response.body) end raise _response.body 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.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/square/loyalty/accounts/client.rb', line 15 def create(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/loyalty/accounts", body: params ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::CreateLoyaltyAccountResponse.load(_response.body) end raise _response.body end |
#get(request_options: {}, **params) ⇒ Square::Types::GetLoyaltyAccountResponse
Retrieves a loyalty account.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/square/loyalty/accounts/client.rb', line 55 def get(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "GET", path: "v2/loyalty/accounts/#{params[:account_id]}" ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::GetLoyaltyAccountResponse.load(_response.body) end raise _response.body 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.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/square/loyalty/accounts/client.rb', line 37 def search(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/loyalty/accounts/search", body: params ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::SearchLoyaltyAccountsResponse.load(_response.body) end raise _response.body end |