Skip to content

Commit

Permalink
Split get_form_fields in 2 parts
Browse files Browse the repository at this point in the history
The first part is handled by `get_field_specs`: this method is
responsible for returning a dict which contains the expected keys.

The second part is handled by the Facade, with its method
`build_payment_form_fields` which take the request and the reslt from
`get_field_specs`.

The `get_field_specs` is also split into multiple methods:

* `get_field_merchant_return_data` handles the content of the field
  `merchantReturnData` (by default it's the order's `amount`)
* `get_field_return_url` handles the content of the field `resURL`.

These changes are backward compatible.
  • Loading branch information
Exirel committed Feb 18, 2016
1 parent 6433549 commit 5328eea
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions adyen/scaffold.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def get_form_fields(self, 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.
"""
field_specs = self.get_field_specs(request, order_data)
return Facade().build_payment_form_fields(request, field_specs)

def get_field_specs(self, request, order_data):
now = timezone.now()
session_validity = now + timezone.timedelta(minutes=20)
session_validity_format = '%Y-%m-%dT%H:%M:%SZ'
Expand All @@ -64,21 +68,34 @@ def get_form_fields(self, request, order_data):
Constants.PAYMENT_AMOUNT: order_data['amount'],
Constants.SHOPPER_LOCALE: order_data['shopper_locale'],
Constants.COUNTRY_CODE: order_data['country_code'],
# Adyen does not provide the payment amount in the return URL, so we store it in
# this field to avoid a database query to get it back then.
Constants.MERCHANT_RETURN_DATA: order_data['amount'],
}

except KeyError:
raise MissingFieldException("One or more fields are missing from the order data.")
raise MissingFieldException(
"One or more fields are missing from the order data.")

# Check for overridden return URL.
return_url = order_data.get('return_url', None)
custom_data = self.get_field_merchant_return_data(request, order_data)
if custom_data is not None:
field_specs[Constants.MERCHANT_RETURN_DATA] = custom_data

return_url = self.get_field_return_url(request, order_data)
if return_url is not None:
return_url = return_url.replace('PAYMENT_PROVIDER_CODE', Constants.ADYEN)
field_specs[Constants.MERCHANT_RETURN_URL] = return_url

return Facade().build_payment_form_fields(request, field_specs)
return field_specs

def get_field_merchant_return_data(self, request, order_data):
# Adyen does not provide the payment amount in the return URL, so we
# store it in this field to avoid a database query to get it back then.
return order_data['amount']

def get_field_return_url(self, request, order_data):
# Check for overridden return URL.
return_url = order_data.get('return_url', None)

if not return_url:
return None

return return_url.replace('PAYMENT_PROVIDER_CODE', Constants.ADYEN)

def _normalize_feedback(self, feedback):
"""
Expand Down

0 comments on commit 5328eea

Please sign in to comment.