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
4 changes: 2 additions & 2 deletions Adyen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .client import AdyenClient
from .services import (
AdyenBase,
AdyenBinLookup,
AdyenBinlookupApi,
AdyenRecurringApi,
AdyenPayment,
AdyenPayoutsApi,
Expand All @@ -32,7 +32,7 @@ class Adyen(AdyenBase):
def __init__(self, **kwargs):
self.client = AdyenClient(**kwargs)
self.payment = AdyenPayment(client=self.client)
self.binlookup = AdyenBinLookup(client=self.client)
self.binlookup = AdyenBinlookupApi(client=self.client)
self.payout = AdyenPayoutsApi(client=self.client)
self.recurring = AdyenRecurringApi(client=self.client)

Expand Down
2 changes: 1 addition & 1 deletion Adyen/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _determine_base_url_and_version(self, platform, service):
'test': settings.PAL_TEST_URL + '/Payout'
}
},
'BinLookup': {
'binlookup': {
'version': self.api_bin_lookup_version,
'base_url': {
'live': live_pal_url + '/BinLookup',
Expand Down
2 changes: 1 addition & 1 deletion Adyen/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .base import AdyenBase
from .binLookup import AdyenBinLookup
from .binLookup import AdyenBinlookupApi
from .checkout import AdyenCheckoutApi
from .payments import AdyenPayment
from .payouts import AdyenPayoutsApi
Expand Down
46 changes: 32 additions & 14 deletions Adyen/services/binLookup.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
from .base import AdyenServiceBase
"""
Adyen BinLookup API

The BIN Lookup API provides endpoints for retrieving information, such as cost estimates, and 3D Secure supported version based on a given BIN. ## Authentication You need an [API credential](https://docs.adyen.com/development-resources/api-credentials) to authenticate to the API. If using an API key, add an `X-API-Key` header with the API key as the value, for example: ``` curl -H \"Content-Type: application/json\" \\ -H \"X-API-Key: YOUR_API_KEY\" \\ ... ``` Alternatively, you can use the username and password to connect to the API using basic authentication, for example: ``` curl -U \"ws@Company.YOUR_COMPANY_ACCOUNT\":\"YOUR_BASIC_AUTHENTICATION_PASSWORD\" \\ -H \"Content-Type: application/json\" \\ ... ``` ## Versioning The BinLookup API supports [versioning](https://docs.adyen.com/development-resources/versioning) using a version suffix in the endpoint URL. This suffix has the following format: \"vXX\", where XX is the version number. For example: ``` https://pal-test.adyen.com/pal/servlet/BinLookup/v52/get3dsAvailability ```## Going live To authneticate to the live endpoints, you need an [API credential](https://docs.adyen.com/development-resources/api-credentials) from your live Customer Area. The live endpoint URLs contain a prefix which is unique to your company account: ``` https://{PREFIX}-pal-live.adyenpayments.com/pal/servlet/BinLookup/v52/get3dsAvailability ``` Get your `{PREFIX}` from your live Customer Area under **Developers** > **API URLs** > **Prefix**. # noqa: E501

The version of the OpenAPI document: 52
Contact: developer-experience@adyen.com
Generated by: https://openapi-generator.tech
"""

from .base import AdyenServiceBase

class AdyenBinLookup(AdyenServiceBase):
"""This represents the Adyen API Bin Lookup service.

API call currently implemented: getCostEstimate.
Please refer to the Bin Lookup Manual for specifics around the API.
https://docs.adyen.com/api-explorer/#/BinLookup/
class AdyenBinlookupApi(AdyenServiceBase):
"""NOTE: This class is auto generated by OpenAPI Generator
Ref: https://openapi-generator.tech

Args:
client (AdyenAPIClient, optional): An API client for the service to
use. If not provided, a new API client will be created.
Do not edit the class manually.
"""

def __init__(self, client=None):
super(AdyenBinLookup, self).__init__(client=client)
self.service = "BinLookup"
super(AdyenBinlookupApi, self).__init__(client=client)
self.service = "binlookup"

def get_cost_estimate(self, request="", **kwargs):
def get_3ds_availability(self, request, idempotency_key=None, **kwargs):
"""
Check if 3D Secure is available
"""
endpoint = f"/get3dsAvailability"
endpoint = endpoint.replace('/', '', 1)
method = "POST"
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)

action = "getCostEstimate"
def get_cost_estimate(self, request, idempotency_key=None, **kwargs):
"""
Get a fees cost estimate
"""
endpoint = f"/getCostEstimate"
endpoint = endpoint.replace('/', '', 1)
method = "POST"
return self.client.call_adyen_api(request, self.service, method, action, **kwargs)
return self.client.call_adyen_api(request, self.service, method, endpoint, idempotency_key, **kwargs)

21 changes: 10 additions & 11 deletions test/mocks/BinLookupTest.py → test/BinLookupTest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from unittest.mock import ANY
import unittest

from BaseTest import BaseTest
import Adyen
from Adyen import settings

try:
from BaseTest import BaseTest
except ImportError:
from .BaseTest import BaseTest

REQUEST_KWARGS = {
'merchantAccount': 'YourMerchantAccount',
Expand All @@ -19,6 +21,7 @@ class TestBinLookup(unittest.TestCase):
client.username = "YourWSUser"
client.password = "YourWSPassword"
client.platform = "test"
binLookup_version = settings.API_BIN_LOOKUP_VERSION

def test_get_cost_estimate_success(self):
self.ady.client.http_client.request.reset_mock()
Expand Down Expand Up @@ -49,18 +52,14 @@ def test_get_cost_estimate_success(self):
result = self.ady.binlookup.get_cost_estimate(REQUEST_KWARGS)
self.assertEqual(expected, result.message)
self.ady.client.http_client.request.assert_called_once_with(
'POST',
'https://pal-test.adyen.com/pal/servlet/'
'BinLookup/v50/getCostEstimate',
f'BinLookup/{self.binLookup_version}/getCostEstimate',
headers={},
json={
'merchantAccount': 'YourMerchantAccount',
'amount': '1000', 'applicationInfo': {
'adyenLibrary': {
'name': 'adyen-python-api-library',
'version': ANY
}
}
},
'amount': '1000',
},
password='YourWSPassword',
username='YourWSUser'
)
Expand Down
2 changes: 1 addition & 1 deletion test/DetermineEndpointTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_pal_url_no_live_endpoint_prefix_test_platform(self):
def test_binlookup_url_no_live_endpoint_prefix_test_platform(self):
self.client.live_endpoint_prefix = None
url = self.adyen.client._determine_api_url(
"test", "BinLookup", "get3dsAvailability"
"test", "binlookup", "get3dsAvailability"
)
self.assertEqual(
url,
Expand Down