Checkout

https://gitlab.com/kb/checkout

Note

This app replaces the old pay

forms.py:

from checkout.forms import CheckoutForm

class JobCheckoutForm(CheckoutForm):

    class Meta:
        model = Job
        fields = (
            'action',
        )

views.py:

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"

Testing:

from checkout.tests.helper import check_checkout

@pytest.mark.django_db
def test_checkout():
    obj = JobFactory()
    check_checkout(obj)

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:

content_object.object_payment_plan.content_object
# <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)
checkout.save()
checkout.fail()

Stripe

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

Testing

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
Customer.objects.all().delete()