fat_zebra 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +0 -0
- data/FatZebra.gemspec +1 -0
- data/lib/fat_zebra/gateway.rb +64 -21
- data/lib/fat_zebra/models/card.rb +7 -0
- data/lib/fat_zebra/models/response.rb +4 -1
- data/lib/fat_zebra/version.rb +1 -1
- data/lib/fat_zebra.rb +2 -1
- data/spec/gateway_spec.rb +34 -2
- metadata +29 -16
data/.rspec
ADDED
File without changes
|
data/FatZebra.gemspec
CHANGED
data/lib/fat_zebra/gateway.rb
CHANGED
@@ -57,6 +57,8 @@ module FatZebra
|
|
57
57
|
# includes:
|
58
58
|
# - id (unique purchase ID)
|
59
59
|
# - reference (merchant reference)
|
60
|
+
# - from (Date)
|
61
|
+
# - to (Date)
|
60
62
|
# - offset (defaults to 0) - for pagination
|
61
63
|
# - limit (defaults to 10) for pagination
|
62
64
|
# @return [Array<Purchase>] array of purchases
|
@@ -64,6 +66,11 @@ module FatZebra
|
|
64
66
|
id = options.delete(:id)
|
65
67
|
options.merge!({:offets => 0, :limit => 10})
|
66
68
|
|
69
|
+
# Format dates for the request
|
70
|
+
options[:from] = options[:from].strftime("%Y%m%dT%H%M") if options[:from]
|
71
|
+
options[:to] = options[:to].strftime("%Y%m%dT%H%M") if options[:to]
|
72
|
+
|
73
|
+
|
67
74
|
if id.nil?
|
68
75
|
response = make_request(:get, "purchases", options)
|
69
76
|
if response["successful"]
|
@@ -146,6 +153,26 @@ module FatZebra
|
|
146
153
|
end
|
147
154
|
end
|
148
155
|
|
156
|
+
# Public: Tokenizes a credit card
|
157
|
+
#
|
158
|
+
# card_holder - the credit card holder name
|
159
|
+
# card_number - the card number
|
160
|
+
# expiry - the credit card expiry date (mm/yyyy)
|
161
|
+
# cvv - the card CVV
|
162
|
+
#
|
163
|
+
# Returns FatZebra::Models::Response
|
164
|
+
def tokenize(card_holder, card_number, expiry, cvv)
|
165
|
+
params = {
|
166
|
+
:card_holder => card_holder,
|
167
|
+
:card_number => card_number,
|
168
|
+
:card_expiry => expiry,
|
169
|
+
:cvv => cvv
|
170
|
+
}
|
171
|
+
|
172
|
+
response = make_request(:post, "credit_cards", params)
|
173
|
+
FatZebra::Models::Response.new(response, :card)
|
174
|
+
end
|
175
|
+
|
149
176
|
|
150
177
|
private
|
151
178
|
# Private: Extracts the date value from a Date/DateTime value
|
@@ -198,10 +225,10 @@ module FatZebra
|
|
198
225
|
end
|
199
226
|
|
200
227
|
unless data.nil?
|
201
|
-
url = url + "?"
|
202
|
-
data.
|
203
|
-
|
204
|
-
end
|
228
|
+
url = url + "?" +
|
229
|
+
data.map do |key, value|
|
230
|
+
"#{key}=#{value}" # TODO: URL Encode this
|
231
|
+
end.join("&")
|
205
232
|
end
|
206
233
|
|
207
234
|
url
|
@@ -222,7 +249,13 @@ module FatZebra
|
|
222
249
|
} : {}
|
223
250
|
|
224
251
|
opts = {:user => self.username, :password => self.token}
|
225
|
-
|
252
|
+
if method == :get
|
253
|
+
url = build_url(uri, data)
|
254
|
+
else
|
255
|
+
url = build_url(uri)
|
256
|
+
end
|
257
|
+
|
258
|
+
RestClient::Resource.new(url, opts.merge(ssl_options))
|
226
259
|
end
|
227
260
|
|
228
261
|
# Public: Performs the HTTP(s) request and returns a response object, handing errors etc
|
@@ -236,25 +269,35 @@ module FatZebra
|
|
236
269
|
resource = get_resource(resource, method, data)
|
237
270
|
|
238
271
|
payload = (method == :post) ? data.to_json : {}
|
272
|
+
headers = options[:headers] || {}
|
239
273
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
JSON.parse(response)
|
244
|
-
when 200
|
245
|
-
JSON.parse(response)
|
246
|
-
when 400
|
247
|
-
raise RequestError, "Bad Data"
|
248
|
-
when 401
|
249
|
-
raise RequestError, "Unauthorized, please check your username and token"
|
250
|
-
when 404
|
251
|
-
raise RequestError, "Requested URL not found"
|
252
|
-
when 500
|
253
|
-
raise RequestError, "Server Error, please check https://www.fatzebra.com.au"
|
254
|
-
when 501
|
255
|
-
raise RequestError, "Problem processing your request - please check your data"
|
274
|
+
if method == :get
|
275
|
+
resource.send(method, headers) do |response, request, result, &block|
|
276
|
+
handle_response(response)
|
256
277
|
end
|
278
|
+
else
|
279
|
+
resource.send(method, payload, headers) do |response, request, result, &block|
|
280
|
+
handle_response(response)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
257
284
|
|
285
|
+
def handle_response(response)
|
286
|
+
case response.code
|
287
|
+
when 201
|
288
|
+
JSON.parse(response)
|
289
|
+
when 200
|
290
|
+
JSON.parse(response)
|
291
|
+
when 400
|
292
|
+
raise RequestError, "Bad Data"
|
293
|
+
when 401
|
294
|
+
raise RequestError, "Unauthorized, please check your username and token"
|
295
|
+
when 404
|
296
|
+
raise RequestError, "Requested URL not found"
|
297
|
+
when 500
|
298
|
+
raise RequestError, "Server Error, please check https://www.fatzebra.com.au"
|
299
|
+
when 501
|
300
|
+
raise RequestError, "Problem processing your request - please check your data"
|
258
301
|
end
|
259
302
|
end
|
260
303
|
end
|
@@ -3,7 +3,7 @@ module FatZebra
|
|
3
3
|
class Response
|
4
4
|
attr_accessor :successful, :result, :errors, :test, :raw
|
5
5
|
def initialize(response, type = :purchase)
|
6
|
-
self.raw = response.dup
|
6
|
+
self.raw = response.dup unless response.nil?
|
7
7
|
self.test = response["test"]
|
8
8
|
self.successful = response["successful"]
|
9
9
|
self.errors = response["errors"]
|
@@ -15,6 +15,9 @@ module FatZebra
|
|
15
15
|
when :refund
|
16
16
|
self.result = Refund.new(response["response"])
|
17
17
|
alias refund result
|
18
|
+
when :card
|
19
|
+
self.result = Card.new(response["response"])
|
20
|
+
alias card result
|
18
21
|
end
|
19
22
|
end
|
20
23
|
|
data/lib/fat_zebra/version.rb
CHANGED
data/lib/fat_zebra.rb
CHANGED
data/spec/gateway_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
TEST_USER = "TEST"
|
4
4
|
TEST_TOKEN = "TEST"
|
5
|
-
TEST_LOCAL = false
|
5
|
+
TEST_LOCAL = ENV["TEST_LOCAL"] == "true" || false
|
6
6
|
|
7
7
|
describe FatZebra::Gateway do
|
8
8
|
before :each do
|
@@ -35,7 +35,33 @@ describe FatZebra::Gateway do
|
|
35
35
|
purchase.id.should == result.purchase.id
|
36
36
|
end
|
37
37
|
|
38
|
-
it "should fetch a purchase
|
38
|
+
it "should fetch a purchase via reference" do
|
39
|
+
ref = "TES#{rand}T"
|
40
|
+
result = @gw.purchase(10000, {:card_holder => "Matthew Savage", :number => "5555555555554444", :expiry => "05/2013", :cvv => 123}, ref, "1.2.3.4")
|
41
|
+
|
42
|
+
purchases = @gw.purchases(:reference => ref)
|
43
|
+
purchases.id.should == result.purchase.id
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should fetch purchases within a date range" do
|
47
|
+
start = Time.now
|
48
|
+
5.times do |i|
|
49
|
+
@gw.purchase(10000, {:card_holder => "Matthew Savage", :number => "5555555555554444", :expiry => "05/2013", :cvv => 123}, "TEST#{rand(1000)}-#{i}", "1.2.3.4")
|
50
|
+
end
|
51
|
+
|
52
|
+
purchases = @gw.purchases(:from => start - 300, :to => Time.now + 300)
|
53
|
+
purchases.count.should >= 5
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should fetch purchases with a from date" do
|
57
|
+
start = Time.now
|
58
|
+
5.times do |i|
|
59
|
+
@gw.purchase(10000, {:card_holder => "Matthew Savage", :number => "5555555555554444", :expiry => "05/2013", :cvv => 123}, "TEST#{rand(1000)}-#{i}", "1.2.3.4")
|
60
|
+
end
|
61
|
+
|
62
|
+
purchases = @gw.purchases(:from => start)
|
63
|
+
purchases.count.should >= 5
|
64
|
+
end
|
39
65
|
|
40
66
|
it "should refund a transaction" do
|
41
67
|
purchase = @gw.purchase(10000, {:card_holder => "Matthew Savage", :number => "5555555555554444", :expiry => "05/2013", :cvv => 123}, "TES#{rand}T", "1.2.3.4")
|
@@ -44,4 +70,10 @@ describe FatZebra::Gateway do
|
|
44
70
|
result.should be_successful
|
45
71
|
result.result.successful.should be_true
|
46
72
|
end
|
73
|
+
|
74
|
+
it "should tokenize a card" do
|
75
|
+
response = @gw.tokenize("M Smith", "5123456789012346", "05/2013", "123")
|
76
|
+
response.should be_successful
|
77
|
+
response.result.token.should_not be_nil
|
78
|
+
end
|
47
79
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fat_zebra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70289032097440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70289032097440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70289032096820 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70289032096820
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: yard
|
38
|
-
requirement: &
|
38
|
+
requirement: &70289032095980 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70289032095980
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: yard-tomdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &70289032095080 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,21 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70289032095080
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: ZenTest
|
60
|
+
requirement: &70289032094060 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70289032094060
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: rest-client
|
60
|
-
requirement: &
|
71
|
+
requirement: &70289032093020 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ! '>='
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: '0'
|
66
77
|
type: :runtime
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *70289032093020
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: json
|
71
|
-
requirement: &
|
82
|
+
requirement: &70289032092480 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ! '>='
|
@@ -76,7 +87,7 @@ dependencies:
|
|
76
87
|
version: '0'
|
77
88
|
type: :runtime
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *70289032092480
|
80
91
|
description: Provides integration with the Fat Zebra internet payment gateway (www.fatzebra.com.au),
|
81
92
|
including purchase, refund, auth, capture and recurring billing functionality.
|
82
93
|
email:
|
@@ -86,6 +97,7 @@ extensions: []
|
|
86
97
|
extra_rdoc_files: []
|
87
98
|
files:
|
88
99
|
- .gitignore
|
100
|
+
- .rspec
|
89
101
|
- .travis.yml
|
90
102
|
- FatZebra.gemspec
|
91
103
|
- Gemfile
|
@@ -96,6 +108,7 @@ files:
|
|
96
108
|
- lib/fat_zebra/errors.rb
|
97
109
|
- lib/fat_zebra/gateway.rb
|
98
110
|
- lib/fat_zebra/models/base.rb
|
111
|
+
- lib/fat_zebra/models/card.rb
|
99
112
|
- lib/fat_zebra/models/purchase.rb
|
100
113
|
- lib/fat_zebra/models/refund.rb
|
101
114
|
- lib/fat_zebra/models/response.rb
|
@@ -120,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
133
|
version: '0'
|
121
134
|
segments:
|
122
135
|
- 0
|
123
|
-
hash:
|
136
|
+
hash: 1093919880626549256
|
124
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
138
|
none: false
|
126
139
|
requirements:
|
@@ -129,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
142
|
version: '0'
|
130
143
|
segments:
|
131
144
|
- 0
|
132
|
-
hash:
|
145
|
+
hash: 1093919880626549256
|
133
146
|
requirements: []
|
134
147
|
rubyforge_project: fat_zebra
|
135
148
|
rubygems_version: 1.8.10
|