examples/examples.rb in balanced-0.3.11 vs examples/examples.rb in balanced-0.5.1
- old
+ new
@@ -1,17 +1,18 @@
-$:.unshift("/Users/mahmoud/code/poundpay/ruby/balanced-ruby/lib")
+cwd = File.dirname(File.dirname(File.absolute_path(__FILE__)))
+$:.unshift(cwd + "/lib")
require 'balanced'
begin
Balanced::Card
rescue NameError
raise "wtf"
end
-host = ENV['BALANCED_HOST'] or nil
+host = ENV.fetch('BALANCED_HOST') { nil }
options = {}
-if host then
+if host
options[:scheme] = 'http'
options[:host] = host
options[:port] = 5000
end
@@ -77,15 +78,15 @@
refund = debit.refund() # the full amount!
puts "ok, we have a merchant that's signing up, let's create an account for them " \
"first, lets create their bank account."
-bank_account = Balanced::BankAccount.new(
+bank_account = marketplace.create_bank_account(
:account_number => "1234567890",
:bank_code => "12",
:name => "Jack Q Merchant",
-).save
+)
merchant = marketplace.create_merchant(
:email_address => "merchant@example.org",
:merchant => {
:type => "person",
@@ -98,13 +99,13 @@
},
:bank_account_uri => bank_account.uri,
:name => "Jack Q Merchant",
)
-puts "oh our buyer is interested in buying something for 130.00$"
+puts "oh our buyer is interested in buying something for 530.00$"
another_debit = buyer.debit(
- :amount => 13000,
+ :amount => 53000,
:appears_on_statement_as => "MARKETPLACE.COM"
)
puts "lets credit our merchant 110.00$"
credit = merchant.credit(
@@ -125,5 +126,34 @@
puts "invalidating a bank account"
bank_account.invalidate
raise "This card is INCORRECTLY VALID" if bank_account.is_valid
+
+puts "let's create a bank account not associated to an account"
+bank_account = Balanced::BankAccount.new(
+ :account_number => "9876543210",
+ :routing_number => "021000021",
+ :name => "Jake Skellington",
+ :type => "checking"
+).save
+
+puts "now let's credit it, the super-simple way"
+credit = bank_account.credit(
+ :amount => 500
+)
+
+raise "Incorrect value for credit" if credit.amount != 500
+
+puts "That was still too hard -- let's credit without creating a bank account first"
+credit = Balanced::Credit.new(
+ :amount => 700,
+ :description => "Amazing",
+ :bank_account => {
+ :account_number => "55555555",
+ :bank_code => "021000021",
+ :name => "Wanda Wandy",
+ :type => "checking"
+ }
+).save
+raise "OOPS -- that was hard after all" if (credit.amount != 700 or
+ credit.created_at.nil?)