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
@@ -1,17 +1,18 @@
1
- $:.unshift File.join(File.dirname(__FILE__), "balanced", "resources")
2
- require "resource"
3
- require "account"
4
- require "api_key"
5
- require "bank_account"
6
- require "card"
7
- require "credit"
8
- require "debit"
9
- require "hold"
10
- require "marketplace"
11
- require "merchant"
12
- require "refund"
13
- require "reversal"
14
- require "transaction"
15
- require "callback"
16
- require "event"
17
- require "customer"
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'balanced', 'resources'))
2
+ require 'resource'
3
+ require 'hypermedia'
4
+ require 'funding_instrument'
5
+ require 'api_key'
6
+ require 'bank_account'
7
+ require 'card'
8
+ require 'credit'
9
+ require 'debit'
10
+ require 'card_hold'
11
+ require 'marketplace'
12
+ require 'refund'
13
+ require 'reversal'
14
+ require 'callback'
15
+ require 'event'
16
+ require 'customer'
17
+ require 'order'
18
+ require 'transfer'
@@ -6,7 +6,11 @@ module Balanced
6
6
  # *NOTE:* Never give out or expose your ApiKey. You may POST to this
7
7
  # endpoint to create new ApiKeys and then DELETE any old keys.
8
8
  class ApiKey
9
+
9
10
  include Balanced::Resource
11
+ include Balanced::HypermediaRegistry
12
+
13
+ define_hypermedia_types [:api_keys]
10
14
 
11
15
  def save
12
16
  Balanced.configure nil
@@ -4,101 +4,52 @@ module Balanced
4
4
  #
5
5
  # *NOTE:* The BankAccount resource does not support creating a Hold.
6
6
  #
7
- class BankAccount
7
+ class BankAccount < Balanced::DebitableFundingInstrument
8
8
  include Balanced::Resource
9
+ include Balanced::HypermediaRegistry
9
10
 
10
- def self.uri
11
- # Override the default nesting -- bank accounts can be top-level now
12
- # but they can also be nested under marketplaces, which is what we
13
- # want to default to unless explicitly set
14
- self.collection_path
15
- end
16
-
17
- def initialize attributes = {}
18
- Balanced::Utils.stringify_keys! attributes
19
- unless attributes.has_key? 'uri'
20
- attributes['uri'] = self.class.uri
21
- end
22
- super attributes
23
- end
24
-
25
- def has_account?
26
- self.respond_to? 'account' and !self.account.nil?
27
- end
11
+ define_hypermedia_types [:bank_accounts]
28
12
 
29
13
  # Creates a Debit of funds from this BankAccount to your Marketplace's escrow account.
30
14
  #
31
- # @param [String] appears_on_statement_as If nil then Balanced will use
32
- # the +domain_name+ property from your Marketplace.
33
15
  # @return [Debit]
34
- def debit *args
35
- warn_on_positional args
36
-
37
- options = args.last.is_a?(Hash) ? args.pop : {}
38
- amount = args[0] || options.fetch(:amount) { nil }
39
- appears_on_statement_as = args[1] || options.fetch(:appears_on_statement_as) { nil }
40
- meta = args[2] || options.fetch(:meta) { nil }
41
- description = args[3] || options.fetch(:description) { nil }
42
-
43
- self.account.debit(
44
- :amount => amount,
45
- :appears_on_statement_as => appears_on_statement_as,
46
- :meta => meta,
47
- :description => description,
48
- :source_uri => self.uri
49
- )
16
+ def debit(options = {})
17
+ options[:href] = self.debits.href
18
+ debit = Balanced::Debit.new(options)
19
+ debit.save
50
20
  end
51
21
 
52
22
  # Creates a Credit of funds from your Marketplace's escrow account to this
53
23
  # Account.
54
24
  #
55
25
  # @return [Credit]
56
- def credit *args
57
- warn_on_positional args
58
-
59
- options = args.last.is_a?(Hash) ? args.pop : {}
60
- amount = args[0] || options.fetch(:amount) { nil }
61
- description = args[1] || options.fetch(:description) { nil }
62
- appears_on_statement_as = args[3] || options.fetch(:appears_on_statement_as) { nil }
63
-
64
- if self.has_account?
65
- meta = args[2] || options.fetch(:meta) { nil }
66
- destination_uri = args[4] || options.fetch(:destination_uri) { self.uri }
67
- credit = self.account.credit(
68
- :amount => amount,
69
- :meta => meta,
70
- :description => description,
71
- :destination_uri => destination_uri,
72
- :appears_on_statement_as => appears_on_statement_as
73
- )
74
- else
75
- credit = Credit.new(
76
- :uri => self.credits_uri,
77
- :amount => amount,
78
- :description => description,
79
- :appears_on_statement_as => appears_on_statement_as
80
- )
81
- credit.save
82
- end
83
-
84
- credit
85
- end
86
-
87
- def invalidate
88
- self.is_valid = false
89
- save
26
+ def credit(options = {})
27
+ options[:href] = self.credits.href
28
+ credit = Balanced::Credit.new(options)
29
+ credit.save
90
30
  end
91
31
 
92
32
  def verify
93
- Verification.new(
94
- 'uri' => self.verifications_uri
95
- ).save
33
+ options = {:href => self.bank_account_verifications.href}
34
+ vf = BankAccountVerification.new(options)
35
+ vf.save
96
36
  end
97
37
 
38
+ def associate_to_customer(customer)
39
+ self.links['customer'] = Balanced::Utils.extract_href_from_object(customer)
40
+ save
41
+ end
98
42
  end
99
43
 
100
- class Verification
44
+ class BankAccountVerification
101
45
  include Balanced::Resource
46
+ include Balanced::HypermediaRegistry
47
+
48
+ define_hypermedia_types [:bank_account_verification,
49
+ :bank_account_verifications,
50
+ :verification,
51
+ :verifications
52
+ ]
102
53
 
103
54
  def confirm(amount_1, amount_2)
104
55
  self.amount_1 = amount_1
@@ -5,6 +5,8 @@ module Balanced
5
5
  #
6
6
  class Callback
7
7
  include Balanced::Resource
8
+ include Balanced::HypermediaRegistry
9
+ define_hypermedia_types [:callbacks]
8
10
 
9
11
  end
10
12
 
@@ -2,85 +2,35 @@ module Balanced
2
2
  # A card represents a source of funds for an Account. You may Hold or Debit
3
3
  # funds from the account associated with the Card.
4
4
  #
5
- class Card
5
+ class Card < Balanced::DebitableFundingInstrument
6
6
  include Balanced::Resource
7
+ include Balanced::HypermediaRegistry
7
8
 
8
- def initialize attributes = {}
9
- Balanced::Utils.stringify_keys! attributes
10
- unless attributes.has_key? 'uri'
11
- attributes['uri'] = self.class.uri
12
- end
13
- super attributes
14
- end
9
+ define_hypermedia_types [:cards]
15
10
 
16
- # Creates a Debit of funds from this Card to your Marketplace's escrow account.
17
- #
18
- # If +appears_on_statement_as+ is nil, then Balanced will use the
19
- # +domain_name+ property from your Marketplace.
20
- #
21
- # @param [Array] args
22
- # @option args [Integer] :amount the amount of the purchase in cents
23
- # @option args [String] :appears_on_statement_as
24
- # @option args [String] :hold_uri
25
- # @option args [Hash] :meta a hash of data to save with the Debit
26
- # @option args [String] :description
27
- # @option args [String] :source_uri
11
+ # Creates a Debit of funds from this Card to the Marketplace's escrow account.
28
12
  #
13
+ # @param [Hash] options
29
14
  # @return [Debit]
30
- def debit *args
31
- warn_on_positional args
32
- options = args.last.is_a?(Hash) ? args.pop : {}
33
- amount = args[0] || options.fetch(:amount) { nil }
34
- appears_on_statement_as = args[1] || options.fetch(:appears_on_statement_as) { nil }
35
- hold_uri = args[2] || options.fetch(:hold_uri) { nil }
36
- meta = args[3] || options.fetch(:meta) { nil }
37
- description = args[3] || options.fetch(:description) { nil }
38
-
39
- ensure_associated_to_account!
40
-
41
- self.account.debit(
42
- :amount => amount,
43
- :appears_on_statement_as => appears_on_statement_as,
44
- :hold_uri => hold_uri,
45
- :meta => meta,
46
- :description => description,
47
- :source_uri => self.uri
48
- )
15
+ def debit(options={})
16
+ options[:href] = self.debits.href
17
+ debit = Balanced::Debit.new(options)
18
+ debit.save
49
19
  end
50
20
 
51
21
  # Creates a Hold of funds from this Card to your Marketplace.
52
22
  #
53
23
  # @return [Hold]
54
- def hold *args
55
- warn_on_positional args
56
- options = args.last.is_a?(Hash) ? args.pop : {}
57
- amount = args[0] || options.fetch(:amount) { nil }
58
- meta = args[1] || options.fetch(:meta) { nil }
59
- description = args[3] || options.fetch(:description) { nil }
60
-
61
- ensure_associated_to_account!
62
-
63
- self.account.hold(
64
- :amount => amount,
65
- :meta => meta,
66
- :source_uri => self.uri,
67
- :description => description
68
- )
24
+ def hold(options={})
25
+ options[:href] = self.card_holds.href
26
+ hold = Balanced::CardHold.new(options)
27
+ hold.save
69
28
  end
70
29
 
71
- def invalidate
72
- self.is_valid = false
30
+ def associate_to_customer(customer)
31
+ self.links['customer'] = Balanced::Utils.extract_href_from_object(customer)
73
32
  save
74
33
  end
75
-
76
- private
77
- # Ensure that one of account, account_uri, customer or customer_uri are set.
78
- # Otherwise raise an exception.
79
- def ensure_associated_to_account!
80
- if attributes.values_at('account', 'account_uri', 'customer', 'customer_uri').compact.empty?
81
- raise UnassociatedCardError.new(self)
82
- end
83
- end
84
34
  end
85
35
 
86
36
  end
@@ -0,0 +1,38 @@
1
+ module Balanced
2
+ # A Hold is a reservation of funds on a funding source such as a Card. This
3
+ # reservation is guaranteed until the +expires_at+ date. You may capture
4
+ # the Hold at any time before then which will create a Debit and transfer
5
+ # the funds to your Marketplace. If you do not capture the Hold it will
6
+ # be marked as invalid which is represented by the +is_void+ field being
7
+ # set to +true+.
8
+ #
9
+ # By default a Hold is created using the most recently added funding source
10
+ # on the Account. You may specify a specific funding source such as a Card
11
+ # or BankAccount uri.
12
+ #
13
+ class CardHold
14
+ include Balanced::Resource
15
+ include Balanced::HypermediaRegistry
16
+
17
+ define_hypermedia_types [:card_holds]
18
+
19
+ # Captures a valid Hold and returns a Debit representing the transfer of
20
+ # funds from the buyer's Account to your Marketplace.
21
+ #
22
+ # @return [Debit]
23
+ def capture(options={})
24
+ options[:href] = self.debits.href
25
+ debit = Balanced::Debit.new(options)
26
+ debit.save
27
+ reload
28
+ debit
29
+ end
30
+
31
+ def unstore
32
+ destroy
33
+ end
34
+ alias_method :delete, :unstore
35
+
36
+ end
37
+ end
38
+
@@ -8,60 +8,16 @@ module Balanced
8
8
  #
9
9
  class Credit
10
10
  include Balanced::Resource
11
+ include Balanced::HypermediaRegistry
11
12
 
12
- # @param [Array] args
13
- # @option [String] :uri the uri of the credit, in the case of an update
14
- # @option [Hash] :bank_account
15
- # @option [Integer] :amount amount in cents
16
- # @option [String] :description a text description of the credit
17
- # @option [String] :appears_on_statement_as
18
- # @option [Hash] :meta
19
- # @option [String] :destination_uri the uri of the bank account to credit
20
- def initialize *args
21
- options = args.last.is_a?(Hash) ? args.pop : {}
22
- uri = options.fetch(:uri) { self.class.uri }
23
- bank_account = options.fetch(:bank_account) {}
24
- amount = args[0] || options.fetch(:amount) { }
25
- description = args[1] || options.fetch(:description) { nil }
13
+ define_hypermedia_types [:credits]
26
14
 
27
- unless bank_account.nil?
28
- # Accountless bank account
29
- attributes = {
30
- :uri => uri,
31
- :amount => amount,
32
- :description => description,
33
- :bank_account => bank_account,
34
- :meta => nil
35
- }
36
- else
37
- meta = args[2] || options.fetch(:meta) { nil }
38
- destination_uri = args[3] || options.fetch(:destination_uri) { nil }
39
- appears_on_statement_as = args[4] || options.fetch(:appears_on_statement_as) { nil }
40
- attributes = {
41
- :uri => uri,
42
- :amount => amount,
43
- :meta => meta,
44
- :description => description,
45
- :destination_uri => destination_uri,
46
- :appears_on_statement_as => appears_on_statement_as
47
- }
48
- end
49
-
50
- Balanced::Utils.stringify_keys! attributes
51
-
52
- super attributes
53
- end
54
-
55
- def reverse *args
56
- warn_on_positional args
57
-
58
- options = args.last.is_a?(Hash) ? args.pop : {}
59
- amount = args[0] || options.fetch(:amount) { nil }
60
- description = args[1] || options.fetch(:description) { nil }
15
+ def reverse(options={})
16
+ amount = options[:amount]
17
+ description = options[:description]
61
18
 
62
19
  reversal = Reversal.new(
63
- :uri => self.reversals_uri,
64
- :credit_uri => self.uri,
20
+ :href => self.reversals.href,
65
21
  :amount => amount,
66
22
  :description => description
67
23
  )
@@ -4,20 +4,11 @@ module Balanced
4
4
  # associated to them.
5
5
  #
6
6
  class Customer
7
- include Balanced::Resource
8
7
 
9
- def self.uri
10
- # Override the default nesting
11
- self.collection_path
12
- end
8
+ include Balanced::Resource
9
+ include Balanced::HypermediaRegistry
13
10
 
14
- def initialize attributes = {}
15
- Balanced::Utils.stringify_keys! attributes
16
- unless attributes.has_key? 'uri'
17
- attributes['uri'] = self.class.uri
18
- end
19
- super attributes
20
- end
11
+ define_hypermedia_types [:customers]
21
12
 
22
13
  # Attempts to find an existing customer by email
23
14
  #
@@ -31,53 +22,41 @@ module Balanced
31
22
  def self.find_by_email email
32
23
  self.find(:first, :email => email)
33
24
  end
34
-
35
- def debit(options = {})
36
- amount = options[:amount]
37
- appears_on_statement_as = options[:appears_on_statement_as]
38
- hold_uri = options[:hold_uri]
39
- meta = options[:meta]
40
- description = options[:description]
41
- source_uri = options[:source_uri]
42
- on_behalf_of = options[:on_behalf_of] || options[:on_behalf_of_uri]
43
25
 
44
- if on_behalf_of
45
- if on_behalf_of.respond_to? :uri
46
- on_behalf_of = on_behalf_of.uri
47
- end
48
- if !on_behalf_of.is_a?(String)
49
- raise ArgumentError, 'The on_behalf_of parameter needs to be a customer URI'
50
- end
51
- if on_behalf_of == self.uri
52
- raise ArgumentError, 'The on_behalf_of parameter MAY NOT be the same account as the customer you are debiting!'
53
- end
54
- end
26
+ def self.owner
27
+ owner_customer = Balanced::Marketplace.mine.owner_customer
28
+ owner_customer
29
+ end
55
30
 
56
- debit = Debit.new(
57
- :uri => self.debits_uri,
58
- :amount => amount,
59
- :appears_on_statement_as => appears_on_statement_as,
60
- :hold_uri => hold_uri,
61
- :meta => meta,
62
- :description => description,
63
- :source_uri => source_uri,
64
- :on_behalf_of_uri => on_behalf_of
65
- )
66
- debit.save
31
+ def debit(options = {})
32
+ if self.source.nil?
33
+ raise "No source available for #{self}"
34
+ end
35
+ self.source.debit(options)
67
36
  end
68
37
 
69
38
  def credit(options = {})
70
- options.merge!(:uri => self.credits_uri)
71
- Credit.new(options).save
39
+ if self.destination.nil?
40
+ raise "No destination available for #{self}"
41
+ end
42
+ self.destination.credit(options)
43
+ end
44
+
45
+ def create_order(options = {})
46
+ options[:href] = self.orders.href
47
+ order = Balanced::Order.new(options)
48
+ order.save
72
49
  end
73
50
 
74
51
  # Associates the Card represented by 'card' with this Customer.
75
52
  #
76
53
  # @return [Customer]
77
-
78
- def add_card(card)
79
- card.save if card.kind_of?(Balanced::Card) && card.hash.nil?
80
- self.card_uri = Balanced::Utils.extract_uri_from_object(card)
54
+ def add_source(source)
55
+ if source.is_a?(Balanced::Resource)
56
+ self.links['source'] = source.id
57
+ else
58
+ self.links['source'] = source
59
+ end
81
60
  save
82
61
  end
83
62
 
@@ -85,31 +64,14 @@ module Balanced
85
64
  # Customer.
86
65
  #
87
66
  # @return [Customer]
88
- def add_bank_account(bank_account)
89
- if bank_account.kind_of?(Balanced::BankAccount) && bank_account.fingerprint.nil?
90
- bank_account.save
67
+ def add_destination(destination)
68
+ if destination.is_a?(Balanced::Resource)
69
+ self.links['destination'] = destination.id
70
+ else
71
+ self.links['destination'] = destination
91
72
  end
92
- self.bank_account_uri = Balanced::Utils.extract_uri_from_object(bank_account)
93
73
  save
94
74
  end
95
75
 
96
- def active_card
97
- pager = Pager.new(
98
- self.cards_uri,
99
- :is_active => true,
100
- :sort => 'created_at,desc',
101
- :limit => 1)
102
- pager.first
103
- end
104
-
105
- def active_bank_account
106
- pager = Pager.new(
107
- self.bank_accounts_uri,
108
- :is_active => true,
109
- :sort => 'created_at,desc',
110
- :limit => 1)
111
- pager.first
112
- end
113
-
114
76
  end
115
77
  end