Skip to content

Onlineweb apps Payment

Torrib edited this page Mar 4, 2015 · 8 revisions

Onlinewebs payment system uses Stripes custom checkout system

Short models description

Payment

The main object that contains a generic link to a content object (Event, prokom thingy, etc)
This object contains a price, deadline(optional) and a boolean for instant payment.
If the instant payment field is set the user is required to pay before attending.

PaymentRelation

The link between the payment and a user. Also contains an unique id and the time of purchase.

Setting up payment for an object

The example code is from events and references to events should be changed with your own object.

Add payments to request.session

The request.session should have a list of payments. (This is to support multiple different forms of payment for for instance an event).
This should be done in the view method that loads the template with the payment button.
The payments should be passed with the context.

payments = Payment.objects.filter(content_type=ContentType.objects.get_for_model(Event), object_id=event_id)
if payments:
   request.session['payment_ids'] = [payment.id for payment in payments]

events/views.py - details

The object should implement the following methods

  1. payment_description()
    Return: String
    Description: Used as the title for the payment and confirmation mail
  2. payment_mail()
    Return: email address
    Description: The confirmation mail is sent from this mail.
  3. payment_complete(user)
    Return: None
    Description: Any logic beyond creating a payment_relation should be done here (ie. creating or updating the attendee object for events)

Template

This is an example of template code that supports multiple payment objects

{% for payment in payments %}
    <p class="status-text payment-price-tag">Prisen er på {{ payment.price }} Kr.</p>
    <button id="stripeButton{{ payment.id }}" class="btn btn-large btn-success payment-button">Betal med kort</button>
{% endfor %}

<script src="{{ STATIC_URL }}js/libs/jquery-2.1.3.min.js"></script>
<script src="https://checkout.stripe.com/checkout.js"></script>
<script src="{{ STATIC_URL }}js/payment.js"></script>

Note: You might have to change the jquery version to the newest one in the js/libs folder.

Confirmation mail is sent and the payment_relation object is created automatically on successful payment.

Dashboard

TBA