Class: Square::Loyalty::Programs::Client
- Inherits:
-
Object
- Object
- Square::Loyalty::Programs::Client
- Defined in:
- lib/square/loyalty/programs/client.rb
Instance Method Summary collapse
-
#calculate(request_options: {}, **params) ⇒ Square::Types::CalculateLoyaltyPointsResponse
Calculates the number of points a buyer can earn from a purchase.
-
#get(request_options: {}, **params) ⇒ Square::Types::GetLoyaltyProgramResponse
Retrieves the loyalty program in a seller’s account, specified by the program ID or the keyword ‘main`.
- #initialize(client:) ⇒ Square::Loyalty::Programs::Client constructor
-
#list(request_options: {}, **_params) ⇒ Square::Types::ListLoyaltyProgramsResponse
Returns a list of loyalty programs in the seller’s account.
- #promotions ⇒ Square::Promotions::Client
Constructor Details
#initialize(client:) ⇒ Square::Loyalty::Programs::Client
8 9 10 |
# File 'lib/square/loyalty/programs/client.rb', line 8 def initialize(client:) @client = client end |
Instance Method Details
#calculate(request_options: {}, **params) ⇒ Square::Types::CalculateLoyaltyPointsResponse
Calculates the number of points a buyer can earn from a purchase. Applications might call this endpoint to display the points to the buyer.
-
If you are using the Orders API to manage orders, provide the ‘order_id` and (optional) `loyalty_account_id`.
Square reads the order to compute the points earned from the base loyalty program and an associated [loyalty promotion](entity:LoyaltyPromotion).
-
If you are not using the Orders API to manage orders, provide ‘transaction_amount_money` with the
purchase amount. Square uses this amount to calculate the points earned from the base loyalty program, but not points earned from a loyalty promotion. For spend-based and visit-based programs, the ‘tax_mode` setting of the accrual rule indicates how taxes should be treated for loyalty points accrual. If the purchase qualifies for program points, call [ListLoyaltyPromotions](api-endpoint:Loyalty-ListLoyaltyPromotions) and perform a client-side computation to calculate whether the purchase also qualifies for promotion points. For more information, see [Calculating promotion points](developer.squareup.com/docs/loyalty-api/loyalty-promotions#calculate-promotion-points).
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/square/loyalty/programs/client.rb', line 69 def calculate(request_options: {}, **params) _path_param_names = ["program_id"] _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "POST", path: "v2/loyalty/programs/#{params[:program_id]}/calculate", body: params.except(*_path_param_names) ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::CalculateLoyaltyPointsResponse.load(_response.body) end raise _response.body end |
#get(request_options: {}, **params) ⇒ Square::Types::GetLoyaltyProgramResponse
Retrieves the loyalty program in a seller’s account, specified by the program ID or the keyword ‘main`.
Loyalty programs define how buyers can earn points and redeem points for rewards. Square sellers can have only one loyalty program, which is created and managed from the Seller Dashboard. For more information, see [Loyalty Program Overview](developer.squareup.com/docs/loyalty/overview).
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/square/loyalty/programs/client.rb', line 38 def get(request_options: {}, **params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "GET", path: "v2/loyalty/programs/#{params[:program_id]}" ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::GetLoyaltyProgramResponse.load(_response.body) end raise _response.body end |
#list(request_options: {}, **_params) ⇒ Square::Types::ListLoyaltyProgramsResponse
Returns a list of loyalty programs in the seller’s account. Loyalty programs define how buyers can earn points and redeem points for rewards. Square sellers can have only one loyalty program, which is created and managed from the Seller Dashboard. For more information, see [Loyalty Program Overview](developer.squareup.com/docs/loyalty/overview).
Replaced with [RetrieveLoyaltyProgram](api-endpoint:Loyalty-RetrieveLoyaltyProgram) when used with the keyword ‘main`.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/square/loyalty/programs/client.rb', line 19 def list(request_options: {}, **_params) _request = Square::Internal::JSON::Request.new( base_url: [:base_url] || Square::Environment::SANDBOX, method: "GET", path: "v2/loyalty/programs" ) _response = @client.send(_request) if _response.code >= "200" && _response.code < "300" return Square::Types::ListLoyaltyProgramsResponse.load(_response.body) end raise _response.body end |