Class: AbacatePay::Clients::CouponClient
- Inherits:
-
Client
- Object
- Client
- AbacatePay::Clients::CouponClient
show all
- Defined in:
- lib/abacate_pay/clients/coupon_client.rb
Overview
Client for discount coupons in the AbacatePay API.
Supports creating, listing, deleting and toggling coupons
between active and inactive.
Constant Summary
collapse
- URI =
"coupons"
Constants inherited
from Client
AbacatePay::Clients::Client::RETRIABLE_EXCEPTIONS, AbacatePay::Clients::Client::RETRIABLE_METHODS, AbacatePay::Clients::Client::RETRIABLE_STATUSES
Instance Method Summary
collapse
Methods inherited from Client
#auto_paging_each, #each_page
Constructor Details
#initialize(client = nil) ⇒ CouponClient
Returns a new instance of CouponClient.
12
13
14
|
# File 'lib/abacate_pay/clients/coupon_client.rb', line 12
def initialize(client = nil)
super(URI, client)
end
|
Instance Method Details
32
33
34
35
36
37
38
39
40
|
# File 'lib/abacate_pay/clients/coupon_client.rb', line 32
def create(data)
response = request("POST", "create", json: {
code: data.code,
discount: data.discount,
discountKind: data.discount_kind,
maxRedeems: data.max_redeems
})
Resources::Coupons.new(response)
end
|
44
45
46
47
|
# File 'lib/abacate_pay/clients/coupon_client.rb', line 44
def delete(id)
response = request("POST", "delete", json: { id: id })
Resources::Coupons.new(response)
end
|
25
26
27
28
|
# File 'lib/abacate_pay/clients/coupon_client.rb', line 25
def get(id)
response = request("GET", "get", params: { id: id })
Resources::Coupons.new(response)
end
|
18
19
20
21
|
# File 'lib/abacate_pay/clients/coupon_client.rb', line 18
def list(**params)
response = request("GET", "list", params: params.empty? ? nil : params)
build_list(response, Resources::Coupons)
end
|
51
52
53
54
|
# File 'lib/abacate_pay/clients/coupon_client.rb', line 51
def toggle(id)
response = request("POST", "toggle", json: { id: id })
Resources::Coupons.new(response)
end
|