def charge_create(self, **params): """Wraps around stripe.Charge.create""" # make RequestResponse object prr = RequestResponse() prr.checkout = self.checkout prr.gateway = 'stripe' prr.method = 'Charge.create' prr.request = params prr.save() # start timer start = time.time() try: response = stripe.Charge.create(**params) prr.duration = time.time() - start prr.response = response if response['paid']: prr.status = prr.SUCCESS else: prr.status = prr.FAIL except (stripe.InvalidRequestError, stripe.AuthenticationError, stripe.CardError, stripe.APIError), e: prr.duration = time.time() - start prr.status = prr.FAIL prr.save() return {'paid': False}
def request(self, params): """makes the API call and returns the response""" # make a RequestResponse object prr = RequestResponse() prr.gateway = 'paypal' prr.checkout = self.checkout prr.method = params['METHOD'] prr.request = copy.deepcopy(params) prr.save() params.update(self.credentials) # start timer start = time.time() # send request response = requests.get(self.API, params=params) # calcuate duration prr.duration = time.time() - start # parse the response response = self._parse_response(response.text) # add any error messages to the self self.error = response.get('L_LONGMESSAGE0', None) # finish the response prr.response = response # assume fail prr.status = prr.FAIL try: if response['ACK'] in ['Success', 'SuccessWihWarning']: prr.status = prr.SUCCESS except KeyError: pass prr.save() return response