README.md
# Mokafaa Client
A Python client for interacting with the Mokafaa loyalty API. This library provides an easy-to-use interface for operations such as fetching OAuth tokens, authorizing customers, redeeming loyalty points, and reversing transactions.
---
## Installation
You can install the package using pip:
```bash
pip install mokafaa-client
Features
The Mokafaa Client provides the following key functionalities:
- Fetch OAuth Token: Obtain an access token using client credentials.
- Authorize a Customer: Validate and register a customer's mobile number.
- Redeem Loyalty Points: Process loyalty point redemptions using OTP-based verification.
- Reverse a Transaction: Rollback or reverse a redemption transaction.
All operations support both development (DEV) and production (PROD) environments, configured using parameters or environment variables.
Usage
The MokafaaClient can be initialized by passing parameters or by using environment variables.
Initialization
Example with Parameters:
from mokafaa_client import MokafaaClient
client = MokafaaClient(
base_url="https://api.mokafaa.com",
client_id="your-client-id",
client_secret="your-client-secret",
environment="DEV", # Use 'PROD' for production
merchant_token="your-merchant-token"
)
Example with Environment Variables:
Set the required environment variables:
export MOKAFAA_API_BASE_URL="https://api.mokafaa.com"
export MOKAFAA_CLIENT_ID="your-client-id"
export MOKAFAA_CLIENT_SECRET="your-client-secret"
export MOKAFAA_ENVIRONMENT="DEV"
export MOKAFAA_MERCHANT_TOKEN="your-merchant-token"
Then initialize:
from mokafaa_client import MokafaaClient
client = MokafaaClient()
Fetch OAuth Token
This method retrieves an access token using the provided client credentials.
token = client.get_oauth_token()
print(f"Access Token: {token}")
URLS
SIT https://gwt.alrajhibank.com.sa:9443/api-factory/sit/blu-loyalty/1.0.0
PROD https://dpw.alrajhibank.com.sa:9443/api-factory/prod/blu-loyalty/1.0.0
Authorize a Customer
Authorize a customer by their mobile number. This returns the customer's unique identifier if successful.
response = client.authorize_customer(mobile="0555555555")
print(response)
Example Response:
{
"status": "success",
"customerID": "12345"
}
Redeem Loyalty Points
Redeem loyalty points using OTP verification. You need the OTP value, OTP token, and the amount to redeem.
response = client.redeem_points(
otp_value="123456",
otp_token="otp-token",
amount=100
)
print(response)
Example Response:
{
"status": "success",
"transactionID": "txn123"
}
Reverse a Transaction
Reverse a redemption transaction using the transaction ID.
response = client.reverse_transaction(transaction_id="txn123")
print(response)
Example Response:
{
"status": "reversed"
}
Development
Running Tests
Unit tests are provided to verify the functionality of the MokafaaClient. Use the following commands to run the tests:
Using unittest:
python -m unittest discover tests
Using pytest:
pytest tests/
Contributing
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit your changes and push to your fork.
- Submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Links
- Source Code: GitHub Repository
- Issue Tracker: Report Issues
---
### Key Enhancements:
1. **Features Section**:
- Expanded explanation of available features.
- Aligned with the methods provided in `MokafaaClient`.
2. **Usage Section**:
- Detailed examples for each feature.
- Includes expected responses for better clarity.
Metadata
Release files for mokafaa-client 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mokafaa_client-0.1.0.tar.gz | 5.3 kB | Without provenance | Details for mokafaa_client-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mokafaa_client-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for mokafaa_client-0.1.0-py3-none-any.whl |
Total release size: 9.9 kB
Release files / mokafaa_client-0.1.0.tar.gz
| Download URL | mokafaa_client-0.1.0.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d87b37645c79f5d79de2c836dda2100da594799150faa1f862b428d74bb8aa67
|
|
BLAKE2b-256 checksum How to use checksums |
e02aba2da78eef1a2f61b1fbe340292375432b783c74568dc17a8cdaca9e4870
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.13.1
|
Release files / mokafaa_client-0.1.0-py3-none-any.whl
| Download URL | mokafaa_client-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
22d36dbb51fbf99c1202139263835521af895bd77d196624c3370eb70ba4e424
|
|
BLAKE2b-256 checksum How to use checksums |
4a3d7bfd631e6606e95e6064fec5f012b0132bc43620dfa0fc7909295a782b61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.13.1
|
Security for mokafaa-client 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.