Creating payment plugins

In order to create a plugin for a payment broker, first you need to write a subclass of BaseProcessor named PaymentProcessor and place it in processor.py in your app.

The only method you have to provide is prepare_transaction() that needs to return a HttpResponse subclass (eg. HttpResponseRedirect or TemplateResponse). The use of all other methods depends directly on how the paywall operates.

To make your plugin available for the rest of the framework, you need to register it. The most convenient way to do so is apps.py:

from django.apps import AppConfig

class MyPluginAppConfig(AppConfig):
    name = "getpaid_myplugin"
    verbose_name = "Some payment broker"

    def ready(self):
        from getpaid.registry import registry

        registry.register(self.module)

This way your plugin will be automatically registered after adding it to INSTALLED_APPS.

Detailed API

class getpaid.processor.BaseProcessor(payment: django.db.models.base.Model)
production_url = None

Base URL of production environment.

sandbox_url = None

Base URL of sandbox environment.

display_name = None

The name of the provider for the choices.

accepted_currencies = None

List of accepted currency codes (ISO 4217).

logo_url = None

Logo URL - can be used in templates.

ok_statuses = [200]

List of potentially successful HTTP status codes returned by paywall when creating payment

slug = None

For friendly urls

static get_our_baseurl(request: django.http.request.HttpRequest = None, **kwargs) → str

Little helper function to get base url for our site. Note that this way ‘https’ is enforced on production environment.

prepare_form_data(post_data: dict, **kwargs) → Mapping[str, Any]

If backend support several modes of operation, POST should probably additionally calculate some sort of signature based on passed data.

get_form(post_data: dict, **kwargs) → django.forms.forms.BaseForm

(Optional) Used to get POST form for backends that use such flow.

abstract prepare_transaction(request: django.http.request.HttpRequest, view: Optional[django.views.generic.base.View] = None, **kwargs) → django.http.response.HttpResponse

Prepare Response for the view asking to prepare transaction.

Returns

HttpResponse instance

handle_paywall_callback(request: django.http.request.HttpRequest, **kwargs) → django.http.response.HttpResponse

This method handles the callback from paywall for the purpose of asynchronously updating the payment status in our system.

Returns

HttpResponse instance that will be presented as answer to the callback.

fetch_payment_status(**kwargs) → getpaid.types.PaymentStatusResponse

Logic for checking payment status with paywall.

charge(amount: Optional[Union[decimal.Decimal, float, int]] = None, **kwargs) → getpaid.types.ChargeResponse

(Optional) Check if payment can be locked and call processor’s method. This method is used eg. in flows that pre-authorize payment during order placement and charge money later.

release_lock(**kwargs) → decimal.Decimal

(Optional) Release locked payment. This can happen if pre-authorized payment cannot be fullfilled (eg. the ordered product is no longer available for some reason). Returns released amount.

start_refund(amount: Optional[Union[decimal.Decimal, float, int]] = None, **kwargs) → decimal.Decimal

Refunds the given amount.

Returns the amount that is refunded.

cancel_refund(**kwargs) → bool

Cancels started refund.

Returns True/False if the cancel succeeded.