Skip to main content

MercadoPago integration for django

Project description

build status coverage report version on pypi licence

django-mercadopago is a simple django application for interacting with MercadoPago, aiming to be rather simple, and only covers the basic uses cases.

Features

Our intention is not to cover 100% of the features of the upstream API, but rather provide a simple app that allows accepting and tracking payments. This should suffice for simple sites like shopping carts, online sales, etc.

Pull requests are always welcome. Please don’t hesitate to open an issue if you encounter a problem. New features will generally only be added as needed, but again, accepted if you submit a patch.

Installation

Installation should generally be done via pip:

pip install django-mercadopago

Configuration

You’ll need to obtainer your API credentials (app id and secret key) here and create an Account object with them. This creation can be done via the django admin included with this app or programmatically.

You should also expose the notifications endpoints like this:

url(r'^mercadopago/', include('django_mercadopago.urls'), namespace='mp'),
# Make sure namespace is 'mp', since we assume it is for notification URL
# contruction.

Note that these endpoints are required, since notification callbacks won’t work without them.

There are also a few Django settings that configure the behaviour of this app:

MERCADOPAGO_AUTOPROCESS

Required

If MERCADOPAGO_AUTOPROCESS is True, notifications will be processed as soon as they are received. Otherwise, it’s up to the developer to process them. A signal is always fired when a notification has been created, and a common pattern if not auto-processing is to have a celery task to process them:

@receiver(notification_received)
def process_notification(sender, **kwargs):
    tasks.process_notification.delay(notification=sender)

MERCADOPAGO_POST_PAYMENT_VIEW

Required

The setting MERCADOPAGO_POST_PAYMENT_VIEW must define name of the view where users are redirected after a payment. This view will receive as an argument the id of the notification created for this payment.

MERCADOPAGO_BASE_HOST

Required

MERCADOPAGO_BASE_HOST defines the domain name to use for notification URLs. It’ll be prepended to the exact URL of the exposed notifications endpoint.

Usage

MercadoPago lets you create preferences, for which you’ll later receive notifications (indicating if it was paid, or what happened):

self.preference = Preference.objects.create(
    title='the product name',
    price=10.0,
    reference='order-38452',
    success_url='http://example.com/mp_done',
    account=account,
)

If your app will only be using a single MercadoPago account, just use:

account = Account.objects.first()

Finally, you can handle payment notifications in real time using a post_update hook:

@receiver(post_save, sender=MercadoPagoPayment)
def process_payment(sender, instance=None, created=False, **kwargs):
    do_stuff()

Backwards compatibility

Note that, prior to v4.2.0, this package was called django-mercadopago-simple on PyPI. Older release exist under that name.

Version 2.0.0 changes the database schema quite a bit. While older data is retained, some missing fields had to be filled. Auto-generated data will have negative key values, and should easily be recognizable.

Regrettably, filling in this data automatically is not possible. However, there is no data loss involved.

Licence

This software is distributed under the ISC licence. See LICENCE for details.

Copyright (c) 2015-2017 Hugo Osvaldo Barrera <hugo@barrera.io>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-mercadopago-4.2.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_mercadopago-4.2.0-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file django-mercadopago-4.2.0.tar.gz.

File metadata

File hashes

Hashes for django-mercadopago-4.2.0.tar.gz
Algorithm Hash digest
SHA256 38bba33df54c0396a61d4aabef2cbdbc78ed22825ccc5598cac557b2f74ef920
MD5 c8e69fa466a208e3dc786f091d2d98f4
BLAKE2b-256 81ee8658d006bd682332a0a38d35373bd21d52af37b6b243265498545ff65ef1

See more details on using hashes here.

File details

Details for the file django_mercadopago-4.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_mercadopago-4.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f832e7bdb8458c2dee0636351b7ee63e3c2ff2d83b83f3c0abb95858f0fbee89
MD5 54a217fc054f4d9c6e9039c3c01411fc
BLAKE2b-256 10f1fe339c17d1fd230446b31507ce70fec700ffcdb9a18d2eadb68cd2b3d9ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page