balanced 0.8.2 → 1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (359) hide show
  1. checksums.yaml +4 -4
  2. data/.rbenv-version +1 -1
  3. data/.ruby-version +1 -1
  4. data/Gemfile +7 -3
  5. data/README.md +2 -10
  6. data/Rakefile +4 -18
  7. data/balanced.gemspec +8 -10
  8. data/lib/balanced.rb +28 -28
  9. data/lib/balanced/client.rb +15 -6
  10. data/lib/balanced/error.rb +21 -12
  11. data/lib/balanced/pager.rb +66 -25
  12. data/lib/balanced/resources.rb +18 -17
  13. data/lib/balanced/resources/api_key.rb +4 -0
  14. data/lib/balanced/resources/bank_account.rb +26 -75
  15. data/lib/balanced/resources/callback.rb +2 -0
  16. data/lib/balanced/resources/card.rb +15 -65
  17. data/lib/balanced/resources/card_hold.rb +38 -0
  18. data/lib/balanced/resources/credit.rb +6 -50
  19. data/lib/balanced/resources/customer.rb +33 -71
  20. data/lib/balanced/resources/debit.rb +6 -14
  21. data/lib/balanced/resources/event.rb +6 -0
  22. data/lib/balanced/resources/funding_instrument.rb +11 -0
  23. data/lib/balanced/resources/hypermedia.rb +28 -0
  24. data/lib/balanced/resources/marketplace.rb +5 -203
  25. data/lib/balanced/resources/order.rb +71 -0
  26. data/lib/balanced/resources/refund.rb +2 -7
  27. data/lib/balanced/resources/resource.rb +169 -106
  28. data/lib/balanced/resources/reversal.rb +2 -8
  29. data/lib/balanced/resources/transfer.rb +11 -0
  30. data/lib/balanced/response/balanced_exception_middleware.rb +2 -2
  31. data/lib/balanced/utils.rb +47 -14
  32. data/lib/balanced/version.rb +1 -1
  33. data/scenario.cache +526 -380
  34. data/scenarios/api_key_create/definition.rb +1 -0
  35. data/scenarios/api_key_create/request.rb +2 -0
  36. data/scenarios/api_key_create/ruby.mako +21 -0
  37. data/scenarios/api_key_delete/definition.rb +1 -0
  38. data/scenarios/api_key_delete/request.rb +3 -0
  39. data/scenarios/api_key_delete/ruby.mako +12 -0
  40. data/scenarios/api_key_list/definition.rb +1 -0
  41. data/scenarios/api_key_list/request.rb +2 -0
  42. data/scenarios/api_key_list/ruby.mako +28 -0
  43. data/scenarios/api_key_show/definition.rb +1 -0
  44. data/scenarios/api_key_show/request.rb +2 -0
  45. data/scenarios/api_key_show/ruby.mako +18 -0
  46. data/scenarios/{customer_add_bank_account → bank_account_associate_to_customer}/definition.rb +0 -0
  47. data/scenarios/bank_account_associate_to_customer/request.rb +3 -0
  48. data/scenarios/bank_account_associate_to_customer/ruby.mako +49 -0
  49. data/scenarios/bank_account_create/definition.rb +1 -1
  50. data/scenarios/bank_account_create/request.rb +1 -1
  51. data/scenarios/bank_account_create/ruby.mako +44 -7
  52. data/scenarios/{credit_create_existing_bank_account → bank_account_credit}/definition.rb +0 -0
  53. data/scenarios/bank_account_credit/request.rb +3 -0
  54. data/scenarios/bank_account_credit/ruby.mako +42 -0
  55. data/scenarios/bank_account_debit/definition.rb +1 -0
  56. data/scenarios/bank_account_debit/request.rb +5 -0
  57. data/scenarios/bank_account_debit/ruby.mako +50 -0
  58. data/scenarios/bank_account_delete/request.rb +1 -1
  59. data/scenarios/bank_account_delete/ruby.mako +5 -3
  60. data/scenarios/bank_account_list/ruby.mako +76 -2
  61. data/scenarios/bank_account_show/definition.rb +1 -1
  62. data/scenarios/bank_account_show/request.rb +1 -1
  63. data/scenarios/bank_account_show/ruby.mako +41 -5
  64. data/scenarios/bank_account_update/definition.rb +1 -0
  65. data/scenarios/bank_account_update/request.rb +6 -0
  66. data/scenarios/bank_account_update/ruby.mako +56 -0
  67. data/scenarios/bank_account_verification_create/request.rb +1 -1
  68. data/scenarios/bank_account_verification_create/ruby.mako +20 -3
  69. data/scenarios/bank_account_verification_show/definition.rb +1 -1
  70. data/scenarios/bank_account_verification_show/request.rb +1 -1
  71. data/scenarios/bank_account_verification_show/ruby.mako +21 -4
  72. data/scenarios/bank_account_verification_update/definition.rb +1 -1
  73. data/scenarios/bank_account_verification_update/request.rb +5 -5
  74. data/scenarios/bank_account_verification_update/ruby.mako +24 -8
  75. data/scenarios/callback_create/definition.rb +1 -1
  76. data/scenarios/callback_create/request.rb +2 -2
  77. data/scenarios/callback_create/ruby.mako +22 -0
  78. data/scenarios/callback_delete/definition.rb +1 -1
  79. data/scenarios/callback_delete/request.rb +2 -2
  80. data/scenarios/callback_delete/ruby.mako +12 -0
  81. data/scenarios/callback_list/definition.rb +1 -1
  82. data/scenarios/callback_list/request.rb +1 -2
  83. data/scenarios/callback_list/ruby.mako +20 -0
  84. data/scenarios/callback_show/definition.rb +1 -1
  85. data/scenarios/callback_show/request.rb +1 -1
  86. data/scenarios/callback_show/ruby.mako +20 -0
  87. data/scenarios/{customer_add_card → card_associate_to_customer}/definition.rb +0 -0
  88. data/scenarios/card_associate_to_customer/request.rb +3 -0
  89. data/scenarios/card_associate_to_customer/ruby.mako +49 -0
  90. data/scenarios/card_create/request.rb +1 -2
  91. data/scenarios/card_create/ruby.mako +44 -7
  92. data/scenarios/card_debit/definition.rb +1 -0
  93. data/scenarios/card_debit/request.rb +5 -0
  94. data/scenarios/card_debit/ruby.mako +49 -0
  95. data/scenarios/card_delete/request.rb +1 -1
  96. data/scenarios/card_delete/ruby.mako +5 -3
  97. data/scenarios/card_hold_capture/definition.rb +1 -0
  98. data/scenarios/card_hold_capture/request.rb +5 -0
  99. data/scenarios/card_hold_capture/ruby.mako +49 -0
  100. data/scenarios/card_hold_create/definition.rb +1 -0
  101. data/scenarios/card_hold_create/request.rb +5 -0
  102. data/scenarios/card_hold_create/ruby.mako +38 -0
  103. data/scenarios/card_hold_list/definition.rb +1 -0
  104. data/scenarios/card_hold_list/request.rb +2 -0
  105. data/scenarios/card_hold_list/ruby.mako +60 -0
  106. data/scenarios/card_hold_show/definition.rb +1 -0
  107. data/scenarios/card_hold_show/request.rb +2 -0
  108. data/scenarios/card_hold_show/ruby.mako +36 -0
  109. data/scenarios/card_hold_update/definition.rb +1 -0
  110. data/scenarios/card_hold_update/request.rb +7 -0
  111. data/scenarios/card_hold_update/ruby.mako +42 -0
  112. data/scenarios/card_hold_void/definition.rb +1 -0
  113. data/scenarios/card_hold_void/request.rb +3 -0
  114. data/scenarios/card_hold_void/ruby.mako +36 -0
  115. data/scenarios/card_list/definition.rb +1 -1
  116. data/scenarios/card_list/request.rb +1 -1
  117. data/scenarios/card_list/ruby.mako +78 -5
  118. data/scenarios/card_show/definition.rb +1 -1
  119. data/scenarios/card_show/request.rb +1 -1
  120. data/scenarios/card_show/ruby.mako +42 -4
  121. data/scenarios/card_update/definition.rb +1 -1
  122. data/scenarios/card_update/request.rb +1 -1
  123. data/scenarios/card_update/ruby.mako +45 -4
  124. data/scenarios/credit_list/request.rb +1 -3
  125. data/scenarios/credit_list/ruby.mako +34 -4
  126. data/scenarios/{credit_bank_account_list → credit_list_bank_account}/definition.rb +0 -0
  127. data/scenarios/credit_list_bank_account/request.rb +3 -0
  128. data/scenarios/credit_list_bank_account/ruby.mako +13 -0
  129. data/scenarios/credit_show/definition.rb +1 -1
  130. data/scenarios/credit_show/request.rb +1 -3
  131. data/scenarios/credit_show/ruby.mako +35 -5
  132. data/scenarios/{credit_create_new_bank_account → credit_update}/definition.rb +0 -0
  133. data/scenarios/credit_update/request.rb +7 -0
  134. data/scenarios/credit_update/ruby.mako +48 -0
  135. data/scenarios/customer_create/request.rb +4 -1
  136. data/scenarios/customer_create/ruby.mako +60 -3
  137. data/scenarios/customer_delete/request.rb +1 -1
  138. data/scenarios/customer_delete/ruby.mako +4 -2
  139. data/scenarios/customer_list/definition.rb +1 -0
  140. data/scenarios/customer_list/request.rb +2 -0
  141. data/scenarios/customer_list/ruby.mako +105 -0
  142. data/scenarios/customer_show/definition.rb +1 -0
  143. data/scenarios/customer_show/request.rb +2 -0
  144. data/scenarios/customer_show/ruby.mako +58 -0
  145. data/scenarios/customer_update/definition.rb +1 -0
  146. data/scenarios/customer_update/request.rb +7 -0
  147. data/scenarios/customer_update/ruby.mako +64 -0
  148. data/scenarios/debit_list/request.rb +1 -3
  149. data/scenarios/debit_list/ruby.mako +70 -4
  150. data/scenarios/debit_show/definition.rb +1 -1
  151. data/scenarios/debit_show/request.rb +1 -1
  152. data/scenarios/debit_show/ruby.mako +39 -4
  153. data/scenarios/debit_update/definition.rb +1 -1
  154. data/scenarios/debit_update/request.rb +1 -1
  155. data/scenarios/debit_update/ruby.mako +39 -4
  156. data/scenarios/event_list/definition.rb +1 -1
  157. data/scenarios/event_list/request.rb +1 -2
  158. data/scenarios/event_list/ruby.mako +54 -5
  159. data/scenarios/event_show/definition.rb +1 -1
  160. data/scenarios/event_show/request.rb +1 -1
  161. data/scenarios/event_show/ruby.mako +54 -4
  162. data/scenarios/helpers.rb +29 -2
  163. data/scenarios/order_create/definition.rb +1 -0
  164. data/scenarios/order_create/request.rb +5 -0
  165. data/scenarios/order_create/ruby.mako +46 -0
  166. data/scenarios/order_list/definition.rb +1 -0
  167. data/scenarios/order_list/request.rb +2 -0
  168. data/scenarios/order_list/ruby.mako +42 -0
  169. data/scenarios/order_show/definition.rb +1 -0
  170. data/scenarios/order_show/request.rb +2 -0
  171. data/scenarios/order_show/ruby.mako +44 -0
  172. data/scenarios/order_update/definition.rb +1 -0
  173. data/scenarios/order_update/request.rb +7 -0
  174. data/scenarios/order_update/ruby.mako +50 -0
  175. data/scenarios/refund_create/definition.rb +1 -1
  176. data/scenarios/refund_create/request.rb +2 -1
  177. data/scenarios/refund_create/ruby.mako +33 -5
  178. data/scenarios/refund_list/request.rb +1 -3
  179. data/scenarios/refund_list/ruby.mako +30 -4
  180. data/scenarios/refund_show/definition.rb +1 -1
  181. data/scenarios/refund_show/request.rb +1 -1
  182. data/scenarios/refund_show/ruby.mako +32 -4
  183. data/scenarios/refund_update/definition.rb +1 -1
  184. data/scenarios/refund_update/request.rb +1 -1
  185. data/scenarios/refund_update/ruby.mako +32 -4
  186. data/scenarios/render_mako.rb +59 -4
  187. data/scenarios/reversal_create/definition.rb +1 -0
  188. data/scenarios/reversal_create/request.rb +9 -0
  189. data/scenarios/reversal_create/ruby.mako +45 -0
  190. data/scenarios/reversal_list/definition.rb +1 -0
  191. data/scenarios/reversal_list/request.rb +2 -0
  192. data/scenarios/reversal_list/ruby.mako +36 -0
  193. data/scenarios/reversal_show/definition.rb +1 -0
  194. data/scenarios/reversal_show/request.rb +2 -0
  195. data/scenarios/reversal_show/ruby.mako +37 -0
  196. data/scenarios/reversal_update/definition.rb +1 -0
  197. data/scenarios/reversal_update/request.rb +7 -0
  198. data/scenarios/reversal_update/ruby.mako +44 -0
  199. data/spec/balanced/error_spec.rb +7 -7
  200. data/spec/balanced/pager_spec.rb +10 -10
  201. data/spec/balanced/resources/api_key_spec.rb +6 -35
  202. data/spec/balanced/resources/bank_account_spec.rb +123 -218
  203. data/spec/balanced/resources/callback_spec.rb +12 -13
  204. data/spec/balanced/resources/card_hold_spec.rb +103 -0
  205. data/spec/balanced/resources/card_spec.rb +101 -27
  206. data/spec/balanced/resources/credit_spec.rb +69 -35
  207. data/spec/balanced/resources/customer_spec.rb +91 -271
  208. data/spec/balanced/resources/debit_spec.rb +95 -0
  209. data/spec/balanced/resources/marketplace_spec.rb +17 -170
  210. data/spec/balanced/resources/order_spec.rb +364 -0
  211. data/spec/balanced/resources/resource_spec.rb +25 -32
  212. data/spec/balanced_spec.rb +18 -36
  213. data/spec/client_spec.rb +7 -7
  214. data/spec/spec_helper.rb +19 -18
  215. data/spec/utils_spec.rb +5 -5
  216. metadata +123 -165
  217. data/examples/bank_account_debits.rb +0 -57
  218. data/examples/customers.rb +0 -114
  219. data/examples/events_and_callbacks.rb +0 -81
  220. data/examples/examples.rb +0 -162
  221. data/examples/exception_handling.rb +0 -44
  222. data/lib/balanced/resources/account.rb +0 -179
  223. data/lib/balanced/resources/hold.rb +0 -61
  224. data/lib/balanced/resources/invoice.rb +0 -11
  225. data/lib/balanced/resources/merchant.rb +0 -21
  226. data/lib/balanced/resources/transaction.rb +0 -17
  227. data/scenarios/account_add_card/definition.rb +0 -1
  228. data/scenarios/account_add_card/request.rb +0 -3
  229. data/scenarios/account_add_card/ruby.mako +0 -11
  230. data/scenarios/account_capture_hold/definition.rb +0 -1
  231. data/scenarios/account_capture_hold/request.rb +0 -3
  232. data/scenarios/account_capture_hold/ruby.mako +0 -11
  233. data/scenarios/account_create/definition.rb +0 -1
  234. data/scenarios/account_create/request.rb +0 -2
  235. data/scenarios/account_create/ruby.mako +0 -10
  236. data/scenarios/account_create_buyer/definition.rb +0 -1
  237. data/scenarios/account_create_buyer/request.rb +0 -5
  238. data/scenarios/account_create_buyer/ruby.mako +0 -13
  239. data/scenarios/account_create_debit/definition.rb +0 -1
  240. data/scenarios/account_create_debit/request.rb +0 -3
  241. data/scenarios/account_create_debit/ruby.mako +0 -11
  242. data/scenarios/account_create_hold/definition.rb +0 -1
  243. data/scenarios/account_create_hold/request.rb +0 -3
  244. data/scenarios/account_create_hold/ruby.mako +0 -11
  245. data/scenarios/account_create_merchant/definition.rb +0 -1
  246. data/scenarios/account_create_merchant/request.rb +0 -3
  247. data/scenarios/account_create_merchant/ruby.mako +0 -11
  248. data/scenarios/account_underwrite_business/definition.rb +0 -1
  249. data/scenarios/account_underwrite_business/request.rb +0 -17
  250. data/scenarios/account_underwrite_business/ruby.mako +0 -37
  251. data/scenarios/account_underwrite_person/definition.rb +0 -1
  252. data/scenarios/account_underwrite_person/request.rb +0 -18
  253. data/scenarios/account_underwrite_person/ruby.mako +0 -31
  254. data/scenarios/bank_account_find_and_credit/definition.rb +0 -1
  255. data/scenarios/bank_account_find_and_credit/request.rb +0 -5
  256. data/scenarios/bank_account_find_and_credit/ruby.mako +0 -13
  257. data/scenarios/bank_account_find_and_delete/definition.rb +0 -1
  258. data/scenarios/bank_account_find_and_delete/request.rb +0 -3
  259. data/scenarios/bank_account_find_and_delete/ruby.mako +0 -10
  260. data/scenarios/bank_account_invalid_routing_number/definition.rb +0 -1
  261. data/scenarios/bank_account_invalid_routing_number/request.rb +0 -11
  262. data/scenarios/bank_account_invalid_routing_number/ruby.mako +0 -16
  263. data/scenarios/card_invalidate/definition.rb +0 -1
  264. data/scenarios/card_invalidate/request.rb +0 -3
  265. data/scenarios/card_invalidate/ruby.mako +0 -10
  266. data/scenarios/credit_account_list/definition.rb +0 -1
  267. data/scenarios/credit_account_list/request.rb +0 -3
  268. data/scenarios/credit_account_list/ruby.mako +0 -10
  269. data/scenarios/credit_account_merchant_create/definition.rb +0 -1
  270. data/scenarios/credit_account_merchant_create/request.rb +0 -5
  271. data/scenarios/credit_account_merchant_create/ruby.mako +0 -12
  272. data/scenarios/credit_bank_account_list/request.rb +0 -5
  273. data/scenarios/credit_bank_account_list/ruby.mako +0 -12
  274. data/scenarios/credit_create_existing_bank_account/request.rb +0 -5
  275. data/scenarios/credit_create_existing_bank_account/ruby.mako +0 -12
  276. data/scenarios/credit_create_new_bank_account/request.rb +0 -10
  277. data/scenarios/credit_create_new_bank_account/ruby.mako +0 -21
  278. data/scenarios/credit_customer_list/definition.rb +0 -1
  279. data/scenarios/credit_customer_list/request.rb +0 -4
  280. data/scenarios/credit_customer_list/ruby.mako +0 -12
  281. data/scenarios/credit_failed_state/definition.rb +0 -1
  282. data/scenarios/credit_failed_state/request.rb +0 -10
  283. data/scenarios/credit_failed_state/ruby.mako +0 -18
  284. data/scenarios/credit_paid_state/definition.rb +0 -1
  285. data/scenarios/credit_paid_state/request.rb +0 -11
  286. data/scenarios/credit_paid_state/ruby.mako +0 -19
  287. data/scenarios/credit_pending_state/definition.rb +0 -1
  288. data/scenarios/credit_pending_state/request.rb +0 -9
  289. data/scenarios/credit_pending_state/ruby.mako +0 -17
  290. data/scenarios/customer_add_bank_account/request.rb +0 -3
  291. data/scenarios/customer_add_bank_account/ruby.mako +0 -11
  292. data/scenarios/customer_add_card/request.rb +0 -3
  293. data/scenarios/customer_add_card/ruby.mako +0 -11
  294. data/scenarios/customer_capture_hold/definition.rb +0 -1
  295. data/scenarios/customer_capture_hold/request.rb +0 -3
  296. data/scenarios/customer_capture_hold/ruby.mako +0 -0
  297. data/scenarios/customer_create_debit/definition.rb +0 -1
  298. data/scenarios/customer_create_debit/request.rb +0 -3
  299. data/scenarios/customer_create_debit/ruby.mako +0 -11
  300. data/scenarios/customer_create_hold/definition.rb +0 -1
  301. data/scenarios/customer_create_hold/request.rb +0 -3
  302. data/scenarios/customer_create_hold/ruby.mako +0 -11
  303. data/scenarios/customer_credit/definition.rb +0 -1
  304. data/scenarios/customer_credit/request.rb +0 -2
  305. data/scenarios/customer_credit/ruby.mako +0 -8
  306. data/scenarios/debit_account_list/definition.rb +0 -1
  307. data/scenarios/debit_account_list/request.rb +0 -3
  308. data/scenarios/debit_account_list/ruby.mako +0 -10
  309. data/scenarios/debit_create/definition.rb +0 -1
  310. data/scenarios/debit_create/request.rb +0 -5
  311. data/scenarios/debit_create/ruby.mako +0 -15
  312. data/scenarios/debit_customer_list/definition.rb +0 -1
  313. data/scenarios/debit_customer_list/request.rb +0 -4
  314. data/scenarios/debit_customer_list/ruby.mako +0 -12
  315. data/scenarios/debit_refund/definition.rb +0 -1
  316. data/scenarios/debit_refund/request.rb +0 -3
  317. data/scenarios/debit_refund/ruby.mako +0 -10
  318. data/scenarios/delete.rb +0 -7
  319. data/scenarios/event_replay/definition.rb +0 -0
  320. data/scenarios/event_replay/request.rb +0 -1
  321. data/scenarios/event_replay/ruby.mako +0 -0
  322. data/scenarios/execute.rb +0 -27
  323. data/scenarios/hold_account_list/definition.rb +0 -1
  324. data/scenarios/hold_account_list/request.rb +0 -3
  325. data/scenarios/hold_account_list/ruby.mako +0 -10
  326. data/scenarios/hold_capture/definition.rb +0 -1
  327. data/scenarios/hold_capture/request.rb +0 -5
  328. data/scenarios/hold_capture/ruby.mako +0 -15
  329. data/scenarios/hold_create/definition.rb +0 -1
  330. data/scenarios/hold_create/request.rb +0 -5
  331. data/scenarios/hold_create/ruby.mako +0 -14
  332. data/scenarios/hold_customer_list/definition.rb +0 -1
  333. data/scenarios/hold_customer_list/request.rb +0 -3
  334. data/scenarios/hold_customer_list/ruby.mako +0 -11
  335. data/scenarios/hold_list/definition.rb +0 -1
  336. data/scenarios/hold_list/request.rb +0 -4
  337. data/scenarios/hold_list/ruby.mako +0 -11
  338. data/scenarios/hold_show/definition.rb +0 -1
  339. data/scenarios/hold_show/request.rb +0 -2
  340. data/scenarios/hold_show/ruby.mako +0 -10
  341. data/scenarios/hold_update/definition.rb +0 -1
  342. data/scenarios/hold_update/request.rb +0 -7
  343. data/scenarios/hold_update/ruby.mako +0 -16
  344. data/scenarios/hold_void/definition.rb +0 -1
  345. data/scenarios/hold_void/request.rb +0 -3
  346. data/scenarios/hold_void/ruby.mako +0 -10
  347. data/scenarios/refund_account_list/definition.rb +0 -1
  348. data/scenarios/refund_account_list/request.rb +0 -3
  349. data/scenarios/refund_account_list/ruby.mako +0 -10
  350. data/scenarios/refund_customer_list/definition.rb +0 -1
  351. data/scenarios/refund_customer_list/request.rb +0 -3
  352. data/scenarios/refund_customer_list/ruby.mako +0 -11
  353. data/scenarios/render.rb +0 -32
  354. data/scenarios/render_one.rb +0 -32
  355. data/spec/balanced/resources/account_spec.rb +0 -636
  356. data/spec/balanced/resources/hold_spec.rb +0 -48
  357. data/spec/balanced/resources/merchant_spec.rb +0 -6
  358. data/spec/scenarios_spec.rb +0 -39
  359. data/upload_docs.rb +0 -40
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ describe Balanced::Debit, :vcr do
4
+
5
+ before do
6
+ api_key = Balanced::ApiKey.new.save
7
+ Balanced.configure api_key.secret
8
+ @marketplace = Balanced::Marketplace.new.save
9
+ end
10
+
11
+ describe '#create', :vcr do
12
+
13
+ describe 'one time debit', :vcr do
14
+ subject do
15
+ debit = Balanced::Debit.new(
16
+ :amount => 1234,
17
+ :source => {
18
+ :number => '5105105105105100',
19
+ :expiration_month => '12',
20
+ :expiration_year => '2015'
21
+ })
22
+ debit.save
23
+ end
24
+ it { should_not be_nil }
25
+ it { should be_instance_of Balanced::Debit }
26
+
27
+ its(:href) { should_not be_nil }
28
+ its(:amount) { should eql 1234 }
29
+ its(:appears_on_statement_as) { should eql 'BAL*example.com' }
30
+ its(:description) { should be_nil }
31
+ its(:status) { should eql 'succeeded' }
32
+ end
33
+
34
+ describe 'from a customer', :vcr do
35
+ before do
36
+ @customer = Balanced::Customer.new.save
37
+ @card = Balanced::Card.new(
38
+ :number => '5105105105105100',
39
+ :expiration_month => '12',
40
+ :expiration_year => '2020'
41
+ ).save
42
+ @card.associate_to_customer(@customer)
43
+ @customer.add_source(@card)
44
+ end
45
+
46
+ context 'tokenized card', :vcr do
47
+ subject do
48
+ @card.debit(:amount => 1234)
49
+ end
50
+ it { should be_instance_of Balanced::Debit }
51
+ its(:href) { should_not be_nil }
52
+ its(:amount) { should eql 1234 }
53
+ its(:appears_on_statement_as) { should eql "BAL*#{@marketplace.domain_url}" }
54
+ its(:description) { should be_nil }
55
+ its(:status) { should eql 'succeeded' }
56
+ its(:source) { should be_instance_of Balanced::Card }
57
+ its('source.href') { should match "#{@card.href}" }
58
+ end
59
+
60
+ context 'default source', :vcr do
61
+ subject do
62
+ @customer.debit(:amount => 1234)
63
+ end
64
+ it { should be_instance_of Balanced::Debit }
65
+ its(:href) { should_not be_nil }
66
+ its(:amount) { should eql 1234 }
67
+ its(:appears_on_statement_as) { should eql "BAL*#{@marketplace.domain_url}" }
68
+ its(:description) { should be_nil }
69
+ its(:status) { should eql 'succeeded' }
70
+ its(:source) { should be_instance_of Balanced::Card }
71
+ its('source.href') { should match "#{@card.href}" }
72
+ end
73
+ end
74
+ end
75
+
76
+ describe '#refund', :vcr do
77
+ subject do
78
+ debit = Balanced::Debit.new(
79
+ :amount => 1234,
80
+ :source => {
81
+ :number => '5105105105105100',
82
+ :expiration_month => '12',
83
+ :expiration_year => '2015'
84
+ })
85
+ debit.save
86
+ refund = debit.refund
87
+ refund
88
+ end
89
+
90
+ it { should_not be_nil }
91
+ it { should be_instance_of Balanced::Refund }
92
+ its(:amount) { should eql 1234 }
93
+
94
+ end
95
+ end
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
 
4
4
  describe Balanced::Marketplace, :vcr do
@@ -6,189 +6,36 @@ describe Balanced::Marketplace, :vcr do
6
6
  api_key = Balanced::ApiKey.new.save
7
7
  Balanced.configure api_key.secret
8
8
  @marketplace = Balanced::Marketplace.new.save
9
- @bank_account = @marketplace.create_bank_account(
10
- :account_number => "1234567890",
11
- :bank_code => "321174851",
12
- :name => "Jack Q Merchant"
13
- )
14
- @merchant = @marketplace.create_merchant(
15
- :name =>"Jack Q Merchant",
16
- :email_address => "merchant@example.org",
17
- :merchant => {
18
- :type => "person",
19
- :name => "Billy Jones",
20
- :street_address => "801 High St.",
21
- :postal_code => "94301",
22
- :country => "USA",
23
- :dob => "1842-01",
24
- :phone_number => "+16505551234"
25
- },
26
- :bank_account_uri => @bank_account.uri
27
- )
28
9
  end
29
10
 
30
- describe "create_bank_account", :vcr do
31
- it "can create a bank account using the option hash" do
32
- bank_account = @marketplace.create_bank_account(
33
- :name => "Jon Q.",
34
- :account_number => "11111111111",
35
- :bank_code => "123456789"
36
- )
37
- bank_account.should be_instance_of Balanced::BankAccount
38
- Balanced.is_collection(bank_account.uri).should be_false
11
+ describe 'marketplace', :vcr do
12
+ it 'should be a Balanced::Marketplace' do
13
+ @marketplace.should be_instance_of Balanced::Marketplace
39
14
  end
40
15
 
41
- end
42
-
43
- describe "create_account", :vcr => { :cassette_name => :new_episodes } do
44
- before do
45
- @account = @marketplace.create_account
46
- @account_with_attributes = @marketplace.create_account(
47
- :name => "Jon Q. Timmy",
48
- :email_address => "bog@example.com"
49
- )
50
- end
51
-
52
- it "creates an account without any roles" do
53
- @account.should be_instance_of Balanced::Account
54
- Balanced.is_collection(@account.uri).should be_false
55
- @account.uri.should match ACCOUNTS_URI_REGEX
56
- @account.roles.size.should eql 0
57
- end
58
-
59
- it "creates an account with some options" do
60
- @account_with_attributes.name.should == "Jon Q. Timmy"
61
- @account_with_attributes.email_address.should == "bog@example.com"
62
- end
63
-
64
- end
65
-
66
- describe "create_card", :vcr do
67
- it "can create a card" do
68
- card = @marketplace.create_card(
69
- :card_number => "4111111111111111",
70
- :expiration_month => "12",
71
- :expiration_year => "2018"
72
- )
73
- card.should be_instance_of Balanced::Card
74
- Balanced.is_collection(card.uri).should be_false
16
+ it 'should conform to application/vnd.api+json' do
17
+ @marketplace.id.should_not be_nil
18
+ @marketplace.href.should_not be_nil
19
+ @marketplace.links.should be_instance_of Hash
75
20
  end
76
- end
77
21
 
78
- describe "create_merchant", :vcr do
79
- describe "class" do
80
- subject { @merchant }
81
- it { should be_instance_of Balanced::Account }
22
+ it '#href' do
23
+ @marketplace.href.should match(/\/marketplaces\/TEST-MP\w{21,23}/)
82
24
  end
83
25
 
84
- describe "attributes" do
85
- describe "#id" do
86
- subject { @merchant.id }
87
- it { should_not be_nil }
88
- it { should_not be_empty }
89
- end
90
- describe "#roles" do
91
- subject { @merchant.roles }
92
- it { should include("merchant") }
93
- end
94
- describe "#email_address" do
95
- subject { @merchant.email_address }
96
- it { should eql "merchant@example.org" }
97
- end
98
- describe "#name" do
99
- subject { @merchant.name }
100
- it { should eql "Jack Q Merchant" }
101
- end
102
- describe "#created_at" do
103
- subject { @merchant.created_at }
104
- it { should_not be_nil }
105
- it { should_not be_empty }
106
- end
107
- describe "#uri" do
108
- subject { @merchant.uri }
109
- it { should match MERCHANT_URI_REGEX }
110
- end
111
- describe "#holds_uri" do
112
- subject { @merchant.holds_uri }
113
- it { should match HOLDS_URI_REGEX }
114
- end
115
- describe "#bank_accounts_uri" do
116
- subject { @merchant.bank_accounts_uri }
117
- it { should match BANK_ACCOUNTS_URI_REGEX }
118
- end
119
- describe "#refunds_uri" do
120
- subject { @merchant.refunds_uri }
121
- it { should match REFUNDS_URI_REGEX }
122
- end
123
- describe "#debits_uri" do
124
- subject { @merchant.debits_uri }
125
- it { should match DEBITS_URI_REGEX }
126
- end
127
- describe "#transactions_uri" do
128
- subject { @merchant.transactions_uri }
129
- it { should match TRANSACTIONS_URI_REGEX }
130
- end
131
- describe "#credits_uri" do
132
- subject { @merchant.credits_uri }
133
- it { should match CREDITS_URI_REGEX }
134
- end
135
- describe "#cards_uri" do
136
- subject { @merchant.cards_uri }
137
- it { should match CARDS_URI_REGEX }
138
- end
26
+ it '#bank_accounts' do
27
+ @marketplace.bank_accounts.should be_instance_of Balanced::Pager
28
+ @marketplace.bank_accounts.href.should eql '/bank_accounts'
139
29
  end
140
- end
141
- end
142
-
143
- describe Balanced::Marketplace, '.marketplace_uri' do
144
- context 'when invoking .my_marketplace', :vcr do
145
- it 'sets the marketplace_id after the first call implicitly' do
146
- Balanced.configure nil
147
- Balanced.is_configured_with_api_key?.should be_false
148
-
149
- Balanced::Marketplace.send(:class_variable_set, :@@marketplace_uri, nil)
150
- Balanced::Marketplace.send(:class_variable_get, :@@marketplace_uri).should be_nil
151
-
152
- api_key = Balanced::ApiKey.new.save
153
- Balanced.configure api_key.secret
154
- marketplace = Balanced::Marketplace.new.save
155
- # creating the marketplace sets `Balanced::Marketplace.marketplace_uri`,
156
- # it will never be unset.
157
-
158
- Balanced::Marketplace.send(:class_variable_get, :@@marketplace_uri).should equal marketplace.uri
159
- old_marketplace_uri = marketplace.uri
160
30
 
161
- api_key = Balanced::ApiKey.new.save
162
- Balanced.configure api_key.secret
163
- marketplace = Balanced::Marketplace.new.save
164
- # creating the marketplace sets `Balanced::Marketplace.marketplace_uri`,
165
- # it will never be unset.
166
-
167
- Balanced::Marketplace.send(:class_variable_get, :@@marketplace_uri).should_not equal old_marketplace_uri
168
- Balanced::Marketplace.send(:class_variable_get, :@@marketplace_uri).should equal marketplace.uri
31
+ it '#owner_customer' do
32
+ @marketplace.owner_customer.should be_instance_of Balanced::Customer
169
33
  end
170
- end
171
-
172
- context 'when creating a Balanced::Marketplace resource', :vcr do
173
- it 'sets the marketplace_uri' do
174
- api_key = Balanced::ApiKey.new.save
175
- Balanced.configure api_key.secret
176
34
 
177
- res = Balanced::Marketplace.new.save
178
- Balanced::Marketplace.marketplace_uri.should == res.uri
179
- Balanced::Marketplace.marketplace_uri.nil?.should be_false
35
+ it '#meta' do
36
+ @marketplace.meta.should be_instance_of Hash
180
37
  end
181
- end
182
- end
183
38
 
184
- describe Balanced::Marketplace, '.marketplace_exists?' do
185
- it 'returns false when nil' do
186
- Balanced::Marketplace.stub(:marketplace_uri) { nil }
187
- Balanced::Marketplace.marketplace_exists?.should == false
188
39
  end
189
40
 
190
- it 'returns true when not nil' do
191
- Balanced::Marketplace.stub(:marketplace_uri) { 'some uri' }
192
- Balanced::Marketplace.marketplace_exists?.should == true
193
- end
194
41
  end
@@ -0,0 +1,364 @@
1
+ require 'spec_helper'
2
+
3
+ describe Balanced::Order, :vcr, :marketplace => true do
4
+
5
+ context 'created with verified merchant' do
6
+ subject(:order) do
7
+ customer = Balanced::Customer.new(
8
+ :name => 'Henry Ford',
9
+ :dob_month => 7,
10
+ :dob_year => 1963,
11
+ :address => {
12
+ :postal_code => '48120'
13
+ }
14
+ ).save
15
+ customer.create_order
16
+ end
17
+
18
+ its(:href) { should eq "/orders/#{subject.id}" }
19
+ its('merchant.merchant_status') { should eq 'underwritten' }
20
+ end
21
+
22
+ describe 'simple order' do
23
+ before do
24
+ # create seller
25
+ @merchant = Balanced::Customer.new(
26
+ :name => 'Henry Ford',
27
+ :dob_month => 7,
28
+ :dob_year => 1963,
29
+ :address => {
30
+ :postal_code => '48120'
31
+ }
32
+ ).save
33
+ @bank_account =@merchant.bank_accounts.create(
34
+ :name => 'William Henry Cavendish III',
35
+ :routing_number => '321174851',
36
+ :account_number => '0987654321',
37
+ :type => 'checking'
38
+ )
39
+
40
+ # create buyer
41
+ @buyer = Balanced::Customer.new(
42
+ :name => 'John Buyer'
43
+ ).save
44
+ @card = @buyer.cards.create(
45
+ :number => '5105105105105100',
46
+ :expiration_month => '12',
47
+ :expiration_year => '2020',
48
+ :cvv => '123'
49
+ )
50
+
51
+ # create order
52
+ @order = @merchant.create_order
53
+ end
54
+
55
+ it 'should debit buyer and pay merchant' do
56
+ debit = @order.debit_from(
57
+ :source => @card,
58
+ :amount => 10000
59
+ )
60
+
61
+ @order.reload
62
+ @order.amount.should eq 10000
63
+ @order.amount_escrowed.should eq 10000
64
+
65
+ @order.credit_to(
66
+ :destination => @bank_account,
67
+ :amount => 8000
68
+ )
69
+ @order.reload
70
+ @order.amount.should eq 10000
71
+ @order.amount_escrowed.should eq 2000
72
+ @order.debits.map { |d| d.href }.should include(debit.href)
73
+ end
74
+
75
+ end
76
+
77
+ describe "can't over credit" do
78
+ before do
79
+ # create seller
80
+ @merchant = Balanced::Customer.new(
81
+ :name => 'Henry Ford',
82
+ :dob_month => 7,
83
+ :dob_year => 1963,
84
+ :address => {
85
+ :postal_code => '48120'
86
+ }
87
+ ).save
88
+ @bank_account =@merchant.bank_accounts.create(
89
+ :name => 'William Henry Cavendish III',
90
+ :routing_number => '321174851',
91
+ :account_number => '0987654321',
92
+ :type => 'checking'
93
+ )
94
+
95
+ # create buyer
96
+ @buyer = Balanced::Customer.new(
97
+ :name => 'John Buyer'
98
+ ).save
99
+ @card = @buyer.cards.create(
100
+ :number => '5105105105105100',
101
+ :expiration_month => '12',
102
+ :expiration_year => '2020',
103
+ :cvv => '123'
104
+ )
105
+
106
+ # create order
107
+ @order = @merchant.create_order
108
+ end
109
+
110
+ it 'credit should fail' do
111
+ @order.debit_from(
112
+ :source => @card,
113
+ :amount => 1234
114
+ )
115
+
116
+ @order.reload
117
+ @order.amount.should eq 1234
118
+ @order.amount_escrowed.should eq 1234
119
+
120
+ expect {
121
+ @order.credit_to(:destination => @bank_account, :amount => 2000)
122
+ }.to raise_exception(Balanced::Conflict)
123
+
124
+ @order.reload
125
+ @order.amount.should eq 1234
126
+ end
127
+ end
128
+
129
+ describe 'create with unverified merchant' do
130
+ before do
131
+ # create seller
132
+ @merchant = Balanced::Customer.new(
133
+ :name => 'William Henry Cavendish III',
134
+ :dob_month => 7,
135
+ :dob_year => 1963
136
+ ).save
137
+ @bank_account =@merchant.bank_accounts.create(
138
+ :name => 'William Henry Cavendish III',
139
+ :routing_number => '321174851',
140
+ :account_number => '0987654321',
141
+ :type => 'checking'
142
+ )
143
+
144
+ # create buyer
145
+ @buyer = Balanced::Customer.new(
146
+ :name => 'John Buyer'
147
+ ).save
148
+ @card = @buyer.cards.create(
149
+ :number => '5105105105105100',
150
+ :expiration_month => '12',
151
+ :expiration_year => '2020',
152
+ :cvv => '123'
153
+ )
154
+
155
+ # create order
156
+ @order = @merchant.create_order
157
+ end
158
+
159
+ it 'credit should succeed when not underwritten' do
160
+ @merchant.merchant_status.should eq 'no-match'
161
+ @bank_account =@merchant.bank_accounts.create(
162
+ :name => 'William Henry Cavendish III',
163
+ :routing_number => '321174851',
164
+ :account_number => '0987654321',
165
+ :type => 'checking'
166
+ )
167
+
168
+ @order.debit_from(:source => @card, :amount => 1234)
169
+
170
+ @order.reload
171
+ @order.amount.should eq 1234
172
+ @order.amount_escrowed.should eq 1234
173
+
174
+ @order.credit_to(
175
+ :destination => @bank_account,
176
+ :amount => 1234
177
+ )
178
+
179
+ @order.reload
180
+ @order.amount.should eq 1234
181
+ end
182
+ end
183
+
184
+ describe 'refund order' do
185
+ before do
186
+
187
+ # create seller
188
+ bank_account = Balanced::BankAccount.new(
189
+ :name => 'William Henry Cavendish III',
190
+ :routing_number => '321174851',
191
+ :account_number => '0987654321',
192
+ :type => 'checking'
193
+ ).save
194
+ @merchant = Balanced::Customer.new(
195
+ :name => 'Henry Ford',
196
+ :dob_month => 7,
197
+ :dob_year => 1963,
198
+ :address => {
199
+ :postal_code => '48120'
200
+ }
201
+ ).save
202
+ bank_account.associate_to_customer(@merchant)
203
+
204
+ # create buyer
205
+ @buyer = Balanced::Customer.new(
206
+ :name => 'John Buyer'
207
+ ).save
208
+ card = @buyer.cards.create(
209
+ :number => '5105105105105100',
210
+ :expiration_month => '12',
211
+ :expiration_year => '2020',
212
+ :cvv => '123'
213
+ )
214
+
215
+ # create order
216
+ @order = @merchant.create_order
217
+
218
+ @debit = @order.debit_from(
219
+ :source => card,
220
+ :amount => 1234
221
+ )
222
+
223
+ @credit = @order.credit_to(
224
+ :destination => bank_account,
225
+ :amount => 1234
226
+ )
227
+ end
228
+
229
+ it 'should create reversal and refund' do
230
+ @order.reload
231
+ @order.amount.should eq 1234
232
+ @order.amount_escrowed.should eq 0
233
+
234
+ @credit.reverse
235
+
236
+ @order.reload
237
+ @order.amount_escrowed.should eq 1234
238
+
239
+ @debit.refund
240
+
241
+ @order.reload
242
+ @order.amount_escrowed.should eq 0
243
+ end
244
+ end
245
+
246
+ describe 'failure behavior' do
247
+ before do
248
+ # create seller
249
+ @bank_account = Balanced::BankAccount.new(
250
+ :name => 'William Henry Cavendish III',
251
+ :routing_number => '321174851',
252
+ :account_number => '0987654321',
253
+ :type => 'checking'
254
+ ).save
255
+ @merchant = Balanced::Customer.new(
256
+ :name => 'Henry Ford',
257
+ :dob_month => 7,
258
+ :dob_year => 1963,
259
+ :address => {
260
+ :postal_code => '48120'
261
+ }
262
+ ).save
263
+
264
+ @bank_account.associate_to_customer(@merchant)
265
+
266
+ # create buyer
267
+ @failing_card = Balanced::Card.new(
268
+ :number => '4444444444444448',
269
+ :expiration_month => '12',
270
+ :expiration_year => '2020',
271
+ :cvv => '123'
272
+ ).save
273
+ @buyer = Balanced::Customer.new(
274
+ :name => 'John Buyer'
275
+ ).save
276
+
277
+ @failing_card.associate_to_customer(@buyer)
278
+
279
+ # create order
280
+ @order = @merchant.create_order
281
+ end
282
+
283
+ it 'should not show failed transactions by default' do
284
+ lambda {
285
+ @order.debit_from(
286
+ :amount => 600,
287
+ :source => @failing_card
288
+ )
289
+ }.should raise_error(Balanced::PaymentRequired)
290
+ lambda {
291
+ @order.credit_to(
292
+ :amount => 600,
293
+ :destination => @bank_account
294
+ )
295
+ }.should raise_error(Balanced::Conflict)
296
+
297
+ @order.reload
298
+ @order.amount.should eq 0
299
+ @order.amount_escrowed.should eq 0
300
+
301
+ @order.debits.to_a.should eql []
302
+ @order.credits.to_a.should eql []
303
+
304
+ @order.debits.where(:status => 'failed').total.should eq 1
305
+ @order.credits.where(:status => 'failed').total.should eq 1
306
+
307
+ end
308
+ end
309
+
310
+ describe 'when seller is not underwritten' do
311
+ before do
312
+ # create seller
313
+ @bank_account = Balanced::BankAccount.new(
314
+ :name => 'William Henry Cavendish III',
315
+ :routing_number => '321174851',
316
+ :account_number => '0987654321',
317
+ :type => 'checking'
318
+ ).save
319
+
320
+ @merchant = Balanced::Customer.new(
321
+ :name => 'Henry Ford'
322
+ ).save
323
+
324
+ @bank_account.associate_to_customer(@merchant)
325
+
326
+ # create buyer
327
+ @buyer_card = Balanced::Card.new(
328
+ :name => 'Darius the Great',
329
+ :number => '4' + '1' * 15,
330
+ :expiration_month => 12,
331
+ :expiration_year => 2016,
332
+ :cvv => '123',
333
+ :address => {
334
+ :line1 => '965 Mission St',
335
+ :line2 => 'Suite 425',
336
+ :city => 'San Francisco',
337
+ :state => 'CA',
338
+ :postal_code => '94103'
339
+ }
340
+ ).save
341
+
342
+ @buyer = Balanced::Customer.new(
343
+ :name => 'Darius the Great',
344
+ :email => 'darius.great@gmail.com',
345
+ :meta => {
346
+ :ip_address => '174.240.15.249'
347
+ }
348
+ ).save
349
+
350
+ @buyer_card.associate_to_customer(@buyer)
351
+
352
+ # create order
353
+ @order = @merchant.create_order
354
+ @order.debit_from(:source => @buyer_card, :amount => 1000)
355
+ end
356
+
357
+ it 'should allow credits to the seller' do
358
+ @order.credit_to(
359
+ :amount => 100,
360
+ :destination => @bank_account
361
+ )
362
+ end
363
+ end
364
+ end