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
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