payments package

Submodules

payments.admin module

Registers admin interfaces for the payments module

class payments.admin.BankAccountAdmin(model, admin_site)[source]

Bases: django.contrib.admin.options.ModelAdmin

Manage bank accounts

actions = ['set_last_used']
autocomplete_fields = ('owner',)
export_csv(request: django.http.request.HttpRequest, queryset: django.db.models.query.QuerySet) → django.http.response.HttpResponse[source]
fields = ('created_at', 'last_used', 'owner', 'iban', 'bic', 'initials', 'last_name', 'mandate_no', 'valid_from', 'valid_until', 'signature')
form

alias of payments.forms.BankAccountAdminForm

list_display = ('iban', 'owner_link', 'last_used', 'valid_from', 'valid_until')
list_filter = (<class 'payments.admin.ValidAccountFilter'>, 'owner__profile__auto_renew')
property media
readonly_fields = ('created_at',)
search_fields = ('owner__username', 'owner__first_name', 'owner__last_name', 'iban')
set_last_used(request: django.http.request.HttpRequest, queryset: django.db.models.query.QuerySet)None[source]

Set the last used date of selected accounts

class payments.admin.PaymentAdmin(model, admin_site)[source]

Bases: django.contrib.admin.options.ModelAdmin

Manage the payments

actions = ['process_cash_selected', 'process_card_selected', 'process_tpay_selected', 'process_wire_selected', 'export_csv']
autocomplete_fields = ('paid_by', 'processed_by')
changeform_view(request: django.http.request.HttpRequest, object_id: int = None, form_url: str = '', extra_context: dict = None) → django.http.response.HttpResponse[source]

Renders the change formview Only allow when the payment has not been processed yet

date_hierarchy = 'created_at'
export_csv(request: django.http.request.HttpRequest, queryset: django.db.models.query.QuerySet) → django.http.response.HttpResponse[source]

Export a CSV of payments :param request: Request :param queryset: Items to be exported

fields = ('created_at', 'amount', 'type', 'processing_date', 'paid_by', 'processed_by', 'topic', 'notes')
get_actions(request: django.http.request.HttpRequest)collections.OrderedDict[source]

Get the actions for the payments

get_readonly_fields(request: django.http.request.HttpRequest, obj: payments.models.Payment = None)[source]

Hook for specifying custom readonly fields.

get_urls()list[source]
list_display = ('created_at', 'amount', 'processing_date', 'type', 'paid_by_link', 'processed_by_link', 'topic')
list_filter = ('type',)
property media
ordering = ('-created_at', 'processing_date')
process_card_selected(request: django.http.request.HttpRequest, queryset: django.db.models.query.QuerySet)None[source]

Process the selected payment as card

process_cash_selected(request: django.http.request.HttpRequest, queryset: django.db.models.query.QuerySet)None[source]

Process the selected payment as cash

process_tpay_selected(request: django.http.request.HttpRequest, queryset: django.db.models.query.QuerySet)None[source]

Process the selected payment as Thalia Pay

process_wire_selected(request: django.http.request.HttpRequest, queryset: django.db.models.query.QuerySet)None[source]

Process the selected payment as wire

readonly_fields = ('created_at', 'amount', 'type', 'processing_date', 'paid_by', 'processed_by', 'topic', 'notes')
search_fields = ('topic', 'notes', 'paid_by__username', 'paid_by__first_name', 'paid_by__last_name', 'processed_by__username', 'processed_by__first_name', 'processed_by__last_name', 'amount')
class payments.admin.ValidAccountFilter(request, params, model, model_admin)[source]

Bases: django.contrib.admin.filters.SimpleListFilter

Filter the memberships by whether they are active or not

lookups(request, model_name)tuple[source]

Must be overridden to return a list of tuples (value, verbose value)

parameter_name = 'active'
queryset(request, queryset)django.db.models.query.QuerySet[source]

Return the filtered queryset.

title = 'mandates'

payments.admin_views module

Admin views provided by the payments package

class payments.admin_views.PaymentAdminView(**kwargs)[source]

Bases: django.views.generic.base.View

View that processes a payment

dispatch(request, *args, **kwargs)
post(request, *args, **kwargs)[source]

payments.apps module

Configuration for the payments package

class payments.apps.PaymentsConfig(app_name, app_module)[source]

Bases: django.apps.config.AppConfig

AppConfig for the payments package

name = 'payments'
verbose_name = 'Payments'

payments.exceptions module

exception payments.exceptions.PaymentError[source]

Bases: Exception

Custom error for problems during payment

payments.forms module

class payments.forms.BankAccountAdminForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]

Bases: django.forms.models.ModelForm

Custom admin form for BankAccount model to add the widget for the signature

class Meta[source]

Bases: object

fields = '__all__'
model

alias of payments.models.BankAccount

widgets = {'signature': <payments.widgets.SignatureWidget object>}
base_fields = {'bic': <localflavor.generic.forms.BICFormField object>, 'created_at': <django.forms.fields.DateTimeField object>, 'iban': <localflavor.generic.forms.IBANFormField object>, 'initials': <django.forms.fields.CharField object>, 'last_name': <django.forms.fields.CharField object>, 'last_used': <django.forms.fields.DateField object>, 'mandate_no': <django.forms.fields.CharField object>, 'owner': <django.forms.models.ModelChoiceField object>, 'signature': <django.forms.fields.CharField object>, 'valid_from': <django.forms.fields.DateField object>, 'valid_until': <django.forms.fields.DateField object>}
declared_fields = {}
property media

Return all media required to render the widgets on this form.

class payments.forms.BankAccountForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]

Bases: django.forms.models.ModelForm

Custom admin form for BankAccount model to add the widget for the signature

class Meta[source]

Bases: object

fields = ('initials', 'last_name', 'iban', 'bic', 'signature', 'valid_from', 'mandate_no', 'owner')
model

alias of payments.models.BankAccount

base_fields = {'bic': <localflavor.generic.forms.BICFormField object>, 'direct_debit': <django.forms.fields.BooleanField object>, 'iban': <localflavor.generic.forms.IBANFormField object>, 'initials': <django.forms.fields.CharField object>, 'last_name': <django.forms.fields.CharField object>, 'mandate_no': <django.forms.fields.CharField object>, 'owner': <django.forms.models.ModelChoiceField object>, 'signature': <django.forms.fields.CharField object>, 'valid_from': <django.forms.fields.DateField object>}
declared_fields = {'direct_debit': <django.forms.fields.BooleanField object>}
property media

Return all media required to render the widgets on this form.

payments.models module

The models defined by the payments package

class payments.models.BankAccount(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Describes a bank account

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

bic

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

clean()[source]

Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
iban

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

initials

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

last_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

last_used

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

mandate_no

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property name
objects = <django.db.models.manager.Manager object>
owner

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

owner_id
signature

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property valid
valid_from

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

valid_until

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class payments.models.Payable[source]

Bases: object

payment = None
property payment_amount
property payment_notes
property payment_payer
property payment_topic
save()[source]
class payments.models.Payment(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Describes a payment

CARD = 'card_payment'
CASH = 'cash_payment'
exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

NONE = 'no_payment'
PAYMENT_TYPE = (('no_payment', 'No payment'), ('cash_payment', 'Cash payment'), ('card_payment', 'Card payment'), ('tpay_payment', 'Thalia Pay payment'), ('wire_payment', 'Wire payment'))
TPAY = 'tpay_payment'
WIRE = 'wire_payment'
amount

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

events_registration

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

get_admin_url()[source]
get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_type_display(*, field=<django.db.models.fields.CharField: type>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

notes

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
paid_by

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

paid_by_id
pizzas_order

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

property processed
processed_by

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

processed_by_id
processing_date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

registrations_entry

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

save(force_insert=False, force_update=False, using=None, update_fields=None)[source]

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

topic

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

payments.services module

The services defined by the payments package

payments.services.create_payment(payable: payments.models.Payable, processed_by: members.models.member.Member, pay_type: Union[cash_payment, card_payment, wire_payment, tpay_payment])payments.models.Payment[source]

Create a new payment from a payable object

Parameters
  • payable – Payable object

  • processed_by – Member that processed this payment

  • pay_type – Payment type

Returns

Payment object

payments.services.delete_payment(payable: payments.models.Payable)[source]

Removes a payment from a payable object :param payable: Payable object :return:

payments.services.process_payment(queryset: django.db.models.query.QuerySet, processed_by: members.models.member.Member, pay_type: str = 'card_payment')list[source]

Process the payment

Parameters
  • queryset (QuerySet[Payment]) – Queryset of payments that should be processed

  • processed_by (Member) – Member that processed this payment

  • pay_type (String) – Type of the payment

payments.services.revoke_old_mandates()int[source]

Revokes all mandates that have not been used for 36 months or more :return: number of affected rows

payments.services.update_last_used(queryset: django.db.models.query.QuerySet, date: datetime.date = None)int[source]

Update the last used field of a BankAccount queryset

Parameters
  • queryset – Queryset of BankAccounts

  • date – date to set last_used to

Returns

number of affected rows

payments.urls module

payments.views module

class payments.views.BankAccountCreateView(**kwargs)[source]

Bases: django.contrib.messages.views.SuccessMessageMixin, django.views.generic.edit.CreateView

dispatch(request, *args, **kwargs)
form_class

alias of payments.forms.BankAccountForm

form_valid(form: payments.forms.BankAccountForm) → django.http.response.HttpResponse[source]

If the form is valid, save the associated model.

get_context_data(**kwargs)dict[source]

Insert the form into the context dict.

model

alias of payments.models.BankAccount

post(request, *args, **kwargs) → django.http.response.HttpResponse[source]

Handle POST requests: instantiate a form instance with the passed POST variables and then check if it’s valid.

success_message = 'Bank account saved successfully.'
success_url = '/user/finance/accounts/'
class payments.views.BankAccountListView(**kwargs)[source]

Bases: django.views.generic.list.ListView

dispatch(request, *args, **kwargs)
get_queryset()django.db.models.query.QuerySet[source]

Return the list of items for this view.

The return value must be an iterable and may be an instance of QuerySet in which case QuerySet specific behavior will be enabled.

model

alias of payments.models.BankAccount

class payments.views.BankAccountRevokeView(**kwargs)[source]

Bases: django.contrib.messages.views.SuccessMessageMixin, django.views.generic.edit.UpdateView

dispatch(request, *args, **kwargs)
fields = ('valid_until',)
get(*args, **kwargs) → django.http.response.HttpResponse[source]

Handle GET requests: instantiate a blank version of the form.

get_queryset()django.db.models.query.QuerySet[source]

Return the QuerySet that will be used to look up the object.

This method is called by the default implementation of get_object() and may not be called if get_object() is overridden.

model

alias of payments.models.BankAccount

post(request, *args, **kwargs) → django.http.response.HttpResponse[source]

Handle POST requests: instantiate a form instance with the passed POST variables and then check if it’s valid.

success_message = 'Direct debit authorisation successfully revoked.'
success_url = '/user/finance/accounts/'
class payments.views.PaymentListView(**kwargs)[source]

Bases: django.views.generic.list.ListView

dispatch(request, *args, **kwargs)
get_context_data(*args, **kwargs)[source]

Get the context for this view.

get_queryset()django.db.models.query.QuerySet[source]

Return the list of items for this view.

The return value must be an iterable and may be an instance of QuerySet in which case QuerySet specific behavior will be enabled.

model

alias of payments.models.Payment

payments.widgets module

Widgets provided by the payments package

class payments.widgets.PaymentWidget(attrs=None)[source]

Bases: django.forms.widgets.Widget

Custom widget for the Payment object, used in registrations

class Media[source]

Bases: object

js = ('admin/payments/js/payments.js',)
get_context(name, value, attrs)dict[source]
property media
template_name = 'payments/widgets/payment.html'
class payments.widgets.SignatureWidget(attrs=None)[source]

Bases: django.forms.widgets.Widget

Widget for signature image

class Media[source]

Bases: object

css = {'all': ('admin/payments/css/signature.css',)}
js = ('payments/js/signature_pad.min.js', 'payments/js/main.js')
property media
template_name = 'payments/widgets/signature.html'