Checkout & paymentΒΆ

To enable basket checkout you need to define a payment method in SALESMAN_PAYMENT_METHODS setting which accepts a list of dotted paths to salesman.checkout.payment.PaymentMethod classes.

Note

For this example we assume your custom app is named shop.

1. Create payment method

First create your custom payment method. Payment methods are required to specify a label and a unique identifier property on class. To enable payment for the basket you should also override the salesman.checkout.payment.PaymentMethod.basket_payment() method. Eg:

# payment.py
from salesman.checkout.payment import PaymentMethod
from salesman.orders.models import Order


class PayInAdvance(PaymentMethod):
    """
    Payment method that requires advance payment via bank account.
    """
    identifier = 'pay-in-advance'
    label = 'Pay in advance'

    def basket_payment(self, basket, request):
        order = Order.objects.create_from_basket(basket, request, status='HOLD')
        basket.delete()
        return f'/success/?token={order.token}'

2. Register payment method

Then register your payment method in settings.py:

SALESMAN_PAYMENT_METHODS = [
    'shop.payment.PayInAdvance',
]

Now you can make a basket purchase through the POST /checkout/ request with payment_method set to pay-in-advance.

For more information about payment methods see Payment methods.