Skip to main content

ZRU Python Bindings

Project description

ZRU Python

Overview

ZRU Python provides integration access to the ZRU API.

Coverage Status

Installation

You can install using pip:

pip install --upgrade zru-python

or easy_install

easy_install --upgrade zru-python

or to install from source, run:

python setup.py install

Migration Guide for Versions Prior to 1.x.x

If you are migrating from a version prior to 1.x.x, you will need to update your import statements to reflect the change from mc2p to zru. Here is a guide to help you make these changes.

Updating Import Statements

For any imports that used the mc2p module, replace mc2p with zru.

Example

Before:

from mc2p.errors import InvalidRequestError

After:

from zru.errors import InvalidRequestError

Updating Client class

Replace MC2PClient with ZRUClient.

Example

Before:

client = MC2PClient(...)

After:

client = ZRUClient(...)

Steps to Update Your Code

  1. Search and Replace: Use your IDE or a text editor to search for mc2p and replace it with zru.
  2. Verify Imports: Ensure all import statements now reference zru.
  3. Run Tests: Run your test suite to verify that your code is functioning correctly with the updated imports.

Summary

By following these steps, you can successfully migrate your project from versions prior to 1.x.x, ensuring compatibility with the new zru module naming convention.

Quick Start Example

from zru import ZRU

zru = ZRUClient('KEY', 'SECRET_KEY')

# Create transaction
transaction = zru.Transaction({
    "currency": "EUR",
    "products": [{
        "amount": 1,
        "product_id": "PRODUCT-ID"
    }]
})
# or with product details
transaction = zru.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 = zru.plan.list()
plans_paginator.count
plans_paginator.results # Application's plans
plans_paginator.get_next_list()

# Get product, change and save
product = zru.Product.get("PRODUCT-ID")
product.price = 10
product.save()

# Create and delete tax
tax = zru.Tax({
    "name": "Tax",
    "percent": 5
})
tax.save()
tax.delete()

# Check if transaction was paid
transaction = zru.Transaction.get("TRANSACTION-ID")
transaction.status == 'D' # Paid

# Create subscription
subscription = zru.Subscription({
    "currency": "EUR",
    "plan_id": "PLAN-ID",
    "note": "Note example"
})
# or with plan details
subscription = zru.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 = zru.NotificationData(JSON_DICT_RECEIVED_FROM_ZRU)
notification_data.is_status_done # Paid
notification_data.transaction # Transaction Paid
notification_data.sale # Sale generated

Exceptions

from zru.errors import InvalidRequestError

# Incorrect data
shipping = zru.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

zru_python-1.0.0.tar.gz (16.8 kB view details)

Uploaded Source

File details

Details for the file zru_python-1.0.0.tar.gz.

File metadata

  • Download URL: zru_python-1.0.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.12

File hashes

Hashes for zru_python-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d220fdb05e3a7771d23f6d3d431efca25d4a1dd08bd3f6e909fe19a583a96ec4
MD5 8cb0482204bde8ddbc3336a0e30a455a
BLAKE2b-256 19b019a6f0149be57374428ad8407c30f07ba2c22b9884bd6ea7d82e4818f50b

See more details on using hashes here.

Supported by

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