fat_zebra 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,6 +23,7 @@ module FatZebra
23
23
  # Public: Performs a purchase transaction against the gateway
24
24
  #
25
25
  # amount - the amount as an integer e.g. (1.00 * 100).to_i
26
+ # card_data - a hash of the card data (example: {:card_holder => "John Smith", :number => "...", :expiry => "...", :cvv => "123"} or {:token => "abcdefg1"})
26
27
  # card_holder - the card holders name
27
28
  # card_number - the customers credit card number
28
29
  # card_expiry - the customers card expiry date (as Date or string [mm/yyyy])
@@ -30,29 +31,58 @@ module FatZebra
30
31
  # reference - a reference for the purchase
31
32
  # customer_ip - the customers IP address (for fraud prevention)
32
33
  #
33
- # Returns a new FatZebra::Models::Purchase object
34
- def purchase(amount, card_holder, card_number, card_expiry, cvv, reference, customer_ip)
34
+ # Returns a new FatZebra::Models::Response (purchase) object
35
+ def purchase(amount, card_data, reference, customer_ip)
35
36
  params = {
36
37
  :amount => amount,
37
- :card_holder => card_holder,
38
- :card_number => card_number,
39
- :card_expiry => extract_date(card_expiry),
40
- :cvv => cvv,
38
+ :card_holder => card_data.delete(:card_holder),
39
+ :card_number => card_data.delete(:number),
40
+ :card_expiry => extract_date(card_data.delete(:expiry)),
41
+ :cvv => card_data.delete(:cvv),
42
+ :card_token => card_data.delete(:token),
41
43
  :reference => reference,
42
44
  :customer_ip => customer_ip
43
45
  }
44
46
 
47
+ params.delete_if {|key, value| value.nil? } # If token is nil, remove, otherwise, remove card values
48
+
45
49
  response = make_request(:post, "purchases", params)
46
50
  FatZebra::Models::Response.new(response)
47
51
  end
48
52
 
49
- def purchases(id = nil)
53
+ # Retrieves purchases specified by the options hash
54
+ #
55
+ # @param [Hash] options for lookup
56
+ # includes:
57
+ # - id (unique purchase ID)
58
+ # - reference (merchant reference)
59
+ # - offset (defaults to 0) - for pagination
60
+ # - limit (defaults to 10) for pagination
61
+ # @return [Array<Purchase>] array of purchases
62
+ def purchases(options = {})
63
+ id = options.delete(:id)
64
+ options.merge!({offets: 0, limit: 10})
65
+
50
66
  if id.nil?
51
- response = make_request(:get, "purchases")
52
- # handle list response
67
+ response = make_request(:get, "purchases", options)
68
+ if response["successful"]
69
+ purchases = []
70
+ response["response"].each do |purchase|
71
+ purchases << FatZebra::Models::Purchase.new(purchase)
72
+ end
73
+
74
+ purchases.size == 1 ? purchases.first : purchases
75
+ else
76
+ # TODO: This should raise a defined exception
77
+ raise StandardError, "Unable to query purchases, #{response["errors"].inspect}"
78
+ end
53
79
  else
54
80
  response = make_request(:get, "purchases/#{id}.json")
55
- puts response.inspect
81
+ if response["successful"]
82
+ FatZebra::Models::Purchase.new(response["response"])
83
+ else
84
+ raise StandardError, "Unable to query purchases, #{response["errors"].inspect}"
85
+ end
56
86
  end
57
87
  end
58
88
 
@@ -116,6 +146,8 @@ module FatZebra
116
146
  #
117
147
  # Returns date string as MM/YYYY
118
148
  def extract_date(value)
149
+ return nil if value.nil?
150
+
119
151
  if value.is_a?(String)
120
152
  return value
121
153
  elsif value.respond_to?(:strftime)
@@ -1,11 +1,31 @@
1
1
  module FatZebra
2
- module Models
3
- class Base
4
- def initialize(attrs = {})
5
- attrs.each do |key, val|
6
- self.send("#{key}=", val) if self.respond_to?("#{key}=")
7
- end
8
- end
9
- end
10
- end
2
+ module Models
3
+ class Base
4
+ @@attributes = []
5
+ def self.attribute(*values)
6
+ @@attributes ||= []
7
+ values.each do |val|
8
+ @@attributes << val
9
+ end
10
+ attr_accessor *values
11
+ end
12
+
13
+ def initialize(attrs = {})
14
+ attrs.each do |key, val|
15
+ self.send("#{key}=", val) if self.respond_to?("#{key}=")
16
+ end
17
+ end
18
+
19
+ def inspect
20
+ inspection = @@attributes.collect { |name|
21
+ "#{name}: #{instance_variable_get("@#{name}")}"
22
+ }.compact.join(", ")
23
+ "#<#{self.class} #{inspection}>"
24
+ end
25
+
26
+ def to_s
27
+ inspect
28
+ end
29
+ end
30
+ end
11
31
  end
@@ -1,7 +1,7 @@
1
1
  module FatZebra
2
2
  module Models
3
3
  class Purchase < Base
4
- attr_accessor :id, :amount, :reference
4
+ attribute :id, :amount, :reference
5
5
  end
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module FatZebra
2
2
  module Models
3
3
  class Refund < Base
4
- attr_accessor :amonut, :reference, :transaction_id, :original_transaction_id
4
+ attribute :amount, :reference, :transaction_id, :original_transaction_id
5
5
 
6
6
  def original_transaction
7
7
  @original_transaction ||= Purchase.find(self.original_transaction_id)
@@ -1,3 +1,3 @@
1
1
  module FatZebra
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/spec/gateway_spec.rb CHANGED
@@ -24,13 +24,18 @@ describe FatZebra::Gateway do
24
24
  end
25
25
 
26
26
  it "should perform a purchase" do
27
- result = @gw.purchase(10000, "Matthew Savage", "5123456789012346", "05/2013", 123, "TEST#{rand}", "1.2.3.4")
27
+ result = @gw.purchase(10000, {:card_holder => "Matthew Savage", :number => "5555555555554444", :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, "Matthew Savage", "5123456789012346", "05/2013", 123, "TES#{rand}T", "1.2.3.4")
34
- @gw.purchases(result.purchase.id)
33
+ result = @gw.purchase(10000, {:card_holder => "Matthew Savage", :number => "5555555555554444", :expiry => "05/2013", :cvv => 123}, "TES#{rand}T", "1.2.3.4")
34
+ purchase = @gw.purchases(:id => result.purchase.id)
35
+ purchase.id.should == result.purchase.id
36
+ end
37
+
38
+ it "should fetch a purchase within a date range" do
39
+
35
40
  end
36
41
  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: 0.0.1
4
+ version: 0.0.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-03-02 00:00:00.000000000 Z
12
+ date: 2012-03-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70188364935140 !ruby/object:Gem::Requirement
16
+ requirement: &70267486703020 !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: *70188364935140
24
+ version_requirements: *70267486703020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70188364933140 !ruby/object:Gem::Requirement
27
+ requirement: &70267486701460 !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: *70188364933140
35
+ version_requirements: *70267486701460
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: yard
38
- requirement: &70188364931500 !ruby/object:Gem::Requirement
38
+ requirement: &70267486717220 !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: *70188364931500
46
+ version_requirements: *70267486717220
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: yard-tomdoc
49
- requirement: &70188364947340 !ruby/object:Gem::Requirement
49
+ requirement: &70267486716700 !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: *70188364947340
57
+ version_requirements: *70267486716700
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rest-client
60
- requirement: &70188364946820 !ruby/object:Gem::Requirement
60
+ requirement: &70267486716240 !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: :runtime
67
67
  prerelease: false
68
- version_requirements: *70188364946820
68
+ version_requirements: *70267486716240
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: json
71
- requirement: &70188364946360 !ruby/object:Gem::Requirement
71
+ requirement: &70267486715800 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70188364946360
79
+ version_requirements: *70267486715800
80
80
  description: Provides integration with the Fat Zebra internet payment gateway (www.fatzebra.com.au),
81
81
  including purchase, refund, auth, capture and recurring billing functionality.
82
82
  email:
@@ -119,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  segments:
121
121
  - 0
122
- hash: 2788965499772095038
122
+ hash: -822384591373257105
123
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  none: false
125
125
  requirements:
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  segments:
130
130
  - 0
131
- hash: 2788965499772095038
131
+ hash: -822384591373257105
132
132
  requirements: []
133
133
  rubyforge_project: fat_zebra
134
134
  rubygems_version: 1.8.10