Skip to content

Commit

Permalink
Merge pull request #136 from Adyen/develop
Browse files Browse the repository at this point in the history
Release 5.0.0
  • Loading branch information
AlexandrosMor authored Mar 23, 2021
2 parents 7eb7196 + 30572b9 commit 5532943
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @Aleffio @AlexandrosMor @martinsrenato @KadoBOT @rikterbeek
* @Aleffio @AlexandrosMor @martinsrenato @rikterbeek @acampos1916 @cyattilakiss
20 changes: 12 additions & 8 deletions Adyen/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __str__(self):


class AdyenClient(object):
IDEMPOTENCY_HEADER_NAME = 'Idempotency-Key'
"""A requesting client that interacts with Adyen. This class holds the
adyen logic of Adyen HTTP API communication. This is the object that can
maintain its own username, password, merchant_account, hmac and skin_code.
Expand Down Expand Up @@ -220,7 +221,7 @@ def call_api(
request_data,
service,
action,
idempotency=False,
idempotency_key=None,
**kwargs
):
"""This will call the adyen api. username, password, merchant_account,
Expand All @@ -229,6 +230,8 @@ def call_api(
is raised.
Args:
idempotency_key: https://docs.adyen.com/development-resources
/api-idempotency
request_data (dict): The dictionary of the request to place. This
should be in the structure of the Adyen API.
https://docs.adyen.com/manuals/api-manual
Expand Down Expand Up @@ -338,8 +341,8 @@ def call_api(
# Adyen requires this header to be set and uses the combination of
# merchant account and merchant reference to determine uniqueness.
headers = {}
if idempotency:
headers['Pragma'] = 'process-retry'
if idempotency_key:
headers[self.IDEMPOTENCY_HEADER_NAME] = idempotency_key

url = self._determine_api_url(platform, service, action)

Expand Down Expand Up @@ -373,9 +376,6 @@ def call_hpp(self, message, action, hmac_key="", **kwargs):
https://docs.adyen.com/manuals/api-manual
service (str): This is the API service to be called.
action (str): The specific action of the API service to be called
idempotency (bool, optional): Whether the transaction should be
processed idempotently.
https://docs.adyen.com/manuals/api-manual#apiidempotency
Returns:
AdyenResult: The AdyenResult is returned when a request was
succesful.
Expand Down Expand Up @@ -433,13 +433,16 @@ class instance.
status_code, headers, message)
return adyen_result

def call_checkout_api(self, request_data, action, **kwargs):
def call_checkout_api(self, request_data, action, idempotency_key=None,
**kwargs):
"""This will call the checkout adyen api. xapi key merchant_account,
and platform are pulled from root module level and or self object.
AdyenResult will be returned on 200 response. Otherwise, an exception
is raised.
Args:
idempotency_key: https://docs.adyen.com/development-resources
/api-idempotency
request_data (dict): The dictionary of the request to place. This
should be in the structure of the Adyen API.
https://docs.adyen.com/developers/checkout/api-integration
Expand Down Expand Up @@ -510,7 +513,8 @@ def call_checkout_api(self, request_data, action, **kwargs):
# Adyen requires this header to be set and uses the combination of
# merchant account and merchant reference to determine uniqueness.
headers = {}

if idempotency_key:
headers[self.IDEMPOTENCY_HEADER_NAME] = idempotency_key
url = self._determine_checkout_url(platform, action)

raw_response, raw_request, status_code, headers = \
Expand Down
34 changes: 18 additions & 16 deletions Adyen/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def __init__(self, client=None):
super(AdyenPayment, self).__init__(client=client)
self.service = "Payment"

def authorise(self, request, **kwargs):
def authorise(self, request, idempotency_key=None, **kwargs):

action = "authorise"

Expand All @@ -162,21 +162,21 @@ def authorise(self, request, **kwargs):
' name when authorising recurring contracts.')

return self.client.call_api(request, self.service,
action, **kwargs)
action, idempotency_key, **kwargs)

def authorise3d(self, request, **kwargs):
def authorise3d(self, request, idempotency_key=None, **kwargs):
action = "authorise3d"

return self.client.call_api(request, self.service,
action, **kwargs)
action, idempotency_key, **kwargs)

def cancel(self, request, **kwargs):
def cancel(self, request, idempotency_key=None, **kwargs):
action = "cancel"

return self.client.call_api(request, self.service,
action, **kwargs)
action, idempotency_key, **kwargs)

def capture(self, request, **kwargs):
def capture(self, request, idempotency_key=None, **kwargs):

action = "capture"

Expand All @@ -192,10 +192,10 @@ def capture(self, request, **kwargs):
"reference of the transaction to be modified")

response = self.client.call_api(request, self.service,
action, **kwargs)
action, idempotency_key, **kwargs)
return response

def refund(self, request, **kwargs):
def refund(self, request, idempotency_key=None, **kwargs):

action = "refund"

Expand All @@ -207,13 +207,13 @@ def refund(self, request, **kwargs):
"to partially refund this payment.")
else:
return self.client.call_api(request, self.service,
action, **kwargs)
action, idempotency_key, **kwargs)

def cancel_or_refund(self, request, **kwargs):
def cancel_or_refund(self, request, idempotency_key=None, **kwargs):
action = "cancelOrRefund"

return self.client.call_api(
request, self.service, action, **kwargs
request, self.service, action, idempotency_key, **kwargs
)


Expand Down Expand Up @@ -296,13 +296,15 @@ def payment_methods(self, request, **kwargs):

return self.client.call_checkout_api(request, action, **kwargs)

def payments(self, request, **kwargs):
def payments(self, request, idempotency_key=None, **kwargs):
action = "payments"
return self.client.call_checkout_api(request, action, **kwargs)
return self.client.call_checkout_api(request, action, idempotency_key,
**kwargs)

def payments_details(self, request=None, **kwargs):
def payments_details(self, request=None, idempotency_key=None, **kwargs):
action = "paymentsDetails"
return self.client.call_checkout_api(request, action, **kwargs)
return self.client.call_checkout_api(request, action, idempotency_key,
**kwargs)

def payment_session(self, request=None, **kwargs):
action = "paymentSession"
Expand Down
4 changes: 2 additions & 2 deletions Adyen/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
ENDPOINT_CHECKOUT_LIVE_SUFFIX = "https://{}-checkout-live" \
".adyenpayments.com/checkout"
API_BIN_LOOKUP_VERSION = "v50"
API_CHECKOUT_VERSION = "v64"
API_CHECKOUT_VERSION = "v67"
API_CHECKOUT_UTILITY_VERSION = "v1"
API_RECURRING_VERSION = "v49"
API_PAYMENT_VERSION = "v64"
API_PAYOUT_VERSION = "v64"
LIB_VERSION = "4.0.0"
LIB_VERSION = "5.0.0"
LIB_NAME = "adyen-python-api-library"
2 changes: 1 addition & 1 deletion Adyen/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def generate_notification_sig(dict_object, hmac_key):
def escape_val(val):
if isinstance(val, int):
return val
return val.replace('\\', '\\\\').replace(':', '\\:')
return val.replace('\\', '\\\\')

hmac_key = binascii.a2b_hex(hmac_key)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name='Adyen',
packages=['Adyen'],
version='4.0.0',
version='5.0.0',
maintainer='Adyen',
maintainer_email='[email protected]',
description='Adyen Python Api',
Expand Down
6 changes: 3 additions & 3 deletions test/CheckoutTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ def test_payments_error_mocked(self):
result = self.adyen.checkout.payments(request)

self.adyen.client.http_client.request.assert_called_once_with(
'https://checkout-test.adyen.com/v64/payments',
'https://checkout-test.adyen.com/v67/payments',
headers={},
json={
'returnUrl': 'https://your-company.com/...',
u'applicationInfo': {
u'adyenLibrary': {
u'version': '4.0.0',
u'version': '5.0.0',
u'name': 'adyen-python-api-library'
}
},
Expand Down Expand Up @@ -134,7 +134,7 @@ def test_payments_details_success_mocked(self):
result = self.adyen.checkout.payments_details(request)

self.adyen.client.http_client.request.assert_called_once_with(
u'https://checkout-test.adyen.com/v64/payments/details',
u'https://checkout-test.adyen.com/v67/payments/details',
headers={},
json={
'paymentData': 'Hee57361f99....',
Expand Down
4 changes: 2 additions & 2 deletions test/DetermineEndpointTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def test_checkout_api_url_custom(self):
url = self.adyen.client._determine_checkout_url("live", "payments")
self.client.live_endpoint_prefix = "1797a841fbb37ca7-AdyenDemo"
self.assertEqual(url, "https://1797a841fbb37ca7-AdyenDemo-checkout-"
"live.adyenpayments.com/checkout/v64/payments")
"live.adyenpayments.com/checkout/v67/payments")

def test_checkout_api_url(self):
self.client.live_endpoint_prefix = None
url = self.adyen.client._determine_checkout_url("test",
"paymentsDetails")
self.assertEqual(url, "https://checkout-test.adyen.com"
"/v64/payments/details")
"/v67/payments/details")

def test_payments_invalid_platform(self):

Expand Down

0 comments on commit 5532943

Please sign in to comment.