4. Authorization and capture¶
Some gateways offer a two-step payment method known as Authorization & Capture, which allows you to collect the payment manually after the buyer has authorized it. To enable this payment type, you have to set the capture
parameter to False
in the configuration of payment backend:
# settings.py
PAYMENT_VARIANTS = {
'default': ('payments.dummy.DummyProvider', {'capture': False})}
4.1. Capturing the payment¶
To capture the payment from the buyer, call the capture()
method on the Payment
instance:
>>> from payments import get_payment_model
>>> Payment = get_payment_model()
>>> payment = Payment.objects.get()
>>> payment.capture()
By default, the total amount will be captured. You can capture a lower amount, by providing the amount
parameter:
>>> from decimal import Decimal
>>> payment.capture(amount=Decimal(10.0))
Note
Only payments with the preauth
status can be captured.
4.2. Releasing the payment¶
To release the payment to the buyer, call the release()
method on your Payment
instance:
>>> from payments import get_payment_model
>>> Payment = get_payment_model()
>>> payment = Payment.objects.get()
>>> payment.release()
Note
Only payments with the preauth
status can be released.