adyen.facade module

class adyen.facade.Facade

Bases: object

Facade used to expose the public behavior of the Adyen gateway.

The Facade class exposes a set of public methods to be used by the plugin internally and by plugin users without having to deal with Adyen internal mecanism (such as how to sign a request form or how to read a payment response).

The first entry point is the payment form:

  • build_payment_form_fields() to handle payment data and generate the payment request form used to submit a payment request to Adyen HPP.

Then payment processing entry points of the Facade are:

These methods will build an appropriate Adyen Payment Response object and call the process_payment_feedback() method to handle the payment feedback.

assess_notification_relevance(request)

Return a (must_process, must_acknowledge) tuple to decide what should be done with this request.

build_notification_response(request)

Return the appropriate response to send to the Adyen servers to acknowledge a transaction notification.

Quoting the Adyen Integration Manual (page 26):

“The Adyen notification system requires a response within 30 seconds of receipt of the notification, the server is expecting a response of [accepted], including the brackets. When our systems receive this response all notifications contained in the message are marked as successfully sent.”

build_payment_form_fields(request, params)

Return a dict containing the name and value of all the hidden fields necessary to build the form that will be POSTed to Adyen.

build_payment_notification(request)

Build a Payment Notification response object from raw request.

Parameters:request – Django HTTP request object
Returns:A PaymentNotification object

This method get the gateway for the request and config and instantiate a PaymentNotification with this gateway and the request.POST parameters.

Plugin users may want to override this method to build any user-made object to handle their own specific cases.

build_payment_return(request)

Build a Payment Return response object from raw request.

Parameters:request – Django HTTP request object
Returns:A PaymentRedirection object

This method get the gateway for the request and config and instantiate a PaymentRedirection with this gateway and the request.GET parameters.

Plugin users may want to override this method to build any user-made object to handle their own specific cases.

handle_payment_feedback(request)

Handle payment feedback (payment return or payment notification).

Deprecated since version 0.6.0: This method is not used internally anymore by the plugin. If you rely on that please switch to handle_payment_return(), handle_payment_notification(), and process_payment_feedback().

handle_payment_notification(request)

Handle payment notification.

Parameters:request – Django HTTP request (POST)

This method should be called when Adyen send its Payment Notification (through a POST request). It instantiate the gateway and the appropriate response object and pass it to process_payment_feedback() to return a result.

handle_payment_return(request)

Handle payment return.

Parameters:request – Django HTTP request (GET)

This method should be called when customers come back from the Adyen HPP (through a GET request). It instantiate the gateway and the appropriate response object and pass it to process_payment_feedback() to return a result.

process_payment_feedback(request, response)

Process payment feedback response.

Parameters:
  • request – Django HTTP request object
  • response – Adyen payment response

Validate, process, optionally record audit trail and provide feedback about the current payment response.

unpack_details(details)

Unpack detailed information from response.process()

Parameters:details (dict) – Dict that contains data from an Adyen notification or when customer come back through the return URL.
Returns:A dict with transaction details.

See also

unpack_details_amount() can be overridden to extract the transaction amount. Note that this plugin decided to use a field for this purpose.

unpack_merchant_return_data() can be overridden to extract specific data from merchantReturnData. This method is called after any others and can be used to override the initial unpacked details.

unpack_details_amount(details)

Unpack amount from the Adyen response details.

Parameters:details (dict) – Dict that contains data from an Adyen notification or when customer come back through the return URL.
Returns:None if amount is not available or an integer.

The payment amount is transmitted by the notification in the value field. However, in the case of a payment return URL, we do not have this parameter.

We decided in Scaffold.get_field_merchant_return_data to provide the order’s amount into this field, but this is not standard. As developers may want to override this behavior, they can extend both part in order to modify only the behavior of the field merchantReturnData, and they can override this method to fetch amount in their own way.

unpack_merchant_return_data(details)

Unpack merchant return data fields from the details.

Parameters:details (dict) – Dict that contains data from an Adyen notification or when customer come back through the return URL.
Returns:A dict of extra details to unpack that handle custom fields.

The return dict is supposed to contain the merchant_return_data, which is by default the raw content of the field merchantReturnData.

Developers may want to override the meaning of this field and extract various other information.

Note

The result of this method will override any existing key extracted in unpack_details(). It is powerful yet it could be dangerous if not handled with care.

adyen.facade.get_gateway(request, config)

Instantiate a adyen.gateway.Gateway from config.

Parameters:
  • request – Django HTTP request object.
  • config (AbstractAdyenConfig) – Adyen Config object.
Returns:

An instance of Gateway configured properly.

The Gateway is built using the given config and request to get specific values for identifier, secret_key and action_url.

The configuration object requires the request in order to allow plugin user to define a per-request configuration, such as a different secret key based on the country or the language (or even the type of customer, its IP address, or other request specific parameter).