Skip to main content
# MyChoice2Pay Django


# Overview

MyChoice2Pay Django provides integration access to the MyChoice2Pay API through django framework.


# Requirements

* [Django][django]
* [MyChoice2Pay Python][mc2p-python]

# Installation

Install using `pip`...

pip install mc2p-django

Add `'django_mc2p'` to your `INSTALLED_APPS` setting.

INSTALLED_APPS = (
...
'django_mc2p',
...
)

Add django_mc2p urls:

urlpatterns = patterns('',
...
url(r'^mc2p/', include('django_mc2p.urls'))
...
)

# Configuration

After execute migrations you must define KEY and SECRET KEY in administration site, section MyChoice2Pay Configuration.

You can obtain KEY and SECRET KEY from [MyChoice2Pay][mychoice2pay-site] site.

# Quick Example

### Basic transaction

# Sending user to pay
from django_mc2p import MC2PClient

mc2p = MC2PClient()
transaction = mc2p.Transaction({
"currency": "EUR",
"order_id": "order id",
"products": [{
"amount": 1,
"product": {
"name": "Product",
"price": 50
}
}],
"notify_url": "https://www.example.com" + reverse('mc2p-notify'),
"return_url": "https://www.example.com/your-return-url/",
"cancel_return": "https://www.example.com/your-cancel-url/"
})
transaction.save()
transaction.pay_url # Send user to this url to pay

# After user pay a notification will be sent to notify_url
from django_mc2p.constants import MC2P_PAYMENT_DONE
from django_mc2p.signals import notification_received

def check_payment(sender, **kwargs):
notification_data = sender
if notification_data.type == MC2P_TYPE_TRANSACTION and notification_data.status == MC2P_PAYMENT_DONE:
transaction = notification_data.transaction
sale = notification_data.sale
order_id = notification_data.order_id
# Use transaction, sale and order_id to check all the data and confirm the payment in your system
notification_received.connect(check_payment)

### Basic subscription

# Sending user to pay a subscription
from django_mc2p import MC2PClient

mc2p = MC2PClient()
subscription = mc2p.Subscription({
"currency": "EUR",
"order_id": "order id",
"plan": {
"name": "Plan",
"price": 5,
"duration": 1,
"unit": "M",
"recurring": true
},
"notify_url": "https://www.example.com" + reverse('mc2p-notify'),
"return_url": "https://www.example.com/your-return-url/",
"cancel_return": "https://www.example.com/your-cancel-url/"
})
subscription.save()
subscription.pay_url # Send user to this url to pay

# After user pay a notification will be sent to notify_url
from django_mc2p.constants import MC2P_PAYMENT_DONE
from django_mc2p.signals import notification_received

def check_payment(sender, **kwargs):
notification_data = sender
if notification_data.type == MC2P_TYPE_SUBSCRIPTION and notification_data.status == MC2P_PAYMENT_DONE:
subscription = notification_data.subscription
sale = notification_data.sale
order_id = notification_data.order_id
# Use subscription, sale and order_id to check all the data and confirm the payment in your system
notification_received.connect(check_payment)

[django]: https://www.djangoproject.com/
[mc2p-python]: https://github.com/mc2p/mc2p-python
[mychoice2pay-site]: https://www.mychoice2pay.com/


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

mc2p_django-0.1.2-py2.py3-none-any.whl (9.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file mc2p_django-0.1.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for mc2p_django-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 04455de04af6d0a37b01a3244c2f75230f2f92a758471c1e94e34154a427e3cd
MD5 40048af94a6e22edfcf86a022d6fa3e8
BLAKE2b-256 bdb540f1f826a1a9313b0cb33f2d8e296fbba22866b6baef8d419a94a4fba1e1

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.6

1 file

0.1.5

1 file

0.1.3

1 file

This release

0.1.2 This release

1 file

0.1.1

1 file

0.1.0

1 file

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