Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ The Factors service is called with the ``factors()`` method:

.. code-block:: pycon

>>> client.factors({'device': {'ip_address': '81.2.69.160'}})
>>> await async_client.factors({'device': {'ip_address': '81.2.69.160'}})
>>> client.factors({'device': {'ip_address': '152.216.7.110'}})
>>> await async_client.factors({'device': {'ip_address': '152.216.7.110'}})

The Insights service is called with the ``insights()`` method:

.. code-block:: pycon

>>> client.insights({'device': {'ip_address': '81.2.69.160'}})
>>> await async_client.insights({'device': {'ip_address': '81.2.69.160'}})
>>> client.insights({'device': {'ip_address': '152.216.7.110'}})
>>> await async_client.insights({'device': {'ip_address': '152.216.7.110'}})

The Score web service is called with the ``score()`` method:

.. code-block:: pycon

>>> client.score({'device': {'ip_address': '81.2.69.160'}})
>>> await async_client.score({'device': {'ip_address': '81.2.69.160'}})
>>> client.score({'device': {'ip_address': '152.216.7.110'}})
>>> await async_client.score({'device': {'ip_address': '152.216.7.110'}})

Each of these methods takes a dictionary representing the transaction to be sent
to the web service. The structure of this dictionary should be in `the format
Expand All @@ -84,8 +84,8 @@ Report Transaction web service is called with the ``report()`` method:

.. code-block:: pycon

>>> client.report({'ip_address': '81.2.69.160', 'tag': 'chargeback'})
>>> await async_client.report({'ip_address': '81.2.69.160', 'tag': 'chargeback'})
>>> client.report({'ip_address': '152.216.7.110', 'tag': 'chargeback'})
>>> await async_client.report({'ip_address': '152.216.7.110', 'tag': 'chargeback'})

The method takes a dictionary representing the report to be sent to the web
service. The structure of this dictionary should be in `the format specified
Expand Down Expand Up @@ -141,7 +141,7 @@ Score, Insights and Factors Example
>>>
>>> request = {
>>> 'device': {
>>> 'ip_address': '81.2.69.160',
>>> 'ip_address': '152.216.7.110',
>>> 'accept_language': 'en-US,en;q=0.8',
>>> 'session_age': 3600,
>>> 'session_id': 'a333a4e127f880d8820e56a66f40717c',
Expand Down Expand Up @@ -172,7 +172,7 @@ Score, Insights and Factors Example
>>> 'country': 'US',
>>> 'postal': '06510',
>>> 'phone_country_code': '1',
>>> 'phone_number': '323-123-4321',
>>> 'phone_number': '123-456-7890',
>>> },
>>> 'shipping': {
>>> 'first_name': 'John',
Expand All @@ -185,17 +185,17 @@ Score, Insights and Factors Example
>>> 'country': 'US',
>>> 'postal': '06510',
>>> 'phone_country_code': '1',
>>> 'phone_number': '403-321-2323',
>>> 'phone_number': '123-456-0000',
>>> 'delivery_speed': 'same_day',
>>> },
>>> 'credit_card': {
>>> 'bank_phone_country_code': '1',
>>> 'avs_result': 'Y',
>>> 'bank_phone_number': '800-342-1232',
>>> 'bank_phone_number': '123-456-1234',
>>> 'last_4_digits': '7643',
>>> 'cvv_result': 'N',
>>> 'bank_name': 'Bank of No Hope',
>>> 'issuer_id_number': '323132'
>>> 'issuer_id_number': '411111'
>>> },
>>> 'payment': {
>>> 'decline_code': 'invalid number',
Expand Down Expand Up @@ -271,7 +271,7 @@ For synchronous reporting:
>>>
>>> with Client(42, 'licensekey') as client
>>> transaction_report = {
>>> 'ip_address': '81.2.69.160',
>>> 'ip_address': '152.216.7.110',
>>> 'tag': 'chargeback',
>>> 'minfraud_id': '2c69df73-01c0-45a5-b218-ed85f40b17aa',
>>> }
Expand All @@ -287,7 +287,7 @@ For asynchronous reporting:
>>> async def report():
>>> async with AsyncClient(42, 'licensekey') as client
>>> transaction_report = {
>>> 'ip_address': '81.2.69.160',
>>> 'ip_address': '152.216.7.110',
>>> 'tag': 'chargeback',
>>> 'minfraud_id': '2c69df73-01c0-45a5-b218-ed85f40b17aa',
>>> }
Expand Down
2 changes: 1 addition & 1 deletion minfraud/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class HTTPError(MinFraudError):
def __init__(
self, message: str, http_status: Optional[int] = None, uri: Optional[str] = None
) -> None:
super(HTTPError, self).__init__(message)
super().__init__(message)
self.http_status = http_status
self.uri = uri

Expand Down
8 changes: 4 additions & 4 deletions minfraud/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class GeoIP2Location(geoip2.records.Location):

def __init__(self, *args, **kwargs) -> None:
self.local_time = kwargs.get("local_time", None)
super(GeoIP2Location, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class GeoIP2Country(geoip2.records.Country):
Expand Down Expand Up @@ -113,7 +113,7 @@ class GeoIP2Country(geoip2.records.Country):

def __init__(self, *args, **kwargs) -> None:
self.is_high_risk = kwargs.get("is_high_risk", False)
super(GeoIP2Country, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class IPAddress(geoip2.models.Insights):
Expand Down Expand Up @@ -196,7 +196,7 @@ def __init__(self, ip_address: Dict[str, Any]) -> None:
locales = ip_address.get("_locales")
if "_locales" in ip_address:
del ip_address["_locales"]
super(IPAddress, self).__init__(ip_address, locales=locales)
super().__init__(ip_address, locales=locales)
self.country = GeoIP2Country(locales, **ip_address.get("country", {}))
self.location = GeoIP2Location(**ip_address.get("location", {}))
self.risk = ip_address.get("risk", None)
Expand All @@ -207,7 +207,7 @@ def __init__(self, ip_address: Dict[str, Any]) -> None:
def __setattr__(self, name: str, value: Any) -> None:
if hasattr(self, "_finalized") and self._finalized:
raise AttributeError("can't set attribute")
super(IPAddress, self).__setattr__(name, value)
super().__setattr__(name, value)


@_inflate_to_namedtuple
Expand Down
10 changes: 6 additions & 4 deletions minfraud/webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _prepare_report(self, request: Dict[str, Any], validate: bool):
try:
validate_report(cleaned_request)
except MultipleInvalid as ex:
raise InvalidRequestError("Invalid report data: {0}".format(ex))
raise InvalidRequestError("Invalid report data: {0}".format(ex)) from ex
return cleaned_request

def _prepare_transaction(self, request: Dict[str, Any], validate: bool):
Expand All @@ -80,7 +80,9 @@ def _prepare_transaction(self, request: Dict[str, Any], validate: bool):
try:
validate_transaction(cleaned_request)
except MultipleInvalid as ex:
raise InvalidRequestError("Invalid transaction data: {0}".format(ex))
raise InvalidRequestError(
"Invalid transaction data: {0}".format(ex)
) from ex
return cleaned_request

def _copy_and_clean(self, data: Any) -> Any:
Expand All @@ -102,14 +104,14 @@ def _handle_success(
"""Handle successful response."""
try:
decoded_body = json.loads(body)
except ValueError:
except ValueError as ex:
raise MinFraudError(
"Received a 200 response"
" but could not decode the response as "
"JSON: {0}".format(body),
200,
uri,
)
) from ex
if "ip_address" in body:
decoded_body["ip_address"]["_locales"] = self._locales
return model_class(decoded_body) # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion tests/data/factors-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
],
"traits": {
"domain": "in-addr.arpa",
"ip_address": "81.2.69.160",
"ip_address": "152.216.7.110",
"is_anonymous": true,
"is_anonymous_vpn": true,
"is_hosting_provider": true,
Expand Down
2 changes: 1 addition & 1 deletion tests/data/full-report-request.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ip_address": "81.2.69.160",
"ip_address": "152.216.7.110",
"tag": "chargeback",
"chargeback_code": "UA01 Fraud - Card Present Transaction",
"maxmind_id": "a1b2c3d4",
Expand Down
10 changes: 5 additions & 5 deletions tests/data/full-transaction-request.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"region": "CT",
"country": "US",
"postal": "06510",
"phone_number": "323-123-4321",
"phone_number": "123-456-7890",
"phone_country_code": "1"
},
"shipping": {
Expand All @@ -36,7 +36,7 @@
"region": "OK",
"country": "US",
"postal": "73003",
"phone_number": "403-321-2323",
"phone_number": "123-456-0000",
"phone_country_code": "1",
"delivery_speed": "same_day"
},
Expand All @@ -46,11 +46,11 @@
"decline_code": "invalid number"
},
"credit_card": {
"issuer_id_number": "323132",
"issuer_id_number": "411111",
"last_4_digits": "7643",
"bank_name": "Bank of No Hope",
"bank_phone_country_code": "1",
"bank_phone_number": "800-342-1232",
"bank_phone_number": "123-456-1234",
"avs_result": "Y",
"cvv_result": "N",
"token": "123456abc1234"
Expand Down Expand Up @@ -80,7 +80,7 @@
}
],
"device": {
"ip_address": "81.2.69.160",
"ip_address": "152.216.7.110",
"user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36",
"accept_language": "en-US,en;q=0.8",
"session_id": "foobar",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/insights-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
],
"traits": {
"domain": "in-addr.arpa",
"ip_address": "81.2.69.160",
"ip_address": "152.216.7.110",
"is_anonymous": true,
"is_anonymous_vpn": true,
"is_hosting_provider": true,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_200(self):
def test_200_on_request_with_nones(self):
model = self.create_success(
request={
"device": {"ip_address": "81.2.69.160", "accept_language": None},
"device": {"ip_address": "152.216.7.110", "accept_language": None},
"event": {"shop_id": None},
"shopping_cart": [{"category": None, "quantity": 2,}, None],
}
Expand Down