Skip to content

Instantly share code, notes, and snippets.

@ajsharp
Created October 2, 2012 00:39
Show Gist options
  • Select an option

  • Save ajsharp/3815488 to your computer and use it in GitHub Desktop.

Select an option

Save ajsharp/3815488 to your computer and use it in GitHub Desktop.
Handling a 409 response when attempting to create a balanced account and a user with that email account already exists
begin
balanced_account = Balanced::Marketplace.my_marketplace.create_merchant(email, merchant_hash, bank_account_uri, name)
rescue Balanced::Error => ex
if ex.response[:status] == 409
# A 409 is returned if the account has already been created.
# Balanced will return the account uri in the error response, so we simply need to
# create an internal account on our end.
decoded_body = ex.response[:body]
uri = decoded_body['extras']['account_uri']
begin
# lookup the existing balanced account object
balanced_account = Balanced::Account.find(uri)
rescue
# this really shouldn't happen...
raise "Could not find Balanced account with uri => #{uri}"
end
else
# re-raise other exceptions
raise ex
end
end
@ajsharp

ajsharp commented Oct 2, 2012

Copy link
Copy Markdown
Author

FWIW, the balanced API will return a 409 status code in the same case (duplicate email address) when attempting to create a buyer as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment