Skip to content

Instantly share code, notes, and snippets.

@martinleblanc
Last active August 27, 2018 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinleblanc/37d14f33a7ba676d1498964f87bd9153 to your computer and use it in GitHub Desktop.
Save martinleblanc/37d14f33a7ba676d1498964f87bd9153 to your computer and use it in GitHub Desktop.
Question 2
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