def process(self): """Attempts to process Preauthorize with transaction details. Returns the values of ``gateway.Preauthorize.process``. Raises: GatewayError: An Oscar error raised when there was an error with the payment API. PaymentError: An Oscar error raised when there was an error processing the payment. """ preauth_instance = gateway.Preauthorize(save_token=self.save_token, django_user=self.django_user, **self.transaction_details) try: return preauth_instance.process() except helcim_exceptions.ProcessingError as error: raise oscar_exceptions.GatewayError(str(error)) except helcim_exceptions.PaymentError as error: raise oscar_exceptions.PaymentError(str(error)) except helcim_exceptions.DjangoError: LOG.exception( 'Preauthorization complete, but errors occured while saving ' 'transaction to database') except helcim_exceptions.HelcimError as error: raise oscar_exceptions.GatewayError(str(error))
def test_process_error_response_preauth(): preauth_request = gateway.Preauthorize() try: preauth_request.process_error_response('') except helcim_exceptions.PaymentError: assert True else: assert False
def test_preauth_processing(): details = { 'amount': 100.00, 'customer_code': 'CST1000', } preauth = gateway.Preauthorize(api_details=API_DETAILS, **details) transaction, _ = preauth.process() assert isinstance(transaction, MockDjangoModel)
def test_process_with_save_token_disabled(): details = { 'amount': 100.00, 'token': 'abcdefghijklmnopqrstuvw', 'token_f4l4': '11119999', 'customer_code': 'CST1000', } preauth = gateway.Preauthorize(api_details=API_DETAILS, save_token=True, **details) _, token = preauth.process() assert token is None
def test_process_with_save_token_enabled(django_user_model): details = { 'amount': 100.00, 'token': 'abcdefghijklmnopqrstuvw', 'token_f4l4': '11119999', 'customer_code': 'CST1000', } user = django_user_model.objects.create_user(username='******', password='******') preauth = gateway.Preauthorize(api_details=API_DETAILS, save_token=True, django_user=user, **details) _, token = preauth.process() assert isinstance(token, MockDjangoModel)