fat_zebra_multi 3.1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.rspec +0 -0
  4. data/.rubocop.yml +44 -0
  5. data/.travis.yml +10 -0
  6. data/Gemfile +4 -0
  7. data/README.md +104 -0
  8. data/Rakefile +11 -0
  9. data/fat_zebra_multi.gemspec +27 -0
  10. data/lib/fat_zebra.rb +65 -0
  11. data/lib/fat_zebra/api_helper.rb +91 -0
  12. data/lib/fat_zebra/api_operation/delete.rb +38 -0
  13. data/lib/fat_zebra/api_operation/find.rb +30 -0
  14. data/lib/fat_zebra/api_operation/save.rb +67 -0
  15. data/lib/fat_zebra/api_operation/search.rb +39 -0
  16. data/lib/fat_zebra/api_operation/void.rb +52 -0
  17. data/lib/fat_zebra/api_resource.rb +88 -0
  18. data/lib/fat_zebra/bank_account.rb +20 -0
  19. data/lib/fat_zebra/batch.rb +60 -0
  20. data/lib/fat_zebra/card.rb +23 -0
  21. data/lib/fat_zebra/config.rb +90 -0
  22. data/lib/fat_zebra/customer.rb +26 -0
  23. data/lib/fat_zebra/direct_credit.rb +26 -0
  24. data/lib/fat_zebra/direct_debit.rb +26 -0
  25. data/lib/fat_zebra/errors.rb +37 -0
  26. data/lib/fat_zebra/fat_zebra_object.rb +68 -0
  27. data/lib/fat_zebra/information.rb +29 -0
  28. data/lib/fat_zebra/object_helper.rb +119 -0
  29. data/lib/fat_zebra/payment_plan.rb +61 -0
  30. data/lib/fat_zebra/purchase.rb +96 -0
  31. data/lib/fat_zebra/refund.rb +27 -0
  32. data/lib/fat_zebra/request.rb +174 -0
  33. data/lib/fat_zebra/request/multipart/epilogue.rb +23 -0
  34. data/lib/fat_zebra/request/multipart/file_io.rb +40 -0
  35. data/lib/fat_zebra/request/multipart/param.rb +37 -0
  36. data/lib/fat_zebra/request/multipart/part.rb +28 -0
  37. data/lib/fat_zebra/request/multipart/stream.rb +57 -0
  38. data/lib/fat_zebra/util.rb +71 -0
  39. data/lib/fat_zebra/validation.rb +67 -0
  40. data/lib/fat_zebra/version.rb +3 -0
  41. data/lib/fat_zebra/web_hook.rb +22 -0
  42. data/spec/cassettes/FatZebra_BankAccount/_create/1_1_1.yml +53 -0
  43. data/spec/cassettes/FatZebra_BankAccount/_create/1_1_2.yml +53 -0
  44. data/spec/cassettes/FatZebra_BankAccount/_search/1_2_1.yml +164 -0
  45. data/spec/cassettes/FatZebra_BankAccount/_search/1_2_2.yml +164 -0
  46. data/spec/cassettes/FatZebra_BankAccount/_search/1_2_3.yml +164 -0
  47. data/spec/cassettes/FatZebra_Batch/_create/with_file/1_1_1_1.yml +61 -0
  48. data/spec/cassettes/FatZebra_Batch/_create/with_file/1_1_1_2.yml +61 -0
  49. data/spec/cassettes/FatZebra_Batch/_create/with_path/1_1_2_1.yml +61 -0
  50. data/spec/cassettes/FatZebra_Batch/_create/with_path/1_1_2_2.yml +61 -0
  51. data/spec/cassettes/FatZebra_Batch/_find/1_2_1.yml +112 -0
  52. data/spec/cassettes/FatZebra_Batch/_find/1_2_2.yml +112 -0
  53. data/spec/cassettes/FatZebra_Batch/_result/1_4_1.yml +163 -0
  54. data/spec/cassettes/FatZebra_Batch/_search/1_3_1.yml +54 -0
  55. data/spec/cassettes/FatZebra_Batch/_search/1_3_2.yml +54 -0
  56. data/spec/cassettes/FatZebra_Batch/_search/1_3_3.yml +54 -0
  57. data/spec/cassettes/FatZebra_Card/_create/1_1_1.yml +54 -0
  58. data/spec/cassettes/FatZebra_Card/_create/1_1_2.yml +54 -0
  59. data/spec/cassettes/FatZebra_Card/_create/1_1_3.yml +54 -0
  60. data/spec/cassettes/FatZebra_Card/_create/1_1_4.yml +54 -0
  61. data/spec/cassettes/FatZebra_Card/_create/1_1_5.yml +54 -0
  62. data/spec/cassettes/FatZebra_Card/_create/1_1_6.yml +54 -0
  63. data/spec/cassettes/FatZebra_Card/_update/1_2_1.yml +105 -0
  64. data/spec/cassettes/FatZebra_Card/_update/1_2_2.yml +105 -0
  65. data/spec/cassettes/FatZebra_Card/_update/1_2_3.yml +105 -0
  66. data/spec/cassettes/FatZebra_Card/_update/validations/1_2_4_1.yml +54 -0
  67. data/spec/cassettes/FatZebra_Customer/_create/1_1_1.yml +55 -0
  68. data/spec/cassettes/FatZebra_Customer/_create/1_1_2.yml +55 -0
  69. data/spec/cassettes/FatZebra_Customer/_create/1_1_3.yml +55 -0
  70. data/spec/cassettes/FatZebra_Customer/_create/1_1_4.yml +55 -0
  71. data/spec/cassettes/FatZebra_Customer/_create/1_1_5.yml +55 -0
  72. data/spec/cassettes/FatZebra_Customer/_create/1_1_6.yml +55 -0
  73. data/spec/cassettes/FatZebra_Customer/_delete/1_5_1.yml +103 -0
  74. data/spec/cassettes/FatZebra_Customer/_find/1_3_1.yml +107 -0
  75. data/spec/cassettes/FatZebra_Customer/_find/1_3_2.yml +107 -0
  76. data/spec/cassettes/FatZebra_Customer/_search/1_2_1.yml +60 -0
  77. data/spec/cassettes/FatZebra_Customer/_search/1_2_2.yml +60 -0
  78. data/spec/cassettes/FatZebra_Customer/_search/1_2_3.yml +60 -0
  79. data/spec/cassettes/FatZebra_Customer/_update/1_4_1.yml +106 -0
  80. data/spec/cassettes/FatZebra_Customer/_update/1_4_2.yml +106 -0
  81. data/spec/cassettes/FatZebra_DirectCredit/_create/1_1_1.yml +52 -0
  82. data/spec/cassettes/FatZebra_DirectCredit/_create/1_1_2.yml +52 -0
  83. data/spec/cassettes/FatZebra_DirectCredit/_create/1_1_3.yml +52 -0
  84. data/spec/cassettes/FatZebra_DirectCredit/_create/1_1_4.yml +52 -0
  85. data/spec/cassettes/FatZebra_DirectCredit/_create/validations/valid/1_1_5_1_1.yml +52 -0
  86. data/spec/cassettes/FatZebra_DirectCredit/_delete/1_4_1.yml +99 -0
  87. data/spec/cassettes/FatZebra_DirectCredit/_find/1_2_1.yml +103 -0
  88. data/spec/cassettes/FatZebra_DirectCredit/_find/1_2_2.yml +103 -0
  89. data/spec/cassettes/FatZebra_DirectCredit/_find/1_2_3.yml +103 -0
  90. data/spec/cassettes/FatZebra_DirectCredit/_search/1_3_1.yml +152 -0
  91. data/spec/cassettes/FatZebra_DirectCredit/_search/1_3_2.yml +152 -0
  92. data/spec/cassettes/FatZebra_DirectDebit/_create/1_1_1.yml +52 -0
  93. data/spec/cassettes/FatZebra_DirectDebit/_create/1_1_2.yml +52 -0
  94. data/spec/cassettes/FatZebra_DirectDebit/_create/1_1_3.yml +52 -0
  95. data/spec/cassettes/FatZebra_DirectDebit/_create/1_1_4.yml +52 -0
  96. data/spec/cassettes/FatZebra_DirectDebit/_create/validations/valid/1_1_5_1_1.yml +52 -0
  97. data/spec/cassettes/FatZebra_DirectDebit/_delete/1_4_1.yml +99 -0
  98. data/spec/cassettes/FatZebra_DirectDebit/_find/1_2_1.yml +103 -0
  99. data/spec/cassettes/FatZebra_DirectDebit/_find/1_2_2.yml +103 -0
  100. data/spec/cassettes/FatZebra_DirectDebit/_find/1_2_3.yml +103 -0
  101. data/spec/cassettes/FatZebra_DirectDebit/_search/1_3_1.yml +152 -0
  102. data/spec/cassettes/FatZebra_DirectDebit/_search/1_3_2.yml +152 -0
  103. data/spec/cassettes/FatZebra_Information/_ping/1_1_1.yml +54 -0
  104. data/spec/cassettes/FatZebra_Information/_ping/1_1_2.yml +54 -0
  105. data/spec/cassettes/FatZebra_PaymentPlan/_active_/1_8_1.yml +222 -0
  106. data/spec/cassettes/FatZebra_PaymentPlan/_active_/1_8_2.yml +222 -0
  107. data/spec/cassettes/FatZebra_PaymentPlan/_create/1_1_1.yml +110 -0
  108. data/spec/cassettes/FatZebra_PaymentPlan/_create/1_1_2.yml +110 -0
  109. data/spec/cassettes/FatZebra_PaymentPlan/_create/1_1_3.yml +110 -0
  110. data/spec/cassettes/FatZebra_PaymentPlan/_delete/1_5_1.yml +158 -0
  111. data/spec/cassettes/FatZebra_PaymentPlan/_destroy/1_6_1.yml +158 -0
  112. data/spec/cassettes/FatZebra_PaymentPlan/_find/1_2_1.yml +167 -0
  113. data/spec/cassettes/FatZebra_PaymentPlan/_find/1_2_2.yml +167 -0
  114. data/spec/cassettes/FatZebra_PaymentPlan/_find/1_2_3.yml +167 -0
  115. data/spec/cassettes/FatZebra_PaymentPlan/_suspend_/1_7_1.yml +166 -0
  116. data/spec/cassettes/FatZebra_PaymentPlan/_suspend_/1_7_2.yml +166 -0
  117. data/spec/cassettes/FatZebra_PaymentPlan/_update/1_3_1.yml +160 -0
  118. data/spec/cassettes/FatZebra_PaymentPlan/_update/1_3_2.yml +160 -0
  119. data/spec/cassettes/FatZebra_PaymentPlan/_update/1_3_3.yml +160 -0
  120. data/spec/cassettes/FatZebra_PaymentPlan/_update/1_4_1.yml +166 -0
  121. data/spec/cassettes/FatZebra_PaymentPlan/_update/1_4_2.yml +166 -0
  122. data/spec/cassettes/FatZebra_Purchase/_capture/1_5_1.yml +115 -0
  123. data/spec/cassettes/FatZebra_Purchase/_capture/1_5_2.yml +115 -0
  124. data/spec/cassettes/FatZebra_Purchase/_capture/1_5_3.yml +115 -0
  125. data/spec/cassettes/FatZebra_Purchase/_create/1_1_1.yml +53 -0
  126. data/spec/cassettes/FatZebra_Purchase/_create/1_1_10.yml +53 -0
  127. data/spec/cassettes/FatZebra_Purchase/_create/1_1_11.yml +53 -0
  128. data/spec/cassettes/FatZebra_Purchase/_create/1_1_12.yml +53 -0
  129. data/spec/cassettes/FatZebra_Purchase/_create/1_1_13.yml +53 -0
  130. data/spec/cassettes/FatZebra_Purchase/_create/1_1_2.yml +53 -0
  131. data/spec/cassettes/FatZebra_Purchase/_create/1_1_3.yml +53 -0
  132. data/spec/cassettes/FatZebra_Purchase/_create/1_1_4.yml +53 -0
  133. data/spec/cassettes/FatZebra_Purchase/_create/1_1_5.yml +53 -0
  134. data/spec/cassettes/FatZebra_Purchase/_create/1_1_6.yml +53 -0
  135. data/spec/cassettes/FatZebra_Purchase/_create/1_1_7.yml +53 -0
  136. data/spec/cassettes/FatZebra_Purchase/_create/1_1_8.yml +53 -0
  137. data/spec/cassettes/FatZebra_Purchase/_create/1_1_9.yml +53 -0
  138. data/spec/cassettes/FatZebra_Purchase/_create/bad_request/1_1_14_1.yml +55 -0
  139. data/spec/cassettes/FatZebra_Purchase/_create/bad_request/1_1_14_2.yml +55 -0
  140. data/spec/cassettes/FatZebra_Purchase/_find/1_2_1.yml +117 -0
  141. data/spec/cassettes/FatZebra_Purchase/_find/1_2_2.yml +117 -0
  142. data/spec/cassettes/FatZebra_Purchase/_find/1_2_3.yml +117 -0
  143. data/spec/cassettes/FatZebra_Purchase/_find/1_2_4.yml +117 -0
  144. data/spec/cassettes/FatZebra_Purchase/_refund/1_4_1.yml +115 -0
  145. data/spec/cassettes/FatZebra_Purchase/_refund/1_4_2.yml +115 -0
  146. data/spec/cassettes/FatZebra_Purchase/_refund/1_4_3.yml +115 -0
  147. data/spec/cassettes/FatZebra_Purchase/_search/1_3_1.yml +164 -0
  148. data/spec/cassettes/FatZebra_Purchase/_search/1_3_2.yml +164 -0
  149. data/spec/cassettes/FatZebra_Purchase/_search/1_3_3.yml +164 -0
  150. data/spec/cassettes/FatZebra_Purchase/_settlement/1_8_1.yml +652 -0
  151. data/spec/cassettes/FatZebra_Purchase/_settlement/1_8_2.yml +652 -0
  152. data/spec/cassettes/FatZebra_Purchase/_settlement/1_8_3.yml +652 -0
  153. data/spec/cassettes/FatZebra_Purchase/_void/1_6_1.yml +103 -0
  154. data/spec/cassettes/FatZebra_Purchase/_void/1_6_2.yml +103 -0
  155. data/spec/cassettes/FatZebra_Purchase/_void/1_6_3.yml +103 -0
  156. data/spec/cassettes/FatZebra_Purchase/_void/1_6_4.yml +103 -0
  157. data/spec/cassettes/FatZebra_Purchase/_void/1_7_1.yml +103 -0
  158. data/spec/cassettes/FatZebra_Purchase/_void/1_7_2.yml +103 -0
  159. data/spec/cassettes/FatZebra_Purchase/_void/1_7_3.yml +103 -0
  160. data/spec/cassettes/FatZebra_Purchase/_void/1_7_4.yml +103 -0
  161. data/spec/cassettes/FatZebra_Refund/_create/1_1_1.yml +103 -0
  162. data/spec/cassettes/FatZebra_Refund/_create/1_1_10.yml +103 -0
  163. data/spec/cassettes/FatZebra_Refund/_create/1_1_2.yml +103 -0
  164. data/spec/cassettes/FatZebra_Refund/_create/1_1_3.yml +103 -0
  165. data/spec/cassettes/FatZebra_Refund/_create/1_1_4.yml +103 -0
  166. data/spec/cassettes/FatZebra_Refund/_create/1_1_5.yml +103 -0
  167. data/spec/cassettes/FatZebra_Refund/_create/1_1_6.yml +103 -0
  168. data/spec/cassettes/FatZebra_Refund/_create/1_1_7.yml +103 -0
  169. data/spec/cassettes/FatZebra_Refund/_create/1_1_8.yml +103 -0
  170. data/spec/cassettes/FatZebra_Refund/_create/1_1_9.yml +103 -0
  171. data/spec/cassettes/FatZebra_Refund/_find/1_2_1.yml +155 -0
  172. data/spec/cassettes/FatZebra_Refund/_find/1_2_2.yml +155 -0
  173. data/spec/cassettes/FatZebra_Refund/_find/1_2_3.yml +155 -0
  174. data/spec/cassettes/FatZebra_Refund/_search/responds_with_the_newly-created_refunds.yml +214 -0
  175. data/spec/cassettes/FatZebra_Refund/_void/1_4_1.yml +153 -0
  176. data/spec/cassettes/FatZebra_Refund/_void/1_4_2.yml +153 -0
  177. data/spec/cassettes/FatZebra_Refund/_void/1_4_3.yml +153 -0
  178. data/spec/cassettes/FatZebra_Refund/_void/1_4_4.yml +153 -0
  179. data/spec/cassettes/FatZebra_WebHook/_create/1_1_1.yml +53 -0
  180. data/spec/cassettes/FatZebra_WebHook/_create/1_1_2.yml +53 -0
  181. data/spec/cassettes/FatZebra_WebHook/_create/1_1_3.yml +53 -0
  182. data/spec/cassettes/FatZebra_WebHook/_delete/1_4_1.yml +101 -0
  183. data/spec/cassettes/FatZebra_WebHook/_search/1_2_1.yml +298 -0
  184. data/spec/cassettes/FatZebra_WebHook/_search/1_2_2.yml +300 -0
  185. data/spec/cassettes/FatZebra_WebHook/_update/1_3_1.yml +104 -0
  186. data/spec/cassettes/FatZebra_WebHook/_update/1_3_2.yml +104 -0
  187. data/spec/cassettes/Multiple_accounts/The_basics/1_1_5.yml +59 -0
  188. data/spec/cassettes/Multiple_accounts/The_basics/1_1_6.yml +59 -0
  189. data/spec/fixtures/batch_test.csv +4 -0
  190. data/spec/lib/fat_zebra/api_resource_spec.rb +25 -0
  191. data/spec/lib/fat_zebra/bank_account_spec.rb +34 -0
  192. data/spec/lib/fat_zebra/batch_spec.rb +59 -0
  193. data/spec/lib/fat_zebra/card_spec.rb +41 -0
  194. data/spec/lib/fat_zebra/config_spec.rb +69 -0
  195. data/spec/lib/fat_zebra/customer_spec.rb +53 -0
  196. data/spec/lib/fat_zebra/direct_credit_spec.rb +74 -0
  197. data/spec/lib/fat_zebra/direct_debit_spec.rb +74 -0
  198. data/spec/lib/fat_zebra/fat_zebra_object_spec.rb +117 -0
  199. data/spec/lib/fat_zebra/information_spec.rb +13 -0
  200. data/spec/lib/fat_zebra/multiple_accounts_spec.rb +69 -0
  201. data/spec/lib/fat_zebra/payment_plan_spec.rb +94 -0
  202. data/spec/lib/fat_zebra/purchase_spec.rb +105 -0
  203. data/spec/lib/fat_zebra/refund_spec.rb +95 -0
  204. data/spec/lib/fat_zebra/request_spec.rb +59 -0
  205. data/spec/lib/fat_zebra/util_spec.rb +43 -0
  206. data/spec/lib/fat_zebra/validation_spec.rb +22 -0
  207. data/spec/lib/fat_zebra/web_hook_spec.rb +50 -0
  208. data/spec/spec_helper.rb +68 -0
  209. data/spec/support/payloads.rb +43 -0
  210. data/vendor/cacert.pem +3390 -0
  211. 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