我通过API在Balanced上创建了一个新的商家帐户。我在此帐户中添加了一个银行帐户,然后将其标记为完全相同的银行帐户,然后再次添加。我期待第二个关联投掷409告诉我该帐户无法添加。
我有两个问题:
以下是我通过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
答案 0 :(得分:3)
您可以索引与用户关联的卡片或银行帐户,Balanced不会返回完整的卡片编号,但通过比较last_four,expiration和名称,您可以判断卡片是否匹配,类似的字段是可用于银行帐户,但与bank_code(路由号码)交换到期。
在Ruby中执行类似操作的代码是:
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 => '%d@example.org' % 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)