voucherify 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +45 -0
- data/examples/validate.rb +15 -0
- data/lib/voucherify/version.rb +1 -1
- data/lib/voucherify.rb +19 -0
- metadata +15 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac6bfd1ead5ca241b7d5d62d1e0a18b2b34f6269
|
4
|
+
data.tar.gz: 334f47cdd657274805b1506b794f7d515df6f982
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 588e0ab94075bebf6cf57feb95528f9ef8d7cc048d0e7a61f8c2864e319498d63b44dc1ec8908da60f01678d21e146c69f633e315c6d74e46c7a1d9bcd7c54fe
|
7
|
+
data.tar.gz: 7e2ca93824f47367b5cdeeece4dabe3d1681e58d3364324ea611c172ac476c33952315114a367a6604fd6352f5c5136e01a7d2a9605fade26b9d88dcddee6034
|
data/README.md
CHANGED
@@ -240,6 +240,50 @@ Possible error:
|
|
240
240
|
}
|
241
241
|
```
|
242
242
|
|
243
|
+
#### Validating vouchers
|
244
|
+
|
245
|
+
Validation lets you check if given voucher code can be successfuly redeemed.
|
246
|
+
|
247
|
+
`voucherify.validate(code, context)`
|
248
|
+
|
249
|
+
The `context` param is generaly optional unless you are validating a gift voucher.
|
250
|
+
Then you have to pass `order.amount` expressed in cents (e.g. $10 is 1000).
|
251
|
+
|
252
|
+
Example:
|
253
|
+
|
254
|
+
```
|
255
|
+
validation_result = voucherify.validate("91Ft4U", {
|
256
|
+
tracking_id: "john@lemon.com",
|
257
|
+
customer: {
|
258
|
+
id: "cust_07sVjVsr71Ewot9lVZSrIVLH",
|
259
|
+
source_id: "john@lemon.com",
|
260
|
+
name: "John Lemon"
|
261
|
+
},
|
262
|
+
order: {
|
263
|
+
amount: 1000
|
264
|
+
}
|
265
|
+
})
|
266
|
+
```
|
267
|
+
|
268
|
+
Successful validation result:
|
269
|
+
```
|
270
|
+
{"code"=>"91Ft4U", "valid"=>true, "gift"=>{"amount"=>10000}, "tracking_id"=>"john@lemon.com"}
|
271
|
+
```
|
272
|
+
|
273
|
+
Failed validation result:
|
274
|
+
```
|
275
|
+
{"code"=>"91Ft4U", "valid"=>true, "reason"=>"gift amount exceeded", "tracking_id"=>"john@lemon.com"}
|
276
|
+
```
|
277
|
+
|
278
|
+
There are several reasons why validation may fail (`valid: false` response). You can find the actual cause in the `reason` field:
|
279
|
+
|
280
|
+
- `voucher not found`
|
281
|
+
- `voucher is disabled`
|
282
|
+
- `voucher not active yet`
|
283
|
+
- `voucher expired`
|
284
|
+
- `quantity exceeded`
|
285
|
+
- `gift amount exceeded`
|
286
|
+
|
243
287
|
#### Redeeming voucher
|
244
288
|
|
245
289
|
##### 1. Just by code
|
@@ -763,6 +807,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
763
807
|
Bug reports and pull requests are welcome on GitHub at https://github.com/rspective/voucherify-ruby-sdk.
|
764
808
|
|
765
809
|
## Changelog
|
810
|
+
- **2016-08-02** - `0.8.0` - validate voucher
|
766
811
|
- **2016-07-18** - `0.7.0` - voucher udpate
|
767
812
|
- **2016-07-05** - `0.6.0` - new utils module
|
768
813
|
- **2016-06-16** - `0.5.0` - unified naming convention
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require '../lib/voucherify'
|
2
|
+
|
3
|
+
voucherify = Voucherify.new({
|
4
|
+
"applicationId" => "c70a6f00-cf91-4756-9df5-47628850002b",
|
5
|
+
"clientSecretKey" => "3266b9f8-e246-4f79-bdf0-833929b1380c"
|
6
|
+
})
|
7
|
+
|
8
|
+
validation_result = voucherify.validate("91Ft4U", {
|
9
|
+
tracking_id: "john@lemon.com",
|
10
|
+
order: {
|
11
|
+
amount: 1000
|
12
|
+
}
|
13
|
+
})
|
14
|
+
|
15
|
+
print(validation_result);
|
data/lib/voucherify/version.rb
CHANGED
data/lib/voucherify.rb
CHANGED
@@ -55,6 +55,25 @@ class Voucherify
|
|
55
55
|
response = RestClient.get(url, @headers.merge({ :params => query }))
|
56
56
|
JSON.parse(response.body)
|
57
57
|
end
|
58
|
+
|
59
|
+
# Sample context:
|
60
|
+
# {
|
61
|
+
# tracking_id: "john@lemon.com",
|
62
|
+
# customer: {
|
63
|
+
# id: "cust_07sVjVsr71Ewot9lVZSrIVLH",
|
64
|
+
# source_id: "john@lemon.com",
|
65
|
+
# name: "John Lemon"
|
66
|
+
# },
|
67
|
+
# order: {
|
68
|
+
# amount: 1000
|
69
|
+
# }
|
70
|
+
# }
|
71
|
+
def validate(code, context = {})
|
72
|
+
url = @backend_url + "/vouchers/" + URI.encode(code) + "/validate"
|
73
|
+
|
74
|
+
response = RestClient.post(url, context.to_json, @headers.merge({ :content_type => :json }))
|
75
|
+
JSON.parse(response.body)
|
76
|
+
end
|
58
77
|
|
59
78
|
def redeem(code, tracking_id = nil)
|
60
79
|
payload = {}
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voucherify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawelrychlik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.11'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.11'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rest-client
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '1.8'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.8'
|
69
69
|
description:
|
@@ -73,7 +73,7 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .gitignore
|
76
|
+
- ".gitignore"
|
77
77
|
- Gemfile
|
78
78
|
- LICENSE
|
79
79
|
- README.md
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- bin/setup
|
83
83
|
- examples/customer.rb
|
84
84
|
- examples/utils.rb
|
85
|
+
- examples/validate.rb
|
85
86
|
- lib/voucherify.rb
|
86
87
|
- lib/voucherify/utils.rb
|
87
88
|
- lib/voucherify/version.rb
|
@@ -96,17 +97,17 @@ require_paths:
|
|
96
97
|
- lib
|
97
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
98
99
|
requirements:
|
99
|
-
- -
|
100
|
+
- - ">="
|
100
101
|
- !ruby/object:Gem::Version
|
101
102
|
version: 1.9.3
|
102
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
104
|
requirements:
|
104
|
-
- -
|
105
|
+
- - ">="
|
105
106
|
- !ruby/object:Gem::Version
|
106
107
|
version: '0'
|
107
108
|
requirements: []
|
108
109
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.2.2
|
110
111
|
signing_key:
|
111
112
|
specification_version: 4
|
112
113
|
summary: Ruby SDK for Voucherify. More info on http://www.voucherify.io
|