Last active
August 27, 2018 14:51
-
-
Save martinleblanc/37d14f33a7ba676d1498964f87bd9153 to your computer and use it in GitHub Desktop.
Question 2
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
class CheckoutView(View): | |
def post(self, request, card, amount, *args, **kwargs): | |
try: | |
credit_card_service.charge_credit_card(card, amount) | |
except InsufficientFundsError: | |
self.errors.append('Insufficient funds') | |
except NotForSaleError: | |
self.errors.append('Asset is not for sale under the given circumstances') | |
except AssetAlreadyPurchasedException, e: | |
self.errors.append("You already purchased {}(id={})".format(e.reference_identifier, e.reference_primary_key)) | |
except NotFoundError: | |
self.errors.append("Asset was not found") | |
except Exception, e: | |
self.errors.append("Exception", str(e)) | |
class DepositCashView(View): | |
def post(self, request, card, amount, *args, **kwargs): | |
try: | |
credit_card_service.charge_credit_card(card, amount) | |
except InsufficientFundsError: | |
self.errors.append('Insufficient funds') | |
except NotForSaleError: | |
self.errors.append('Asset is not for sale under the given circumstances') | |
except AssetAlreadyPurchasedException, e: | |
self.errors.append("You already purchased {}(id={})".format(e.reference_identifier, e.reference_primary_key)) | |
except NotFoundError: | |
self.errors.append("Asset was not found") | |
except Exception, e: | |
self.errors.append("Exception", str(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment