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,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe FatZebra::DirectDebit do
4
+
5
+ let(:valid_direct_debit_payload) {{
6
+ description: 'Confirmation',
7
+ amount: 42.0,
8
+ bsb: '123-123',
9
+ account_name: 'Test',
10
+ account_number: '012345678'
11
+ }}
12
+
13
+ describe '.create', :vcr do
14
+ subject(:direct_debit) { FatZebra::DirectDebit.create(valid_direct_debit_payload) }
15
+
16
+ it { is_expected.to be_accepted }
17
+ it { expect(direct_debit.bsb).to eq(valid_direct_debit_payload[:bsb]) }
18
+ it { expect(direct_debit.reference).to_not be_empty }
19
+ it { expect(direct_debit.id).to_not be_empty }
20
+
21
+ context 'validations' do
22
+ context 'valid' do
23
+ before { valid_direct_debit_payload[:amount] = 42.42 }
24
+
25
+ it { is_expected.to be_accepted }
26
+ end
27
+
28
+ context 'failed' do
29
+ let(:valid_direct_debit_payload) {{}}
30
+
31
+ it { expect{ direct_debit }.to raise_error(FatZebra::RequestValidationError) }
32
+ end
33
+
34
+ context 'failed with non-float' do
35
+ let(:valid_direct_debit_payload) {{
36
+ description: 'Confirmation',
37
+ amount: 123,
38
+ bsb: '123-123',
39
+ account_name: 'Test',
40
+ account_number: '012345678'
41
+ }}
42
+
43
+ it { expect{ direct_debit }.to raise_error(FatZebra::RequestValidationError) }
44
+ end
45
+ end
46
+ end
47
+
48
+ describe '.find', :vcr do
49
+ let!(:create) { FatZebra::DirectDebit.create(valid_direct_debit_payload) }
50
+ subject(:direct_debit) { FatZebra::DirectDebit.find(create.reference) }
51
+
52
+ it { is_expected.to be_accepted }
53
+ it { expect(direct_debit.reference).to eq(create.reference) }
54
+ it { expect(direct_debit.amount).to be_instance_of(Float) }
55
+ end
56
+
57
+ describe '.search', :vcr do
58
+ let!(:start) { Time.now }
59
+ subject(:direct_debits) { FatZebra::DirectDebit.search }
60
+
61
+ before { 2.times { |i| FatZebra::DirectDebit.create(valid_direct_debit_payload) } }
62
+
63
+ it { is_expected.to be_accepted }
64
+ it { expect(direct_debits.data.count).to be >= 2 }
65
+ end
66
+
67
+ describe '.delete', :vcr do
68
+ let(:create) { FatZebra::DirectDebit.create(valid_direct_debit_payload) }
69
+ subject(:direct_debit) { FatZebra::DirectDebit.delete(create.id) }
70
+
71
+ it { is_expected.to be_accepted }
72
+ end
73
+
74
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ describe FatZebra::FatZebraObject do
4
+
5
+ let(:klass) { Class.new(FatZebra::FatZebraObject) }
6
+ subject(:instance) { klass.new(id: 42, name: 'test', test: true) }
7
+
8
+ let(:api_response) {{
9
+ 'successful' => true,
10
+ 'response' => {
11
+ successful: true,
12
+ id: 84,
13
+ other: 'other test'
14
+ }
15
+ }}
16
+
17
+ let(:api_responses) {{
18
+ 'successful' => true,
19
+ 'response' => [{
20
+ id: 84,
21
+ other: 'other test'
22
+ }]
23
+ }}
24
+
25
+ describe 'add attribute accessors' do
26
+ it { expect(instance.id).to eq(42) }
27
+ it { expect(instance.name).to eq('test') }
28
+ it { expect(instance.test).to be_truthy }
29
+ it { expect(instance.test?).to be_truthy }
30
+ end
31
+
32
+ describe 'add array attribute' do
33
+ it { expect(instance[:id]).to eq(42) }
34
+ it { expect(instance[:name]).to eq('test') }
35
+ it { expect(instance[:test]).to be_truthy }
36
+ end
37
+
38
+ describe 'set array attribute' do
39
+ before { instance[:id] = 84 }
40
+
41
+ it { expect(instance.id).to eq(84) }
42
+ it { expect(instance[:id]).to eq(84) }
43
+ end
44
+
45
+ describe 'method missing' do
46
+ before { instance.card = '42' }
47
+
48
+ it { expect(instance.card).to eq('42') }
49
+ it { expect { instance.other }.to raise_error(NameError) }
50
+ end
51
+
52
+ describe '#keys' do
53
+ it { expect(instance.keys).to match_array([:id, :name, :test]) }
54
+ end
55
+
56
+ describe '#to_hash' do
57
+ it { expect(instance.to_hash).to eq(id: 42, name: 'test', test: true) }
58
+ end
59
+
60
+ describe '#to_json' do
61
+ it { expect(instance.to_json).to eq(JSON.generate(id: 42, name: 'test', test: true)) }
62
+ end
63
+
64
+ describe '#load_response_api' do
65
+ let(:response) {{
66
+ 'successful' => true,
67
+ 'errors' => []
68
+ }}
69
+
70
+ before { instance.load_response_api(response) }
71
+
72
+ it { expect(instance.accepted).to be_truthy }
73
+ it { expect(instance.errors).to eq([]) }
74
+ end
75
+
76
+ describe '#add_data' do
77
+ before { instance.add_data(:test) }
78
+
79
+ it { expect(instance.data).to match_array([:test]) }
80
+ end
81
+
82
+ describe '#update_attributes' do
83
+ before { instance.update_attributes(id: 84, other: 'other test') }
84
+
85
+ it { expect(instance.id).to eq(84) }
86
+ it { expect(instance.other).to eq('other test') }
87
+ it { expect(instance.name).to eq('test') }
88
+ end
89
+
90
+ describe '.initialize_from' do
91
+ context 'with single object' do
92
+ subject(:instance) { klass.initialize_from(api_response) }
93
+
94
+ it { is_expected.to be_successful }
95
+ it { expect(instance.id).to eq(84) }
96
+ it { expect(instance.other).to eq('other test') }
97
+ it { expect { instance.name }.to raise_error(NameError) }
98
+ end
99
+
100
+ context 'with array' do
101
+ subject(:instance) { klass.initialize_from(api_responses) }
102
+
103
+ it { is_expected.to be_accepted }
104
+ it { expect(instance.data.size).to eq(1) }
105
+ end
106
+ end
107
+
108
+ describe '#update_from' do
109
+ before { instance.update_from(api_response) }
110
+
111
+ it { is_expected.to be_successful }
112
+ it { expect(instance.id).to eq(84) }
113
+ it { expect(instance.other).to eq('other test') }
114
+ it { expect { instance.name }.to raise_error(NameError) }
115
+ end
116
+
117
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe FatZebra::Information do
4
+
5
+ describe '.ping', :vcr do
6
+ let(:nonce) { '262ca5679c2dd86ac866200a7b57fab0' }
7
+ subject(:ping) { FatZebra::Information.ping(nonce) }
8
+
9
+ it { expect(ping.timestamp.to_s).to_not be_empty }
10
+ it { expect(ping.echo).to eq(nonce) }
11
+ end
12
+
13
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Multiple accounts', :vcr, :no_default_account do
4
+
5
+ describe 'The basics' do
6
+ it { expect(FatZebra.configurations).to be_nil }
7
+
8
+ let(:purchase_0) { FatZebra::Purchase.create valid_purchase_payload }
9
+
10
+ it { expect { purchase_0 }.to raise_error(FatZebra::ConfigurationError, 'No account specified') }
11
+
12
+ let(:account_1) {
13
+ FatZebra::Config.new(
14
+ username: 'TEST_USERNAME_1',
15
+ token: 'TEST_TOKEN_1',
16
+ gateway: :sandbox,
17
+ test_mode: true
18
+ )
19
+ }
20
+ let(:account_2) {
21
+ FatZebra::Config.new(
22
+ username: 'TEST_USERNAME_2',
23
+ token: 'TEST_TOKEN_2',
24
+ gateway: :sandbox,
25
+ test_mode: true
26
+ )
27
+ }
28
+
29
+ it { expect(account_1.valid!).to be_truthy }
30
+ it { expect(account_2.valid!).to be_truthy }
31
+
32
+ let(:purchase_1) { FatZebra::Purchase.create valid_purchase_payload, account: account_1 }
33
+
34
+ let(:purchase_2) { FatZebra::Purchase.create valid_purchase_payload, account: account_2 }
35
+
36
+ it {
37
+ expect(purchase_1.accepted?).to be_truthy
38
+ expect(purchase_1.id).to eq('071-P-ACCOUNT-1')
39
+ }
40
+
41
+ it {
42
+ expect(purchase_2.accepted?).to be_truthy
43
+ expect(purchase_2.id).to eq('071-P-ACCOUNT-2')
44
+ }
45
+ end
46
+
47
+ describe 'Conflicting accounts' do
48
+ it {
49
+ expect(FatZebra.configurations).to be_nil
50
+
51
+ FatZebra.configure do |config|
52
+ config.username = 'TEST_USERNAME_1'
53
+ config.token = 'TEST_TOKEN_1'
54
+ config.gateway = :sandbox
55
+ config.test_mode = true
56
+ end
57
+
58
+ account = FatZebra::Config.new(
59
+ username: 'TEST_USERNAME_2',
60
+ token: 'TEST_TOKEN_2',
61
+ gateway: :sandbox,
62
+ test_mode: true
63
+ )
64
+
65
+ expect { FatZebra::Purchase.create valid_purchase_payload, account: account }.to raise_error(FatZebra::ConfigurationError, 'Ambiguous accounts specified')
66
+ }
67
+ end
68
+
69
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe FatZebra::PaymentPlan do
4
+ let(:customer) { FatZebra::Customer.create(customer_valid_payload) }
5
+
6
+ let(:payment_plan_valid_payload) {{
7
+ payment_method: 'Credit Card',
8
+ customer: customer.id,
9
+ reference: SecureRandom.hex,
10
+ setup_fee: 0,
11
+ amount: 100,
12
+ start_date: (Date.today + 90).strftime('%Y-%m-%d'),
13
+ frequency: 'Weekly',
14
+ anniversary: 5,
15
+ total_count: 5,
16
+ total_amount: 500
17
+ }}
18
+
19
+ describe '.create', :vcr do
20
+ subject(:payment_plan) { FatZebra::PaymentPlan.create(payment_plan_valid_payload) }
21
+
22
+ it { is_expected.to be_accepted }
23
+ it { expect(payment_plan.id).to_not be_empty }
24
+ it { expect(payment_plan.payments.count).to eq(5) }
25
+
26
+ context 'validations' do
27
+ let(:payment_plan_valid_payload) {{}}
28
+
29
+ it { expect { payment_plan }.to raise_error(FatZebra::RequestValidationError) }
30
+ end
31
+ end
32
+
33
+ describe '.find', :vcr do
34
+ let!(:create) { FatZebra::PaymentPlan.create(payment_plan_valid_payload) }
35
+ subject(:payment_plan) { FatZebra::PaymentPlan.find(create.reference) }
36
+
37
+ it { is_expected.to be_accepted }
38
+ it { expect(payment_plan.reference).to eq(create.reference) }
39
+ it { expect(payment_plan).to be_a(FatZebra::PaymentPlan) }
40
+ end
41
+
42
+ describe '.update', :vcr do
43
+ let(:create) { FatZebra::PaymentPlan.create(payment_plan_valid_payload) }
44
+
45
+ subject(:payment_plan) { FatZebra::PaymentPlan.update(create.id, new_status: 'Suspended') }
46
+
47
+ it { is_expected.to be_accepted }
48
+ it { expect(payment_plan.status).to eq('Suspended') }
49
+ it { expect(payment_plan).to be_a(FatZebra::PaymentPlan) }
50
+ end
51
+
52
+ context '#update', :vcr do
53
+ let(:payment_plan) { FatZebra::PaymentPlan.new(payment_plan_valid_payload) }
54
+ before { payment_plan.save }
55
+ before { payment_plan.update(new_status: 'Suspended') }
56
+
57
+ it { expect(payment_plan.status).to eq('Suspended') }
58
+ it { expect(payment_plan).to be_a(FatZebra::PaymentPlan) }
59
+ end
60
+
61
+ describe '.delete', :vcr do
62
+ let(:create) { FatZebra::PaymentPlan.create(payment_plan_valid_payload) }
63
+ subject(:payment_plan) { FatZebra::PaymentPlan.delete(create.id) }
64
+
65
+ it { is_expected.to be_accepted }
66
+ end
67
+
68
+ describe '#destroy', :vcr do
69
+ let(:payment_plan) { FatZebra::PaymentPlan.create(payment_plan_valid_payload) }
70
+ before { payment_plan.destroy }
71
+
72
+ it { expect(payment_plan.status).to eq('Cancelled') }
73
+ end
74
+
75
+ describe '#suspend!', :vcr do
76
+ let(:payment_plan) { FatZebra::PaymentPlan.new(payment_plan_valid_payload) }
77
+ before { payment_plan.save }
78
+ before { payment_plan.suspend! }
79
+
80
+ it { expect(payment_plan.status).to eq('Suspended') }
81
+ it { expect(payment_plan).to be_a(FatZebra::PaymentPlan) }
82
+ end
83
+
84
+ describe '#active!', :vcr do
85
+ let(:payment_plan) { FatZebra::PaymentPlan.new(payment_plan_valid_payload) }
86
+ before { payment_plan.save }
87
+ before { expect(payment_plan.suspend!.status).to eq('Suspended') }
88
+ before { payment_plan.active! }
89
+
90
+ it { expect(payment_plan.status).to eq('Active') }
91
+ it { expect(payment_plan).to be_a(FatZebra::PaymentPlan) }
92
+ end
93
+
94
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe FatZebra::Purchase do
4
+
5
+ describe '.create', :vcr do
6
+ subject(:purchase) { FatZebra::Purchase.create(valid_purchase_payload) }
7
+
8
+ it { is_expected.to be_accepted }
9
+ it { is_expected.to be_successful }
10
+ it { expect(purchase.card_holder).to eq(valid_purchase_payload[:card_holder]) }
11
+ it { expect(purchase.currency).to eq('AUD') }
12
+ it { expect(purchase.reference).to_not be_empty }
13
+ it { expect(purchase.transaction_id).to_not be_empty }
14
+ it { expect(purchase.decimal_amount).to eq(100) }
15
+ it { expect(purchase.card_type).to eq('MasterCard') }
16
+ it { expect(purchase.card_category).to eq('Credit') }
17
+ it { expect(purchase.card_token).to_not be_empty }
18
+ it { expect(purchase.addendum_data).to eq({}) }
19
+ it { expect(purchase.metadata).to eq({ "authorization_tracking_id" => "", "original_transaction_reference" => "" }) }
20
+ it { expect(purchase.response_code).to eq('00') }
21
+
22
+ context 'bad request' do
23
+ subject(:purchase) { FatZebra::Purchase.create(valid_purchase_payload.merge(currency: 'XXX' )) }
24
+
25
+ it { is_expected.to_not be_accepted }
26
+ it { is_expected.to_not be_successful }
27
+ end
28
+
29
+ context 'validations' do
30
+ let(:valid_purchase_payload) {{}}
31
+
32
+ it { expect{ purchase }.to raise_error(FatZebra::RequestValidationError) }
33
+ end
34
+ end
35
+
36
+ describe '.find', :vcr do
37
+ let!(:create) { FatZebra::Purchase.create(valid_purchase_payload) }
38
+ subject(:purchase) { FatZebra::Purchase.find(create.reference) }
39
+
40
+ it { is_expected.to be_accepted }
41
+ it { is_expected.to be_successful }
42
+ it { expect(purchase.reference).to eq(create.reference) }
43
+ it { expect(purchase.transaction_id).to eq(create.transaction_id) }
44
+ end
45
+
46
+ describe '.search', :vcr do
47
+ let!(:start) { Date.parse('2017-07-03') }
48
+ subject(:purchases) { FatZebra::Purchase.search(from: start) }
49
+
50
+ before { 2.times { |i| FatZebra::Purchase.create(valid_purchase_payload.merge(reference: "#{SecureRandom.hex}-#{i}")) } }
51
+
52
+ it { is_expected.to be_accepted }
53
+ it { expect(purchases.data.count).to be >= 2 }
54
+ it { expect(purchases.data.first).to be_a(FatZebra::Purchase) }
55
+ end
56
+
57
+ describe '#refund', :vcr do
58
+ let(:purchase) { FatZebra::Purchase.create(valid_purchase_payload) }
59
+ subject(:refund) { purchase.refund }
60
+
61
+ it { is_expected.to be_accepted }
62
+ it { is_expected.to be_successful }
63
+ it { expect(refund).to be_a(FatZebra::Refund) }
64
+ end
65
+
66
+ describe '#capture', :vcr do
67
+ let(:purchase) { FatZebra::Purchase.create(valid_purchase_payload.merge(capture: false)) }
68
+ subject(:capture) { purchase.capture }
69
+
70
+ it { is_expected.to be_accepted }
71
+ it { is_expected.to be_successful }
72
+ it { expect(capture).to be_a(FatZebra::Purchase) }
73
+ end
74
+
75
+ describe '.void', :vcr do
76
+ let(:purchase) { FatZebra::Purchase.create(valid_purchase_payload) }
77
+ subject(:void) { FatZebra::Purchase.void(purchase.id) }
78
+
79
+ it { is_expected.to be_accepted }
80
+ it { is_expected.to be_successful }
81
+ it { expect(void.message).to eq('Voided') }
82
+ it { expect(void).to be_a(FatZebra::Purchase) }
83
+ end
84
+
85
+ describe '#void', :vcr do
86
+ subject(:purchase) { FatZebra::Purchase.create(valid_purchase_payload) }
87
+ before { expect(purchase.void).to be_truthy }
88
+
89
+ it { is_expected.to be_accepted }
90
+ it { is_expected.to be_successful }
91
+ it { expect(purchase.message).to eq('Voided') }
92
+ it { expect(purchase).to be_a(FatZebra::Purchase) }
93
+ end
94
+
95
+ describe '.settlement', :vcr do
96
+ before { 2.times { |i| FatZebra::Purchase.create(valid_purchase_payload.merge(reference: "#{SecureRandom.hex}-#{i}")) } }
97
+
98
+ subject(:settlement) { FatZebra::Purchase.settlement(from: Date.parse('2017/06/22'), to: Date.parse('2017-06-27')) }
99
+
100
+ it { is_expected.to be_accepted }
101
+ it { expect(settlement.data.count).to be >= 2 }
102
+ it { expect(settlement.data.first).to be_a(FatZebra::Purchase) }
103
+ end
104
+
105
+ end