fat_zebra 1.1.0 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,7 +1,7 @@
1
1
  Ruby API Library for Fat Zebra
2
2
  ==============================
3
3
 
4
- Release 1.0.0 for API version 1.0
4
+ Release 1.1.3 for API version 1.0
5
5
 
6
6
  A Ruby client for the [Fat Zebra](https://www.fatzebra.com.au) Online Payment Gateway (for Australian Merchants)
7
7
 
@@ -31,18 +31,36 @@ module FatZebra
31
31
  # cvv - the credit card verification value (cvv, cav, csc etc)
32
32
  # reference - a reference for the purchase
33
33
  # customer_ip - the customers IP address (for fraud prevention)
34
+ # currency - the currency of the transaction, ISO 4217 code (http://en.wikipedia.org/wiki/ISO_4217)
34
35
  #
35
36
  # Returns a new FatZebra::Models::Response (purchase) object
36
- def purchase(amount, card_data, reference, customer_ip)
37
+ def purchase(amount, card_data, reference, customer_ip, currency = "AUD")
38
+
39
+ if card_data.keys.include?(:token)
40
+ warn "[DEPRECATED] please use {:card_token => \".....\"} instead of {:token => \".....\"}"
41
+ card_data[:card_token] ||= card_data.delete(:token)
42
+ end
43
+
44
+ if card_data.keys.include?(:number)
45
+ warn "[DEPRECATED] please use :card_number instead of :number"
46
+ card_data[:card_number] ||= card_data.delete(:number)
47
+ end
48
+
49
+ if card_data.keys.include?(:expiry)
50
+ warn "[DEPRECATED] please use :card_expiry instead of :expiry"
51
+ card_data[:card_expiry] ||= card_data.delete(:expiry)
52
+ end
53
+
37
54
  params = {
38
55
  :amount => amount,
39
56
  :card_holder => card_data.delete(:card_holder),
40
- :card_number => card_data.delete(:number),
41
- :card_expiry => extract_date(card_data.delete(:expiry)),
57
+ :card_number => card_data.delete(:card_number),
58
+ :card_expiry => extract_date(card_data.delete(:card_expiry)),
42
59
  :cvv => card_data.delete(:cvv),
43
- :card_token => card_data.delete(:token),
60
+ :card_token => card_data.delete(:card_token),
44
61
  :reference => reference,
45
- :customer_ip => customer_ip
62
+ :customer_ip => customer_ip,
63
+ :currency => currency
46
64
  }
47
65
 
48
66
  params.delete_if {|key, value| value.nil? } # If token is nil, remove, otherwise, remove card values
@@ -173,6 +191,34 @@ module FatZebra
173
191
  FatZebra::Models::Response.new(response, :card)
174
192
  end
175
193
 
194
+ # Public: Fetch a previously tokenized card
195
+ #
196
+ # token - the card token
197
+ #
198
+ # Returns FatZebra::Models::Response (Card)
199
+ def tokenized_card(token)
200
+ response = make_request(:get, "credit_cards/#{token}.json")
201
+ FatZebra::Models::Response.new(response, :card)
202
+ end
203
+
204
+ def tokenized_cards
205
+ records = []
206
+ options = {:offets => 0, :limit => 10}
207
+
208
+ # Format dates for the request
209
+ options[:from] = options[:from].strftime("%Y%m%dT%H%M") if options[:from]
210
+ options[:to] = options[:to].strftime("%Y%m%dT%H%M") if options[:to]
211
+
212
+ response = make_request(:get, "credit_cards.json", options)
213
+ if response["successful"]
214
+ response["response"].each do |record|
215
+ records << FatZebra::Models::Card.new(record)
216
+ end
217
+ records
218
+ else
219
+ raise StandardError, "Unable to query credit cards, #{response["errors"].inspect}"
220
+ end
221
+ end
176
222
 
177
223
  private
178
224
  # Private: Extracts the date value from a Date/DateTime value
@@ -2,6 +2,32 @@ module FatZebra
2
2
  module Models
3
3
  class Card < Base
4
4
  attribute :token, :card_holder, :card_number, :card_expiry, :transaction_count, :raw
5
- end
6
- end
5
+
6
+ def charge!()
7
+
8
+ end
9
+
10
+ class << self
11
+ # Tokenizes a credit card
12
+ #
13
+ # @param [String] the credit card holder name
14
+ # @param [String] the card number
15
+ # @param [String] the credit card expiry date (mm/yyyy)
16
+ # @param [String] the card CVV
17
+ #
18
+ # @return Response
19
+ def create(card_holder, card_number, expiry, cvv)
20
+ params = {
21
+ :card_holder => card_holder,
22
+ :card_number => card_number,
23
+ :card_expiry => expiry,
24
+ :cvv => cvv
25
+ }
26
+
27
+ response = FatZebra.gateway.make_request(:post, "credit_cards", params)
28
+ Response.new(response, :card)
29
+ end
30
+ end
31
+ end
32
+ end
7
33
  end
@@ -2,7 +2,18 @@ module FatZebra
2
2
  module Models
3
3
  class Purchase < Base
4
4
  attribute :id, :amount, :reference, :message, :authorization, :transaction_id, :card_number,
5
- :card_holder, :card_expiry, :authorized, :successful, :card_token, :raw
5
+ :card_holder, :card_expiry, :authorized, :successful, :card_token, :raw, :currency
6
+
7
+ def approved?
8
+ self.successful
9
+ end
10
+
11
+ def card_type
12
+ cards = []
13
+ cards[4] = "VISA"
14
+ cards[5] = "MasterCard"
15
+ cards[3] = "AMEX/JCB"
16
+ end
6
17
  end
7
18
  end
8
19
  end
@@ -1,3 +1,3 @@
1
1
  module FatZebra
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.3"
3
3
  end
data/spec/gateway_spec.rb CHANGED
@@ -24,39 +24,39 @@ describe FatZebra::Gateway do
24
24
  end
25
25
 
26
26
  it "should perform a purchase" do
27
- result = @gw.purchase(10000, {:card_holder => "Matthew Savage", :number => "5555555555554444", :expiry => "05/2013", :cvv => 123}, "TEST#{rand}", "1.2.3.4")
27
+ result = @gw.purchase(10000, {:card_holder => "Matthew Savage", :card_number => "5555555555554444", :card_expiry => "05/2013", :cvv => 123}, "TEST#{rand}", "1.2.3.4")
28
28
  result.should be_successful
29
29
  result.errors.should be_empty
30
30
  end
31
31
 
32
32
  it "should fetch a purchase" do
33
- result = @gw.purchase(10000, {:card_holder => "Matthew Savage", :number => "5555555555554444", :expiry => "05/2013", :cvv => 123}, "TES#{rand}T", "1.2.3.4")
33
+ result = @gw.purchase(10000, {:card_holder => "Matthew Savage", :card_number => "5555555555554444", :card_expiry => "05/2013", :cvv => 123}, "TES#{rand}T", "1.2.3.4")
34
34
  purchase = @gw.purchases(:id => result.purchase.id)
35
35
  purchase.id.should == result.purchase.id
36
36
  end
37
37
 
38
38
  it "should fetch a purchase via reference" do
39
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")
40
+ result = @gw.purchase(10000, {:card_holder => "Matthew Savage", :card_number => "5555555555554444", :card_expiry => "05/2013", :cvv => 123}, ref, "1.2.3.4")
41
41
 
42
42
  purchases = @gw.purchases(:reference => ref)
43
43
  purchases.id.should == result.purchase.id
44
44
  end
45
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
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", :card_number => "5555555555554444", :card_expiry => "05/2013", :cvv => 123}, "TEST#{rand(1000)}-#{i}", "1.2.3.4")
50
+ # end
51
51
 
52
- purchases = @gw.purchases(:from => start - 300, :to => Time.now + 300)
53
- purchases.count.should >= 5
54
- end
52
+ # purchases = @gw.purchases(:from => start - 300, :to => Time.now + 300)
53
+ # purchases.count.should >= 5
54
+ # end
55
55
 
56
56
  it "should fetch purchases with a from date" do
57
57
  start = Time.now
58
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")
59
+ @gw.purchase(10000, {:card_holder => "Matthew Savage", :card_number => "5555555555554444", :card_expiry => "05/2013", :cvv => 123}, "TEST#{rand(1000)}-#{i}", "1.2.3.4")
60
60
  end
61
61
 
62
62
  purchases = @gw.purchases(:from => start)
@@ -64,7 +64,7 @@ describe FatZebra::Gateway do
64
64
  end
65
65
 
66
66
  it "should refund a transaction" do
67
- purchase = @gw.purchase(10000, {:card_holder => "Matthew Savage", :number => "5555555555554444", :expiry => "05/2013", :cvv => 123}, "TES#{rand}T", "1.2.3.4")
67
+ purchase = @gw.purchase(10000, {:card_holder => "Matthew Savage", :card_number => "5555555555554444", :card_expiry => "05/2013", :cvv => 123}, "TES#{rand}T", "1.2.3.4")
68
68
  result = @gw.refund(purchase.result.id, 100, "REFUND-#{purchase.result.id}")
69
69
 
70
70
  result.should be_successful
@@ -76,4 +76,27 @@ describe FatZebra::Gateway do
76
76
  response.should be_successful
77
77
  response.result.token.should_not be_nil
78
78
  end
79
+
80
+ it "should fetch a tokenized card" do
81
+ token = @gw.tokenize("M Smith", "5123456789012346", "05/2013", "123").result.token
82
+ card_response = @gw.tokenized_card(token)
83
+
84
+ card_response.should be_successful
85
+ card_response.result.token.should == token
86
+ card_response.result.card_number.should == "512345XXXXXX2346"
87
+ end
88
+
89
+ it "should fetch all cards" do
90
+ cards = @gw.tokenized_cards
91
+
92
+ cards.first.should be_instance_of(FatZebra::Models::Card)
93
+ end
94
+
95
+ it "should perform a purchase with a tokenized card" do
96
+ token = @gw.tokenize("M Smith", "5123456789012346", "05/2013", "123").result.token
97
+ purchase = @gw.purchase(10000, {:card_token => token}, "TEST#{rand}}", "127.0.0.1")
98
+
99
+ purchase.should be_successful
100
+ purchase.result.successful.should be_true
101
+ end
79
102
  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.1.0
4
+ version: 1.1.3
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-27 00:00:00.000000000 Z
12
+ date: 2013-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70289032097440 !ruby/object:Gem::Requirement
16
+ requirement: &70319775786820 !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: *70289032097440
24
+ version_requirements: *70319775786820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70289032096820 !ruby/object:Gem::Requirement
27
+ requirement: &70319775828120 !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: *70289032096820
35
+ version_requirements: *70319775828120
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: yard
38
- requirement: &70289032095980 !ruby/object:Gem::Requirement
38
+ requirement: &70319775827160 !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: *70289032095980
46
+ version_requirements: *70319775827160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: yard-tomdoc
49
- requirement: &70289032095080 !ruby/object:Gem::Requirement
49
+ requirement: &70319775826140 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70289032095080
57
+ version_requirements: *70319775826140
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: ZenTest
60
- requirement: &70289032094060 !ruby/object:Gem::Requirement
60
+ requirement: &70319775824660 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70289032094060
68
+ version_requirements: *70319775824660
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rest-client
71
- requirement: &70289032093020 !ruby/object:Gem::Requirement
71
+ requirement: &70319775824080 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70289032093020
79
+ version_requirements: *70319775824080
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: json
82
- requirement: &70289032092480 !ruby/object:Gem::Requirement
82
+ requirement: &70319775823500 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70289032092480
90
+ version_requirements: *70319775823500
91
91
  description: Provides integration with the Fat Zebra internet payment gateway (www.fatzebra.com.au),
92
92
  including purchase, refund, auth, capture and recurring billing functionality.
93
93
  email:
@@ -133,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  segments:
135
135
  - 0
136
- hash: 1093919880626549256
136
+ hash: -2567456050335982654
137
137
  required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
@@ -142,10 +142,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  version: '0'
143
143
  segments:
144
144
  - 0
145
- hash: 1093919880626549256
145
+ hash: -2567456050335982654
146
146
  requirements: []
147
147
  rubyforge_project: fat_zebra
148
- rubygems_version: 1.8.10
148
+ rubygems_version: 1.8.17
149
149
  signing_key:
150
150
  specification_version: 3
151
151
  summary: Fat Zebra payments gem - integrate your ruby app with Fat Zebra