I am adding Balanced Payments (-v 0.6.0) to an existing system to enable marketplace features, and am running into an issues with the cleanup (invalidation) of a stored Bank Account when a new Bank Account is added/stored to a Customer Account (we only want sellers in marketplace to have at most one Bank Account active, to reduce complexity).
to make my question simple, here is a simple version of the what we are attempting, and the log response (error)
if (!params[:balanced_uri].blank?)
begin
@balanced_acctresponse = Balanced::Account.find(params[:balanced_uri])
bankaccts = Balanced::BankAccount.find(@balanced_acctresponse.bank_accounts_uri)
bankaccts.invalidate
rescue => e
logger.debug("Balanced Bank Account error :: #{e}")
end
this is generating the following exception
Balanced Bank Account error :: Balanced::BadRequest(400)::Bad Request:: POST https://api.balancedpayments.com/v1/marketplaces/xxxxxx/accounts/xxxxxx/bank_accounts?limit=10&offset=0: request: Missing required field [name]
I'm confused as to what name field is missing. As defined here http://rubydoc.info/gems/balanced/0.6.0/Balanced/BankAccount there is no name param required for invalidate
I suggest you upgrade to the latest version of balanced-ruby (0.7.4). I recommend you then try something like:
begin
@account = Balanced::Account.find(current_user.balanced_account_uri)
@account.bank_accounts.each do |ba|
ba.invalidate
end
rescue => e
logger.debug("Balanced Bank Account error :: #{e}")
end
This will find the Account instance in Balanced, loop through its bank accounts and invalidate each of them.
NOTE: Account was deprecated about 9 months ago, superseded by Customer. Account will not be in the next API revision.
If you have any other questions, feel free to also drop by #balanced on Freenode IRC. There you can get assistance directly from developers.