Verify a successful PayPal purchase - 31

Next step is to create a specific view when processing the PayPal order, so for the rest, I don't think I have much more to do here:

def capture_payment(request, order_id):

    paypal = PayPalPayment()
    res = paypal.capture_order(order_id)


    if res:
        return render(request,'elements/capture_payment.html', {'res': res, 
          'id': res['id'], 
          'status': res['status'], 
          price': res['purchase_units'][0]['payments']['captures'][0]['amount']['value']})	

    return render(request,'elements/error.html')

The template looks like this:

mystore\elements\templates\elements\capture_payment.html

{% extends "base.html" %}

{% block content %}

<script src="https://www.paypal.com/sdk/js?client-id={{paypal_client_id}}"></script>

<div class="card">
   <div class="card-header">
       <h1>Payment Process</h1>
   </div>

   <div class="card-body">

       <ul>
           <li>id: {{id }}</li>
           <li>status: {{ status }}</li>
           <li>price: {{ price }}</li>
       </ul>

   </div>
   <div class="card-header">
       <h5>Traze</h5>
   </div>
   <div class="card-body">
       {{res}}
   </div>
</div>


{% endblock %}

With this, when processing the order, you should see the trace in the previous template.

I agree to receive announcements of interest about this Blog.

We implemented the process of processing a successful order in PayPal with Django.

- Andrés Cruz

En español

This material is part of my complete course and book; You can purchase them from the books and/or courses section, Curso y Libro desarrollo web con Django 5 y Python 3 + integración con Vue 3, Bootstrap y Alpine.js.