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

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 clone https://github.com/yourusername/mvola_api.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.0.tar.gz (53.9 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.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mvola_api_lib-1.0.0.tar.gz
  • Upload date:
  • Size: 53.9 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.0.tar.gz
Algorithm Hash digest
SHA256 ca21d97a59fc239e96c4e02867f878c1ff7d7e198fe33e7c97133eb5934d8418
MD5 3e061f251ea40ffae07b2e79a5cab419
BLAKE2b-256 f1215e64f09ab386f570316866aa8534aa3801b42376d3aa606b679681394019

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mvola_api_lib-1.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f6161925379f52c7e67bcc3771f31b4db42ce8f3fa88ede69edab7932e95f3b
MD5 da2e267f1d9b2f646da074c5891adc97
BLAKE2b-256 722096e44d06576c343a96ffd230e3e97f195608dfdc5085f7d9612a2ac958a3

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