Skip to content

Commit

Permalink
query
Browse files Browse the repository at this point in the history
  • Loading branch information
nwolff committed Oct 14, 2019
1 parent 1eb0315 commit 71f7212
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions payment/gateways/netaxept/netaxept_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
API details: https://shop.nets.eu/web/partners/appi
Test card numbers: https://shop.nets.eu/web/partners/test-cards
"""
from dataclasses import dataclass
from decimal import Decimal
from enum import Enum
from typing import Optional, Union, Dict, Any
from urllib.parse import urlencode, urljoin

import requests
import xmltodict
from dataclasses import dataclass
from moneyed import Money
from structlog import get_logger
from typing import Optional, Union, Dict

logger = get_logger()

Expand Down Expand Up @@ -94,10 +94,8 @@ def register(config: NetaxeptConfig, amount: Money, order_number: Union[str, int
'redirectUrl': config.after_terminal_url
}

response = requests.post(url=urljoin(config.base_url, 'Netaxept/Register.aspx'),
data=params)
response = requests.post(url=urljoin(config.base_url, 'Netaxept/Register.aspx'), data=params)
raw_response = _build_raw_response(response)

logger.info('netaxept-register', amount=amount, order_number=order_number, language=language,
description=description, raw_response=raw_response)

Expand Down Expand Up @@ -138,11 +136,8 @@ def process(config: NetaxeptConfig, transaction_id: str, operation: NetaxeptOper
'transactionAmount': _decimal_to_netaxept_amount(amount),
}

response = requests.post(url=urljoin(config.base_url, 'Netaxept/Process.aspx'),
data=params)

response = requests.post(url=urljoin(config.base_url, 'Netaxept/Process.aspx'), data=params)
raw_response = _build_raw_response(response)

logger.info('netaxept-process-response', transaction_id=transaction_id, operation=operation.value,
amount=amount, raw_response=raw_response)

Expand All @@ -162,6 +157,18 @@ def get_payment_terminal_url(config: NetaxeptConfig, transaction_id: str) -> str
return '{}?{}'.format(urljoin(config.base_url, 'Terminal/default.aspx'), qs)


def query(config: NetaxeptConfig, transaction_id: str) -> Any: # XXX: more precise type
logger.info('netaxept-query', transaction_id=transaction_id)

params = {
'merchantId': config.merchant_id,
'token': config.secret,
'transactionId': transaction_id,
}

response = requests.post(url=urljoin(config.base_url, 'Netaxept/Query.aspx'), data=params)


def _decimal_to_netaxept_amount(decimal_amount: Decimal) -> int:
""" Return the netaxept representation of the decimal representation of the amount. """
return int((decimal_amount * 100).to_integral_value())
Expand Down

0 comments on commit 71f7212

Please sign in to comment.