Skip to main content

Mercy Pay pour Django

Mercy Pay dans un projet Django 4.2 ou plus : un client configuré par vos settings, et une vue qui reçoit les webhooks, vérifie leur signature et envoie un signal.

pip install mercy-pay-django

Configurer

# settings.py
INSTALLED_APPS = [..., "mercypay_django"]

MERCY_PAY = {
    "API_KEY": env("MERCY_PAY_API_KEY"),            # mp_sandbox_… ou mp_live_…
    "WEBHOOK_SECRET": env("MERCY_PAY_WEBHOOK_SECRET"),  # whsec_…
}

Sans MERCY_PAY, les variables d'environnement MERCY_PAY_API_KEY et MERCY_PAY_WEBHOOK_SECRET sont lues.

# urls.py
urlpatterns = [
    path("webhooks/mercy-pay/", include("mercypay_django.urls")),
]

Encaisser un paiement

from django.shortcuts import redirect
from mercypay_django import get_client

def pay(request, order_id):
    order = Order.objects.get(pk=order_id, customer=request.user)
    session = get_client().checkout_sessions.create(
        amount=order.total,
        currency="XAF",
        success_url=request.build_absolute_uri(order.get_absolute_url()),
        metadata={"order_id": str(order.pk)},
        idempotency_key=f"order-{order.pk}",
    )
    return redirect(session.checkout_url)

get_client() renvoie le client mercy-pay, avec toutes ses méthodes.

Recevoir les webhooks

Déclarez https://votre-site/webhooks/mercy-pay/ comme endpoint dans Développeurs > Webhooks, puis écoutez le signal :

# orders/receivers.py, importé dans OrdersConfig.ready()
from django.dispatch import receiver
from mercypay_django import webhook_received

@receiver(webhook_received)
def on_mercy_pay_event(sender, event, event_type, **kwargs):
    if event_type == "payment.succeeded":
        Order.objects.filter(pk=event.data.metadata["order_id"]).update(status="paid")
  • Une mauvaise signature reçoit un 400, et le signal n'est pas envoyé. La vue est exemptée de CSRF.
  • Si un receveur lève une erreur, la vue répond 500 : Mercy Pay renverra l'événement plus tard.
  • Un même événement peut arriver deux fois : servez-vous de event.id.
  • Pour un travail long, passez-le à Celery ou à une autre file depuis le receveur.

En local

mercypay listen --forward-to localhost:8000/webhooks/mercy-pay/
mercypay trigger payment.succeeded

La CLI affiche son secret de signature au démarrage : mettez-le dans MERCY_PAY_WEBHOOK_SECRET en local.

Metadata

Release files for mercy-pay-django 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mercy-pay-django 0.1.0
File Size Uploaded Provenance Actions
mercy_pay_django-0.1.0.tar.gz 5.5 kB With provenance Details for mercy_pay_django-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mercy-pay-django 0.1.0
File Interpreter ABI Platform Actions
mercy_pay_django-0.1.0-py3-none-any.whl Python 3 none any Details for mercy_pay_django-0.1.0-py3-none-any.whl

Total release size: 11.7 kB

Release files / mercy_pay_django-0.1.0.tar.gz

Download URL mercy_pay_django-0.1.0.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
cebe79c0d6bb58b0878c0d88f48307eae44092456757983d1abef75cc36077bc
BLAKE2b-256 checksum
How to use checksums
10cd526b6a892cf81d5e25c4804eda7c4578c507cbbe99ceee6454d29fa4872d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / mercy_pay_django-0.1.0-py3-none-any.whl

Download URL mercy_pay_django-0.1.0-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5317c299dcdac0b9a6cb073c55e1fba15b9c1d16af498b5c31e92f505c946566
BLAKE2b-256 checksum
How to use checksums
e39fc0043820af9f9991958a1cffd5ff16145258acfcb310501de180863486a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Security for mercy-pay-django 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mercy_pay_django-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page