Skip to main content

ZRU Python Bindings

Project description

ZRU Python SDK

Overview

The ZRU Python SDK provides easy access to the ZRU API, allowing developers to manage transactions, products, plans, taxes, subscriptions, and notifications seamlessly.

Coverage Status

Installation

Install the SDK via pip:

pip install --upgrade zru-python

Alternatively, you can use easy_install:

easy_install --upgrade zru-python

To install from the source, run:

python setup.py install

Migration Guide for Versions Prior to 1.x.x

If you're upgrading from a version earlier than 1.x.x, you will need to update your import statements to reflect the transition from mc2p to zru. Here's a guide to help with this transition:

Updating Import Statements

Replace any imports from the mc2p module with zru.

Example:

Before:

from mc2p.errors import InvalidRequestError

After:

from zru.errors import InvalidRequestError

Updating the Client Class

Replace instances of MC2PClient with ZRUClient.

Example:

Before:

client = MC2PClient(...)

After:

client = ZRUClient(...)

Steps to Update Your Code

  1. Search and Replace: Use an IDE or text editor to search for mc2p and replace it with zru.
  2. Verify Imports: Ensure all import statements now reference zru.
  3. Run Tests: Test your code to ensure everything functions correctly after the migration.

Summary

Following these steps will help you 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 ZRUClient

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

# Create a transaction
transaction = zru.Transaction({
    "currency": "EUR",
    "products": [{
        "amount": 1,
        "product_id": "PRODUCT-ID"
    }]
})

# Create a transaction with product details
transaction = zru.Transaction({
    "currency": "EUR",
    "products": [{
        "amount": 1,
        "product": {
            "name": "Product",
            "price": 5
        }
    }]
})
transaction.save()

# Get payment URLs
print('Payment URL:', transaction.pay_url)     # URL for user to complete the payment
print('Iframe URL:', transaction.iframe_url)  # URL for embedding in an iframe

# List available plans
plans_paginator = zru.Plan.list()
print('Plan Count:', plans_paginator.count)
print('Plan Results:', plans_paginator.results)    # List of plans
plans_paginator.get_next_list()  # Fetch next set of plans

# Get a product, update its price, and save changes
product = zru.Product.get("PRODUCT-ID")
product.price = 10
product.save()

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

# Check if a transaction is paid
transaction = zru.Transaction.get("TRANSACTION-ID")
is_paid = transaction.status == 'D'  # 'D' stands for 'Paid'
print('Transaction Paid:', is_paid)

# Create a subscription
subscription = zru.Subscription({
    "currency": "EUR",
    "plan_id": "PLAN-ID",
    "note": "Note example"
})

# Create a subscription with plan details
subscription = zru.Subscription({
    "currency": "EUR",
    "plan": {
        "name": "Plan",
        "price": 5,
        "duration": 1,
        "unit": "M",
        "recurring": True
    },
    "note": "Note example"
})
subscription.save()

# Get subscription payment URLs
print('Subscription Payment URL:', subscription.pay_url)     # URL for user to complete the subscription payment
print('Subscription Iframe URL:', subscription.iframe_url)  # URL for embedding in an iframe

# Handling notifications
notification_data = zru.NotificationData(JSON_DICT_RECEIVED_FROM_ZRU)
is_paid = notification_data.is_status_done   # Check if payment is completed
print('Notification Payment Status:', is_paid)
transaction = notification_data.transaction  # Get the transaction details
sale = notification_data.sale                # Get the sale details

Handling Exceptions

from zru.errors import InvalidRequestError

# Example of incorrect data
shipping = zru.Shipping({
    "name": "Normal shipping",
    "price": "text"  # Price must be a number
})

try:
    shipping.save()
except InvalidRequestError as e:
    print("Error:", e._message)      # Status code of the error
    print("Details:", e.json_body)   # JSON response from the server
    print("Resource:", e.resource)   # The resource involved in the error
    print("Resource ID:", e.resource_id)  # The resource ID that caused the error

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.1.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

zru_python-1.0.1-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zru_python-1.0.1.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for zru_python-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9132b9a5a3806ee205cd421cece0fb0f8ac0f682e4dd16c0d035ab147c169d54
MD5 c66606fb351bcb8e6179b986058bb150
BLAKE2b-256 93af320159397f68bd2bfe131494a87ce8f156d7ed850694545ab7fe7880e43f

See more details on using hashes here.

File details

Details for the file zru_python-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: zru_python-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for zru_python-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2c1d2316ccac7049daa1b09f18bc084842f1c2f8ef977de68701e6911bb61aaf
MD5 6a6c7a685962bd1aecb0d26aa25f734d
BLAKE2b-256 ab0172e9604f9f5dd95398844f3f8c825c5979389de3d7f3adc9978adcac2a03

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