fat_zebra 2.0.13 → 3.0.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 +5 -13
- data/.rubocop.yml +42 -0
- data/.travis.yml +9 -2
- data/Gemfile +1 -1
- data/{README.markdown → README.md} +19 -20
- data/Rakefile +2 -12
- data/fat_zebra.gemspec +27 -0
- data/lib/fat_zebra/api_operation/delete.rb +38 -0
- data/lib/fat_zebra/api_operation/find.rb +23 -0
- data/lib/fat_zebra/api_operation/save.rb +62 -0
- data/lib/fat_zebra/api_operation/search.rb +32 -0
- data/lib/fat_zebra/api_operation/void.rb +52 -0
- data/lib/fat_zebra/api_resource.rb +135 -0
- data/lib/fat_zebra/bank_account.rb +21 -0
- data/lib/fat_zebra/batch.rb +56 -0
- data/lib/fat_zebra/card.rb +22 -0
- data/lib/fat_zebra/config.rb +65 -25
- data/lib/fat_zebra/customer.rb +27 -0
- data/lib/fat_zebra/direct_credit.rb +27 -0
- data/lib/fat_zebra/direct_debit.rb +27 -0
- data/lib/fat_zebra/errors.rb +18 -4
- data/lib/fat_zebra/fat_zebra_object.rb +179 -0
- data/lib/fat_zebra/information.rb +25 -0
- data/lib/fat_zebra/payment_plan.rb +62 -0
- data/lib/fat_zebra/purchase.rb +99 -0
- data/lib/fat_zebra/refund.rb +25 -0
- data/lib/fat_zebra/request/multipart/epilogue.rb +23 -0
- data/lib/fat_zebra/request/multipart/file_io.rb +40 -0
- data/lib/fat_zebra/request/multipart/param.rb +37 -0
- data/lib/fat_zebra/request/multipart/part.rb +28 -0
- data/lib/fat_zebra/request/multipart/stream.rb +55 -0
- data/lib/fat_zebra/request.rb +162 -0
- data/lib/fat_zebra/util.rb +70 -0
- data/lib/fat_zebra/validation.rb +47 -0
- data/lib/fat_zebra/version.rb +1 -1
- data/lib/fat_zebra/web_hook.rb +23 -0
- data/lib/fat_zebra.rb +51 -55
- data/spec/cassettes/FatZebra_BankAccount/_create/1_1_1.yml +57 -0
- data/spec/cassettes/FatZebra_BankAccount/_create/1_1_2.yml +57 -0
- data/spec/cassettes/FatZebra_BankAccount/_create/validations/1_1_3_1.yml +57 -0
- data/spec/cassettes/FatZebra_BankAccount/_search/1_2_1.yml +172 -0
- data/spec/cassettes/FatZebra_BankAccount/_search/1_2_2.yml +172 -0
- data/spec/cassettes/FatZebra_BankAccount/_search/1_2_3.yml +172 -0
- data/spec/cassettes/FatZebra_Batch/_create/1_1_1.yml +58 -0
- data/spec/cassettes/FatZebra_Batch/_create/1_1_2.yml +58 -0
- data/spec/cassettes/FatZebra_Batch/_create/validations/1_1_3_1.yml +57 -0
- data/spec/cassettes/FatZebra_Batch/_create/with_file/1_1_1_1.yml +58 -0
- data/spec/cassettes/FatZebra_Batch/_create/with_file/1_1_1_2.yml +58 -0
- data/spec/cassettes/FatZebra_Batch/_create/with_path/1_1_2_1.yml +58 -0
- data/spec/cassettes/FatZebra_Batch/_create/with_path/1_1_2_2.yml +58 -0
- data/spec/cassettes/FatZebra_Batch/_find/1_2_1.yml +109 -0
- data/spec/cassettes/FatZebra_Batch/_find/1_2_2.yml +109 -0
- data/spec/cassettes/FatZebra_Batch/_result/1_4_1.yml +160 -0
- data/spec/cassettes/FatZebra_Batch/_search/1_3_1.yml +54 -0
- data/spec/cassettes/FatZebra_Batch/_search/1_3_2.yml +54 -0
- data/spec/cassettes/FatZebra_Batch/_search/1_3_3.yml +54 -0
- data/spec/cassettes/FatZebra_Card/_create/1_1_1.yml +55 -0
- data/spec/cassettes/FatZebra_Card/_create/1_1_2.yml +55 -0
- data/spec/cassettes/FatZebra_Card/_create/1_1_3.yml +55 -0
- data/spec/cassettes/FatZebra_Card/_create/1_1_4.yml +55 -0
- data/spec/cassettes/FatZebra_Card/_create/1_1_5.yml +55 -0
- data/spec/cassettes/FatZebra_Card/_create/1_1_6.yml +55 -0
- data/spec/cassettes/FatZebra_Card/_create/validations/1_1_7_1.yml +56 -0
- data/spec/cassettes/FatZebra_Card/_update/1_2_1.yml +105 -0
- data/spec/cassettes/FatZebra_Card/_update/1_2_2.yml +105 -0
- data/spec/cassettes/FatZebra_Card/_update/1_2_3.yml +105 -0
- data/spec/cassettes/FatZebra_Card/_update/validations/1_2_4_1.yml +55 -0
- data/spec/cassettes/FatZebra_Customer/_create/1_1_1.yml +59 -0
- data/spec/cassettes/FatZebra_Customer/_create/1_1_2.yml +59 -0
- data/spec/cassettes/FatZebra_Customer/_create/1_1_3.yml +59 -0
- data/spec/cassettes/FatZebra_Customer/_create/1_1_4.yml +59 -0
- data/spec/cassettes/FatZebra_Customer/_create/1_1_5.yml +59 -0
- data/spec/cassettes/FatZebra_Customer/_create/1_1_6.yml +59 -0
- data/spec/cassettes/FatZebra_Customer/_create/validations/1_1_7_1.yml +56 -0
- data/spec/cassettes/FatZebra_Customer/_delete/1_4_1.yml +113 -0
- data/spec/cassettes/FatZebra_Customer/_delete/1_5_1.yml +113 -0
- data/spec/cassettes/FatZebra_Customer/_find/1_2_1.yml +111 -0
- data/spec/cassettes/FatZebra_Customer/_find/1_2_2.yml +111 -0
- data/spec/cassettes/FatZebra_Customer/_find/1_3_1.yml +111 -0
- data/spec/cassettes/FatZebra_Customer/_find/1_3_2.yml +111 -0
- data/spec/cassettes/FatZebra_Customer/_search/1_2_1.yml +56 -0
- data/spec/cassettes/FatZebra_Customer/_search/1_2_2.yml +56 -0
- data/spec/cassettes/FatZebra_Customer/_search/1_2_3.yml +56 -0
- data/spec/cassettes/FatZebra_Customer/_update/1_3_1.yml +114 -0
- data/spec/cassettes/FatZebra_Customer/_update/1_3_2.yml +114 -0
- data/spec/cassettes/FatZebra_Customer/_update/1_4_1.yml +114 -0
- data/spec/cassettes/FatZebra_Customer/_update/1_4_2.yml +114 -0
- data/spec/cassettes/FatZebra_DirectCredit/_create/1_1_1.yml +56 -0
- data/spec/cassettes/FatZebra_DirectCredit/_create/1_1_2.yml +56 -0
- data/spec/cassettes/FatZebra_DirectCredit/_create/1_1_3.yml +56 -0
- data/spec/cassettes/FatZebra_DirectCredit/_create/1_1_4.yml +56 -0
- data/spec/cassettes/FatZebra_DirectCredit/_create/validations/1_1_5_1.yml +59 -0
- data/spec/cassettes/FatZebra_DirectCredit/_delete/1_4_1.yml +109 -0
- data/spec/cassettes/FatZebra_DirectCredit/_find/1_2_1.yml +107 -0
- data/spec/cassettes/FatZebra_DirectCredit/_find/1_2_2.yml +107 -0
- data/spec/cassettes/FatZebra_DirectCredit/_search/1_3_1.yml +160 -0
- data/spec/cassettes/FatZebra_DirectCredit/_search/1_3_2.yml +160 -0
- data/spec/cassettes/FatZebra_DirectDebit/_create/1_1_1.yml +56 -0
- data/spec/cassettes/FatZebra_DirectDebit/_create/1_1_2.yml +56 -0
- data/spec/cassettes/FatZebra_DirectDebit/_create/1_1_3.yml +56 -0
- data/spec/cassettes/FatZebra_DirectDebit/_create/1_1_4.yml +56 -0
- data/spec/cassettes/FatZebra_DirectDebit/_create/validations/1_1_5_1.yml +59 -0
- data/spec/cassettes/FatZebra_DirectDebit/_delete/1_4_1.yml +109 -0
- data/spec/cassettes/FatZebra_DirectDebit/_find/1_2_1.yml +107 -0
- data/spec/cassettes/FatZebra_DirectDebit/_find/1_2_2.yml +107 -0
- data/spec/cassettes/FatZebra_DirectDebit/_search/1_3_1.yml +160 -0
- data/spec/cassettes/FatZebra_DirectDebit/_search/1_3_2.yml +160 -0
- data/spec/cassettes/FatZebra_Information/_ping/1_1_1.yml +54 -0
- data/spec/cassettes/FatZebra_Information/_ping/1_1_2.yml +54 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_active_/1_7_1.yml +238 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_active_/1_7_2.yml +238 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_active_/1_8_1.yml +238 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_active_/1_8_2.yml +238 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_create/1_1_1.yml +118 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_create/1_1_2.yml +118 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_create/1_1_3.yml +118 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_create/validations/1_1_4_1.yml +55 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_delete/1_5_1.yml +172 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_destroy/1_6_1.yml +172 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_find/1_2_1.yml +175 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_find/1_2_2.yml +175 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_find/1_2_3.yml +175 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_suspend_/1_6_1.yml +178 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_suspend_/1_6_2.yml +178 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_suspend_/1_7_1.yml +178 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_suspend_/1_7_2.yml +178 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_update/1_3_1.yml +172 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_update/1_3_2.yml +172 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_update/1_3_3.yml +172 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_update/1_4_1.yml +178 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_update/1_4_2.yml +178 -0
- data/spec/cassettes/FatZebra_Purchase/_capture/1_5_1.yml +111 -0
- data/spec/cassettes/FatZebra_Purchase/_capture/1_5_2.yml +111 -0
- data/spec/cassettes/FatZebra_Purchase/_capture/1_6_1.yml +111 -0
- data/spec/cassettes/FatZebra_Purchase/_capture/1_6_2.yml +111 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_1.yml +57 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_10.yml +57 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_11.yml +57 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_12.yml +57 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_2.yml +57 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_3.yml +57 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_4.yml +57 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_5.yml +57 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_6.yml +57 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_7.yml +57 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_8.yml +57 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_9.yml +57 -0
- data/spec/cassettes/FatZebra_Purchase/_find/1_2_1.yml +109 -0
- data/spec/cassettes/FatZebra_Purchase/_find/1_2_2.yml +109 -0
- data/spec/cassettes/FatZebra_Purchase/_find/1_2_3.yml +109 -0
- data/spec/cassettes/FatZebra_Purchase/_find/1_4_1.yml +109 -0
- data/spec/cassettes/FatZebra_Purchase/_find/1_4_2.yml +109 -0
- data/spec/cassettes/FatZebra_Purchase/_find/1_4_3.yml +109 -0
- data/spec/cassettes/FatZebra_Purchase/_refund/1_4_1.yml +111 -0
- data/spec/cassettes/FatZebra_Purchase/_refund/1_4_2.yml +111 -0
- data/spec/cassettes/FatZebra_Purchase/_refund/1_5_1.yml +111 -0
- data/spec/cassettes/FatZebra_Purchase/_refund/1_5_2.yml +111 -0
- data/spec/cassettes/FatZebra_Purchase/_search/1_3_1.yml +170 -0
- data/spec/cassettes/FatZebra_Purchase/_search/1_3_2.yml +170 -0
- data/spec/cassettes/FatZebra_Purchase/_search/1_3_3.yml +170 -0
- data/spec/cassettes/FatZebra_Purchase/_search/with_data/1_3_2_1.yml +164 -0
- data/spec/cassettes/FatZebra_Purchase/_search/with_data/1_3_2_2.yml +165 -0
- data/spec/cassettes/FatZebra_Purchase/_search/with_data/1_3_2_3.yml +164 -0
- data/spec/cassettes/FatZebra_Purchase/_search/without_data/1_3_1_1.yml +54 -0
- data/spec/cassettes/FatZebra_Purchase/_search/without_data/1_3_1_2.yml +54 -0
- data/spec/cassettes/FatZebra_Purchase/_search/without_data/1_3_1_3.yml +54 -0
- data/spec/cassettes/FatZebra_Purchase/_settlement/1_8_1.yml +613 -0
- data/spec/cassettes/FatZebra_Purchase/_settlement/1_8_2.yml +615 -0
- data/spec/cassettes/FatZebra_Purchase/_settlement/1_8_3.yml +617 -0
- data/spec/cassettes/FatZebra_Purchase/_void/1_6_1.yml +111 -0
- data/spec/cassettes/FatZebra_Purchase/_void/1_6_2.yml +111 -0
- data/spec/cassettes/FatZebra_Purchase/_void/1_6_3.yml +111 -0
- data/spec/cassettes/FatZebra_Purchase/_void/1_7_1.yml +111 -0
- data/spec/cassettes/FatZebra_Purchase/_void/1_7_2.yml +111 -0
- data/spec/cassettes/FatZebra_Purchase/_void/1_7_3.yml +111 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_1.yml +111 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_2.yml +111 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_3.yml +111 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_4.yml +111 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_5.yml +111 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_6.yml +111 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_7.yml +111 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_8.yml +111 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_9.yml +111 -0
- data/spec/cassettes/FatZebra_Refund/_find/1_2_1.yml +163 -0
- data/spec/cassettes/FatZebra_Refund/_find/1_2_2.yml +163 -0
- data/spec/cassettes/FatZebra_Refund/_search/1_3_1.yml +281 -0
- data/spec/cassettes/FatZebra_Refund/_search/1_3_2.yml +281 -0
- data/spec/cassettes/FatZebra_Refund/_void/1_4_1.yml +165 -0
- data/spec/cassettes/FatZebra_Refund/_void/1_4_2.yml +165 -0
- data/spec/cassettes/FatZebra_Refund/_void/1_4_3.yml +165 -0
- data/spec/cassettes/FatZebra_WebHook/_create/1_1_1.yml +57 -0
- data/spec/cassettes/FatZebra_WebHook/_create/1_1_2.yml +57 -0
- data/spec/cassettes/FatZebra_WebHook/_create/1_1_3.yml +57 -0
- data/spec/cassettes/FatZebra_WebHook/_create/validations/1_1_4_1.yml +56 -0
- data/spec/cassettes/FatZebra_WebHook/_delete/1_4_1.yml +111 -0
- data/spec/cassettes/FatZebra_WebHook/_search/1_2_1.yml +222 -0
- data/spec/cassettes/FatZebra_WebHook/_search/1_2_2.yml +224 -0
- data/spec/cassettes/FatZebra_WebHook/_update/1_3_1.yml +112 -0
- data/spec/cassettes/FatZebra_WebHook/_update/1_3_2.yml +112 -0
- data/spec/fixtures/batch_test.csv +4 -0
- data/spec/lib/fat_zebra/bank_account_spec.rb +34 -0
- data/spec/lib/fat_zebra/batch_spec.rb +59 -0
- data/spec/lib/fat_zebra/card_spec.rb +41 -0
- data/spec/lib/fat_zebra/config_spec.rb +52 -0
- data/spec/lib/fat_zebra/customer_spec.rb +53 -0
- data/spec/lib/fat_zebra/direct_credit_spec.rb +53 -0
- data/spec/lib/fat_zebra/direct_debit_spec.rb +53 -0
- data/spec/lib/fat_zebra/fat_zebra_object_spec.rb +116 -0
- data/spec/lib/fat_zebra/information_spec.rb +13 -0
- data/spec/lib/fat_zebra/payment_plan_spec.rb +94 -0
- data/spec/lib/fat_zebra/purchase_spec.rb +92 -0
- data/spec/lib/fat_zebra/refund_spec.rb +72 -0
- data/spec/lib/fat_zebra/util_spec.rb +24 -0
- data/spec/lib/fat_zebra/validation_spec.rb +22 -0
- data/spec/lib/fat_zebra/web_hook_spec.rb +50 -0
- data/spec/spec_helper.rb +49 -3
- data/spec/support/payloads.rb +43 -0
- metadata +238 -65
- data/FatZebra.gemspec +0 -31
- data/lib/fat_zebra/constants.rb +0 -2
- data/lib/fat_zebra/gateway.rb +0 -292
- data/lib/fat_zebra/models/base.rb +0 -33
- data/lib/fat_zebra/models/card.rb +0 -49
- data/lib/fat_zebra/models/purchase.rb +0 -185
- data/lib/fat_zebra/models/refund.rb +0 -46
- data/lib/fat_zebra/models/response.rb +0 -33
- data/lib/rest-client/request_ext.rb +0 -15
- data/spec/config_spec.rb +0 -37
- data/spec/gateway_spec.rb +0 -120
- data/spec/models/purchase_spec.rb +0 -55
- data/spec/models/refund_spec.rb +0 -9
- data/spec/models/response_spec.rb +0 -25
data/lib/fat_zebra/gateway.rb
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
module FatZebra
|
|
2
|
-
class Gateway
|
|
3
|
-
attr_accessor :username, :token, :gateway_server, :options
|
|
4
|
-
|
|
5
|
-
DEFAULT_OPTIONS = {:secure => true, :version => API_VERSION}
|
|
6
|
-
|
|
7
|
-
class << self
|
|
8
|
-
def configure(config)
|
|
9
|
-
g = Gateway.new(config.username, config.token, config.gateway || GATEWAY_SERVER)
|
|
10
|
-
g.options ||= {}
|
|
11
|
-
g.options[:test_mode] = config.test_mode
|
|
12
|
-
g.options.merge!(config.options || {})
|
|
13
|
-
g.proxy = g.options[:proxy]
|
|
14
|
-
|
|
15
|
-
g
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# Initializes a new gateway object
|
|
20
|
-
#
|
|
21
|
-
# @param [String] merchants username
|
|
22
|
-
# @param [String] merchants token for authentication
|
|
23
|
-
# @param [String] the server for the gateway, defaults to 'gateway.fatzebra.com.au'
|
|
24
|
-
# @param [Hash] the options for the gateway connection (e.g. secure, version etc)
|
|
25
|
-
#
|
|
26
|
-
# @return FatZebra::Gateway instance
|
|
27
|
-
def initialize(username, token, gateway_server = GATEWAY_SERVER, options = {})
|
|
28
|
-
self.username = username
|
|
29
|
-
self.token = token
|
|
30
|
-
self.gateway_server = gateway_server
|
|
31
|
-
self.options = DEFAULT_OPTIONS.merge(options)
|
|
32
|
-
self.proxy = self.options[:proxy]
|
|
33
|
-
|
|
34
|
-
require_field :username, :token, :gateway_server
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# Set the proxy for RestClient
|
|
38
|
-
#
|
|
39
|
-
# @param [String] val the proxy
|
|
40
|
-
#
|
|
41
|
-
# @return Nil
|
|
42
|
-
def proxy=(val)
|
|
43
|
-
self.options[:proxy] = val
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# Get the proxy set for RestClient
|
|
47
|
-
#
|
|
48
|
-
# @return [String] the proxy set for RestClient
|
|
49
|
-
def proxy
|
|
50
|
-
self.options[:proxy]
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# Performs a purchase transaction against the gateway
|
|
54
|
-
#
|
|
55
|
-
# amount - the amount as an integer e.g. (1.00 * 100).to_i
|
|
56
|
-
# card_data - a hash of the card data (example: {:card_holder => "John Smith", :number => "...", :expiry => "...", :cvv => "123"} or {:token => "abcdefg1"})
|
|
57
|
-
# card_holder - the card holders name
|
|
58
|
-
# card_number - the customers credit card number
|
|
59
|
-
# card_expiry - the customers card expiry date (as Date or string [mm/yyyy])
|
|
60
|
-
# cvv - the credit card verification value (cvv, cav, csc etc)
|
|
61
|
-
# reference - a reference for the purchase
|
|
62
|
-
# customer_ip - the customers IP address (for fraud prevention)
|
|
63
|
-
# currency - the currency of the transaction, ISO 4217 code (http://en.wikipedia.org/wiki/ISO_4217)
|
|
64
|
-
#
|
|
65
|
-
# Returns a new FatZebra::Models::Response (purchase) object
|
|
66
|
-
def purchase(amount, card_data, reference, customer_ip, currency = "AUD")
|
|
67
|
-
warn "[DEPRECATED] Gateway#purchase is deprecated, please use Purchase.create instead" unless options[:silence]
|
|
68
|
-
Models::Purchase.create(amount, card_data, reference, customer_ip, currency)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# Retrieves purchases specified by the options hash
|
|
72
|
-
#
|
|
73
|
-
# @param [Hash] options for lookup
|
|
74
|
-
# includes:
|
|
75
|
-
# - id (unique purchase ID)
|
|
76
|
-
# - reference (merchant reference)
|
|
77
|
-
# - from (Date)
|
|
78
|
-
# - to (Date)
|
|
79
|
-
# - offset (defaults to 0) - for pagination
|
|
80
|
-
# - limit (defaults to 10) for pagination
|
|
81
|
-
# @return [Array<Purchase>] array of purchases
|
|
82
|
-
# @deprecated Please use Purchase.find(options) instead
|
|
83
|
-
def purchases(options = {})
|
|
84
|
-
warn "[DEPRECATED] Gateway#purchases is deprecated, please use Purchase.find instead" unless options[:silence]
|
|
85
|
-
Models::Purchase.find(options)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# Public: Performs an authorization transaction against the gateway
|
|
89
|
-
# Note: Successful transactions must then be captured for funds to settle.
|
|
90
|
-
#
|
|
91
|
-
# amount - the amount as an integer e.g. (1.00 * 100).to_i
|
|
92
|
-
# card_number - the customers credit card number
|
|
93
|
-
# card_expiry - the customers card expiry date
|
|
94
|
-
# cvv - the credit card verification value (cvv, cav, csc etc)
|
|
95
|
-
# reference - a reference for the purchase
|
|
96
|
-
# customer_ip - the customers IP address (for fraud prevention)
|
|
97
|
-
#
|
|
98
|
-
# Returns a new FatZebra::Models::Purchase object
|
|
99
|
-
def authorize(amount, card_number, card_expiry, cvv, reference, customer_ip)
|
|
100
|
-
raise "Sorry we haven't compelted this functionality yet."
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
# Public: Captures a pre-authorized transaction
|
|
104
|
-
#
|
|
105
|
-
# transaction_id - the authorization ID
|
|
106
|
-
# amount - the amount to capture, as an integer
|
|
107
|
-
#
|
|
108
|
-
# Returns a new FatZebra::Models::Purchase object
|
|
109
|
-
def capture(transaction_id, amount)
|
|
110
|
-
raise "Sorry we haven't compelted this functionality yet."
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
# Refunds a transaction
|
|
114
|
-
#
|
|
115
|
-
# @param [String] the ID of the original transaction to be refunded
|
|
116
|
-
# @param [Integer] the amount to be refunded, as an integer
|
|
117
|
-
# @param [String] the reference for the refund
|
|
118
|
-
#
|
|
119
|
-
# @return [Refund] refund result object
|
|
120
|
-
# @deprecated Please use Refund.create or Purchase#refund instead
|
|
121
|
-
def refund(transaction_id, amount, reference)
|
|
122
|
-
warn "[DEPRECATED] Gateway#refund is deprecated, please use Refund.create or Purchase#refund instead`" unless options[:silence]
|
|
123
|
-
Models::Refund.create(transaction_id, amount, reference)
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
# Pings the Fat Zebra service
|
|
127
|
-
#
|
|
128
|
-
# @param [String] the data to be echoed back
|
|
129
|
-
#
|
|
130
|
-
# @return true if reply is valid, false if the request times out, or otherwise
|
|
131
|
-
def ping(nonce = SecureRandom.hex)
|
|
132
|
-
begin
|
|
133
|
-
response = RestClient.get(build_url("ping") + "?echo=#{nonce}")
|
|
134
|
-
response = JSON.parse(response)
|
|
135
|
-
|
|
136
|
-
response["echo"] == nonce
|
|
137
|
-
rescue => e
|
|
138
|
-
return false
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
# Tokenizes a credit card
|
|
143
|
-
#
|
|
144
|
-
# @param [String] the credit card holder name
|
|
145
|
-
# @param [String] the card number
|
|
146
|
-
# @param [String] the credit card expiry date (mm/yyyy)
|
|
147
|
-
# @param [String] the card CVV
|
|
148
|
-
#
|
|
149
|
-
# @return Response
|
|
150
|
-
# @deprecated Please use Card.create instead
|
|
151
|
-
def tokenize(card_holder, card_number, expiry, cvv)
|
|
152
|
-
warn "[DEPRECATED] Gateway#tokenize is deprecated, please use Card.create instead" unless options[:silence]
|
|
153
|
-
Models::Card.create(card_holder, card_number, expiry, cvv)
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
# Public: Performs the HTTP(s) request and returns a response object, handing errors etc
|
|
157
|
-
#
|
|
158
|
-
# method - the request method (:post or :get)
|
|
159
|
-
# resource - the resource for the request
|
|
160
|
-
# data - a hash of the data for the request
|
|
161
|
-
#
|
|
162
|
-
# Returns hash of response data
|
|
163
|
-
def make_request(method, resource, data = nil)
|
|
164
|
-
resource = get_resource(resource, method, data)
|
|
165
|
-
|
|
166
|
-
if [:post, :put, :patch].include?(method)
|
|
167
|
-
data[:test] = options[:test_mode] if options[:test_mode]
|
|
168
|
-
payload = data.to_json
|
|
169
|
-
else
|
|
170
|
-
payload = {}
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
headers = options[:headers] || {}
|
|
174
|
-
|
|
175
|
-
if method == :get
|
|
176
|
-
resource.send(method, headers) do |response, request, result, &block|
|
|
177
|
-
handle_response(response)
|
|
178
|
-
end
|
|
179
|
-
else
|
|
180
|
-
# Add in test flag is test mode...
|
|
181
|
-
resource.send(method, payload, headers) do |response, request, result, &block|
|
|
182
|
-
handle_response(response)
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
private
|
|
188
|
-
# Private: Extracts the date value from a Date/DateTime value
|
|
189
|
-
#
|
|
190
|
-
# value - the string or date value to extract the value from
|
|
191
|
-
#
|
|
192
|
-
# Returns date string as MM/YYYY
|
|
193
|
-
def extract_date(value)
|
|
194
|
-
return nil if value.nil?
|
|
195
|
-
|
|
196
|
-
if value.is_a?(String)
|
|
197
|
-
return value
|
|
198
|
-
elsif value.respond_to?(:strftime)
|
|
199
|
-
return value.strftime("%m/%Y")
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
# Private: Verifies a require field is present and has a value
|
|
204
|
-
#
|
|
205
|
-
# fields - array of fields required to be present
|
|
206
|
-
#
|
|
207
|
-
# Returns nil
|
|
208
|
-
# Raises InvalidArgumentError if field is missing
|
|
209
|
-
def require_field(*fields)
|
|
210
|
-
fields.each do |field|
|
|
211
|
-
val = self.send(field)
|
|
212
|
-
raise InvalidArgumentError, "Parameter #{field} is required", caller if (val.nil? || val.to_s.length == 0)
|
|
213
|
-
end
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
# Public: Builds the URL for the request
|
|
217
|
-
# If data is provided it will append as name/value pairs for a get request
|
|
218
|
-
#
|
|
219
|
-
# resource - the resource to append to the URL (e.g. purchases for https://something.com/purchases)
|
|
220
|
-
# data (optional) - a hash of the data name value pairs - if nil it will be ignored
|
|
221
|
-
#
|
|
222
|
-
# Returns the URL as a string
|
|
223
|
-
def build_url(resource, data = nil)
|
|
224
|
-
proto = case options[:secure]
|
|
225
|
-
when true
|
|
226
|
-
"https://"
|
|
227
|
-
when false
|
|
228
|
-
"http://"
|
|
229
|
-
end
|
|
230
|
-
version = options[:version]
|
|
231
|
-
if version.nil?
|
|
232
|
-
url = "#{proto}#{self.gateway_server}/#{resource}"
|
|
233
|
-
else
|
|
234
|
-
url = "#{proto}#{self.gateway_server}/v#{version}/#{resource}"
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
unless data.nil?
|
|
238
|
-
url = url + "?" +
|
|
239
|
-
data.map do |key, value|
|
|
240
|
-
"#{key}=#{value}" # TODO: URL Encode this
|
|
241
|
-
end.join("&")
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
url
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
# Public: Builds a new RestClient resource object
|
|
248
|
-
#
|
|
249
|
-
# uri - the full URI for the request
|
|
250
|
-
# method - the method for the request - either :post or :get
|
|
251
|
-
# data - the data for the request - only required for :get methods
|
|
252
|
-
#
|
|
253
|
-
# Returns a new RestClient resource
|
|
254
|
-
def get_resource(uri, method = :post, data = nil)
|
|
255
|
-
url = build_url(uri, (method == :get ? data : nil))
|
|
256
|
-
ssl_options = options[:secure] ? {
|
|
257
|
-
:ssl_ca_file => File.expand_path(File.dirname(__FILE__) + "/../../vendor/cacert.pem"),
|
|
258
|
-
:verify_ssl => OpenSSL::SSL::VERIFY_PEER
|
|
259
|
-
} : {}
|
|
260
|
-
|
|
261
|
-
opts = {:user => self.username, :password => self.token, proxy: self.options[:proxy]}
|
|
262
|
-
if method == :get
|
|
263
|
-
url = build_url(uri, data)
|
|
264
|
-
else
|
|
265
|
-
url = build_url(uri)
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
RestClient::Resource.new(url, opts.merge(ssl_options))
|
|
269
|
-
end
|
|
270
|
-
|
|
271
|
-
def handle_response(response)
|
|
272
|
-
case response.code
|
|
273
|
-
when 201
|
|
274
|
-
JSON.parse(response)
|
|
275
|
-
when 200
|
|
276
|
-
JSON.parse(response)
|
|
277
|
-
when 422
|
|
278
|
-
JSON.parse(response)
|
|
279
|
-
when 400
|
|
280
|
-
raise RequestError, "Bad Data"
|
|
281
|
-
when 401
|
|
282
|
-
raise RequestError, "Unauthorized, please check your username and token"
|
|
283
|
-
when 404
|
|
284
|
-
raise RequestError, "Requested Resource not found"
|
|
285
|
-
when 500
|
|
286
|
-
raise RequestError, "Server Error, please check with Gateway"
|
|
287
|
-
when 501
|
|
288
|
-
raise RequestError, "Problem processing your request - please check your data"
|
|
289
|
-
end
|
|
290
|
-
end
|
|
291
|
-
end
|
|
292
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
module FatZebra
|
|
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
|
-
|
|
18
|
-
self.raw = attrs if self.respond_to?(:raw=)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def inspect
|
|
22
|
-
inspection = @@attributes.collect { |name|
|
|
23
|
-
"#{name}: #{instance_variable_get("@#{name}")}"
|
|
24
|
-
}.compact.join(", ")
|
|
25
|
-
"#<#{self.class} #{inspection}>"
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def to_s
|
|
29
|
-
inspect
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
module FatZebra
|
|
2
|
-
module Models
|
|
3
|
-
class Card < Base
|
|
4
|
-
attribute :token, :card_holder, :card_number, :card_expiry, :transaction_count, :raw
|
|
5
|
-
|
|
6
|
-
def successful; true; end
|
|
7
|
-
|
|
8
|
-
class << self
|
|
9
|
-
# Tokenizes a credit card
|
|
10
|
-
#
|
|
11
|
-
# @param [String] the credit card holder name
|
|
12
|
-
# @param [String] the card number
|
|
13
|
-
# @param [String] the credit card expiry date (mm/yyyy)
|
|
14
|
-
# @param [String] the card CVV
|
|
15
|
-
# @param [Hash] optional any additional data which should be merged into the request
|
|
16
|
-
#
|
|
17
|
-
# @return Response
|
|
18
|
-
def create(card_holder, card_number, expiry, cvv, optional = {})
|
|
19
|
-
params = {
|
|
20
|
-
:card_holder => card_holder,
|
|
21
|
-
:card_number => card_number,
|
|
22
|
-
:card_expiry => expiry,
|
|
23
|
-
:cvv => cvv
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
params.merge!(optional)
|
|
27
|
-
|
|
28
|
-
response = FatZebra.gateway.make_request(:post, "credit_cards", params)
|
|
29
|
-
Response.new(response, :card)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# Update the credit card expiry date
|
|
33
|
-
#
|
|
34
|
-
# @param [String] token the credit card token
|
|
35
|
-
# @param [String] expiry the new expiry date (format: mm/yyyy)
|
|
36
|
-
#
|
|
37
|
-
# @return [Response]
|
|
38
|
-
def update_expiry(token, expiry)
|
|
39
|
-
params = {
|
|
40
|
-
card_expiry: expiry
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
response = FatZebra.gateway.make_request(:put, "credit_cards/#{token}", params)
|
|
44
|
-
Response.new(response, :card)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
module FatZebra
|
|
2
|
-
module Models
|
|
3
|
-
class Purchase < Base
|
|
4
|
-
attribute :id, :amount, :reference, :message, :authorization, :transaction_id, :card_number,
|
|
5
|
-
:card_holder, :card_expiry, :authorized, :successful, :card_token, :currency, :raw, :captured, :captured_amount,
|
|
6
|
-
:response_code, :rrn, :cvv_match, :fraud_result, :fraud_messages, :settlement_date, :transaction_date, :metadata
|
|
7
|
-
|
|
8
|
-
# Refunds the current transaction
|
|
9
|
-
#
|
|
10
|
-
# @param [Integer] amount the amount to be refunded
|
|
11
|
-
# @param [String] reference the refund reference
|
|
12
|
-
#
|
|
13
|
-
# @return Response (Refund) object
|
|
14
|
-
def refund(amount, reference)
|
|
15
|
-
Refund.create(self.id, amount, reference)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# Captures an authorization
|
|
19
|
-
#
|
|
20
|
-
# @param [Integer] amount the amount to capture. (Optional)
|
|
21
|
-
#
|
|
22
|
-
# @return [Response] Purchase response object
|
|
23
|
-
def capture(amount = nil)
|
|
24
|
-
if amount.nil?
|
|
25
|
-
params = {}
|
|
26
|
-
else
|
|
27
|
-
params = {
|
|
28
|
-
:amount => amount
|
|
29
|
-
}
|
|
30
|
-
end
|
|
31
|
-
response = FatZebra.gateway.make_request(:post, "purchases/#{self.id}/capture", params)
|
|
32
|
-
resp = Response.new(response)
|
|
33
|
-
|
|
34
|
-
if resp.successful && resp.purchase.successful
|
|
35
|
-
self.captured_amount = amount || self.amount
|
|
36
|
-
return true
|
|
37
|
-
else
|
|
38
|
-
raise StandardError, "Unable to capture purchase - #{resp.errors.join(',')}"
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Returns the record as a Hash
|
|
43
|
-
#
|
|
44
|
-
# @return [Hash]
|
|
45
|
-
def to_hash
|
|
46
|
-
{
|
|
47
|
-
id: self.id,
|
|
48
|
-
amount: self.amount,
|
|
49
|
-
reference: self.reference,
|
|
50
|
-
message: self.message,
|
|
51
|
-
authorization: self.authorization,
|
|
52
|
-
card_number: self.card_number,
|
|
53
|
-
card_holder: self.card_holder,
|
|
54
|
-
card_expiry: self.card_expiry,
|
|
55
|
-
card_token: self.card_token,
|
|
56
|
-
currency: self.currency,
|
|
57
|
-
authorized: self.authorized,
|
|
58
|
-
successful: self.successful,
|
|
59
|
-
captured: self.captured,
|
|
60
|
-
captured_amount: self.captured_amount,
|
|
61
|
-
response_code: self.response_code,
|
|
62
|
-
cvv_match: self.cvv_match,
|
|
63
|
-
rrn: self.rrn,
|
|
64
|
-
fraud_result: self.fraud_result,
|
|
65
|
-
fraud_messages: self.fraud_messages,
|
|
66
|
-
settlement_date: self.settlement_date,
|
|
67
|
-
transaction_date: self.transaction_date,
|
|
68
|
-
metadata: self.metadata || {}
|
|
69
|
-
}
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
class << self
|
|
73
|
-
# Performs a purchase transaction against the gateway
|
|
74
|
-
#
|
|
75
|
-
# @param [Integer] amount the amount as an integer e.g. (1.00 * 100).to_i
|
|
76
|
-
# @param [Hash] card_data a hash of the card data (example: {:card_holder => "John Smith", :number => "...", :expiry => "...", :cvv => "123"} or {:token => "abcdefg1"})
|
|
77
|
-
# @option card_data [String] card_holder the card holders name
|
|
78
|
-
# @option card_data [String] card_number the customers credit card number
|
|
79
|
-
# @option card_data [Date] expiry the customers card expiry date (as Date or string [mm/yyyy])
|
|
80
|
-
# @option card_data [String] cvv the credit card verification value (cvv, cav, csc etc)
|
|
81
|
-
# @param [String] reference a reference for the purchase
|
|
82
|
-
# @param [String] customer_ip the customers IP address (for fraud prevention)
|
|
83
|
-
# @param [String] currency currency code ("AUD", "USD", etc)
|
|
84
|
-
# @param [Hash] optional any optional parameters to be included in the payload
|
|
85
|
-
#
|
|
86
|
-
# @return [Response] response (purchase) object
|
|
87
|
-
def create(amount, card_data, reference, customer_ip, currency = 'AUD', optional = {})
|
|
88
|
-
params = {
|
|
89
|
-
:amount => amount,
|
|
90
|
-
:card_holder => card_data.delete(:card_holder),
|
|
91
|
-
:card_number => card_data.delete(:number),
|
|
92
|
-
:card_expiry => extract_date(card_data.delete(:expiry)),
|
|
93
|
-
:cvv => card_data.delete(:cvv),
|
|
94
|
-
:card_token => card_data.delete(:token),
|
|
95
|
-
:reference => reference,
|
|
96
|
-
:customer_ip => customer_ip,
|
|
97
|
-
:currency => currency
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
params.delete_if {|_, value| value.nil? } # If token is nil, remove, otherwise, remove card values
|
|
101
|
-
params.merge!(optional)
|
|
102
|
-
validate_params!(params)
|
|
103
|
-
response = FatZebra.gateway.make_request(:post, 'purchases', params)
|
|
104
|
-
Response.new(response)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# Retrieves purchases specified by the options hash
|
|
108
|
-
#
|
|
109
|
-
# @param [Hash] options for lookup
|
|
110
|
-
# @option options [String] id the unique purchase ID
|
|
111
|
-
# @option options [String] reference the merchant reference
|
|
112
|
-
# @option options [DateTime] from the start date to search from
|
|
113
|
-
# @option options [DateTime] to the end date time to search to
|
|
114
|
-
# @option options [Integer] offset the start page for pagination
|
|
115
|
-
# @option options [Integer] limit the maximum number of records to return in the query. Maximum 10
|
|
116
|
-
#
|
|
117
|
-
# @return [Array<Purchase>] array of purchases
|
|
118
|
-
def find(options = {})
|
|
119
|
-
id = options.delete(:id)
|
|
120
|
-
options.merge!({:offets => 0, :limit => 10})
|
|
121
|
-
|
|
122
|
-
# Format dates for the request
|
|
123
|
-
options[:from] = options[:from].strftime('%Y%m%dT%H%M') if options[:from]
|
|
124
|
-
options[:to] = options[:to].strftime('%Y%m%dT%H%M') if options[:to]
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if id.nil?
|
|
128
|
-
response = FatZebra.gateway.make_request(:get, 'purchases', options)
|
|
129
|
-
if response['successful']
|
|
130
|
-
purchases = []
|
|
131
|
-
response['response'].each do |purchase|
|
|
132
|
-
purchases << Purchase.new(purchase)
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
purchases.size == 1 ? purchases.first : purchases
|
|
136
|
-
else
|
|
137
|
-
# TODO: This should raise a defined exception
|
|
138
|
-
raise StandardError, "Unable to query purchases, #{response['errors'].inspect}"
|
|
139
|
-
end
|
|
140
|
-
else
|
|
141
|
-
response = FatZebra.gateway.make_request(:get, "purchases/#{id}.json")
|
|
142
|
-
if response['successful']
|
|
143
|
-
Purchase.new(response['response'])
|
|
144
|
-
else
|
|
145
|
-
raise StandardError, "Unable to query purchases - #{response['errors'].inspect}"
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
private
|
|
151
|
-
# Private: Extracts the date value from a Date/DateTime value
|
|
152
|
-
#
|
|
153
|
-
# value - the string or date value to extract the value from
|
|
154
|
-
#
|
|
155
|
-
# Returns date string as MM/YYYY
|
|
156
|
-
def extract_date(value)
|
|
157
|
-
return nil if value.nil?
|
|
158
|
-
|
|
159
|
-
if value.is_a?(String)
|
|
160
|
-
return value
|
|
161
|
-
elsif value.respond_to?(:strftime)
|
|
162
|
-
return value.strftime('%m/%Y')
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
# Private: Validates the parameters provided meet the gateway requirements
|
|
167
|
-
#
|
|
168
|
-
# params - the parameter hash to be validated
|
|
169
|
-
#
|
|
170
|
-
# Returns nil
|
|
171
|
-
# Raises FatZebra::RequestError if errors are present.
|
|
172
|
-
def validate_params!(params)
|
|
173
|
-
@errors = []
|
|
174
|
-
@errors << 'number or token must be provided' unless params[:card_number].present? || params[:card_token].present? || params[:wallet].present?
|
|
175
|
-
@errors << 'amount must be provided' unless params[:amount].present? && params[:amount].to_f >= 0
|
|
176
|
-
@errors << 'expiry must be provided' unless params[:card_token].present? || params[:card_expiry].present? || params[:wallet].present?
|
|
177
|
-
@errors << 'reference must be provided' unless params[:reference].present?
|
|
178
|
-
@errors << 'customer_ip must be provided' unless params[:customer_ip].present?
|
|
179
|
-
|
|
180
|
-
raise FatZebra::RequestError.new("The following errors prevent the transaction from being submitted: #{@errors.to_sentence}") if @errors.any?
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
module FatZebra
|
|
2
|
-
module Models
|
|
3
|
-
class Refund < Base
|
|
4
|
-
attribute :amount, :reference, :refunded, :id, :message, :transaction_id, :original_transaction_id, :transaction_date, :settlement_date,
|
|
5
|
-
:response_code, :message, :rrn, :authorisation, :raw
|
|
6
|
-
|
|
7
|
-
# Returns the original transaction for this refund
|
|
8
|
-
#
|
|
9
|
-
# @return Purchase
|
|
10
|
-
def original_transaction
|
|
11
|
-
@original_transaction ||= Purchase.find(self.original_transaction_id)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# Indicates if the refund was successful or not
|
|
15
|
-
#
|
|
16
|
-
# @return Boolean
|
|
17
|
-
def successful
|
|
18
|
-
self.refunded == "Approved"
|
|
19
|
-
end
|
|
20
|
-
alias successful? successful
|
|
21
|
-
|
|
22
|
-
class << self
|
|
23
|
-
# Refunds a transaction
|
|
24
|
-
#
|
|
25
|
-
# @param [String] the ID of the original transaction to be refunded
|
|
26
|
-
# @param [Integer] the amount to be refunded, as an integer
|
|
27
|
-
# @param [String] the reference for the refund
|
|
28
|
-
# @param [Hash] optional optional parameters to be included in the request
|
|
29
|
-
#
|
|
30
|
-
# @return [Refund] refund result object
|
|
31
|
-
def create(transaction_id, amount, reference, optional = {})
|
|
32
|
-
params = {
|
|
33
|
-
:transaction_id => transaction_id,
|
|
34
|
-
:amount => amount,
|
|
35
|
-
:reference => reference
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
params.merge!(optional)
|
|
39
|
-
|
|
40
|
-
response = FatZebra.gateway.make_request(:post, "refunds", params)
|
|
41
|
-
Response.new(response, :refund)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
module FatZebra
|
|
2
|
-
module Models
|
|
3
|
-
class Response
|
|
4
|
-
attr_accessor :successful, :result, :errors, :test, :raw
|
|
5
|
-
def initialize(response, type = :purchase)
|
|
6
|
-
self.raw = response.dup unless response.nil?
|
|
7
|
-
self.test = response["test"]
|
|
8
|
-
self.successful = response["successful"]
|
|
9
|
-
self.errors = response["errors"]
|
|
10
|
-
|
|
11
|
-
case type
|
|
12
|
-
when :purchase
|
|
13
|
-
self.result = Purchase.new(response["response"])
|
|
14
|
-
alias purchase result
|
|
15
|
-
when :refund
|
|
16
|
-
self.result = Refund.new(response["response"])
|
|
17
|
-
alias refund result
|
|
18
|
-
when :card
|
|
19
|
-
self.result = Card.new(response["response"])
|
|
20
|
-
alias card result
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def successful?
|
|
25
|
-
self.successful
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def test?
|
|
29
|
-
self.test
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module RestClientExt
|
|
2
|
-
module ProxyRequest
|
|
3
|
-
def net_http_class
|
|
4
|
-
if RestClient.proxy
|
|
5
|
-
proxy_uri = URI.parse(RestClient.proxy)
|
|
6
|
-
Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
|
|
7
|
-
elsif @args[:proxy]
|
|
8
|
-
proxy_uri = URI.parse(@args[:proxy])
|
|
9
|
-
Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
|
|
10
|
-
else
|
|
11
|
-
Net::HTTP
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
data/spec/config_spec.rb
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe FatZebra::Config do
|
|
4
|
-
it "should configure with a block" do
|
|
5
|
-
FatZebra.configure do
|
|
6
|
-
username "TEST"
|
|
7
|
-
token "TEST"
|
|
8
|
-
sandbox true
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
FatZebra.config.username.should == "TEST"
|
|
12
|
-
FatZebra.config.token.should == "TEST"
|
|
13
|
-
FatZebra.config.sandbox.should be_true
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "should configure from a hash" do
|
|
17
|
-
config = FatZebra.configure(:username => "TEST", :token => "TEST", :sandbox => true)
|
|
18
|
-
config.username.should == 'TEST'
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "should prepare a new gateway when configured" do
|
|
22
|
-
FatZebra.configure do
|
|
23
|
-
username "TEST"
|
|
24
|
-
token "TEST"
|
|
25
|
-
test_mode true
|
|
26
|
-
sandbox true
|
|
27
|
-
options :headers => {"A" => "B"}
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
FatZebra.gateway.should_not be_nil
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "should raise an error when trying to access the gateway before it is configured" do
|
|
34
|
-
FatZebra.config = nil
|
|
35
|
-
lambda { FatZebra.gateway }.should raise_exception(FatZebra::GatewayError)
|
|
36
|
-
end
|
|
37
|
-
end
|