balanced 0.8.2 → 1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rbenv-version +1 -1
- data/.ruby-version +1 -1
- data/Gemfile +7 -3
- data/README.md +2 -10
- data/Rakefile +4 -18
- data/balanced.gemspec +8 -10
- data/lib/balanced.rb +28 -28
- data/lib/balanced/client.rb +15 -6
- data/lib/balanced/error.rb +21 -12
- data/lib/balanced/pager.rb +66 -25
- data/lib/balanced/resources.rb +18 -17
- data/lib/balanced/resources/api_key.rb +4 -0
- data/lib/balanced/resources/bank_account.rb +26 -75
- data/lib/balanced/resources/callback.rb +2 -0
- data/lib/balanced/resources/card.rb +15 -65
- data/lib/balanced/resources/card_hold.rb +38 -0
- data/lib/balanced/resources/credit.rb +6 -50
- data/lib/balanced/resources/customer.rb +33 -71
- data/lib/balanced/resources/debit.rb +6 -14
- data/lib/balanced/resources/event.rb +6 -0
- data/lib/balanced/resources/funding_instrument.rb +11 -0
- data/lib/balanced/resources/hypermedia.rb +28 -0
- data/lib/balanced/resources/marketplace.rb +5 -203
- data/lib/balanced/resources/order.rb +71 -0
- data/lib/balanced/resources/refund.rb +2 -7
- data/lib/balanced/resources/resource.rb +169 -106
- data/lib/balanced/resources/reversal.rb +2 -8
- data/lib/balanced/resources/transfer.rb +11 -0
- data/lib/balanced/response/balanced_exception_middleware.rb +2 -2
- data/lib/balanced/utils.rb +47 -14
- data/lib/balanced/version.rb +1 -1
- data/scenario.cache +526 -380
- data/scenarios/api_key_create/definition.rb +1 -0
- data/scenarios/api_key_create/request.rb +2 -0
- data/scenarios/api_key_create/ruby.mako +21 -0
- data/scenarios/api_key_delete/definition.rb +1 -0
- data/scenarios/api_key_delete/request.rb +3 -0
- data/scenarios/api_key_delete/ruby.mako +12 -0
- data/scenarios/api_key_list/definition.rb +1 -0
- data/scenarios/api_key_list/request.rb +2 -0
- data/scenarios/api_key_list/ruby.mako +28 -0
- data/scenarios/api_key_show/definition.rb +1 -0
- data/scenarios/api_key_show/request.rb +2 -0
- data/scenarios/api_key_show/ruby.mako +18 -0
- data/scenarios/{customer_add_bank_account → bank_account_associate_to_customer}/definition.rb +0 -0
- data/scenarios/bank_account_associate_to_customer/request.rb +3 -0
- data/scenarios/bank_account_associate_to_customer/ruby.mako +49 -0
- data/scenarios/bank_account_create/definition.rb +1 -1
- data/scenarios/bank_account_create/request.rb +1 -1
- data/scenarios/bank_account_create/ruby.mako +44 -7
- data/scenarios/{credit_create_existing_bank_account → bank_account_credit}/definition.rb +0 -0
- data/scenarios/bank_account_credit/request.rb +3 -0
- data/scenarios/bank_account_credit/ruby.mako +42 -0
- data/scenarios/bank_account_debit/definition.rb +1 -0
- data/scenarios/bank_account_debit/request.rb +5 -0
- data/scenarios/bank_account_debit/ruby.mako +50 -0
- data/scenarios/bank_account_delete/request.rb +1 -1
- data/scenarios/bank_account_delete/ruby.mako +5 -3
- data/scenarios/bank_account_list/ruby.mako +76 -2
- data/scenarios/bank_account_show/definition.rb +1 -1
- data/scenarios/bank_account_show/request.rb +1 -1
- data/scenarios/bank_account_show/ruby.mako +41 -5
- data/scenarios/bank_account_update/definition.rb +1 -0
- data/scenarios/bank_account_update/request.rb +6 -0
- data/scenarios/bank_account_update/ruby.mako +56 -0
- data/scenarios/bank_account_verification_create/request.rb +1 -1
- data/scenarios/bank_account_verification_create/ruby.mako +20 -3
- data/scenarios/bank_account_verification_show/definition.rb +1 -1
- data/scenarios/bank_account_verification_show/request.rb +1 -1
- data/scenarios/bank_account_verification_show/ruby.mako +21 -4
- data/scenarios/bank_account_verification_update/definition.rb +1 -1
- data/scenarios/bank_account_verification_update/request.rb +5 -5
- data/scenarios/bank_account_verification_update/ruby.mako +24 -8
- data/scenarios/callback_create/definition.rb +1 -1
- data/scenarios/callback_create/request.rb +2 -2
- data/scenarios/callback_create/ruby.mako +22 -0
- data/scenarios/callback_delete/definition.rb +1 -1
- data/scenarios/callback_delete/request.rb +2 -2
- data/scenarios/callback_delete/ruby.mako +12 -0
- data/scenarios/callback_list/definition.rb +1 -1
- data/scenarios/callback_list/request.rb +1 -2
- data/scenarios/callback_list/ruby.mako +20 -0
- data/scenarios/callback_show/definition.rb +1 -1
- data/scenarios/callback_show/request.rb +1 -1
- data/scenarios/callback_show/ruby.mako +20 -0
- data/scenarios/{customer_add_card → card_associate_to_customer}/definition.rb +0 -0
- data/scenarios/card_associate_to_customer/request.rb +3 -0
- data/scenarios/card_associate_to_customer/ruby.mako +49 -0
- data/scenarios/card_create/request.rb +1 -2
- data/scenarios/card_create/ruby.mako +44 -7
- data/scenarios/card_debit/definition.rb +1 -0
- data/scenarios/card_debit/request.rb +5 -0
- data/scenarios/card_debit/ruby.mako +49 -0
- data/scenarios/card_delete/request.rb +1 -1
- data/scenarios/card_delete/ruby.mako +5 -3
- data/scenarios/card_hold_capture/definition.rb +1 -0
- data/scenarios/card_hold_capture/request.rb +5 -0
- data/scenarios/card_hold_capture/ruby.mako +49 -0
- data/scenarios/card_hold_create/definition.rb +1 -0
- data/scenarios/card_hold_create/request.rb +5 -0
- data/scenarios/card_hold_create/ruby.mako +38 -0
- data/scenarios/card_hold_list/definition.rb +1 -0
- data/scenarios/card_hold_list/request.rb +2 -0
- data/scenarios/card_hold_list/ruby.mako +60 -0
- data/scenarios/card_hold_show/definition.rb +1 -0
- data/scenarios/card_hold_show/request.rb +2 -0
- data/scenarios/card_hold_show/ruby.mako +36 -0
- data/scenarios/card_hold_update/definition.rb +1 -0
- data/scenarios/card_hold_update/request.rb +7 -0
- data/scenarios/card_hold_update/ruby.mako +42 -0
- data/scenarios/card_hold_void/definition.rb +1 -0
- data/scenarios/card_hold_void/request.rb +3 -0
- data/scenarios/card_hold_void/ruby.mako +36 -0
- data/scenarios/card_list/definition.rb +1 -1
- data/scenarios/card_list/request.rb +1 -1
- data/scenarios/card_list/ruby.mako +78 -5
- data/scenarios/card_show/definition.rb +1 -1
- data/scenarios/card_show/request.rb +1 -1
- data/scenarios/card_show/ruby.mako +42 -4
- data/scenarios/card_update/definition.rb +1 -1
- data/scenarios/card_update/request.rb +1 -1
- data/scenarios/card_update/ruby.mako +45 -4
- data/scenarios/credit_list/request.rb +1 -3
- data/scenarios/credit_list/ruby.mako +34 -4
- data/scenarios/{credit_bank_account_list → credit_list_bank_account}/definition.rb +0 -0
- data/scenarios/credit_list_bank_account/request.rb +3 -0
- data/scenarios/credit_list_bank_account/ruby.mako +13 -0
- data/scenarios/credit_show/definition.rb +1 -1
- data/scenarios/credit_show/request.rb +1 -3
- data/scenarios/credit_show/ruby.mako +35 -5
- data/scenarios/{credit_create_new_bank_account → credit_update}/definition.rb +0 -0
- data/scenarios/credit_update/request.rb +7 -0
- data/scenarios/credit_update/ruby.mako +48 -0
- data/scenarios/customer_create/request.rb +4 -1
- data/scenarios/customer_create/ruby.mako +60 -3
- data/scenarios/customer_delete/request.rb +1 -1
- data/scenarios/customer_delete/ruby.mako +4 -2
- data/scenarios/customer_list/definition.rb +1 -0
- data/scenarios/customer_list/request.rb +2 -0
- data/scenarios/customer_list/ruby.mako +105 -0
- data/scenarios/customer_show/definition.rb +1 -0
- data/scenarios/customer_show/request.rb +2 -0
- data/scenarios/customer_show/ruby.mako +58 -0
- data/scenarios/customer_update/definition.rb +1 -0
- data/scenarios/customer_update/request.rb +7 -0
- data/scenarios/customer_update/ruby.mako +64 -0
- data/scenarios/debit_list/request.rb +1 -3
- data/scenarios/debit_list/ruby.mako +70 -4
- data/scenarios/debit_show/definition.rb +1 -1
- data/scenarios/debit_show/request.rb +1 -1
- data/scenarios/debit_show/ruby.mako +39 -4
- data/scenarios/debit_update/definition.rb +1 -1
- data/scenarios/debit_update/request.rb +1 -1
- data/scenarios/debit_update/ruby.mako +39 -4
- data/scenarios/event_list/definition.rb +1 -1
- data/scenarios/event_list/request.rb +1 -2
- data/scenarios/event_list/ruby.mako +54 -5
- data/scenarios/event_show/definition.rb +1 -1
- data/scenarios/event_show/request.rb +1 -1
- data/scenarios/event_show/ruby.mako +54 -4
- data/scenarios/helpers.rb +29 -2
- data/scenarios/order_create/definition.rb +1 -0
- data/scenarios/order_create/request.rb +5 -0
- data/scenarios/order_create/ruby.mako +46 -0
- data/scenarios/order_list/definition.rb +1 -0
- data/scenarios/order_list/request.rb +2 -0
- data/scenarios/order_list/ruby.mako +42 -0
- data/scenarios/order_show/definition.rb +1 -0
- data/scenarios/order_show/request.rb +2 -0
- data/scenarios/order_show/ruby.mako +44 -0
- data/scenarios/order_update/definition.rb +1 -0
- data/scenarios/order_update/request.rb +7 -0
- data/scenarios/order_update/ruby.mako +50 -0
- data/scenarios/refund_create/definition.rb +1 -1
- data/scenarios/refund_create/request.rb +2 -1
- data/scenarios/refund_create/ruby.mako +33 -5
- data/scenarios/refund_list/request.rb +1 -3
- data/scenarios/refund_list/ruby.mako +30 -4
- data/scenarios/refund_show/definition.rb +1 -1
- data/scenarios/refund_show/request.rb +1 -1
- data/scenarios/refund_show/ruby.mako +32 -4
- data/scenarios/refund_update/definition.rb +1 -1
- data/scenarios/refund_update/request.rb +1 -1
- data/scenarios/refund_update/ruby.mako +32 -4
- data/scenarios/render_mako.rb +59 -4
- data/scenarios/reversal_create/definition.rb +1 -0
- data/scenarios/reversal_create/request.rb +9 -0
- data/scenarios/reversal_create/ruby.mako +45 -0
- data/scenarios/reversal_list/definition.rb +1 -0
- data/scenarios/reversal_list/request.rb +2 -0
- data/scenarios/reversal_list/ruby.mako +36 -0
- data/scenarios/reversal_show/definition.rb +1 -0
- data/scenarios/reversal_show/request.rb +2 -0
- data/scenarios/reversal_show/ruby.mako +37 -0
- data/scenarios/reversal_update/definition.rb +1 -0
- data/scenarios/reversal_update/request.rb +7 -0
- data/scenarios/reversal_update/ruby.mako +44 -0
- data/spec/balanced/error_spec.rb +7 -7
- data/spec/balanced/pager_spec.rb +10 -10
- data/spec/balanced/resources/api_key_spec.rb +6 -35
- data/spec/balanced/resources/bank_account_spec.rb +123 -218
- data/spec/balanced/resources/callback_spec.rb +12 -13
- data/spec/balanced/resources/card_hold_spec.rb +103 -0
- data/spec/balanced/resources/card_spec.rb +101 -27
- data/spec/balanced/resources/credit_spec.rb +69 -35
- data/spec/balanced/resources/customer_spec.rb +91 -271
- data/spec/balanced/resources/debit_spec.rb +95 -0
- data/spec/balanced/resources/marketplace_spec.rb +17 -170
- data/spec/balanced/resources/order_spec.rb +364 -0
- data/spec/balanced/resources/resource_spec.rb +25 -32
- data/spec/balanced_spec.rb +18 -36
- data/spec/client_spec.rb +7 -7
- data/spec/spec_helper.rb +19 -18
- data/spec/utils_spec.rb +5 -5
- metadata +123 -165
- data/examples/bank_account_debits.rb +0 -57
- data/examples/customers.rb +0 -114
- data/examples/events_and_callbacks.rb +0 -81
- data/examples/examples.rb +0 -162
- data/examples/exception_handling.rb +0 -44
- data/lib/balanced/resources/account.rb +0 -179
- data/lib/balanced/resources/hold.rb +0 -61
- data/lib/balanced/resources/invoice.rb +0 -11
- data/lib/balanced/resources/merchant.rb +0 -21
- data/lib/balanced/resources/transaction.rb +0 -17
- data/scenarios/account_add_card/definition.rb +0 -1
- data/scenarios/account_add_card/request.rb +0 -3
- data/scenarios/account_add_card/ruby.mako +0 -11
- data/scenarios/account_capture_hold/definition.rb +0 -1
- data/scenarios/account_capture_hold/request.rb +0 -3
- data/scenarios/account_capture_hold/ruby.mako +0 -11
- data/scenarios/account_create/definition.rb +0 -1
- data/scenarios/account_create/request.rb +0 -2
- data/scenarios/account_create/ruby.mako +0 -10
- data/scenarios/account_create_buyer/definition.rb +0 -1
- data/scenarios/account_create_buyer/request.rb +0 -5
- data/scenarios/account_create_buyer/ruby.mako +0 -13
- data/scenarios/account_create_debit/definition.rb +0 -1
- data/scenarios/account_create_debit/request.rb +0 -3
- data/scenarios/account_create_debit/ruby.mako +0 -11
- data/scenarios/account_create_hold/definition.rb +0 -1
- data/scenarios/account_create_hold/request.rb +0 -3
- data/scenarios/account_create_hold/ruby.mako +0 -11
- data/scenarios/account_create_merchant/definition.rb +0 -1
- data/scenarios/account_create_merchant/request.rb +0 -3
- data/scenarios/account_create_merchant/ruby.mako +0 -11
- data/scenarios/account_underwrite_business/definition.rb +0 -1
- data/scenarios/account_underwrite_business/request.rb +0 -17
- data/scenarios/account_underwrite_business/ruby.mako +0 -37
- data/scenarios/account_underwrite_person/definition.rb +0 -1
- data/scenarios/account_underwrite_person/request.rb +0 -18
- data/scenarios/account_underwrite_person/ruby.mako +0 -31
- data/scenarios/bank_account_find_and_credit/definition.rb +0 -1
- data/scenarios/bank_account_find_and_credit/request.rb +0 -5
- data/scenarios/bank_account_find_and_credit/ruby.mako +0 -13
- data/scenarios/bank_account_find_and_delete/definition.rb +0 -1
- data/scenarios/bank_account_find_and_delete/request.rb +0 -3
- data/scenarios/bank_account_find_and_delete/ruby.mako +0 -10
- data/scenarios/bank_account_invalid_routing_number/definition.rb +0 -1
- data/scenarios/bank_account_invalid_routing_number/request.rb +0 -11
- data/scenarios/bank_account_invalid_routing_number/ruby.mako +0 -16
- data/scenarios/card_invalidate/definition.rb +0 -1
- data/scenarios/card_invalidate/request.rb +0 -3
- data/scenarios/card_invalidate/ruby.mako +0 -10
- data/scenarios/credit_account_list/definition.rb +0 -1
- data/scenarios/credit_account_list/request.rb +0 -3
- data/scenarios/credit_account_list/ruby.mako +0 -10
- data/scenarios/credit_account_merchant_create/definition.rb +0 -1
- data/scenarios/credit_account_merchant_create/request.rb +0 -5
- data/scenarios/credit_account_merchant_create/ruby.mako +0 -12
- data/scenarios/credit_bank_account_list/request.rb +0 -5
- data/scenarios/credit_bank_account_list/ruby.mako +0 -12
- data/scenarios/credit_create_existing_bank_account/request.rb +0 -5
- data/scenarios/credit_create_existing_bank_account/ruby.mako +0 -12
- data/scenarios/credit_create_new_bank_account/request.rb +0 -10
- data/scenarios/credit_create_new_bank_account/ruby.mako +0 -21
- data/scenarios/credit_customer_list/definition.rb +0 -1
- data/scenarios/credit_customer_list/request.rb +0 -4
- data/scenarios/credit_customer_list/ruby.mako +0 -12
- data/scenarios/credit_failed_state/definition.rb +0 -1
- data/scenarios/credit_failed_state/request.rb +0 -10
- data/scenarios/credit_failed_state/ruby.mako +0 -18
- data/scenarios/credit_paid_state/definition.rb +0 -1
- data/scenarios/credit_paid_state/request.rb +0 -11
- data/scenarios/credit_paid_state/ruby.mako +0 -19
- data/scenarios/credit_pending_state/definition.rb +0 -1
- data/scenarios/credit_pending_state/request.rb +0 -9
- data/scenarios/credit_pending_state/ruby.mako +0 -17
- data/scenarios/customer_add_bank_account/request.rb +0 -3
- data/scenarios/customer_add_bank_account/ruby.mako +0 -11
- data/scenarios/customer_add_card/request.rb +0 -3
- data/scenarios/customer_add_card/ruby.mako +0 -11
- data/scenarios/customer_capture_hold/definition.rb +0 -1
- data/scenarios/customer_capture_hold/request.rb +0 -3
- data/scenarios/customer_capture_hold/ruby.mako +0 -0
- data/scenarios/customer_create_debit/definition.rb +0 -1
- data/scenarios/customer_create_debit/request.rb +0 -3
- data/scenarios/customer_create_debit/ruby.mako +0 -11
- data/scenarios/customer_create_hold/definition.rb +0 -1
- data/scenarios/customer_create_hold/request.rb +0 -3
- data/scenarios/customer_create_hold/ruby.mako +0 -11
- data/scenarios/customer_credit/definition.rb +0 -1
- data/scenarios/customer_credit/request.rb +0 -2
- data/scenarios/customer_credit/ruby.mako +0 -8
- data/scenarios/debit_account_list/definition.rb +0 -1
- data/scenarios/debit_account_list/request.rb +0 -3
- data/scenarios/debit_account_list/ruby.mako +0 -10
- data/scenarios/debit_create/definition.rb +0 -1
- data/scenarios/debit_create/request.rb +0 -5
- data/scenarios/debit_create/ruby.mako +0 -15
- data/scenarios/debit_customer_list/definition.rb +0 -1
- data/scenarios/debit_customer_list/request.rb +0 -4
- data/scenarios/debit_customer_list/ruby.mako +0 -12
- data/scenarios/debit_refund/definition.rb +0 -1
- data/scenarios/debit_refund/request.rb +0 -3
- data/scenarios/debit_refund/ruby.mako +0 -10
- data/scenarios/delete.rb +0 -7
- data/scenarios/event_replay/definition.rb +0 -0
- data/scenarios/event_replay/request.rb +0 -1
- data/scenarios/event_replay/ruby.mako +0 -0
- data/scenarios/execute.rb +0 -27
- data/scenarios/hold_account_list/definition.rb +0 -1
- data/scenarios/hold_account_list/request.rb +0 -3
- data/scenarios/hold_account_list/ruby.mako +0 -10
- data/scenarios/hold_capture/definition.rb +0 -1
- data/scenarios/hold_capture/request.rb +0 -5
- data/scenarios/hold_capture/ruby.mako +0 -15
- data/scenarios/hold_create/definition.rb +0 -1
- data/scenarios/hold_create/request.rb +0 -5
- data/scenarios/hold_create/ruby.mako +0 -14
- data/scenarios/hold_customer_list/definition.rb +0 -1
- data/scenarios/hold_customer_list/request.rb +0 -3
- data/scenarios/hold_customer_list/ruby.mako +0 -11
- data/scenarios/hold_list/definition.rb +0 -1
- data/scenarios/hold_list/request.rb +0 -4
- data/scenarios/hold_list/ruby.mako +0 -11
- data/scenarios/hold_show/definition.rb +0 -1
- data/scenarios/hold_show/request.rb +0 -2
- data/scenarios/hold_show/ruby.mako +0 -10
- data/scenarios/hold_update/definition.rb +0 -1
- data/scenarios/hold_update/request.rb +0 -7
- data/scenarios/hold_update/ruby.mako +0 -16
- data/scenarios/hold_void/definition.rb +0 -1
- data/scenarios/hold_void/request.rb +0 -3
- data/scenarios/hold_void/ruby.mako +0 -10
- data/scenarios/refund_account_list/definition.rb +0 -1
- data/scenarios/refund_account_list/request.rb +0 -3
- data/scenarios/refund_account_list/ruby.mako +0 -10
- data/scenarios/refund_customer_list/definition.rb +0 -1
- data/scenarios/refund_customer_list/request.rb +0 -3
- data/scenarios/refund_customer_list/ruby.mako +0 -11
- data/scenarios/render.rb +0 -32
- data/scenarios/render_one.rb +0 -32
- data/spec/balanced/resources/account_spec.rb +0 -636
- data/spec/balanced/resources/hold_spec.rb +0 -48
- data/spec/balanced/resources/merchant_spec.rb +0 -6
- data/spec/scenarios_spec.rb +0 -39
- data/upload_docs.rb +0 -40
@@ -1,179 +0,0 @@
|
|
1
|
-
module Balanced
|
2
|
-
# An Account represents a user within your Marketplace. An Account can have
|
3
|
-
# two +roles+. If the Account has the +buyer+ role then you may create
|
4
|
-
# Debits using this Account. If they have the +merchant+ role then you may
|
5
|
-
# create Credits to transfer funds to this Account.
|
6
|
-
#
|
7
|
-
class Account
|
8
|
-
include Balanced::Resource
|
9
|
-
|
10
|
-
def initialize attributes = {}
|
11
|
-
Balanced::Utils.stringify_keys! attributes
|
12
|
-
unless attributes.has_key? 'uri'
|
13
|
-
attributes['uri'] = self.class.uri
|
14
|
-
end
|
15
|
-
super attributes
|
16
|
-
end
|
17
|
-
|
18
|
-
# Attempts to find an existing buyer account by email
|
19
|
-
#
|
20
|
-
# @param [String] email An email of an account
|
21
|
-
# @return [Account] if account is found
|
22
|
-
# @return [nil] if account is not found
|
23
|
-
def self.find_by_email email
|
24
|
-
self.find(:first, :email_address => email)
|
25
|
-
end
|
26
|
-
|
27
|
-
# Returns a new Debit that represents a flow of money from this
|
28
|
-
# Account to your Marketplace's escrow account.
|
29
|
-
#
|
30
|
-
# @return [Debit]
|
31
|
-
def debit *args
|
32
|
-
warn_on_positional args
|
33
|
-
|
34
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
35
|
-
amount = args[0] || options.fetch(:amount) { nil }
|
36
|
-
appears_on_statement_as = args[1] || options.fetch(:appears_on_statement_as) { nil }
|
37
|
-
hold_uri = args[2] || options.fetch(:hold_uri) { nil }
|
38
|
-
meta = args[3] || options.fetch(:meta) { nil }
|
39
|
-
description = args[4] || options.fetch(:description) { nil }
|
40
|
-
source_uri = args[5] || options.fetch(:source_uri) { nil }
|
41
|
-
on_behalf_of = args[6] || options.fetch(:on_behalf_of) { nil }
|
42
|
-
|
43
|
-
if on_behalf_of
|
44
|
-
if on_behalf_of.respond_to? :uri
|
45
|
-
on_behalf_of = on_behalf_of.uri
|
46
|
-
end
|
47
|
-
if !on_behalf_of.is_a?(String)
|
48
|
-
raise ArgumentError, 'The on_behalf_of parameter needs to be an account URI'
|
49
|
-
end
|
50
|
-
if on_behalf_of == self.uri
|
51
|
-
raise ArgumentError, 'The on_behalf_of parameter MAY NOT be the same account as the account you are debiting!'
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
debit = Debit.new(
|
56
|
-
:uri => self.debits_uri,
|
57
|
-
:amount => amount,
|
58
|
-
:appears_on_statement_as => appears_on_statement_as,
|
59
|
-
:hold_uri => hold_uri,
|
60
|
-
:meta => meta,
|
61
|
-
:description => description,
|
62
|
-
:source_uri => source_uri,
|
63
|
-
:on_behalf_of_uri => on_behalf_of
|
64
|
-
)
|
65
|
-
debit.save
|
66
|
-
end
|
67
|
-
|
68
|
-
# Returns a new Hold that represents a reservation of money on this
|
69
|
-
# Account which can be transferred via a Debit to your Marketplace
|
70
|
-
# up to 7 days later.
|
71
|
-
#
|
72
|
-
# @param [String] source_uri A specific funding source such as a Card
|
73
|
-
# associated with this account. If not specified the most recently
|
74
|
-
# added Card is used.
|
75
|
-
# @return [Hold] A Hold representing the reservation of funds from
|
76
|
-
# this Account to your Marketplace.
|
77
|
-
def hold *args
|
78
|
-
warn_on_positional args
|
79
|
-
|
80
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
81
|
-
amount = args[0] || options.fetch(:amount) { }
|
82
|
-
meta = args[1] || options.fetch(:meta) { nil }
|
83
|
-
source_uri = args[2] || options.fetch(:source_uri) { nil }
|
84
|
-
description = args[3] || options.fetch(:description) { nil }
|
85
|
-
|
86
|
-
hold = Hold.new(
|
87
|
-
:uri => self.holds_uri,
|
88
|
-
:amount => amount,
|
89
|
-
:meta => meta,
|
90
|
-
:source_uri => source_uri,
|
91
|
-
:description => description
|
92
|
-
)
|
93
|
-
hold.save
|
94
|
-
end
|
95
|
-
|
96
|
-
# Returns a new Credit representing a transfer of funds from your
|
97
|
-
# Marketplace to this Account.
|
98
|
-
#
|
99
|
-
# @param [String] destination_uri A specific funding destination such as
|
100
|
-
# a BankAccount already associated with this account.
|
101
|
-
# @return [Credit] A Credit representing the transfer of funds from
|
102
|
-
# your Marketplace to this Account.
|
103
|
-
def credit *args
|
104
|
-
warn_on_positional args
|
105
|
-
|
106
|
-
if args.last.is_a? Hash
|
107
|
-
args.last.merge! :uri => self.credits_uri
|
108
|
-
else
|
109
|
-
args << { :uri => self.credits_uri }
|
110
|
-
end
|
111
|
-
Credit.new(*args).save
|
112
|
-
end
|
113
|
-
|
114
|
-
# Associates the Card represented by +card_uri+ with this Account.
|
115
|
-
#
|
116
|
-
# @return [Account]
|
117
|
-
def add_card(card)
|
118
|
-
card.save if card.kind_of?(Balanced::Card) && card.hash.nil?
|
119
|
-
self.card_uri = Balanced::Utils.extract_uri_from_object(card)
|
120
|
-
save
|
121
|
-
end
|
122
|
-
|
123
|
-
# Associates the BankAccount represented by +bank_account_uri+ with this
|
124
|
-
# Account.
|
125
|
-
#
|
126
|
-
# @return [Account]
|
127
|
-
def add_bank_account(bank_account)
|
128
|
-
if bank_account.kind_of?(Balanced::BankAccount) && bank_account.fingerprint.nil?
|
129
|
-
bank_account.save
|
130
|
-
end
|
131
|
-
self.bank_account_uri = Balanced::Utils.extract_uri_from_object(bank_account)
|
132
|
-
save
|
133
|
-
end
|
134
|
-
|
135
|
-
# Adds the role Merchant to this Account.
|
136
|
-
#
|
137
|
-
# The merchant data for a *person* should look like:
|
138
|
-
#
|
139
|
-
# {
|
140
|
-
# :type => "person",
|
141
|
-
# :name => "William James", # Legal name
|
142
|
-
# :street_address => "167 West 74th Street",
|
143
|
-
# :postal_code => "10023",
|
144
|
-
# :country_code => "USA", # ISO 3166-1 alpha-3
|
145
|
-
# :dob => "1842-01",
|
146
|
-
# :phone_number => "+16505551234"
|
147
|
-
# }
|
148
|
-
#
|
149
|
-
# For a *business*, the payload should look like:
|
150
|
-
#
|
151
|
-
# {
|
152
|
-
# :name => "Levain Bakery",
|
153
|
-
# :tax_id => "253912384", # Optional
|
154
|
-
# :street_address => "167 West 74th Street",
|
155
|
-
# :postal_code => "10023",
|
156
|
-
# :phone_number => "+16505551234",
|
157
|
-
# :country_code => "USA", # ISO 3166-1 alpha-3
|
158
|
-
# :person => {
|
159
|
-
# :name => "William James", # Legal name
|
160
|
-
# :tax_id => "393483992", # Optional
|
161
|
-
# :street_address => "167 West 74th Street", # Home address
|
162
|
-
# :postal_code => "10023",
|
163
|
-
# :dob => "1842-01-01",
|
164
|
-
# :phone_number => "+16505551234",
|
165
|
-
# :country_code => "USA" # ISO 3166-1 alpha-3
|
166
|
-
# }
|
167
|
-
# }
|
168
|
-
#
|
169
|
-
def promote_to_merchant merchant
|
170
|
-
if merchant.is_a?(String)
|
171
|
-
self.merchant_uri = merchant
|
172
|
-
else
|
173
|
-
self.merchant = merchant
|
174
|
-
end
|
175
|
-
save
|
176
|
-
end
|
177
|
-
|
178
|
-
end
|
179
|
-
end
|
@@ -1,61 +0,0 @@
|
|
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 Hold
|
14
|
-
include Balanced::Resource
|
15
|
-
|
16
|
-
def initialize attributes = {}
|
17
|
-
Balanced::Utils.stringify_keys! attributes
|
18
|
-
unless attributes.has_key? 'uri'
|
19
|
-
attributes['uri'] = self.class.uri
|
20
|
-
end
|
21
|
-
super attributes
|
22
|
-
end
|
23
|
-
|
24
|
-
# Cancels an active Hold.
|
25
|
-
#
|
26
|
-
def void
|
27
|
-
self.is_void = true
|
28
|
-
begin
|
29
|
-
save
|
30
|
-
rescue Balanced::Error
|
31
|
-
self.is_void = false
|
32
|
-
raise
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Captures a valid Hold and returns a Debit representing the transfer of
|
37
|
-
# funds from the buyer's Account to your Marketplace.
|
38
|
-
#
|
39
|
-
# @return [Debit]
|
40
|
-
def capture *args
|
41
|
-
warn_on_positional args
|
42
|
-
|
43
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
44
|
-
amount = args[0] || options.fetch(:amount) { nil }
|
45
|
-
appears_on_statement_as = args[1] || options.fetch(:appears_on_statement_as) { nil }
|
46
|
-
meta = args[2] || options.fetch(:meta) { nil }
|
47
|
-
description = args[3] || options.fetch(:description) { nil }
|
48
|
-
|
49
|
-
amount ||= self.amount
|
50
|
-
self.account.debit(
|
51
|
-
:amount => amount,
|
52
|
-
:appears_on_statement_as => appears_on_statement_as,
|
53
|
-
:hold_uri => self.uri,
|
54
|
-
:meta => meta,
|
55
|
-
:description => description
|
56
|
-
)
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Balanced
|
2
|
-
# Resource representing the marketplace merchant object.
|
3
|
-
class Merchant
|
4
|
-
include Balanced::Resource
|
5
|
-
|
6
|
-
# Returns the Merchant associated with your Marketplace.
|
7
|
-
#
|
8
|
-
# @return [Merchant]
|
9
|
-
def self.me
|
10
|
-
self.all.first
|
11
|
-
end
|
12
|
-
|
13
|
-
# Returns the Merchant associated with your Marketplace.
|
14
|
-
#
|
15
|
-
# @return [Merchant]
|
16
|
-
def me
|
17
|
-
self.class.me
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Balanced
|
2
|
-
# Any transfer, or potential transfer of, funds from or to, your
|
3
|
-
# Marketplace. E.g. a Credit, Debit, Refund, Reversal, or Hold.
|
4
|
-
#
|
5
|
-
class Transaction
|
6
|
-
include Balanced::Resource
|
7
|
-
|
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
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
Balanced::Account.add_card
|
@@ -1,11 +0,0 @@
|
|
1
|
-
% if mode == 'definition':
|
2
|
-
Balanced::Account.add_card
|
3
|
-
|
4
|
-
% else:
|
5
|
-
require 'balanced'
|
6
|
-
Balanced.configure('8c3aeeb80e9e11e38901026ba7f8ec28')
|
7
|
-
|
8
|
-
account = Balanced::Account.find('/v1/marketplaces/TEST-MP4h8BxozeLxe7VAllP6b5gj/accounts/AC4SoZJ23TvXIUcUOBSTXYHQ')
|
9
|
-
response = account.add_card('/v1/marketplaces/TEST-MP4h8BxozeLxe7VAllP6b5gj/cards/CC4Y12fGIP0HQ1jhcDgE9cFi')
|
10
|
-
|
11
|
-
% endif
|
@@ -1 +0,0 @@
|
|
1
|
-
Balanced::Account.debit
|
@@ -1,11 +0,0 @@
|
|
1
|
-
% if mode == 'definition':
|
2
|
-
Balanced::Account.debit
|
3
|
-
|
4
|
-
% else:
|
5
|
-
require 'balanced'
|
6
|
-
Balanced.configure('8af725c6d54611e2bf5e026ba7f8ec28')
|
7
|
-
|
8
|
-
account = Balanced::Account.find('/v1/marketplaces/TEST-MP4erLnXCYoaeyr3tx95WSKc/accounts/AC6jdot989BbUks8LFIdRVcX/debits')
|
9
|
-
account.debit(:amount => '1000', :hold_uri => '/v1/marketplaces/TEST-MP4erLnXCYoaeyr3tx95WSKc/holds/HL6t6iMvY9Touhig2PZnCOHk')
|
10
|
-
|
11
|
-
% endif
|
@@ -1 +0,0 @@
|
|
1
|
-
Balanced::Account.new
|
@@ -1 +0,0 @@
|
|
1
|
-
Balanced::Marketplace.create_buyer
|
@@ -1,13 +0,0 @@
|
|
1
|
-
% if mode == 'definition':
|
2
|
-
Balanced::Marketplace.create_buyer
|
3
|
-
|
4
|
-
% else:
|
5
|
-
require 'balanced'
|
6
|
-
Balanced.configure('8c3aeeb80e9e11e38901026ba7f8ec28')
|
7
|
-
|
8
|
-
|
9
|
-
buyer = Balanced::Marketplace.my_marketplace.create_buyer(
|
10
|
-
:card_uri => '/v1/marketplaces/TEST-MP4h8BxozeLxe7VAllP6b5gj/cards/CC4KUcbT2dmJRIYoG0hBpO6S'
|
11
|
-
)
|
12
|
-
|
13
|
-
% endif
|
@@ -1 +0,0 @@
|
|
1
|
-
Balanced::Account.debit
|
@@ -1,11 +0,0 @@
|
|
1
|
-
% if mode == 'definition':
|
2
|
-
Balanced::Account.debit
|
3
|
-
|
4
|
-
% else:
|
5
|
-
require 'balanced'
|
6
|
-
Balanced.configure('8af725c6d54611e2bf5e026ba7f8ec28')
|
7
|
-
|
8
|
-
account = Balanced::Account.find('/v1/marketplaces/TEST-MP4erLnXCYoaeyr3tx95WSKc/accounts/AC6jdot989BbUks8LFIdRVcX/debits')
|
9
|
-
account.debit(:amount => '1000')
|
10
|
-
|
11
|
-
% endif
|
@@ -1 +0,0 @@
|
|
1
|
-
Balanced::Account.hold
|
@@ -1,11 +0,0 @@
|
|
1
|
-
% if mode == 'definition':
|
2
|
-
Balanced::Account.hold
|
3
|
-
|
4
|
-
% else:
|
5
|
-
require 'balanced'
|
6
|
-
Balanced.configure('8af725c6d54611e2bf5e026ba7f8ec28')
|
7
|
-
|
8
|
-
account = Balanced::Account.find('/v1/marketplaces/TEST-MP4erLnXCYoaeyr3tx95WSKc/accounts/AC6jdot989BbUks8LFIdRVcX')
|
9
|
-
account.hold(:amount => '1000')
|
10
|
-
|
11
|
-
% endif
|
@@ -1 +0,0 @@
|
|
1
|
-
Balanced::Account.add_bank_account
|
@@ -1,11 +0,0 @@
|
|
1
|
-
% if mode == 'definition':
|
2
|
-
Balanced::Account.add_bank_account
|
3
|
-
|
4
|
-
% else:
|
5
|
-
require 'balanced'
|
6
|
-
Balanced.configure('8c3aeeb80e9e11e38901026ba7f8ec28')
|
7
|
-
|
8
|
-
account = Balanced::Account.find('/v1/marketplaces/TEST-MP4h8BxozeLxe7VAllP6b5gj/accounts/AC4SoZJ23TvXIUcUOBSTXYHQ')
|
9
|
-
account.add_bank_account("/v1/bank_accounts/BA5hNwwQFEWByAcdf1U5D5ok")
|
10
|
-
|
11
|
-
% endif
|