Reputation: 6906
I've create a new merchant account on Balanced via the API. I added a bank account to this account and then tokenized the exact same bank account and then added that again. I was expecting the second association to throw a 409 telling me that the account could not be added.
I have two questions:
Here is the example of two bank accounts I've created on an account via the Ruby gem:
irb(main):029:0> @bank_accounts.items.each { |a|
puts "#{a["bank_name"]} #{a["bank_code"]} created-#{a["created_at"]} #{a["last_four"]} uri=#{a["uri"]} id=#{a["id"]}"
}; nil
123456789 created-2012-07-11T23:36:57.290555Z 2333 uri=/v1/marketplaces/TEST-MP4Z4RaRDF6TWqeupiVUSu8m/accounts/AC2tip2eDhi92THXXEkIdys1/bank_accounts/BA2mP9GtEPVB3v9DzWJ7ZH8B id=BA2mP9GtEPVB3v9DzWJ7ZH8B
123456789 created-2012-07-11T23:37:22.655007Z 2333 uri=/v1/marketplaces/TEST-MP4Z4RaRDF6TWqeupiVUSu8m/accounts/AC2tip2eDhi92THXXEkIdys1/bank_accounts/BA2PlMIVFyMSSzo2zzUZb2XA id=BA2PlMIVFyMSSzo2zzUZb2XA
=> nil
Upvotes: 0
Views: 344
Reputation: 10092
You can index the cards or bank accounts associated with a user, Balanced does not return the full card number but by comparing the last_four, expiration, and name you can tell if a card is a match, similar fields are available for bank accounts but swap expiration with bank_code (routing number).
The code to do something like this in Ruby would be:
require 'balanced'
Balanced.configure 'e1c5ad38d1c711e1b36c026ba7e239a9'
# duplicate cards
card1 = Balanced::Card.new(:card_number=>"4111111111111111", :expiration_month=>"12", :expiration_year=>"2020").save() # original card
card2 = Balanced::Card.new(:card_number=>"4111111111111111", :expiration_month=>"12", :expiration_year=>"2020").save() # our duplicate card
card3 = Balanced::Card.new(:card_number=>"4111111111111111", :expiration_month=>"12", :expiration_year=>"2021").save() # a different card
# create a new account
buyer = Balanced::Account.new(:email_address => '%[email protected]' % Time.now).save()
buyer.add_card(card1.uri)
# helper function
def has_card(cards, card)
cards.map { |c| c.last_four == card.last_four && c.expiration_month == card.expiration_month && c.expiration_year == card.expiration_year }.include? true
end
puts 'buyer already has this card' if has_card(buyer.cards, card2)
puts 'buyer does not have this card' if not has_card(buyer.cards, card3)
Upvotes: 3