diff --git a/Adyen/client.py b/Adyen/client.py index c6171b6c..9a7ad500 100644 --- a/Adyen/client.py +++ b/Adyen/client.py @@ -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. @@ -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, @@ -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 @@ -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) @@ -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. @@ -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 @@ -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 = \ diff --git a/Adyen/services.py b/Adyen/services.py index 90099f74..81b40ee9 100644 --- a/Adyen/services.py +++ b/Adyen/services.py @@ -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" @@ -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" @@ -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" @@ -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 ) @@ -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"