Class: Square::Loyalty::Programs::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/square/loyalty/programs/client.rb

Instance Method Summary collapse

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).



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/square/loyalty/programs/client.rb', line 81

def calculate(request_options: {}, **params)
  _path_param_names = ["program_id"]

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/loyalty/programs/#{params[:program_id]}/calculate",
    body: params.except(*_path_param_names)
  )
  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::CalculateLoyaltyPointsResponse.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::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).



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/square/loyalty/programs/client.rb', line 44

def get(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/loyalty/programs/#{params[:program_id]}"
  )
  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::GetLoyaltyProgramResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
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
32
33
34
35
36
37
# File 'lib/square/loyalty/programs/client.rb', line 19

def list(request_options: {}, **_params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/loyalty/programs"
  )
  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::ListLoyaltyProgramsResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#promotionsSquare::Promotions::Client

Returns:

  • (Square::Promotions::Client)


105
106
107
# File 'lib/square/loyalty/programs/client.rb', line 105

def promotions
  @promotions ||= Square::Loyalty::Programs::Promotions::Client.new(client: @client)
end