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
data/lib/balanced/resources.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
|
-
$:.unshift
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
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
|
-
|
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
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
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
|
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
|
@@ -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
|
-
|
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
|
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
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
72
|
-
self.
|
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
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
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
|
-
:
|
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
|
-
|
10
|
-
|
11
|
-
self.collection_path
|
12
|
-
end
|
8
|
+
include Balanced::Resource
|
9
|
+
include Balanced::HypermediaRegistry
|
13
10
|
|
14
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
71
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
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
|
89
|
-
if
|
90
|
-
|
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
|