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
-
#create_discount(name:, type:, discount_amount: nil, applies_to: DEFAULT_APPLIES_TO, enabled: true) ⇒ Hash
Create a new discount.
-
#delete_discount(discount_id) ⇒ Hash
Delete a discount.
-
#get_discount(discount_id) ⇒ Hash
Get a specific discount by ID.
-
#list_discounts(limit: 250, cursor: nil, updated_at_min: nil, updated_at_max: nil) ⇒ Hash
List discounts.
-
#update_discount(discount_id, name: nil, type: nil, discount_amount: nil, applies_to: nil, enabled: nil) ⇒ Hash
Update an existing discount.
Instance Method Details
#create_discount(name:, type:, discount_amount: nil, applies_to: DEFAULT_APPLIES_TO, enabled: true) ⇒ Hash
Create a new discount
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
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
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
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
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 |