Created
October 3, 2013 19:31
-
-
Save jcoletaylor/6815673 to your computer and use it in GitHub Desktop.
balanced account adding a card
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_card(card_uri, reuse=false) | |
card = self.balanced_cards.where(:uri => card_uri).first | |
unless card | |
BalancedAccount.transaction do | |
begin | |
card = BalancedCard.new(:uri => card_uri, :reuse => reuse, :balanced_accout => self) | |
self.balanced_cards << card | |
card.save! | |
save! | |
# remote_object is an instance of Balanced::Account | |
remote_object.add_card(card_uri) | |
rescue Balanced::Error => e | |
# NOTE: balanceable.email is safe because we only add cards to User objects | |
logger.error "ERROR: unable to add card #{card_uri} for #{balanceable.email}: #{e.message}" | |
card = nil | |
raise ActiveRecord::Rollback | |
rescue Exception => e | |
# NOTE: balanceable.email is safe because we only add cards to User objects | |
logger.error "ERROR: unable to add card #{card_uri} for #{balanceable.email}: #{e.message}" | |
card = nil | |
raise ActiveRecord::Rollback | |
end # end begin / rescue | |
end # end transaction | |
end # end unless | |
card | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment