forked from bigcommerce/bigcommerce-api-ruby
-
Notifications
You must be signed in to change notification settings - Fork 1
/
coupon.rb
44 lines (36 loc) · 856 Bytes
/
coupon.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'bigcommerce'
require 'securerandom'
Bigcommerce.configure do |config|
config.store_hash = ENV['BC_STORE_HASH']
config.client_id = ENV['BC_CLIENT_ID']
config.access_token = ENV['BC_ACCESS_TOKEN']
end
# List coupons
@coupons = Bigcommerce::Coupon.all
puts @coupons
# Get a coupon
puts Bigcommerce::Coupon.find(@coupons[0].id)
# Get a count of coupons
puts Bigcommerce::Coupon.count
# Create a coupon
@coupon = Bigcommerce::Coupon.create(
name: SecureRandom.hex,
code: SecureRandom.hex,
type: 'per_item_discount',
amount: 5,
applies_to: {
entity: 'categories',
ids: [0]
}
)
puts @coupon
# Update a coupon
puts Bigcommerce::Coupon.update(
@coupon.id,
name: SecureRandom.hex,
amount: 10
)
# Delete a coupon
puts Bigcommerce::Coupon.destroy(@coupon.id)
# Delete all coupons
# puts Bigcommerce::Coupon.destroy_all