Checkout (before Stripe SCA)


This app replaces the old pay

from checkout.forms import CheckoutForm

class JobCheckoutForm(CheckoutForm):

    class Meta:
        model = Job
        fields = (

from checkout.views import CheckoutMixin

class JobCheckoutView(
    PageFormMixin, CheckoutMixin, BaseMixin, UpdateView):

    model = Job
    form_class = JobCheckoutForm

In the html template:

{% include '_form.html' with submit='Checkout' form_id='id_checkout_form' %}

{% block script %}
  {{ block.super }}
  {% include 'checkout/_stripe.js.html' %}
{% endblock script %}

In your .private file, add your test keys for Stripe:

export STRIPE_PUBLISH_KEY="pk_test_123"
export STRIPE_SECRET_KEY="sk_test_456"


from checkout.tests.helper import check_checkout

def test_checkout():
    obj = JobFactory()

Payment Plan Instalment

If a user has marked a payment plan instalment as paid (using Mark Paid) and you want to make it due again.

Find the primary key of the ObjectPaymentPlanInstalment which is due:

from checkout.models import ObjectPaymentPlanInstalment
content_object = ObjectPaymentPlanInstalment.objects.get(pk=3164)

Check the payment plan is for the correct person:

# <Enrol: Mr P Kimber>

Create a Checkout object and fail the payment:

from checkout.models import Checkout, CheckoutAction
from django.contrib.auth.models import User

user = User.objects.get(username="patrick.kimber")
checkout = Checkout.objects.create_checkout(CheckoutAction.objects.manual, content_object, user)


To set-up Stripe, tick Payment reviews in Emails (Settings). Stripe will send email notifications for new payments placed in the review queue.



To mock stripe.Charge.create and stripe.Customer.create:

import attr
from unittest.mock import patch

class StripeCustomer:
    id = attr.ib()

@patch("stripe.Customer.create", return_value=StripeCustomer(id="xyz"))
def test_payment(mock_charge, mock_customer, client):
    assert mock_charge.called is True
    assert mock_customer.called is True


If you are using a copy of the live data set and you want to run test payments, then you might get a No such customer error. This is because the customer numbers on the live system will not match the customer numbers on your test system.

To remove the customer records on the live system:

from checkout.models import Customer

Payment Plan

To test the payment plans…

Find a valid customer ID on the Stripe dashboard e.g:: cus_DsK5YbWqKHP9jj.


from datetime import date
from checkout.models import Customer, ObjectPaymentPlanInstalment

Update all customers on your data set to point to this customer e.g:


Find an instalment which is due:

next_due = date(2018, 11, 1)
instalment = ObjectPaymentPlanInstalment.objects.filter(due=next_due).first()

Set the date on the instalment to today:

instalment.due =

Check the instalment is due (and meets all other conditions):


Run the payment run management command: process_payments