Changeset - 67b047e7b30e
[Not reviewed]
0 1 0
Christopher Neugebauer - 8 years ago 2016-04-24 21:20:41
chrisjrn@gmail.com
Simplifies invoice-getting documentation.
1 file changed with 1 insertions and 4 deletions:
0 comments (0 inline, 0 general)
docs/payments.rst
Show inline comments
...
 
@@ -11,52 +11,49 @@ Registrasion also keeps track of money that is not currently attached to invoice
 

	
 
Finally, Registrasion provides a `manual payments`_ feature, which allows for staff members to manually report payments into the system. This is the only payment facility built into Registrasion, but it's not intended as a reference implementation.
 

	
 

	
 
Making payments
 
---------------
 

	
 
Making payments is a three-step process:
 

	
 
#. Validate that the invoice is ready to be paid,
 
#. Create a payment object for the amount that you are paying towards an invoice,
 
#. Ask the invoice to calculate its status now that the payment has been made.
 

	
 
Pre-validation
 
~~~~~~~~~~~~~~
 
Registrasion's ``InvoiceController`` has a ``validate_allowed_to_pay`` method, which performs all of the pre-payment checks (is the invoice still unpaid and non-void? has the registration been amended?).
 

	
 
If the pre-payment check fails, ``InvoiceController`` will raise a Django ``ValidationError``.
 

	
 
Our the ``demopay`` view from the ``registrasion-demo`` project implements pre-validation like so::
 

	
 
    from registrasion.controllers.invoice import InvoiceController
 
    from django.core.exceptions import ValidationError
 

	
 
    # Get the Registrasion Invoice model
 
    inv = get_object_or_404(rego.Invoice.objects, pk=invoice_id)
 

	
 
    invoice = InvoiceController(inv)
 
    invoice = InvoiceController.for_id_or_404(invoice.id)
 

	
 
    try:
 
        invoice.validate_allowed_to_pay()  # Verify that we're allowed to do this.
 
    except ValidationError as ve:
 
        messages.error(request, ve.message)
 
        return REDIRECT_TO_INVOICE  # And display the validation message.
 

	
 
In most cases, you don't engage your actual payment application until after pre-validation is finished, as this gives you an opportunity to bail out if the invoice isn't able to have funds applied to it.
 

	
 
Applying payments
 
~~~~~~~~~~~~~~~~~
 
Payments in Registrasion are represented as subclasses of the ``PaymentBase`` model. ``PaymentBase`` looks like this:
 

	
 
.. autoclass :: PaymentBase
 

	
 
When you implement your own payment application, you'll need to subclass ``PaymentBase``, as this will allow you to add metadata that lets you link the Registrasion payment object with your payment platform's object.
 

	
 
Generally, the ``reference`` field should be something that lets your end-users identify the payment on their credit card statement, and to provide to your team's tech support in case something goes wrong.
 

	
 
Once you've subclassed ``PaymentBase``, applying a payment is really quite simple. In the ``demopay`` view, we have a subclass called ``DemoPayment``::
 

	
 
    invoice = InvoiceController(some_invoice_model)
 

	
 
    # Create the payment object
0 comments (0 inline, 0 general)