adyen.scaffold module

class adyen.scaffold.Scaffold

Bases: object

Entry point to handle Adyen HPP.

The Scaffold exposes an interface that can be used in any Django Oscar application. It aims to hide the inner complexity of payment form management and payment notification processing.

The key methods are:

ADYEN_TO_COMMON_PAYMENT_STATUSES = {'ERROR': 'ERROR', 'CANCELLED': 'CANCELLED', 'AUTHORISED': 'ACCEPTED', 'REFUSED': 'REFUSED', 'PENDING': 'PENDING'}

This is the mapping between Adyen-specific and these standard statuses

PAYMENT_STATUS_ACCEPTED = 'ACCEPTED'
PAYMENT_STATUS_CANCELLED = 'CANCELLED'
PAYMENT_STATUS_ERROR = 'ERROR'
PAYMENT_STATUS_PENDING = 'PENDING'
PAYMENT_STATUS_REFUSED = 'REFUSED'
assess_notification_relevance(request)

Assess if a notification request is relevant.

Parameters:request – Django HTTP request object.
Returns:A 2-value tuple as must_process and must_acknowledge

One should call this method when receiving a notification request and they want to know if the notification must:

  1. Be processed, ie. is a call to handle_payment() is relevant,
  2. Be acknowledged with a response to Adyen, using build_notification_response()

New in version 0.6.0: This method has been added to replace the generic handle_payment_feedback().

build_notification_response(request)

Build a notification response for an Adyen Payment Notification

Parameters:request – Django HTTP request object.
Returns:A Django HTTP Response object.

From the Adyen Integration Manual:

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

This method simply call the adyen.facade.Facade.build_notification_response() method and returns its result.

get_field_allowed_methods(request, order_data)

Get a string of comma separated allowed payment methods.

Parameters:
  • request – Django HTTP request object.
  • order_data (dict) – Order’s data.
Returns:

If defined by the configuration, a string composed of a list of comma separated payment methods (ex. card,bankTransfert). Otherwise None.

This methods is used to populate the allowedMethods field of the payment request form. See Adyen HPP manual for more information.

If a source_type is available into the provided order_data, then it is used as a parameter to adyen.config.AbstractAdyenConfig.get_allowed_methods().

New in version 0.6.0: Added to handle allowedMethods field. May require extra work on the configuration object to work properly.

get_field_merchant_return_data(request, order_data)
get_field_return_url(request, order_data)
get_field_specs(request, order_data)
get_fields_billing(request, order_data)

Extract and return billing related fields from order_data.

Parameters:
  • request – Django HTTP request object.
  • order_data (dict) – Order’s data.
Returns:

A dict of payment’s billing fields.

get_fields_delivery(request, order_data)

Extract and return delivery related fields from order_data.

Parameters:
  • request – Django HTTP request object.
  • order_data (dict) – Order’s data.
Returns:

A dict of payment’s delivery fields.

get_fields_shopper(request, order_data)

Extract and return shopper related fields from order_data.

Parameters:
  • request – Django HTTP request object.
  • order_data (dict) – Order’s data.
Returns:

The Adyen specific shopper’s fields.

get_form_action(request)

Return the URL where the payment form should be submitted.

get_form_fields(request, order_data)

Return the payment form fields as a list of dicts. Expects a large-ish order_data dictionary with details of the order.

handle_payment_feedback(request)

Handle payment feedback from return URL or POST notification.

Parameters:request – Django HTTP request object.
Returns:A normalized payment feedback.

If the request.method is POST, this method consider we handle an Adyen Payment Notification. Otherwise it considers it is a simple Payment Return case.

See also

handle_payment_notification() and handle_payment_return() to see how to handle both cases.

Deprecated since version 0.6.0: This method is deprecated in favor of more specific methods and should not be used in plugin user’s code anymore.

handle_payment_notification(request)

Handle payment notification.

Parameters:request – Django HTTP request object
Returns:A 3-values tuple with success, status and details.

One should call this method when handling the POST request that come as an Adyen Payment Notification.

New in version 0.6.0: This method has been added to replace the generic handle_payment_feedback().

handle_payment_return(request)

Handle payment return.

Parameters:request – Django HTTP request object
Returns:A 3-values tuple with success, status and details.

One should call this method when handling the GET request that come after a redirection from Adyen.

New in version 0.6.0: This method has been added to replace the generic handle_payment_feedback().

adyen.scaffold.sanitize_field(value)

Clean field used in the payment request form

Parameters:value (string) –
Returns:A sanitized value

Adyen suggest to remove all new-line, so we do.