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,57 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Learn how to authenticate a bank account so you can debit with it.
|
3
|
-
"""
|
4
|
-
cwd = File.dirname(File.dirname(File.expand_path(__FILE__)))
|
5
|
-
$:.unshift(cwd + "/lib")
|
6
|
-
require 'rubygems'
|
7
|
-
require 'balanced'
|
8
|
-
|
9
|
-
host = ENV.fetch('BALANCED_HOST') { nil }
|
10
|
-
options = {}
|
11
|
-
if host
|
12
|
-
options[:scheme] = 'http'
|
13
|
-
options[:host] = host
|
14
|
-
options[:port] = 5000
|
15
|
-
end
|
16
|
-
|
17
|
-
Balanced.configure(nil, options)
|
18
|
-
|
19
|
-
# create a new marketplace
|
20
|
-
api_key = Balanced::ApiKey.new.save
|
21
|
-
Balanced.configure(api_key.secret)
|
22
|
-
marketplace = Balanced::Marketplace.new.save
|
23
|
-
|
24
|
-
# create a bank account
|
25
|
-
bank_account = marketplace.create_bank_account(
|
26
|
-
:account_number => "1234567890",
|
27
|
-
:bank_code => "12",
|
28
|
-
:name => "Jack Q Merchant"
|
29
|
-
)
|
30
|
-
account = marketplace.create_account()
|
31
|
-
account.add_bank_account(bank_account.uri)
|
32
|
-
|
33
|
-
puts "you can't debit until you authenticate"
|
34
|
-
begin
|
35
|
-
account.debit(:amount => 100)
|
36
|
-
rescue Balanced::Error => ex
|
37
|
-
puts "Debit failed, %s" % ex.message
|
38
|
-
end
|
39
|
-
|
40
|
-
# authenticate
|
41
|
-
verification = bank_account.verify
|
42
|
-
|
43
|
-
begin
|
44
|
-
verification.confirm(1,2)
|
45
|
-
rescue Balanced::BankAccountVerificationFailure => ex
|
46
|
-
puts 'Authentication error , %s' % ex.message
|
47
|
-
puts "PROTIP: for TEST bank accounts the valid amount is always 1 and 1"
|
48
|
-
end
|
49
|
-
verification = bank_account.verifications.find(:first).first
|
50
|
-
|
51
|
-
raise "unpossible" if verification.confirm(1, 1).state != 'verified'
|
52
|
-
debit = account.debit(:amount => 100)
|
53
|
-
puts "debited the bank account %s for %d cents" % [
|
54
|
-
debit.source.uri,
|
55
|
-
debit.amount
|
56
|
-
]
|
57
|
-
puts "and there you have it"
|
data/examples/customers.rb
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
cwd = File.dirname(File.dirname(File.expand_path(__FILE__)))
|
2
|
-
$:.unshift(cwd + "/lib")
|
3
|
-
require 'rubygems'
|
4
|
-
require 'balanced'
|
5
|
-
|
6
|
-
begin
|
7
|
-
Balanced::Card
|
8
|
-
rescue NameError
|
9
|
-
raise "wtf"
|
10
|
-
end
|
11
|
-
|
12
|
-
host = ENV.fetch('BALANCED_HOST') { nil }
|
13
|
-
options = {}
|
14
|
-
if host
|
15
|
-
options[:scheme] = 'http'
|
16
|
-
options[:host] = host
|
17
|
-
options[:port] = 5000
|
18
|
-
end
|
19
|
-
|
20
|
-
Balanced.configure(nil, options)
|
21
|
-
|
22
|
-
puts "create our new api key"
|
23
|
-
api_key = Balanced::ApiKey.new.save
|
24
|
-
puts "Our secret is: ", api_key.secret
|
25
|
-
secret = api_key.secret
|
26
|
-
|
27
|
-
puts "configure with our secret #{secret}"
|
28
|
-
Balanced.configure(secret)
|
29
|
-
|
30
|
-
puts "create our marketplace"
|
31
|
-
begin
|
32
|
-
marketplace = Balanced::Marketplace.new.save
|
33
|
-
rescue Balanced::Conflict => ex
|
34
|
-
marketplace = Balanced::Marketplace.mine
|
35
|
-
end
|
36
|
-
|
37
|
-
puts "create a customer"
|
38
|
-
#
|
39
|
-
customer = marketplace.create_customer(
|
40
|
-
:name => "Bill",
|
41
|
-
:email => "bill@bill.com",
|
42
|
-
:business_name => "Bill Inc.",
|
43
|
-
:ssn_last4 => "1234",
|
44
|
-
:address => {
|
45
|
-
:line1 => "1234 1st Street",
|
46
|
-
:city => "San Francisco",
|
47
|
-
:state => "CA"
|
48
|
-
}
|
49
|
-
).save
|
50
|
-
|
51
|
-
puts "our customer uri is #{customer.uri}"
|
52
|
-
|
53
|
-
puts "create a card and a bank account for our customer"
|
54
|
-
|
55
|
-
bank_account = marketplace.create_bank_account(
|
56
|
-
:account_number => "1234567980",
|
57
|
-
:bank_code => "321174811",
|
58
|
-
:name => "Jack Q Merchant"
|
59
|
-
)
|
60
|
-
|
61
|
-
card = marketplace.create_card(
|
62
|
-
:card_number => "4111111111111111",
|
63
|
-
:expiration_month => "12",
|
64
|
-
:expiration_year => "2015"
|
65
|
-
).save
|
66
|
-
|
67
|
-
puts "our bank account uri is #{bank_account.uri}"
|
68
|
-
puts "our card uri is #{card.uri}"
|
69
|
-
|
70
|
-
puts "associate the newly created bank account and card to our customer"
|
71
|
-
|
72
|
-
customer.add_card(card)
|
73
|
-
customer.add_bank_account(bank_account)
|
74
|
-
|
75
|
-
puts "check and make sure our customer now has a card and bank account listed"
|
76
|
-
|
77
|
-
raise "customer's cards should not be empty" unless customer.cards.any?
|
78
|
-
raise "customer's bank accounts should not be empty" unless customer.bank_accounts.any?
|
79
|
-
|
80
|
-
puts "create a debit on our customer"
|
81
|
-
|
82
|
-
customer.debit(
|
83
|
-
:amount => 5000,
|
84
|
-
:description => "new debit"
|
85
|
-
)
|
86
|
-
|
87
|
-
puts "check to make sure debit is added"
|
88
|
-
|
89
|
-
raise "customer should not have 0 debits" unless customer.debits.any?
|
90
|
-
raise "customer debit should be 5000" unless customer.debits.first.amount == 5000
|
91
|
-
|
92
|
-
puts "create a credit on our customer"
|
93
|
-
|
94
|
-
customer.credit(
|
95
|
-
:amount => 2500,
|
96
|
-
:description => "new credit"
|
97
|
-
)
|
98
|
-
|
99
|
-
puts "check to make sure credit is added"
|
100
|
-
|
101
|
-
raise "customer should not have 0 credits" unless customer.credits.any?
|
102
|
-
raise "customer should be 2500" unless customer.credits.first.amount == 2500
|
103
|
-
|
104
|
-
puts "check to see what is the active card for a customer"
|
105
|
-
|
106
|
-
raise "active card is incorrect" unless customer.active_card.id == card.id
|
107
|
-
|
108
|
-
puts "check to see what is the active bank_account for a customer"
|
109
|
-
|
110
|
-
raise "active bank account is incorrect" unless customer.active_bank_account.id == bank_account.id
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
@@ -1,81 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Welcome weary traveller. Sick of polling for state changes? Well today have I
|
3
|
-
got good news for you. Run this example below to see how to get yourself some
|
4
|
-
callback goodness and to understand how events work.
|
5
|
-
"""
|
6
|
-
cwd = File.dirname(File.dirname(File.expand_path(__FILE__)))
|
7
|
-
$:.unshift(cwd + "/lib")
|
8
|
-
require 'rubygems'
|
9
|
-
require 'balanced'
|
10
|
-
require 'net/http'
|
11
|
-
require 'uri'
|
12
|
-
require 'json'
|
13
|
-
|
14
|
-
api_key = Balanced::ApiKey.new.save
|
15
|
-
Balanced.configure(api_key.secret)
|
16
|
-
marketplace = Balanced::Marketplace.new.save
|
17
|
-
|
18
|
-
# mumble, let's create a requestb.in
|
19
|
-
request_bin = Net::HTTP.post_form(URI.parse('http://requestb.in/api/v1/bins'), {})
|
20
|
-
response = JSON.parse request_bin.body
|
21
|
-
bin_name = response['name']
|
22
|
-
callback_url = 'http://requestb.in/' + bin_name
|
23
|
-
requests_url = 'http://requestb.in/api/v1/bins/%s/requests' % bin_name
|
24
|
-
|
25
|
-
puts 'let\'s create a callback'
|
26
|
-
marketplace.create_callback(
|
27
|
-
:url => callback_url
|
28
|
-
)
|
29
|
-
|
30
|
-
puts 'let\'s create a card and associate it with a new account'
|
31
|
-
card = Balanced::Card.new(
|
32
|
-
:expiration_month => '12',
|
33
|
-
:security_code => '123',
|
34
|
-
:card_number => '5105105105105100',
|
35
|
-
:expiration_year => '2020'
|
36
|
-
).save()
|
37
|
-
buyer = Balanced::Account.new(
|
38
|
-
'card_uri' => card.uri
|
39
|
-
).save()
|
40
|
-
|
41
|
-
puts 'generate a debit (which implicitly creates and captures a hold)'
|
42
|
-
buyer.debit(:amount => 100)
|
43
|
-
|
44
|
-
puts 'event creation is an async operation, let\'s wait until we have ' \
|
45
|
-
'some events!'
|
46
|
-
while Balanced::Event.find(:all).length == 0
|
47
|
-
puts 'Zzzz'
|
48
|
-
sleep(0)
|
49
|
-
end
|
50
|
-
|
51
|
-
puts 'Woop, we got some events, let us see what there is to look at'
|
52
|
-
for event in Balanced::Event.find(:all)
|
53
|
-
puts 'this was a %s event, it occurred at %s, the callback has a ' \
|
54
|
-
'status of %s' % [
|
55
|
-
event.type,
|
56
|
-
event.occurred_at,
|
57
|
-
event.callback_statuses
|
58
|
-
]
|
59
|
-
end
|
60
|
-
|
61
|
-
puts 'you can inspect each event to see the logs'
|
62
|
-
event = Balanced::Event.find(:first)
|
63
|
-
for callback in event.callbacks
|
64
|
-
puts 'inspecting callback to %s for event %s' % [
|
65
|
-
callback.url,
|
66
|
-
event.type
|
67
|
-
]
|
68
|
-
|
69
|
-
for log in callback.logs
|
70
|
-
puts 'this attempt to the callback has a status of %s' % [log.status]
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
puts 'ok, let\'s check with requestb.in to see if our callbacks fired at %s' % callback_url
|
75
|
-
uri = URI.parse(requests_url)
|
76
|
-
request_bin = Net::HTTP.get_response(uri)
|
77
|
-
response = JSON.parse request_bin.body
|
78
|
-
puts 'we received %s callbacks, you can view them at http://requestb.in/%s?inspect' % [
|
79
|
-
response.length,
|
80
|
-
bin_name,
|
81
|
-
]
|
data/examples/examples.rb
DELETED
@@ -1,162 +0,0 @@
|
|
1
|
-
cwd = File.dirname(File.dirname(File.expand_path(__FILE__)))
|
2
|
-
$:.unshift(cwd + "/lib")
|
3
|
-
require 'rubygems'
|
4
|
-
require 'balanced'
|
5
|
-
|
6
|
-
begin
|
7
|
-
Balanced::Card
|
8
|
-
rescue NameError
|
9
|
-
raise "wtf"
|
10
|
-
end
|
11
|
-
|
12
|
-
host = ENV.fetch('BALANCED_HOST') { nil }
|
13
|
-
options = {}
|
14
|
-
if host
|
15
|
-
options[:scheme] = 'http'
|
16
|
-
options[:host] = host
|
17
|
-
options[:port] = 5000
|
18
|
-
end
|
19
|
-
|
20
|
-
Balanced.configure(nil, options)
|
21
|
-
|
22
|
-
puts "create our new api key"
|
23
|
-
api_key = Balanced::ApiKey.new.save
|
24
|
-
puts "Our secret is: ", api_key.secret
|
25
|
-
secret = api_key.secret
|
26
|
-
|
27
|
-
puts "configure with our secret #{secret}"
|
28
|
-
Balanced.configure(secret)
|
29
|
-
|
30
|
-
puts "create our marketplace"
|
31
|
-
begin
|
32
|
-
marketplace = Balanced::Marketplace.new.save
|
33
|
-
rescue Balanced::Conflict => ex
|
34
|
-
marketplace = Balanced::Marketplace.mine
|
35
|
-
end
|
36
|
-
|
37
|
-
raise "Merchant.me should not be nil" if Balanced::Merchant.me.nil?
|
38
|
-
puts "what's my merchant?, easy: Merchant.me: ", Balanced::Merchant.me
|
39
|
-
|
40
|
-
# what's my marketplace?
|
41
|
-
raise "Marketplace.mine should not be nil" if Balanced::Marketplace.mine.nil?
|
42
|
-
puts "what's my marketplace?, easy: Marketplace.mine: ", Balanced::Marketplace.mine
|
43
|
-
|
44
|
-
puts "My marketplace's name is: #{marketplace.name}"
|
45
|
-
random_name = (0...10).map{ ('a'..'z').to_a[rand(26)] }.join
|
46
|
-
puts "Changing it to #{random_name}"
|
47
|
-
marketplace.name = random_name
|
48
|
-
marketplace.save
|
49
|
-
puts "My marketplace name is now: #{Balanced::Marketplace.mine.name}"
|
50
|
-
raise "Marketplace name is NOT #{random_name}!" if Balanced::Marketplace.mine.name != random_name
|
51
|
-
|
52
|
-
puts "cool! let's create a new card."
|
53
|
-
card = Balanced::Card.new(
|
54
|
-
:card_number => "5105105105105100",
|
55
|
-
:expiration_month => "12",
|
56
|
-
:expiration_year => "2015"
|
57
|
-
).save
|
58
|
-
puts "Our card uri: #{card.uri}"
|
59
|
-
|
60
|
-
puts "create our **buyer** account"
|
61
|
-
buyer = marketplace.create_buyer(
|
62
|
-
:email_address => "buyer@example.org",
|
63
|
-
:card_uri => card.uri
|
64
|
-
)
|
65
|
-
puts "our buyer account: #{buyer.uri}"
|
66
|
-
|
67
|
-
puts "hold some amount of funds on the buyer, lets say 15$"
|
68
|
-
the_hold = buyer.hold(:amount => 1500)
|
69
|
-
|
70
|
-
puts "ok, no more holds! lets just capture it (for the full amount)"
|
71
|
-
debit = the_hold.capture
|
72
|
-
|
73
|
-
puts "hmm, how much money do i have in escrow? should equal the debit amount"
|
74
|
-
marketplace = marketplace.reload
|
75
|
-
raise "1500 is not in escrow! this is wrong" if marketplace.in_escrow != 1500
|
76
|
-
puts "i have #{marketplace.in_escrow} in escrow!"
|
77
|
-
|
78
|
-
puts "cool. now let me refund the full amount"
|
79
|
-
refund = debit.refund() # the full amount!
|
80
|
-
|
81
|
-
puts "ok, we have a merchant that's signing up, let's create an account for them " \
|
82
|
-
"first, lets create their bank account."
|
83
|
-
|
84
|
-
bank_account = marketplace.create_bank_account(
|
85
|
-
:account_number => "1234567890",
|
86
|
-
:routing_number => "322271627",
|
87
|
-
:name => "Jack Q Merchant"
|
88
|
-
)
|
89
|
-
|
90
|
-
merchant = marketplace.create_merchant(
|
91
|
-
:email_address => "merchant@example.org",
|
92
|
-
:merchant => {
|
93
|
-
:type => "person",
|
94
|
-
:name => "Billy Jones",
|
95
|
-
:street_address => "801 High St.",
|
96
|
-
:postal_code => "94301",
|
97
|
-
:country => "USA",
|
98
|
-
:dob => "1842-01",
|
99
|
-
:phone_number => "+16505551234"
|
100
|
-
},
|
101
|
-
:bank_account_uri => bank_account.uri,
|
102
|
-
:name => "Jack Q Merchant"
|
103
|
-
)
|
104
|
-
|
105
|
-
puts "oh our buyer is interested in buying something for 530.00$"
|
106
|
-
another_debit = buyer.debit(
|
107
|
-
:amount => 53000,
|
108
|
-
:appears_on_statement_as => "MARKETPLACE.COM"
|
109
|
-
)
|
110
|
-
|
111
|
-
puts "lets credit our merchant 110.00$"
|
112
|
-
credit = merchant.credit(
|
113
|
-
:amount => 11000,
|
114
|
-
:description => "Buyer purchased something on MARKETPLACE.COM"
|
115
|
-
)
|
116
|
-
|
117
|
-
puts "lets assume the marketplace charges 15%, so it earned ~20"
|
118
|
-
mp_credit = marketplace.owner_account.credit(
|
119
|
-
:amount => 2000,
|
120
|
-
:description => "Our commission from MARKETPLACE.COM"
|
121
|
-
)
|
122
|
-
|
123
|
-
puts "ok lets invalid a card"
|
124
|
-
card.invalidate
|
125
|
-
|
126
|
-
raise "This card is INCORRECTLY VALID" if card.is_valid
|
127
|
-
|
128
|
-
puts "invalidating a bank account"
|
129
|
-
bank_account.invalidate
|
130
|
-
|
131
|
-
raise "This card is INCORRECTLY VALID" if bank_account.is_valid
|
132
|
-
|
133
|
-
puts "let's create a bank account not associated to an account"
|
134
|
-
bank_account = Balanced::BankAccount.new(
|
135
|
-
:account_number => "9876543210",
|
136
|
-
:routing_number => "021000021",
|
137
|
-
:name => "Jake Skellington",
|
138
|
-
:type => "checking"
|
139
|
-
).save
|
140
|
-
|
141
|
-
raise "Should not have an account" if bank_account.has_account?
|
142
|
-
|
143
|
-
puts "now let's credit it, the super-simple way"
|
144
|
-
credit = bank_account.credit(
|
145
|
-
:amount => 500
|
146
|
-
)
|
147
|
-
|
148
|
-
raise "Incorrect value for credit" if credit.amount != 500
|
149
|
-
|
150
|
-
puts "That was still too hard -- let's credit without creating a bank account first"
|
151
|
-
credit = Balanced::Credit.new(
|
152
|
-
:amount => 700,
|
153
|
-
:description => "Amazing",
|
154
|
-
:bank_account => {
|
155
|
-
:account_number => "55555555",
|
156
|
-
:bank_code => "021000021",
|
157
|
-
:name => "Wanda Wandy",
|
158
|
-
:type => "checking"
|
159
|
-
}
|
160
|
-
).save
|
161
|
-
raise "OOPS -- that was hard after all" if (credit.amount != 700 or
|
162
|
-
credit.created_at.nil?)
|
@@ -1,44 +0,0 @@
|
|
1
|
-
cwd = File.dirname(File.dirname(File.expand_path(__FILE__)))
|
2
|
-
$:.unshift(cwd + "/lib")
|
3
|
-
require 'rubygems'
|
4
|
-
require 'balanced'
|
5
|
-
|
6
|
-
begin
|
7
|
-
Balanced::Card
|
8
|
-
rescue NameError
|
9
|
-
raise "wtf"
|
10
|
-
end
|
11
|
-
|
12
|
-
require 'balanced'
|
13
|
-
|
14
|
-
Balanced.configure("8bb66df4e80711e290df026ba7cd33d0")
|
15
|
-
|
16
|
-
puts "create our marketplace"
|
17
|
-
begin
|
18
|
-
marketplace = Balanced::Marketplace.new.save
|
19
|
-
rescue Balanced::Conflict => ex
|
20
|
-
# balanced automatically maps the body's response
|
21
|
-
# for convenience, so for example:
|
22
|
-
puts ex.response[:body]
|
23
|
-
# you'll notice this hash is mapped to nice attributes
|
24
|
-
raise "Not Present" if ex.response[:body]["status"] != ex.status
|
25
|
-
# you can find all of the attributes here:
|
26
|
-
# https://docs.balancedpayments.com/current/api?language=bash#errors
|
27
|
-
marketplace = Balanced::Marketplace.mine
|
28
|
-
end
|
29
|
-
|
30
|
-
# create a new card
|
31
|
-
|
32
|
-
card = Balanced::Card.new(
|
33
|
-
:card_number => "5105105105105100",
|
34
|
-
:expiration_month => "12",
|
35
|
-
:expiration_year => "2015",
|
36
|
-
:phone_number => "INCORRECT PHONE NUMBER"
|
37
|
-
)
|
38
|
-
|
39
|
-
begin
|
40
|
-
card.save
|
41
|
-
rescue Balanced::BadRequest => ex
|
42
|
-
puts ex.extras[:phone_number]
|
43
|
-
puts "All the fields that have errors are: #{ex.extras.keys}"
|
44
|
-
end
|