Skip to main content

A Python client for the Mokafaa loyalty API

Project description

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:

  1. Fetch OAuth Token: Obtain an access token using client credentials.
  2. Authorize a Customer: Validate and register a customer's mobile number.
  3. Redeem Loyalty Points: Process loyalty point redemptions using OTP-based verification.
  4. 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:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Commit your changes and push to your fork.
  4. Submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Links


---

### 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.


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

mokafaa_client-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

mokafaa_client-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file mokafaa_client-0.1.0.tar.gz.

File metadata

  • Download URL: mokafaa_client-0.1.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for mokafaa_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d87b37645c79f5d79de2c836dda2100da594799150faa1f862b428d74bb8aa67
MD5 ee4c6264d553d95aa6fa8fbe40cbcf74
BLAKE2b-256 e02aba2da78eef1a2f61b1fbe340292375432b783c74568dc17a8cdaca9e4870

See more details on using hashes here.

File details

Details for the file mokafaa_client-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mokafaa_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for mokafaa_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22d36dbb51fbf99c1202139263835521af895bd77d196624c3370eb70ba4e424
MD5 47d5e4c3f1c0affc2e221e33fa99e0bd
BLAKE2b-256 4a3d7bfd631e6606e95e6064fec5f012b0132bc43620dfa0fc7909295a782b61

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