Skip to main content

Une bibliothèque Python robuste pour l'intégration de l'API de paiement MVola

Project description

MVola API Python Library

A robust Python library for integrating with MVola mobile payment API in Madagascar.

Installation

 pip install mvola-api-lib

Documentation

La documentation complète de l'API est disponible dans docs/documentation.md.

Pour consulter la documentation en ligne, visitez https://niainarisoa01.github.io/Mvlola_API_Lib/documentation/

Features

  • Simple and intuitive API for MVola payment integration
  • Handles authentication token generation and management
  • Supports merchant payment operations
  • Comprehensive error handling
  • Logging support
  • Built-in parameter validation
  • Works with both sandbox and production environments

Quick Start

from mvola_api import MVolaClient, SANDBOX_URL

# Initialize the client
client = MVolaClient(
    consumer_key="your_consumer_key",
    consumer_secret="your_consumer_secret",
    partner_name="Your Application Name",
    partner_msisdn="0340000000",  # Your merchant number
    sandbox=True  # Use sandbox environment
)

# Generate a token
token_data = client.generate_token()
print(f"Token generated: {token_data['access_token'][:10]}...")

# Initiate a payment
result = client.initiate_payment(
    amount=10000,
    debit_msisdn="0343500003",  # Customer phone number
    credit_msisdn="0343500004",  # Merchant phone number
    description="Payment for service",
    callback_url="https://example.com/callback"
)

# Track the server correlation ID for status checks
server_correlation_id = result['response']['serverCorrelationId']
print(f"Transaction initiated with correlation ID: {server_correlation_id}")

# Check transaction status
status = client.get_transaction_status(server_correlation_id)
print(f"Transaction status: {status['response']['status']}")

# Once transaction is completed, get details using transaction ID
transaction_id = status['response'].get('objectReference')
if transaction_id:
    details = client.get_transaction_details(transaction_id)
    print(f"Transaction details: {details['response']}")

Sandbox Testing

For sandbox testing, use the following test phone numbers:

  • 0343500003
  • 0343500004

Error Handling

The library provides custom exceptions for different error types:

from mvola_api import MVolaClient, MVolaError, MVolaAuthError, MVolaTransactionError

client = MVolaClient(...)

try:
    result = client.initiate_payment(...)
except MVolaAuthError as e:
    print(f"Authentication error: {e}")
except MVolaTransactionError as e:
    print(f"Transaction error: {e}")
except MVolaError as e:
    print(f"General MVola error: {e}")

API Documentation

MVolaClient

The main client class for interacting with MVola API.

Initialization

client = MVolaClient(
    consumer_key,          # Consumer key from MVola Developer Portal
    consumer_secret,       # Consumer secret from MVola Developer Portal
    partner_name,          # Your application/merchant name
    partner_msisdn=None,   # Partner MSISDN (phone number)
    sandbox=True,          # Use sandbox environment
    logger=None            # Custom logger
)

Methods

  • generate_token(force_refresh=False): Generate an access token
  • initiate_payment(amount, debit_msisdn, credit_msisdn, description, ...): Initiate a merchant payment
  • get_transaction_status(server_correlation_id, user_language="FR"): Get transaction status
  • get_transaction_details(transaction_id, user_language="FR"): Get transaction details

Best Practices

  1. Token Management: The library handles token refresh automatically, but you can force a refresh if needed.
  2. Error Handling: Always implement proper error handling in your application.
  3. Logging: The library includes logging, but you can provide your own logger.
  4. Sandbox Testing: Always test your integration in the sandbox environment before going live.
  5. Webhook Handling: Implement proper webhook handling for transaction notifications.

Development

Requirements

  • Python 3.6+
  • requests library

Installation for Development

git https://github.com/Niainarisoa01/Mvlola_API_Lib.git
cd mvola_api
pip install -e .

License

MIT

Credits

Developed based on the official MVola API documentation.

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

mvola_api_lib-1.0.2.tar.gz (312.5 kB view details)

Uploaded Source

Built Distribution

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

mvola_api_lib-1.0.2-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file mvola_api_lib-1.0.2.tar.gz.

File metadata

  • Download URL: mvola_api_lib-1.0.2.tar.gz
  • Upload date:
  • Size: 312.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for mvola_api_lib-1.0.2.tar.gz
Algorithm Hash digest
SHA256 0fd96356339cec287ef582cd5cc15599c390c922fff364054749065750289155
MD5 f1f08f684b9ac008301d9e6bf58037b1
BLAKE2b-256 18e40add12e821429f21b469fa190d2d9c429e77ec85808978239c76ae12fc3e

See more details on using hashes here.

File details

Details for the file mvola_api_lib-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: mvola_api_lib-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for mvola_api_lib-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e83906bc2f752e1fe563cdbca6070a4f530d7a8e7dbb84e8c9ce474bdd51bab3
MD5 14230d197351e225a45ae75139ab82a4
BLAKE2b-256 5686fa70c92e151aa8830c15d42e4236a7780f007274eb0a563beb90ac7a231e

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