fat_zebra 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +3 -3
- data/lib/fat_zebra/models/purchase.rb +30 -30
- data/lib/fat_zebra/version.rb +1 -1
- data/lib/fat_zebra.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12eca7538a469a8a681e37ee9fb816e113941ceb
|
4
|
+
data.tar.gz: c0b4b46f1dbe9b7da713f7e1b44d814bae1e11db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bd161af6c85201b40d375d0a6d5833cf98216323d874204fe7d2e35b8e3d3f30dca9840c7d6dc655078dc902f8b4eb8f194f0a69e8184ba9ccca580d90e1fe4
|
7
|
+
data.tar.gz: 0290013901adfb328ccbb28a556dd1761c3dd806018b6f9a4bb6b77c272cf3bc2724597a4ab86712553b29d69c4f64692e0a0c539cf2ec9145c1bab965fc7fbf
|
data/README.markdown
CHANGED
@@ -40,15 +40,15 @@ card_data = {
|
|
40
40
|
number: "5123456789012346",
|
41
41
|
card_holder: "Bill Simpson",
|
42
42
|
expiry: "05/2023",
|
43
|
-
|
43
|
+
cvv: "123"
|
44
44
|
}
|
45
45
|
|
46
|
-
response = FatZebra::Purchase.create(10000, card_data, "ORDER-23", "203.99.87.4")
|
46
|
+
response = FatZebra::Models::Purchase.create(10000, card_data, "ORDER-23", "203.99.87.4")
|
47
47
|
|
48
48
|
if response.successful? && response.result.successful
|
49
49
|
puts "Transaction ID: #{response.result.id}"
|
50
50
|
else
|
51
|
-
abort "Error in transaction: #{response.
|
51
|
+
abort "Error in transaction: #{response.errors}"
|
52
52
|
end
|
53
53
|
```
|
54
54
|
|
@@ -7,8 +7,8 @@ module FatZebra
|
|
7
7
|
|
8
8
|
# Refunds the current transaction
|
9
9
|
#
|
10
|
-
# @param [Integer] the amount to be refunded
|
11
|
-
# @param [String] the refund reference
|
10
|
+
# @param [Integer] amount the amount to be refunded
|
11
|
+
# @param [String] reference the refund reference
|
12
12
|
#
|
13
13
|
# @return Response (Refund) object
|
14
14
|
def refund(amount, reference)
|
@@ -44,19 +44,19 @@ module FatZebra
|
|
44
44
|
class << self
|
45
45
|
# Performs a purchase transaction against the gateway
|
46
46
|
#
|
47
|
-
# @param [Integer] the amount as an integer e.g. (1.00 * 100).to_i
|
48
|
-
# @param [Hash] a hash of the card data (example: {:card_holder => "John Smith", :number => "...", :expiry => "...", :cvv => "123"} or {:token => "abcdefg1"})
|
49
|
-
# @
|
50
|
-
# @
|
51
|
-
# @
|
52
|
-
# @
|
53
|
-
# @param [String] a reference for the purchase
|
54
|
-
# @param [String] the customers IP address (for fraud prevention)
|
55
|
-
# @param [String] currency code ("AUD", "USD", etc)
|
47
|
+
# @param [Integer] amount the amount as an integer e.g. (1.00 * 100).to_i
|
48
|
+
# @param [Hash] card_data a hash of the card data (example: {:card_holder => "John Smith", :number => "...", :expiry => "...", :cvv => "123"} or {:token => "abcdefg1"})
|
49
|
+
# @option card_data [String] card_holder the card holders name
|
50
|
+
# @option card_data [String] card_number the customers credit card number
|
51
|
+
# @option card_data [Date] expiry the customers card expiry date (as Date or string [mm/yyyy])
|
52
|
+
# @option card_data [String] cvv the credit card verification value (cvv, cav, csc etc)
|
53
|
+
# @param [String] reference a reference for the purchase
|
54
|
+
# @param [String] customer_ip the customers IP address (for fraud prevention)
|
55
|
+
# @param [String] currency currency code ("AUD", "USD", etc)
|
56
56
|
# @param [Hash] optional any optional parameters to be included in the payload
|
57
57
|
#
|
58
58
|
# @return [Response] response (purchase) object
|
59
|
-
def create(amount, card_data, reference, customer_ip, currency =
|
59
|
+
def create(amount, card_data, reference, customer_ip, currency = 'AUD', optional = {})
|
60
60
|
params = {
|
61
61
|
:amount => amount,
|
62
62
|
:card_holder => card_data.delete(:card_holder),
|
@@ -69,10 +69,10 @@ module FatZebra
|
|
69
69
|
:currency => currency
|
70
70
|
}
|
71
71
|
|
72
|
-
params.delete_if {|
|
73
|
-
validate_params!(params)
|
72
|
+
params.delete_if {|_, value| value.nil? } # If token is nil, remove, otherwise, remove card values
|
74
73
|
params.merge!(optional)
|
75
|
-
|
74
|
+
validate_params!(params)
|
75
|
+
response = FatZebra.gateway.make_request(:post, 'purchases', params)
|
76
76
|
Response.new(response)
|
77
77
|
end
|
78
78
|
|
@@ -92,29 +92,29 @@ module FatZebra
|
|
92
92
|
options.merge!({:offets => 0, :limit => 10})
|
93
93
|
|
94
94
|
# Format dates for the request
|
95
|
-
options[:from] = options[:from].strftime(
|
96
|
-
options[:to] = options[:to].strftime(
|
95
|
+
options[:from] = options[:from].strftime('%Y%m%dT%H%M') if options[:from]
|
96
|
+
options[:to] = options[:to].strftime('%Y%m%dT%H%M') if options[:to]
|
97
97
|
|
98
98
|
|
99
99
|
if id.nil?
|
100
|
-
response = FatZebra.gateway.make_request(:get,
|
101
|
-
if response[
|
100
|
+
response = FatZebra.gateway.make_request(:get, 'purchases', options)
|
101
|
+
if response['successful']
|
102
102
|
purchases = []
|
103
|
-
response[
|
103
|
+
response['response'].each do |purchase|
|
104
104
|
purchases << Purchase.new(purchase)
|
105
105
|
end
|
106
106
|
|
107
107
|
purchases.size == 1 ? purchases.first : purchases
|
108
108
|
else
|
109
109
|
# TODO: This should raise a defined exception
|
110
|
-
raise StandardError, "Unable to query purchases, #{response[
|
110
|
+
raise StandardError, "Unable to query purchases, #{response['errors'].inspect}"
|
111
111
|
end
|
112
112
|
else
|
113
113
|
response = FatZebra.gateway.make_request(:get, "purchases/#{id}.json")
|
114
|
-
if response[
|
115
|
-
Purchase.new(response[
|
114
|
+
if response['successful']
|
115
|
+
Purchase.new(response['response'])
|
116
116
|
else
|
117
|
-
raise StandardError, "Unable to query purchases, #{response[
|
117
|
+
raise StandardError, "Unable to query purchases, #{response['errors'].inspect}"
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|
@@ -131,7 +131,7 @@ module FatZebra
|
|
131
131
|
if value.is_a?(String)
|
132
132
|
return value
|
133
133
|
elsif value.respond_to?(:strftime)
|
134
|
-
return value.strftime(
|
134
|
+
return value.strftime('%m/%Y')
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
@@ -143,11 +143,11 @@ module FatZebra
|
|
143
143
|
# Raises FatZebra::RequestError if errors are present.
|
144
144
|
def validate_params!(params)
|
145
145
|
@errors = []
|
146
|
-
@errors <<
|
147
|
-
@errors <<
|
148
|
-
@errors <<
|
149
|
-
@errors <<
|
150
|
-
@errors <<
|
146
|
+
@errors << 'number or token must be provided' unless params[:card_number].present? || params[:card_token].present? || params[:wallet].present?
|
147
|
+
@errors << 'amount must be provided or greater then 0' unless params[:amount].present? && params[:amount].to_f > 0
|
148
|
+
@errors << 'expiry must be provided' unless params[:card_token].present? || params[:card_expiry].present? || params[:wallet].present?
|
149
|
+
@errors << 'reference must be provided' unless params[:reference].present?
|
150
|
+
@errors << 'customer_ip must be provided' unless params[:customer_ip].present?
|
151
151
|
|
152
152
|
raise FatZebra::RequestError.new("The following errors prevent the transaction from being submitted: #{@errors.to_sentence}") if @errors.any?
|
153
153
|
end
|
data/lib/fat_zebra/version.rb
CHANGED
data/lib/fat_zebra.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fat_zebra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Savage
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|