Django adyen payment integration
Project description
1 DjAdyen
- Version:
4.1.1
- Source:
- Keywords:
django, adyen, payment
- PythonVersion:
3.9
This module is used to connect your django application to the payment provider Adyen using the “Web Components” and “Web Drop-in”
This is only tested on a postgres database.
1.1 Supported Ayden Payments
Alipay - adyen name: alipay
Bancontact card - adyen name: bcmc, uses brands
(Debit/Credit) Card - adyen name: schema, uses brands
Finnish E-Banking - adyen name: ebanking_FI
iDEAL - adyen name: ideal
SEPA Bank Transfer - adyen name: bankTransfer_IBAN
SEPA Direct Debit - adyen name: sepadirectdebit
1.1.1 Issuers & Brands
Both issuers and brands are used for AdyenIssuer objects for different payment options. Some will use one adyen_id for one issuer while some others will use a list of adyen_ids for allowed brands.
1.2 Installation
Install with pip
pip install djadyen
Add ‘djadyen’ to the installed apps
# settings.py
INSTALLED_APPS = [
...
'djadyen',
...
]
Add the Adyen notifications urls (This is not required). These url will save all the notifications to the database. You need to make an implementation to handle the notifications
# urls.py
urlpatterns = [
...
url(r'^adyen/notifications/', include('djadyen.notifications.urls', namespace='adyen-notifications')),
...
]
# models.py
from djadyen.models import AdyenOrder
class CustomOrder(AdyenOrder):
def get_price_in_cents(self):
"""
:return int Return the price in cents for this order.
"""
raise NotImplementedError
def get_return_url(self):
raise NotImplementedError(
"Please override 'get_return_url' on the '{model_name}'".format(
model_name=self.\_meta.object_name
)
)
1.3 Usage
1.3.1 Management command
There is a management command that will sync the payment methods for you. This can be used if you want the users to select a payment method/issuer on your own site.
manage.py sync_payment_methods
There is a command that will call the function process_notification to handle notifications. This can be added to a crontab.
manage.py adyen_maintenance
1.3.2 Required settings
DJADYEN_SERVER_KEY This is the server key. This should be a secret string.
DJADYEN_CLIENT_KEY This is the client key. This key will be used in the components in the frontend.
DJADYEN_MERCHANT_ACCOUNT This is the merchant accont that is used in Adyen.
DJADYEN_ORDER_MODELS A list of models that are used to store Orders (Inherit from AdyenOrder). The models should be strings in the . form
DJADYEN_NOTIFICATION_KEY The key to verify the notifications are from adyen
1.3.3 Optional settings
DJADYEN_CURRENCYCODE (default=‘EUR’) This can be set to any other currency Adyen supports.
DJADYEN_ENVIRONMENT (default=‘test’) This can be ‘test’ or ‘live’.
DJADYEN_APPNAME (default=‘Djadyen Payment’) This is the name that will be send along with the payment.
DJADYEN_REFETCH_OLD_STATUS (default=False) This is so you will always have the latest saved status. This will cause an extra db query!
DJADYEN_HANDLE_NOTIFICATION_MINUTES_AGO (default=15) This defaults to 15 minutes. You can change the value to make this shorter or longer depending on the need.
1.3.3.1 DJADYEN_STYLES
(Optional) Customize the appearance of Adyen payment components.
This setting allows you to configure the styling of Adyen Web Components by providing style definitions that are passed to the payment component configuration. This enables you to customize colors, fonts, and other visual properties of the payment form fields.
Example:
# settings.py
DJADYEN_STYLES = {
'base': {
'color': '#000000',
'fontSize': '16px',
'fontFamily': 'Arial, sans-serif',
},
'placeholder': {
'color': '#999999',
},
'error': {
'color': '#ff0000',
},
'validated': {
'color': '#00ff00',
}
}
How it works:
The styles object is passed to the Adyen payment component configuration, allowing you to customize the appearance of input fields. The configuration supports several style categories:
base: Default styling for form input fields
placeholder: Styling for placeholder text
error: Styling for fields in an error state
validated: Styling for successfully validated fields
Available style properties:
Within each category, you can use properties like: - color: Text color - fontSize: Font size (e.g., ‘16px’, ‘1rem’) - fontFamily: Font family - fontWeight: Font weight - lineHeight: Line height - And other CSS-like properties supported by Adyen components
For a complete list of available styling options and examples, refer to the Adyen Card Component Styling Documentation.
Note: These styles apply specifically to Adyen’s secured fields (like card number, CVV, expiry date). For styling the container or other elements, use regular CSS in your stylesheets.
If DJADYEN_STYLES is not set, Adyen’s default styling will be used.
1.3.4 Order object
There is an abstract order in this package. This will save you some time on creating an order for adyen. There are some features on the order that will make it easier to integrate your order with this package.
The added fields are:
status This is the status of the object. This will be changed by adyen.
created_at This field is used for when the order is created.
reference This field is a communication field. It is not used outside the communication. This will be set by uuid4, but can be overwritten.
psp_reference This field is the reference from Adyen. With this field you are able to search in the Adyen inderface.
payment_option This is the Adyen payment option from this package.
issuer This is the Adyen issuer from this package.
You should implement the following methods
get_price_in_cents Return the price to be paid for this order
process_authorized_notification Process a ‘authorized’ notification which adyen has sent
process_notification Process the notification, if you are using the adyen-maintenance management command
1.3.5 AdyenPaymentView
This view is used to show the payment page.
This page can be customized in 2 ways.
overwrite the template (adyen/pay.html)
Overwrite the view and changing the template_name
from djadyen.views import AdyenPaymentView
class PaymentView(AdyenPaymentView):
template_name = "my_adyen/pay.html" # Optional
Adyen requires a language locale i.e. nl-NL or en-US instead of nl or en. If Django’s uses language codes, adyen_language should be converted in the view context similarly to this:
ADYEN_LANGUAGES = {
"nl": "nl-NL",
"en": "en-US",
}
class PaymentView(AdyenPaymentView):
...
def get_locale(self):
return ADYEN_LANGUAGES[self.request.LANGUAGE_CODE]
1.3.6 AdyenResponseView
Adyen also creates a response. This will help you with catching the response. This view will check if the response from Adyen is valid. It will also provide some useful functions so you don’t have to overwrite anything.
In this example the order is automatically fetched from the reference that is passed in the merchantReference. It will also set the order in the self object for easy access. In the done function the order is saved and the template will be rendered.
from djadyen.views import AdyenResponseView
from djadyen.choices import Status
class ConfirmationView(AdyenResponseView):
template_name = 'my_project/confirmation.html'
model = Order
def handle_authorised(self):
self.order.status = Status.Authorised
return self.done()
1.3.7 AdyenAdvancedPaymentView
Similar to the AdyenPaymentView but uses the advanced checkout from adyen-web. This allows for more payment methods and allows for the new Giving donation component. The advanced view can handle adyen responses and does not need the AdyenResponseView.
The view should implement the adyen_advanced_payment_component template tag in the template. The AdyenAdvancedPaymentView also needs to override get_locale to get the correct locale if it is not already.
from djadyen.views import AdyenAdvancedPaymentView
class AdvancedPaymentView(AdyenAdvancedPaymentView):
template_name = 'my_project/confirmation.html'
model = Order
2 Adyen notifications
Setup the standard notifications in Adyen. These will comunicate about the payments if they were succesful or not. This is very important because the notifications will be needed when a payment is redirected with a pending payment.
The notifications will be stored in the database. You need to write the handling of the notifications yourself or use the adyen_maintenance command.
2.1 License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file djadyen-4.1.1.tar.gz.
File metadata
- Download URL: djadyen-4.1.1.tar.gz
- Upload date:
- Size: 262.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53fd6d202c371836749e96375a56674b54fc088998de8724a53389bbd9892be8
|
|
| MD5 |
516d35c83e5ae4ea5836c325e738e6d7
|
|
| BLAKE2b-256 |
ac20c0fca62738f0f7b617627dc7f54467d3648b9825742416d09db5a16ed8ed
|
File details
Details for the file djadyen-4.1.1-py3-none-any.whl.
File metadata
- Download URL: djadyen-4.1.1-py3-none-any.whl
- Upload date:
- Size: 263.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b42ac1cf09d2f9ce3cd7722b04cda9039b6e2451be951c8a04ffd3068a3771f
|
|
| MD5 |
7fd056c1304a2442782088610ff12c0b
|
|
| BLAKE2b-256 |
bfa53c1ff68c78dc80e0e2b737e9d94cbbe29ab123675dbec1dc9d10ccfb11b7
|