MyChoice2Pay Python Bindings
Project description
# MyChoice2Pay Python
# Overview
MyChoice2Pay Python provides integration access to the MyChoice2Pay API.
[![Build Status](https://travis-ci.org/mc2p/mc2p-python.svg?branch=master)](https://travis-ci.org/mc2p/mc2p-python)
[![Coverage Status](https://coveralls.io/repos/github/mc2p/mc2p-python/badge.svg?branch=master)](https://coveralls.io/github/mc2p/mc2p-python?branch=master)
[![Code Health](https://landscape.io/github/mc2p/mc2p-python/master/landscape.svg?style=flat)](https://landscape.io/github/mc2p/mc2p-python/master)
# Installation
You can install using `pip`:
pip install --upgrade mc2p-python
or `easy_install`
easy_install --upgrade mc2p-python
or to install from source, run:
python setup.py install
# Quick Start Example
from mc2p import MC2P
mc2p = MC2PClient('KEY', 'SECRET_KEY')
# Create transaction
transaction = mc2p.Transaction({
"currency": "EUR",
"products": [{
"amount": 1,
"product": {
"name": "Product",
"price": 5
}
}]
})
transaction.save()
transaction.pay_url # Send user to this url to pay
transaction.iframe_url # Use this url to show an iframe in your site
# Get plans
plans_paginator = mc2p.plan.list()
plans_paginator.count
plans_paginator.results # Application's plans
plans_paginator.get_next_list()
# Get product, change and save
product = mc2p.Product.get("PRODUCT-ID")
product.price = 10
product.save()
# Create and delete tax
tax = mc2p.Tax({
"name": "Tax",
"percent": 5
})
tax.save()
tax.delete()
# Check if transaction was paid
transaction = mc2p.Transaction.get("TRANSACTION-ID")
transaction.status == 'D' # Paid
# Create subscription
subscription = mc2p.Subscription({
"currency": "EUR",
"plan_id": "PLAN-ID",
"note": "Note example"
})
# or
subscription = mc2p.Subscription({
"currency": "EUR",
"plan": {
"name": "Plan",
"price": 5,
"duration": 1,
"unit": "M",
"recurring": True
},
"note": "Note example"
})
subscription.save()
subscription.pay_url # Send user to this url to pay
subscription.iframe_url # Use this url to show an iframe in your site
# Receive a notification
notification_data = mc2p.NotificationData(JSON_DICT_RECEIVED_FROM_MYCHOICE2PAY)
notification_data.status == 'D' # Paid
notification_data.transaction # Transaction Paid
notification_data.sale # Sale generated
# Exceptions
from mc2p.errors import InvalidRequestError
# Incorrect data
shipping = mc2p.Shipping({
"name": "Normal shipping",
"price": "text" # Price must be number
})
try:
shipping.save()
except InvalidRequestError as e:
e._message # Status code of error
e.json_body # Info from server
e.resource # Resource used to make the server request
e.resource_id # Resource id requested
# Overview
MyChoice2Pay Python provides integration access to the MyChoice2Pay API.
[![Build Status](https://travis-ci.org/mc2p/mc2p-python.svg?branch=master)](https://travis-ci.org/mc2p/mc2p-python)
[![Coverage Status](https://coveralls.io/repos/github/mc2p/mc2p-python/badge.svg?branch=master)](https://coveralls.io/github/mc2p/mc2p-python?branch=master)
[![Code Health](https://landscape.io/github/mc2p/mc2p-python/master/landscape.svg?style=flat)](https://landscape.io/github/mc2p/mc2p-python/master)
# Installation
You can install using `pip`:
pip install --upgrade mc2p-python
or `easy_install`
easy_install --upgrade mc2p-python
or to install from source, run:
python setup.py install
# Quick Start Example
from mc2p import MC2P
mc2p = MC2PClient('KEY', 'SECRET_KEY')
# Create transaction
transaction = mc2p.Transaction({
"currency": "EUR",
"products": [{
"amount": 1,
"product": {
"name": "Product",
"price": 5
}
}]
})
transaction.save()
transaction.pay_url # Send user to this url to pay
transaction.iframe_url # Use this url to show an iframe in your site
# Get plans
plans_paginator = mc2p.plan.list()
plans_paginator.count
plans_paginator.results # Application's plans
plans_paginator.get_next_list()
# Get product, change and save
product = mc2p.Product.get("PRODUCT-ID")
product.price = 10
product.save()
# Create and delete tax
tax = mc2p.Tax({
"name": "Tax",
"percent": 5
})
tax.save()
tax.delete()
# Check if transaction was paid
transaction = mc2p.Transaction.get("TRANSACTION-ID")
transaction.status == 'D' # Paid
# Create subscription
subscription = mc2p.Subscription({
"currency": "EUR",
"plan_id": "PLAN-ID",
"note": "Note example"
})
# or
subscription = mc2p.Subscription({
"currency": "EUR",
"plan": {
"name": "Plan",
"price": 5,
"duration": 1,
"unit": "M",
"recurring": True
},
"note": "Note example"
})
subscription.save()
subscription.pay_url # Send user to this url to pay
subscription.iframe_url # Use this url to show an iframe in your site
# Receive a notification
notification_data = mc2p.NotificationData(JSON_DICT_RECEIVED_FROM_MYCHOICE2PAY)
notification_data.status == 'D' # Paid
notification_data.transaction # Transaction Paid
notification_data.sale # Sale generated
# Exceptions
from mc2p.errors import InvalidRequestError
# Incorrect data
shipping = mc2p.Shipping({
"name": "Normal shipping",
"price": "text" # Price must be number
})
try:
shipping.save()
except InvalidRequestError as e:
e._message # Status code of error
e.json_body # Info from server
e.resource # Resource used to make the server request
e.resource_id # Resource id requested
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
mc2p-python-0.1.0.tar.gz
(10.9 kB
view hashes)
Built Distributions
Close
Hashes for mc2p_python-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd0493219f49a4c7f30b9e4f5eb112e0fa42d2d1154fe5bf9250bbb165f4073e |
|
MD5 | 15b1be612679b2f8f9d1d3cafa2d7099 |
|
BLAKE2b-256 | 739a079f67ffa024d57377c3f0b313b2301efde7ed3fa9e2f488326cea822fe7 |
Close
Hashes for mc2p_python-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0c975ab12401325a471858ce65e15f06a0177a5f846d6b1dffda1e55dfa238a |
|
MD5 | 09f7b69f14b96406d72c32cd3aef78f1 |
|
BLAKE2b-256 | ad2198bdc92435b5d4ff55445040e28d36163b82b2738231c7cc0a4cb6e20f19 |