Beispiel #1
0
def it_should_handle_registration_failure(requests_post):
    mock_response = MockResponse(
        status_code=200,
        url='https://test.epayment.nets.eu/Netaxept/Register.aspx',
        encoding='ISO-8859-1',
        reason='OK',
        text="""<?xml version="1.0" encoding="utf-8"?>
        <Exception xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <Error xsi:type="GenericError">
            <Message>Unable to translate supermerchant to submerchant, please check currency code and merchant ID</Message>
          </Error>
        </Exception>""")
    requests_post.return_value = mock_response
    with raises(NetaxeptProtocolError) as excinfo:
        register(_netaxept_config, amount=Money(10, 'CAD'), order_number='123')
        assert excinfo.value == NetaxeptProtocolError(
            error=
            'Unable to translate supermerchant to submerchant, please check currency code and merchant ID',
            raw_response=asdict(mock_response))
    requests_post.assert_called_once_with(
        url='https://test.epayment.nets.eu/Netaxept/Register.aspx',
        data={
            'merchantId': '123456',
            'token': 'supersekret',
            'description': None,
            'orderNumber': '123',
            'amount': 1000,
            'currencyCode': 'CAD',
            'autoAuth': True,
            'terminalSinglePage': True,
            'language': None,
            'redirectUrl': 'http://localhost'
        })
Beispiel #2
0
def it_should_register(requests_post):
    mock_response = MockResponse(
        status_code=200,
        url='https://test.epayment.nets.eu/Netaxept/Register.aspx',
        encoding='ISO-8859-1',
        reason='OK',
        text="""<?xml version="1.0" encoding="utf-8"?>
        <RegisterResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
           <TransactionId>7624b99699f344e3b6da9884d20f0b27</TransactionId>
         </RegisterResponse>""")
    requests_post.return_value = mock_response
    register_response = register(config=_netaxept_config,
                                 amount=Money(10, 'CHF'),
                                 order_number='123',
                                 customer_email='*****@*****.**')
    assert register_response == RegisterResponse(
        transaction_id='7624b99699f344e3b6da9884d20f0b27',
        raw_response=asdict(mock_response))
    requests_post.assert_called_once_with(
        url='https://test.epayment.nets.eu/Netaxept/Register.aspx',
        data={
            'merchantId': '123456',
            'token': 'supersekret',
            'description': None,
            'orderNumber': '123',
            'amount': 1000,
            'currencyCode': 'CHF',
            'autoAuth': True,
            'terminalSinglePage': True,
            'language': None,
            'customerEmail': '*****@*****.**',
            'redirectUrl': 'http://localhost'
        })
Beispiel #3
0
def register_payment(payment: Payment) -> str:
    """
    - Registers the payment with netaxept.
    - Stores the newly created netaxept transaction_id in the Payment.
    - Records a Transaction representing the registration.

    :param payment: A payment to register.
    :return: The newly created netaxept transaction_id
    :raises NetaxeptException: If the payment was already registered or the registration fails
    """
    logger.info('netaxept-actions-register', payment_id=payment.id)

    if payment.token != '':  # The payment was already registered.
        if payment.is_authorized:
            raise PaymentAlreadyRegisteredAndAuthorized()
        else:
            # If payment was registered but not yet authorized we re-register it so that a later authorize can succeeed.
            # Otherwise when the user gets to the netaxept terminal page he sees a 'payment already processed' error.
            logger.info('netaxept-regegister-payment', payment_id=payment.id)

    _payment_gateway, gateway_config = get_payment_gateway(payment.gateway)
    netaxept_config = gateway_to_netaxept_config(gateway_config)

    try:
        register_response = netaxept_protocol.register(
            config=netaxept_config,
            order_number=payment.id,
            amount=payment.total,
            language='en',
            customer_email=payment.customer_email)
    except NetaxeptProtocolError as exception:
        Transaction.objects.create(payment=payment,
                                   kind=TransactionKind.REGISTER,
                                   token='',
                                   is_success=False,
                                   amount=payment.total,
                                   error=exception.error,
                                   gateway_response=exception.raw_response)
        raise NetaxeptException(exception.error)

    with transaction.atomic():
        payment.token = register_response.transaction_id
        payment.save()

        Transaction.objects.create(
            payment=payment,
            kind=TransactionKind.REGISTER,
            token=register_response.transaction_id,
            is_success=True,
            amount=payment.total,
            error=None,
            gateway_response=register_response.raw_response)

    return register_response.transaction_id
Beispiel #4
0
def register_payment(payment: Payment) -> str:
    """
    This part of the process is unique to netaxept so it cannot be implemented inside the
    payment generic SPI. This implies that a programmer who wants to use the netaxept gateway will have to know
    to call this specific function.

    This function:

    - Registers the payment with netaxept
    - Stores the newly created netaxept transaction_id in the Payment (the transaction_id represents the payment on
       the netaxept side, and needs to be passed to netaxept for further operations like capturing, refunding, etc)
    - Create a Transaction object representing the registration for auditing purposes.

    :param payment: A payment to register
    :return: The the newly created netaxept transaction id
    :raises NetaxeptException: If the payment was already registered or the registration fails
    """
    logger.info('netaxept-actions-register', payment_id=payment.id)

    if payment.token != '':  # The payment was already registered.
        if payment.is_authorized:
            raise PaymentAlreadyRegisteredAndAuthorized()
        else:
            # If payment was registered but not yet authorized we re-register it so that a later authorize can succeeed:
            # Otherwise when the user gets to the netaxept terminal page he sees a 'payment already processed' error.
            logger.info('netaxept-regegister-payment', payment_id=payment.id)

    _payment_gateway, gateway_config = get_payment_gateway(payment.gateway)
    netaxept_config = gateway_to_netaxept_config(gateway_config)

    try:
        register_response = netaxept_protocol.register(
            config=netaxept_config,
            order_number=payment.id,
            amount=payment.total,
            language='en',
            customer_email=payment.customer_email)
    except NetaxeptProtocolError as exception:
        Transaction.objects.create(
            payment=payment,
            kind=TransactionKind.REGISTER,
            token='',
            is_success=False,
            amount=payment.total,
            error=exception.error,
            gateway_response=exception.raw_response)
        raise NetaxeptException(exception.error)

    with transaction.atomic():
        payment.token = register_response.transaction_id
        payment.save()

        Transaction.objects.create(
            payment=payment,
            kind=TransactionKind.REGISTER,
            token=register_response.transaction_id,
            is_success=True,
            amount=payment.total,
            error=None,
            gateway_response=register_response.raw_response)

    return register_response.transaction_id