fat_zebra_multi 3.1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.rspec +0 -0
- data/.rubocop.yml +44 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/README.md +104 -0
- data/Rakefile +11 -0
- data/fat_zebra_multi.gemspec +27 -0
- data/lib/fat_zebra.rb +65 -0
- data/lib/fat_zebra/api_helper.rb +91 -0
- data/lib/fat_zebra/api_operation/delete.rb +38 -0
- data/lib/fat_zebra/api_operation/find.rb +30 -0
- data/lib/fat_zebra/api_operation/save.rb +67 -0
- data/lib/fat_zebra/api_operation/search.rb +39 -0
- data/lib/fat_zebra/api_operation/void.rb +52 -0
- data/lib/fat_zebra/api_resource.rb +88 -0
- data/lib/fat_zebra/bank_account.rb +20 -0
- data/lib/fat_zebra/batch.rb +60 -0
- data/lib/fat_zebra/card.rb +23 -0
- data/lib/fat_zebra/config.rb +90 -0
- data/lib/fat_zebra/customer.rb +26 -0
- data/lib/fat_zebra/direct_credit.rb +26 -0
- data/lib/fat_zebra/direct_debit.rb +26 -0
- data/lib/fat_zebra/errors.rb +37 -0
- data/lib/fat_zebra/fat_zebra_object.rb +68 -0
- data/lib/fat_zebra/information.rb +29 -0
- data/lib/fat_zebra/object_helper.rb +119 -0
- data/lib/fat_zebra/payment_plan.rb +61 -0
- data/lib/fat_zebra/purchase.rb +96 -0
- data/lib/fat_zebra/refund.rb +27 -0
- data/lib/fat_zebra/request.rb +174 -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 +57 -0
- data/lib/fat_zebra/util.rb +71 -0
- data/lib/fat_zebra/validation.rb +67 -0
- data/lib/fat_zebra/version.rb +3 -0
- data/lib/fat_zebra/web_hook.rb +22 -0
- data/spec/cassettes/FatZebra_BankAccount/_create/1_1_1.yml +53 -0
- data/spec/cassettes/FatZebra_BankAccount/_create/1_1_2.yml +53 -0
- data/spec/cassettes/FatZebra_BankAccount/_search/1_2_1.yml +164 -0
- data/spec/cassettes/FatZebra_BankAccount/_search/1_2_2.yml +164 -0
- data/spec/cassettes/FatZebra_BankAccount/_search/1_2_3.yml +164 -0
- data/spec/cassettes/FatZebra_Batch/_create/with_file/1_1_1_1.yml +61 -0
- data/spec/cassettes/FatZebra_Batch/_create/with_file/1_1_1_2.yml +61 -0
- data/spec/cassettes/FatZebra_Batch/_create/with_path/1_1_2_1.yml +61 -0
- data/spec/cassettes/FatZebra_Batch/_create/with_path/1_1_2_2.yml +61 -0
- data/spec/cassettes/FatZebra_Batch/_find/1_2_1.yml +112 -0
- data/spec/cassettes/FatZebra_Batch/_find/1_2_2.yml +112 -0
- data/spec/cassettes/FatZebra_Batch/_result/1_4_1.yml +163 -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 +54 -0
- data/spec/cassettes/FatZebra_Card/_create/1_1_2.yml +54 -0
- data/spec/cassettes/FatZebra_Card/_create/1_1_3.yml +54 -0
- data/spec/cassettes/FatZebra_Card/_create/1_1_4.yml +54 -0
- data/spec/cassettes/FatZebra_Card/_create/1_1_5.yml +54 -0
- data/spec/cassettes/FatZebra_Card/_create/1_1_6.yml +54 -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 +54 -0
- data/spec/cassettes/FatZebra_Customer/_create/1_1_1.yml +55 -0
- data/spec/cassettes/FatZebra_Customer/_create/1_1_2.yml +55 -0
- data/spec/cassettes/FatZebra_Customer/_create/1_1_3.yml +55 -0
- data/spec/cassettes/FatZebra_Customer/_create/1_1_4.yml +55 -0
- data/spec/cassettes/FatZebra_Customer/_create/1_1_5.yml +55 -0
- data/spec/cassettes/FatZebra_Customer/_create/1_1_6.yml +55 -0
- data/spec/cassettes/FatZebra_Customer/_delete/1_5_1.yml +103 -0
- data/spec/cassettes/FatZebra_Customer/_find/1_3_1.yml +107 -0
- data/spec/cassettes/FatZebra_Customer/_find/1_3_2.yml +107 -0
- data/spec/cassettes/FatZebra_Customer/_search/1_2_1.yml +60 -0
- data/spec/cassettes/FatZebra_Customer/_search/1_2_2.yml +60 -0
- data/spec/cassettes/FatZebra_Customer/_search/1_2_3.yml +60 -0
- data/spec/cassettes/FatZebra_Customer/_update/1_4_1.yml +106 -0
- data/spec/cassettes/FatZebra_Customer/_update/1_4_2.yml +106 -0
- data/spec/cassettes/FatZebra_DirectCredit/_create/1_1_1.yml +52 -0
- data/spec/cassettes/FatZebra_DirectCredit/_create/1_1_2.yml +52 -0
- data/spec/cassettes/FatZebra_DirectCredit/_create/1_1_3.yml +52 -0
- data/spec/cassettes/FatZebra_DirectCredit/_create/1_1_4.yml +52 -0
- data/spec/cassettes/FatZebra_DirectCredit/_create/validations/valid/1_1_5_1_1.yml +52 -0
- data/spec/cassettes/FatZebra_DirectCredit/_delete/1_4_1.yml +99 -0
- data/spec/cassettes/FatZebra_DirectCredit/_find/1_2_1.yml +103 -0
- data/spec/cassettes/FatZebra_DirectCredit/_find/1_2_2.yml +103 -0
- data/spec/cassettes/FatZebra_DirectCredit/_find/1_2_3.yml +103 -0
- data/spec/cassettes/FatZebra_DirectCredit/_search/1_3_1.yml +152 -0
- data/spec/cassettes/FatZebra_DirectCredit/_search/1_3_2.yml +152 -0
- data/spec/cassettes/FatZebra_DirectDebit/_create/1_1_1.yml +52 -0
- data/spec/cassettes/FatZebra_DirectDebit/_create/1_1_2.yml +52 -0
- data/spec/cassettes/FatZebra_DirectDebit/_create/1_1_3.yml +52 -0
- data/spec/cassettes/FatZebra_DirectDebit/_create/1_1_4.yml +52 -0
- data/spec/cassettes/FatZebra_DirectDebit/_create/validations/valid/1_1_5_1_1.yml +52 -0
- data/spec/cassettes/FatZebra_DirectDebit/_delete/1_4_1.yml +99 -0
- data/spec/cassettes/FatZebra_DirectDebit/_find/1_2_1.yml +103 -0
- data/spec/cassettes/FatZebra_DirectDebit/_find/1_2_2.yml +103 -0
- data/spec/cassettes/FatZebra_DirectDebit/_find/1_2_3.yml +103 -0
- data/spec/cassettes/FatZebra_DirectDebit/_search/1_3_1.yml +152 -0
- data/spec/cassettes/FatZebra_DirectDebit/_search/1_3_2.yml +152 -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_8_1.yml +222 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_active_/1_8_2.yml +222 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_create/1_1_1.yml +110 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_create/1_1_2.yml +110 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_create/1_1_3.yml +110 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_delete/1_5_1.yml +158 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_destroy/1_6_1.yml +158 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_find/1_2_1.yml +167 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_find/1_2_2.yml +167 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_find/1_2_3.yml +167 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_suspend_/1_7_1.yml +166 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_suspend_/1_7_2.yml +166 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_update/1_3_1.yml +160 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_update/1_3_2.yml +160 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_update/1_3_3.yml +160 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_update/1_4_1.yml +166 -0
- data/spec/cassettes/FatZebra_PaymentPlan/_update/1_4_2.yml +166 -0
- data/spec/cassettes/FatZebra_Purchase/_capture/1_5_1.yml +115 -0
- data/spec/cassettes/FatZebra_Purchase/_capture/1_5_2.yml +115 -0
- data/spec/cassettes/FatZebra_Purchase/_capture/1_5_3.yml +115 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_1.yml +53 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_10.yml +53 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_11.yml +53 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_12.yml +53 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_13.yml +53 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_2.yml +53 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_3.yml +53 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_4.yml +53 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_5.yml +53 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_6.yml +53 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_7.yml +53 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_8.yml +53 -0
- data/spec/cassettes/FatZebra_Purchase/_create/1_1_9.yml +53 -0
- data/spec/cassettes/FatZebra_Purchase/_create/bad_request/1_1_14_1.yml +55 -0
- data/spec/cassettes/FatZebra_Purchase/_create/bad_request/1_1_14_2.yml +55 -0
- data/spec/cassettes/FatZebra_Purchase/_find/1_2_1.yml +117 -0
- data/spec/cassettes/FatZebra_Purchase/_find/1_2_2.yml +117 -0
- data/spec/cassettes/FatZebra_Purchase/_find/1_2_3.yml +117 -0
- data/spec/cassettes/FatZebra_Purchase/_find/1_2_4.yml +117 -0
- data/spec/cassettes/FatZebra_Purchase/_refund/1_4_1.yml +115 -0
- data/spec/cassettes/FatZebra_Purchase/_refund/1_4_2.yml +115 -0
- data/spec/cassettes/FatZebra_Purchase/_refund/1_4_3.yml +115 -0
- data/spec/cassettes/FatZebra_Purchase/_search/1_3_1.yml +164 -0
- data/spec/cassettes/FatZebra_Purchase/_search/1_3_2.yml +164 -0
- data/spec/cassettes/FatZebra_Purchase/_search/1_3_3.yml +164 -0
- data/spec/cassettes/FatZebra_Purchase/_settlement/1_8_1.yml +652 -0
- data/spec/cassettes/FatZebra_Purchase/_settlement/1_8_2.yml +652 -0
- data/spec/cassettes/FatZebra_Purchase/_settlement/1_8_3.yml +652 -0
- data/spec/cassettes/FatZebra_Purchase/_void/1_6_1.yml +103 -0
- data/spec/cassettes/FatZebra_Purchase/_void/1_6_2.yml +103 -0
- data/spec/cassettes/FatZebra_Purchase/_void/1_6_3.yml +103 -0
- data/spec/cassettes/FatZebra_Purchase/_void/1_6_4.yml +103 -0
- data/spec/cassettes/FatZebra_Purchase/_void/1_7_1.yml +103 -0
- data/spec/cassettes/FatZebra_Purchase/_void/1_7_2.yml +103 -0
- data/spec/cassettes/FatZebra_Purchase/_void/1_7_3.yml +103 -0
- data/spec/cassettes/FatZebra_Purchase/_void/1_7_4.yml +103 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_1.yml +103 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_10.yml +103 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_2.yml +103 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_3.yml +103 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_4.yml +103 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_5.yml +103 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_6.yml +103 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_7.yml +103 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_8.yml +103 -0
- data/spec/cassettes/FatZebra_Refund/_create/1_1_9.yml +103 -0
- data/spec/cassettes/FatZebra_Refund/_find/1_2_1.yml +155 -0
- data/spec/cassettes/FatZebra_Refund/_find/1_2_2.yml +155 -0
- data/spec/cassettes/FatZebra_Refund/_find/1_2_3.yml +155 -0
- data/spec/cassettes/FatZebra_Refund/_search/responds_with_the_newly-created_refunds.yml +214 -0
- data/spec/cassettes/FatZebra_Refund/_void/1_4_1.yml +153 -0
- data/spec/cassettes/FatZebra_Refund/_void/1_4_2.yml +153 -0
- data/spec/cassettes/FatZebra_Refund/_void/1_4_3.yml +153 -0
- data/spec/cassettes/FatZebra_Refund/_void/1_4_4.yml +153 -0
- data/spec/cassettes/FatZebra_WebHook/_create/1_1_1.yml +53 -0
- data/spec/cassettes/FatZebra_WebHook/_create/1_1_2.yml +53 -0
- data/spec/cassettes/FatZebra_WebHook/_create/1_1_3.yml +53 -0
- data/spec/cassettes/FatZebra_WebHook/_delete/1_4_1.yml +101 -0
- data/spec/cassettes/FatZebra_WebHook/_search/1_2_1.yml +298 -0
- data/spec/cassettes/FatZebra_WebHook/_search/1_2_2.yml +300 -0
- data/spec/cassettes/FatZebra_WebHook/_update/1_3_1.yml +104 -0
- data/spec/cassettes/FatZebra_WebHook/_update/1_3_2.yml +104 -0
- data/spec/cassettes/Multiple_accounts/The_basics/1_1_5.yml +59 -0
- data/spec/cassettes/Multiple_accounts/The_basics/1_1_6.yml +59 -0
- data/spec/fixtures/batch_test.csv +4 -0
- data/spec/lib/fat_zebra/api_resource_spec.rb +25 -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 +69 -0
- data/spec/lib/fat_zebra/customer_spec.rb +53 -0
- data/spec/lib/fat_zebra/direct_credit_spec.rb +74 -0
- data/spec/lib/fat_zebra/direct_debit_spec.rb +74 -0
- data/spec/lib/fat_zebra/fat_zebra_object_spec.rb +117 -0
- data/spec/lib/fat_zebra/information_spec.rb +13 -0
- data/spec/lib/fat_zebra/multiple_accounts_spec.rb +69 -0
- data/spec/lib/fat_zebra/payment_plan_spec.rb +94 -0
- data/spec/lib/fat_zebra/purchase_spec.rb +105 -0
- data/spec/lib/fat_zebra/refund_spec.rb +95 -0
- data/spec/lib/fat_zebra/request_spec.rb +59 -0
- data/spec/lib/fat_zebra/util_spec.rb +43 -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 +68 -0
- data/spec/support/payloads.rb +43 -0
- data/vendor/cacert.pem +3390 -0
- metadata +338 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
module FatZebra
|
2
|
+
class APIOperation
|
3
|
+
##
|
4
|
+
# == Save (create or update) a resource for the API
|
5
|
+
#
|
6
|
+
module Save
|
7
|
+
module ClassMethods
|
8
|
+
|
9
|
+
##
|
10
|
+
# Create an API Resource and validate the params for the API.
|
11
|
+
#
|
12
|
+
# @param [Hash] params for the request
|
13
|
+
# @param [Hash] Additional options for the request
|
14
|
+
#
|
15
|
+
# @return [FatZebra::Object] response from the API
|
16
|
+
def create(params = {}, options = {})
|
17
|
+
valid!(params, :create) if respond_to?(:valid!)
|
18
|
+
|
19
|
+
response = request(:post, resource_path, params, options)
|
20
|
+
initialize_from(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Update an API Resource and validate params for the API
|
25
|
+
#
|
26
|
+
# @param [String] id for the request
|
27
|
+
# @param [Hash] params for the request
|
28
|
+
# @param [Hash] Additional options for the request
|
29
|
+
#
|
30
|
+
# @return [FatZebra::Object] response from the API
|
31
|
+
def update(id, params = {}, options = {})
|
32
|
+
valid!(params, :update) if respond_to?(:valid!)
|
33
|
+
|
34
|
+
response = request(:put, "#{resource_path}/#{id}", params, options)
|
35
|
+
initialize_from(response)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Create or Update an API Resource
|
42
|
+
#
|
43
|
+
# @param [Hash] params for the request
|
44
|
+
# @param [Hash] Additional options for the request
|
45
|
+
#
|
46
|
+
# @return [FatZebra::Object] response from the API
|
47
|
+
def save(params = {}, options = {})
|
48
|
+
path = singleton_methods.include?(:id) ? "#{resource_path}/#{id}" : resource_path
|
49
|
+
method = singleton_methods.include?(:id) ? :put : :post
|
50
|
+
|
51
|
+
params_for_save = to_hash.merge(params)
|
52
|
+
|
53
|
+
# Remove the id from the params to save, it should not be updated.
|
54
|
+
params_for_save.delete('id')
|
55
|
+
|
56
|
+
response = request(method, path, params_for_save, options)
|
57
|
+
update_from(response)
|
58
|
+
end
|
59
|
+
alias update save
|
60
|
+
|
61
|
+
def self.included(base)
|
62
|
+
base.extend(ClassMethods)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module FatZebra
|
2
|
+
class APIOperation
|
3
|
+
##
|
4
|
+
# == Search resources for the API
|
5
|
+
#
|
6
|
+
module Search
|
7
|
+
|
8
|
+
##
|
9
|
+
# Default params for the API
|
10
|
+
DEFAULT_PARAMS = {
|
11
|
+
offset: 0,
|
12
|
+
limit: 10
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
|
17
|
+
##
|
18
|
+
# Search for API Resources
|
19
|
+
#
|
20
|
+
# @param [Hash] params for the request
|
21
|
+
# @param [Hash] Additional options for the request
|
22
|
+
#
|
23
|
+
# @return [FatZebra::Object] response from the API
|
24
|
+
def search(params = {}, options = {})
|
25
|
+
params = DEFAULT_PARAMS.merge(params)
|
26
|
+
|
27
|
+
response = request(:get, resource_path, params, options)
|
28
|
+
initialize_from(response)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.included(base)
|
34
|
+
base.extend(ClassMethods)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module FatZebra
|
2
|
+
class APIOperation
|
3
|
+
##
|
4
|
+
# == Void a resource for the API
|
5
|
+
#
|
6
|
+
module Void
|
7
|
+
module ClassMethods
|
8
|
+
|
9
|
+
##
|
10
|
+
# Void an API Resource and validate params for the API
|
11
|
+
#
|
12
|
+
# @param [String] id for the request
|
13
|
+
# @param [Hash] params for the request
|
14
|
+
# @param [Hash] Additional options for the request
|
15
|
+
#
|
16
|
+
# @return [FatZebra::Object] response from the API
|
17
|
+
def void(id, params = {}, options = {})
|
18
|
+
valid!(params, :void) if respond_to?(:valid!)
|
19
|
+
|
20
|
+
params = {
|
21
|
+
id: id
|
22
|
+
}.merge(params)
|
23
|
+
|
24
|
+
response = request(:post, "#{resource_path}/void", params, options)
|
25
|
+
initialize_from(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Void an API Resource
|
32
|
+
#
|
33
|
+
# @param [Hash] params for the request
|
34
|
+
# @param [Hash] Additional options for the request
|
35
|
+
#
|
36
|
+
# @return [FatZebra::Object] response from the API
|
37
|
+
def void(params = {}, options = {})
|
38
|
+
params = {
|
39
|
+
id: id
|
40
|
+
}.merge(params)
|
41
|
+
|
42
|
+
response = request(:post, "#{resource_path}/void", params, options)
|
43
|
+
update_from(response)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.included(base)
|
47
|
+
base.extend(ClassMethods)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module FatZebra
|
2
|
+
##
|
3
|
+
# == FatZebra \API \Resource
|
4
|
+
#
|
5
|
+
# Define the API requests methods
|
6
|
+
class APIResource < FatZebraObject
|
7
|
+
include APIHelper
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def base_path(account)
|
12
|
+
"#{account.api_version}/"
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Send a request to the API
|
17
|
+
#
|
18
|
+
# @param [Symbol] method for the request
|
19
|
+
# @param [String] endpoint for the request
|
20
|
+
# @param [Hash] options
|
21
|
+
# @param [Hash] Payload
|
22
|
+
#
|
23
|
+
# @return [Hash] response
|
24
|
+
# @raise [FatZebra::RequestError] if the request is invalid
|
25
|
+
# rubocop:disable Metrics/AbcSize
|
26
|
+
def request(method, path, payload = {}, options = {})
|
27
|
+
account = get_account options
|
28
|
+
full_path = "/#{base_path account}#{path}"
|
29
|
+
|
30
|
+
payload[:test] = true if account.test_mode
|
31
|
+
payload = Util.format_dates_in_hash(payload)
|
32
|
+
url_params = URI.encode_www_form(payload) if method == :get
|
33
|
+
uri = build_endpoint_url(account.gateway, full_path, url_params, http_secure: account.http_secure)
|
34
|
+
|
35
|
+
request_options = Util.compact(
|
36
|
+
method: method,
|
37
|
+
url: uri.to_s,
|
38
|
+
payload: payload,
|
39
|
+
proxy: account.proxy,
|
40
|
+
use_ssl: account.http_secure
|
41
|
+
).merge(authentication(account)).merge(default_headers).merge(account.global_options).merge(options)
|
42
|
+
|
43
|
+
Request.execute(request_options).body
|
44
|
+
rescue FatZebra::RequestError => error
|
45
|
+
return error.http_body if error.http_status == 422
|
46
|
+
raise
|
47
|
+
end
|
48
|
+
# rubocop:enable Metrics/AbcSize
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def ssl_options
|
53
|
+
return {} unless get_account.http_secure
|
54
|
+
{
|
55
|
+
ca_file: File.expand_path(File.dirname(__FILE__) + '/../../vendor/cacert.pem'),
|
56
|
+
verify_mode: OpenSSL::SSL::VERIFY_PEER
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def authentication(account)
|
61
|
+
{
|
62
|
+
basic_auth: {
|
63
|
+
user: account.username,
|
64
|
+
password: account.token
|
65
|
+
}
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def configurations
|
70
|
+
FatZebra.configurations
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_account(options)
|
74
|
+
case [options[:account].nil?, configurations.nil?]
|
75
|
+
when [true, false]
|
76
|
+
configurations
|
77
|
+
when [false, true]
|
78
|
+
options[:account]
|
79
|
+
when [true, true]
|
80
|
+
raise ConfigurationError, 'No account specified'
|
81
|
+
else # [false, false]
|
82
|
+
raise ConfigurationError, 'Ambiguous accounts specified' if options[:account] != configurations
|
83
|
+
configurations
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module FatZebra
|
2
|
+
##
|
3
|
+
# == FatZebra \Bank \Account
|
4
|
+
#
|
5
|
+
# Manage bank account for the API
|
6
|
+
#
|
7
|
+
# * search
|
8
|
+
# * save
|
9
|
+
#
|
10
|
+
class BankAccount < APIResource
|
11
|
+
|
12
|
+
include FatZebra::APIOperation::Search
|
13
|
+
include FatZebra::APIOperation::Save
|
14
|
+
|
15
|
+
validates :account_name, required: true, on: :create
|
16
|
+
validates :account_number, required: true, on: :create
|
17
|
+
validates :bsb, required: true, on: :create
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module FatZebra
|
2
|
+
##
|
3
|
+
# == FatZebra \Batch
|
4
|
+
#
|
5
|
+
# Manage Batch for the API
|
6
|
+
#
|
7
|
+
# * create
|
8
|
+
# * search
|
9
|
+
# * find
|
10
|
+
# * result
|
11
|
+
#
|
12
|
+
class Batch < APIResource
|
13
|
+
@resource_name = 'batches'
|
14
|
+
|
15
|
+
include FatZebra::APIOperation::Search
|
16
|
+
include FatZebra::APIOperation::Find
|
17
|
+
include FatZebra::APIOperation::Save
|
18
|
+
include FatZebra::APIOperation::Delete
|
19
|
+
|
20
|
+
validates :filename, required: true, type: :batch_filename, on: :create
|
21
|
+
validates :file, required: true, type: :file_type, on: :create
|
22
|
+
validates :multipart, required: true, type: :boolean, on: :create
|
23
|
+
|
24
|
+
class << self
|
25
|
+
|
26
|
+
##
|
27
|
+
# Upload a batch file
|
28
|
+
#
|
29
|
+
# @param [Hash] params for the request
|
30
|
+
# @param [Hash] Additional options for the request
|
31
|
+
#
|
32
|
+
# @return [FatZebra::Batch] response from the API
|
33
|
+
def create(params, options = {})
|
34
|
+
params[:multipart] = true
|
35
|
+
params[:content_type] = 'text/csv'
|
36
|
+
params[:file] = File.new(params.delete(:path)) if params.key?(:path)
|
37
|
+
@resource_name = "batches/#{params[:filename]}"
|
38
|
+
super(params, options)
|
39
|
+
ensure
|
40
|
+
@resource_name = 'batches'
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Return result from the batch
|
47
|
+
#
|
48
|
+
# @param [Hash] params for capture API (Optional)
|
49
|
+
# @param [Hash] options for the request, and configurations (Optional)
|
50
|
+
#
|
51
|
+
# @return [String] formated as CSV
|
52
|
+
def result(params = {}, options = {})
|
53
|
+
request(:get, "#{resource_path}/#{id}/result.csv", params, options)
|
54
|
+
rescue FatZebra::RequestError => error
|
55
|
+
return error.http_body if error.http_status == 422
|
56
|
+
raise
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module FatZebra
|
2
|
+
##
|
3
|
+
# == FatZebra \Card
|
4
|
+
#
|
5
|
+
# Manage credit card for the API
|
6
|
+
#
|
7
|
+
# * save
|
8
|
+
#
|
9
|
+
class Card < APIResource
|
10
|
+
@resource_name = 'credit_cards'
|
11
|
+
|
12
|
+
include FatZebra::APIOperation::Save
|
13
|
+
|
14
|
+
validates :card_holder, required: { unless: %i[wallet] }, on: :create
|
15
|
+
validates :card_number, required: { unless: %i[wallet] }, on: :create
|
16
|
+
validates :card_expiry, required: { unless: %i[wallet] }, on: :create
|
17
|
+
|
18
|
+
validates :wallet, required: { unless: %i[card_number] }, on: :create
|
19
|
+
|
20
|
+
validates :card_expiry, required: true, on: :update
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module FatZebra
|
2
|
+
##
|
3
|
+
# == FatZebra \Config
|
4
|
+
#
|
5
|
+
# Represent the FatZebra configuration for the API
|
6
|
+
class Config
|
7
|
+
|
8
|
+
GATEWAY_URLS = {
|
9
|
+
production: 'gateway.fatzebra.com.au',
|
10
|
+
sandbox: 'gateway.sandbox.fatzebra.com.au'
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
##
|
14
|
+
# @return [String] Username
|
15
|
+
attr_accessor :username
|
16
|
+
|
17
|
+
##
|
18
|
+
# @return [String] Token
|
19
|
+
attr_accessor :token
|
20
|
+
|
21
|
+
##
|
22
|
+
# @return [String] Test mode
|
23
|
+
attr_accessor :test_mode
|
24
|
+
|
25
|
+
##
|
26
|
+
# @return [String] Gateway url
|
27
|
+
attr_accessor :gateway
|
28
|
+
|
29
|
+
##
|
30
|
+
# @return [String] Proxy url
|
31
|
+
attr_accessor :proxy
|
32
|
+
|
33
|
+
##
|
34
|
+
# @return [String] http secure
|
35
|
+
attr_accessor :http_secure
|
36
|
+
|
37
|
+
##
|
38
|
+
# @return [String] api version
|
39
|
+
attr_accessor :api_version
|
40
|
+
|
41
|
+
##
|
42
|
+
# @return [String] global request options
|
43
|
+
attr_accessor :global_options
|
44
|
+
|
45
|
+
##
|
46
|
+
# @param [Hash{Symbol=>Object}]
|
47
|
+
# Initialize and validate the configuration
|
48
|
+
def initialize(options = {})
|
49
|
+
self.token = options[:token]
|
50
|
+
self.username = options[:username]
|
51
|
+
self.gateway = options[:gateway] || :production
|
52
|
+
self.test_mode = options[:test_mode] || false
|
53
|
+
self.http_secure = options[:http_secure] || true
|
54
|
+
self.api_version = options[:api_version] || 'v1.0'
|
55
|
+
self.proxy = options[:proxy]
|
56
|
+
self.global_options = options[:global_options] || {}
|
57
|
+
|
58
|
+
valid! unless options.empty?
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# validate the configuration
|
63
|
+
# Raise when configuration is not valid
|
64
|
+
# Remove "http://" or "https://" from urls
|
65
|
+
#
|
66
|
+
# @return [Boolean] true
|
67
|
+
def valid!
|
68
|
+
format!
|
69
|
+
|
70
|
+
%i[username token gateway api_version].each do |field|
|
71
|
+
validate_presence(field)
|
72
|
+
end
|
73
|
+
|
74
|
+
true
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def format!
|
80
|
+
self.gateway = GATEWAY_URLS[gateway] if gateway.is_a?(Symbol)
|
81
|
+
|
82
|
+
self.gateway = Util.cleanup_host(gateway)
|
83
|
+
end
|
84
|
+
|
85
|
+
def validate_presence(field)
|
86
|
+
raise FatZebra::ConfigurationError, "#{field} can't be blank" if send(field).nil? || send(field).empty?
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|