예제 #1
0
    def process(self):
        """Attempts to process Purchase with transaction details.

            Returns the values of ``gateway.Purchase.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.
        """
        purchase_instance = gateway.Purchase(save_token=self.save_token,
                                             django_user=self.django_user,
                                             **self.transaction_details)

        try:
            return purchase_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('Purchase complete, but errors occured while saving '
                          'transaction to database')
        except helcim_exceptions.HelcimError as error:
            raise oscar_exceptions.GatewayError(str(error))
예제 #2
0
def test_process_error_response_purchase():
    purchase_request = gateway.Purchase()

    try:
        purchase_request.process_error_response('')
    except helcim_exceptions.PaymentError:
        assert True
    else:
        assert False
예제 #3
0
def test_purchase_processing():
    details = {
        'amount': 100.00,
        'customer_code': 'CST1000',
    }

    purchase = gateway.Purchase(api_details=API_DETAILS, **details)
    transaction, _ = purchase.process()

    assert isinstance(transaction, MockDjangoModel)
예제 #4
0
def test_process_with_save_token_disabled():
    details = {
        'amount': 100.00,
        'token': 'abcdefghijklmnopqrstuvw',
        'token_f4l4': '11119999',
        'customer_code': 'CST1000',
    }

    purchase = gateway.Purchase(
        api_details=API_DETAILS, save_token=True, **details
    )
    _, token = purchase.process()

    assert token is None
예제 #5
0
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='******'
    )

    purchase = gateway.Purchase(
        api_details=API_DETAILS, save_token=True, django_user=user, **details
    )
    _, token = purchase.process()

    assert isinstance(token, MockDjangoModel)