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

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.1.tar.gz (53.7 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.1-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mvola_api_lib-1.0.1.tar.gz
  • Upload date:
  • Size: 53.7 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.1.tar.gz
Algorithm Hash digest
SHA256 84d5ede5a7cb3e230e638ba60b187e0d32d6a2a5d453be00c5bafce484994811
MD5 e8de0ee7cc02f844cc0dc2835796e18b
BLAKE2b-256 ab6c731d4f244c5e9a07e61c223720199a374b2b6f6b510f32053e61f38d002a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mvola_api_lib-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dae2575a2ba0d86d22e704337ebec9c209f9a9c937cf4979d36955f607763b73
MD5 08a91468445377bd3b9a742e2169eae3
BLAKE2b-256 9974d08a5a8a8df0739a8e0a3510e9055896d4533f8ab9808565b1d834f162ee

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