I am using the stripe library in Python for credit card charging. I use the customerID for purposes of charging rather than the token as I want to re-use the card without asking for it each time. The success process works just fine, however, if I create an error condition the "except" is never thrown. I am testing the failure state by using an invalid customer ID.
The server log shows the following error: "InvalidRequestError: Request req_8949iJfEmeX39p: No such customer: 22" but again this is not handled in try/except.
class ChargeCustomerCard(webapp2.RequestHandler):
def post(self):
stripe.api_key = stripeApiKey
customerID = self.request.get("cust")
amount = self.request.get("amt")
try:
charge = stripe.Charge.create(amount=int(amount),currency="usd",customer=customerID,description=customerID)
except stripe.error.CardError, e:
output = {"result":e}
else:
output = {"result":"1"}
self.response.out.write(json.dumps(output))
except Exception as eclause below the specificstripe.error.CardErrorand before theelseof yourtryblock, and see if that gives you the appropriate error. If so, you may want to file an issue at github.com/stripe/stripe-python/issues unless it was intended not to be a stripe specific Exception/Error, or maybe there is another specific Error understripe.errornamespace you need toexcept