Module: LoyverseApi::Endpoints::Discounts

Included in:
Client
Defined in:
lib/loyverse_api/endpoints/discounts.rb

Constant Summary collapse

TYPE_FIXED_PERCENT =

Discount type constants

"FIXED_PERCENT"
TYPE_FIXED_AMOUNT =
"FIXED_AMOUNT"
TYPE_VARIABLE_PERCENT =
"VARIABLE_PERCENT"
TYPE_VARIABLE_AMOUNT =
"VARIABLE_AMOUNT"
TYPE_DISCOUNT_BY_POINTS =
"DISCOUNT_BY_POINTS"
APPLIES_TO_RECEIPT =

Applies to constants

"RECEIPT"
APPLIES_TO_ITEM =
"ITEM"
DEFAULT_APPLIES_TO =

Default applies_to value

APPLIES_TO_RECEIPT

Instance Method Summary collapse

Instance Method Details

#create_discount(name:, type:, discount_amount: nil, applies_to: DEFAULT_APPLIES_TO, enabled: true) ⇒ Hash

Create a new discount

Parameters:

  • name (String) —

    Discount name

  • type (String) —

    Type of discount: "FIXED_PERCENT", "FIXED_AMOUNT", "VARIABLE_PERCENT", "VARIABLE_AMOUNT", or "DISCOUNT_BY_POINTS"

  • discount_amount (Float) (defaults to: nil) —

    Discount amount (percentage or fixed value, optional for variable types)

  • applies_to (String) (defaults to: DEFAULT_APPLIES_TO) —

    What the discount applies to: "RECEIPT" or "ITEM" (optional, default: "RECEIPT")

  • enabled (Boolean) (defaults to: true) —

    Whether the discount is enabled (optional)

Returns:

  • (Hash) —

    Created discount details



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/loyverse_api/endpoints/discounts.rb', line 51

def create_discount(name:, type:, discount_amount: nil, applies_to: DEFAULT_APPLIES_TO, enabled: true)
  body = {
    name: name,
    type: type.upcase,
    discount_amount: discount_amount,
    applies_to: applies_to.upcase,
    enabled: enabled
  }.compact

  post("discounts", body: body)
end

#delete_discount(discount_id) ⇒ Hash

Delete a discount

Parameters:

  • discount_id (String) —

    UUID of the discount

Returns:

  • (Hash) —

    Response



86
87
88
# File 'lib/loyverse_api/endpoints/discounts.rb', line 86

def delete_discount(discount_id)
  delete("discounts/#{discount_id}")
end

#get_discount(discount_id) ⇒ Hash

Get a specific discount by ID

Parameters:

  • discount_id (String) —

    UUID of the discount

Returns:

  • (Hash) —

    Discount details



23
24
25
# File 'lib/loyverse_api/endpoints/discounts.rb', line 23

def get_discount(discount_id)
  get("discounts/#{discount_id}")
end

#list_discounts(limit: 250, cursor: nil, updated_at_min: nil, updated_at_max: nil) ⇒ Hash

List discounts

Parameters:

  • limit (Integer) (defaults to: 250) —

    Maximum number of results per page (default: 250)

  • cursor (String) (defaults to: nil) —

    Pagination cursor for next page

  • updated_at_min (String, Time) (defaults to: nil) —

    Filter by minimum update time (ISO 8601)

  • updated_at_max (String, Time) (defaults to: nil) —

    Filter by maximum update time (ISO 8601)

Returns:

  • (Hash) —

    Response with discounts array



33
34
35
36
37
38
39
40
41
42
# File 'lib/loyverse_api/endpoints/discounts.rb', line 33

def list_discounts(limit: 250, cursor: nil, updated_at_min: nil, updated_at_max: nil)
  params = {
    limit: limit,
    cursor: cursor,
    updated_at_min: format_time(updated_at_min),
    updated_at_max: format_time(updated_at_max)
  }.compact

  get("discounts", params: params)
end

#update_discount(discount_id, name: nil, type: nil, discount_amount: nil, applies_to: nil, enabled: nil) ⇒ Hash

Update an existing discount

Parameters:

  • discount_id (String) —

    UUID of the discount

  • name (String) (defaults to: nil) —

    Discount name (optional)

  • type (String) (defaults to: nil) —

    Type of discount: "FIXED_PERCENT", "FIXED_AMOUNT", "VARIABLE_PERCENT", "VARIABLE_AMOUNT", or "DISCOUNT_BY_POINTS" (optional)

  • discount_amount (Float) (defaults to: nil) —

    Discount amount (optional)

  • applies_to (String) (defaults to: nil) —

    What the discount applies to (optional)

  • enabled (Boolean) (defaults to: nil) —

    Whether the discount is enabled (optional)

Returns:

  • (Hash) —

    Updated discount details



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/loyverse_api/endpoints/discounts.rb', line 71

def update_discount(discount_id, name: nil, type: nil, discount_amount: nil, applies_to: nil, enabled: nil)
  body = {
    name: name,
    type: type&.upcase,
    discount_amount: discount_amount,
    applies_to: applies_to&.upcase,
    enabled: enabled
  }.compact

  put("discounts/#{discount_id}", body: body)
end