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):
        """
        Create a new order and mark it on-hold. Reserve items from stock and await
        manual payment from customer via back account. When paid order status should be
        changed to `PROCESSING`, `SHIPPED` or `COMPLETED` and a new payment should be
        added to order.
        """
        order = Order.objects.create_from_basket(basket, request, status='HOLD')
        basket.delete()
        url = reverse('salesman-order-last') + f'?token={order.token}'
        return request.build_absolute_uri(url)

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.