djpg is a Django module that integrates with the online payment service PagSeguro.

pip install djpg==0.2.0



djpg is a Django module that integrates with the online payment service PagSeguro.

It will not touch your database neither alter your Django installation, djpg simply provides the machinery for you to send and receive requests from PagSeguro in a clean and pythonic way.


Simply run:

$ pip install djpg

After installing, the only configurations required are PAGSEGURO_EMAIL and PAGSEGURO_TOKEN. You should add them to your file. The first is your signup email from PagSeguro, the other is the token they'll give you when you have a seller account. For example:



Creating a cart and redirecting the user

from djpg import Cart, Item

def my_checkout_view(request):
    cart = Cart(reference='myref123', redirect_url='')
    item = Item(id=1, amount=19.50, description='Cool T-shirts!', quantity=2)

    code = cart.checkout()
    if code:
        # This will redirect the user to the checkout page,
        # where the cart can be paid.
        return cart.proceed(code)

Receiving notifications

The following snippet will ensure djpg receives notifications from PagSeguro and dispatch them to the respective signals.

urlpatterns += patterns('',
    url(r'^pagseguro/', include('djpg.urls'))

Keep in mind that this endpoint needs to be configured in your PagSeguro account also (e.g.: Then you can connect listeners to the signals that are relevant to you.

from djpg.signals import transaction_paid

def on_paid(sender, **kwargs):
    transaction = kwargs.pop('transaction')
    ref = transaction['reference']
    status = transaction['status']
    # ...


The following signals are available:

  • notification_received
  • transaction_received
  • transaction_waiting
  • transaction_analysis
  • transaction_paid
  • transaction_available
  • transaction_dispute
  • transaction_returned
  • transaction_canceled
  • transaction_unknown