forked from voucherifyio/voucherify-ruby-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcampaigns.rb
129 lines (114 loc) · 3.91 KB
/
campaigns.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
require_relative 'utils.rb'
require 'VoucherifySdk'
require 'json'
def create_validation_rule_applicable_to(validation_rules_api_instance, product_id)
begin
created_validation_rule = validation_rules_api_instance.create_validation_rules({
validation_rules_create_request_body: VoucherifySdk::ValidationRulesCreateRequestBody.new({
name: generate_random_string(),
applicable_to: VoucherifySdk::ValidationRuleBaseApplicableTo.new({
included: [VoucherifySdk::ApplicableTo.new({
object: "product",
id: product_id
})]
}),
type:"basic",
})
})
return created_validation_rule
rescue VoucherifySdk::ApiError => e
return nil
end
end
def create_validation_rule_more_than(validation_rules_api_instance, product_id)
begin
created_validation_rule = validation_rules_api_instance.create_validation_rules({
validation_rules_create_request_body: VoucherifySdk::ValidationRulesCreateRequestBody.new({
name: generate_random_string(),
rules: {
"1": {
name: "order.amount",
conditions: {
"$more_than": [500000]
},
rules: {}
}
},
type:"basic",
})
})
return created_validation_rule
rescue VoucherifySdk::ApiError => e
return nil
end
end
def create_discount_campaign(campaigns_api_instance, validation_rule_id)
begin
campaign = campaigns_api_instance.create_campaign({
campaigns_create_request_body: VoucherifySdk::CampaignsCreateRequestBody.new({
campaign_type: "DISCOUNT_COUPONS",
name: generate_random_string(),
type: "AUTO_UPDATE",
voucher: VoucherifySdk::CampaignsCreateRequestBodyVoucher.new({
type: 'DISCOUNT_VOUCHER',
discount: VoucherifySdk::Discount.new({
type: 'AMOUNT',
amount_off: 1000
})
}),
validation_rules: [validation_rule_id]
})
})
return campaign
rescue VoucherifySdk::ApiError => e
return nil
end
end
def create_promotion_campaign(campaigns_api_instance)
begin
campaign = campaigns_api_instance.create_campaign({
campaigns_create_request_body: {
campaign_type: "PROMOTION",
name: generate_random_string(),
promotion: {
tiers: [
{
name: generate_random_string(),
banner: generate_random_string(),
action: {
discount: {
type: "AMOUNT",
amount_off: 1000
}
}
}
]}
}
})
return campaign
end
end
def create_loyalty_campaign(campaigns_api_instance)
begin
campaign = campaigns_api_instance.create_campaign({
campaigns_create_request_body: {
campaign_type: "LOYALTY_PROGRAM",
name: generate_random_string(),
voucher: {
type: "LOYALTY_CARD",
loyalty_card: {
points: 1000,
}
}
}
})
end
end
def delete_campaign(campaigns_api_instance, campaign_id)
begin
result = campaigns_api_instance.delete_campaign(campaign_id)
return result
rescue VoucherifySdk::ApiError => e
return nil
end
end