Skip to main content

codecov

FIB Payment SDK

The FIB Payment SDK provides seamless integration with the FIB payment system, empowering developers to streamline payment transactions and facilitate secure refunds within their applications.


Table of Contents


Features

  • Payment Transactions: Enable users to make payments securely through the FIB payment system.
  • Refund Processing: Process refunds securely and efficiently.
  • Payment Status Checking: Track the status of payments accurately.
  • Payment Cancellation: Cancel payments securely and easily.

Installation

Install the SDK using pip:

pip install fib-python-payment-sdk

Alternative Installation (Without pip)

You can clone the repository and manually include the SDK in your project:

git clone https://github.com/First-Iraqi-Bank/fib-python-payment-sdk.git

Ensure to include the SDK directory in your Python path.


Configuration

Set the following environment variables to configure the SDK:

  • FIB_API_KEY: Your FIB payment API key.
  • FIB_API_SECRET: Your FIB payment API secret.
  • FIB_BASE_URL: Base URL for the FIB payment API.
  • FIB_GRANT_TYPE: Authentication grant type (default: client_credentials).
  • FIB_REFUNDABLE_FOR: Transaction refund period (default: P7D).
  • FIB_CURRENCY: Transaction currency (default: IQD).
  • FIB_CALLBACK_URL: Callback URL for handling payment notifications.

Usage of the SDK

Below is a basic example of how to use the SDK to handle payment operations directly within your application.

Payment Operations Example

This example demonstrates how to perform common payment operations, including creating a payment, checking its status, issuing a refund, and canceling a payment.

  1. Setup Environment Variables: Ensure you have loaded the necessary environment variables for the SDK.

    from dotenv import load_dotenv
    import os
    
    # Load environment variables from the .env file
    load_dotenv()
    
  2. Full example: Below is a full example of how to use the SDK to handle payment operations:

    import asyncio
    from fib_payments import FIBPaymentsClient, FIBConfig, APIError
    
    async def main():
        config = FIBConfig(
            base_url="https://fib.dev.fib.iq",
            client_id="your token",
            client_secret="your secret"
        )
    
        # or config = FIBConfig()
       async with FIBPaymentsClient(config) as client:
         try:
             # Create a payment
             payment = await client.create_payment(100.00, currency="USD", callback_url="https://example.com/callback", description="Test payment", redirect_uri="https://example.com/redirect")
    
             payment_details = {
                'fib_payment_id': payment['paymentId'],
                'readable_code': payment['readableCode'],
                'personal_app_link': payment['personalAppLink'],
                'valid_until': payment['validUntil'],
            }
             print(f"Payment created: {payment_details}")
    
             # Check payment status
             status = await client.get_payment_status(payment['paymentId'])
             print(f"Payment status: {status}")
    
             # Refund the payment
             refund = await client.refund_payment(payment['paymentId'])
             print(f"Refund initiated: {refund}")
    
         except APIError as e:
             print(f"An API error occurred: {str(e)}")
    

Documentation

For more detailed documentation, refer to the FIB Online Payment API Documentation.


Testing

Run the SDK tests using unittest:

python -m unittest discover -s tests -p 'test_*.py'

Run a specific test case:

python -m unittest tests.test_module.TestClassName

Run a specific test method:

python -m unittest tests.test_module.TestClassName.test_method_name

To run tests with custom formatting, use:

python test.py

Contributing

Contributions are welcome! Please refer to the CONTRIBUTING.md for guidelines.


License

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


Support

For support, contact support@fib-payment.com.


Acknowledgments

Thanks to the FIB Payment development team and the requests library.


Versioning

We follow Semantic Versioning for releases.


FAQ

Q: How do I get an API key for the FIB Payment system?

A: Contact support@fib-payment.com to request an API key.

Q: Can I use this SDK in production?

A: Yes, but ensure it is correctly configured and tested for your environment.

Metadata

Release files for fib-python-payment-sdk 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fib-python-payment-sdk 0.4.0
File Size Uploaded
fib-python-payment-sdk-0.4.0.tar.gz 10.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fib-python-payment-sdk 0.4.0
File Interpreter ABI Platform
fib_python_payment_sdk-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.2 kB

Release files / fib-python-payment-sdk-0.4.0.tar.gz

Download URL fib-python-payment-sdk-0.4.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b6886fbc26e0ea9caa3abc31abcca30d9daf324c6076b39c6df1696be822a50e
BLAKE2b-256 checksum
How to use checksums
9f0f3e1b71eced4544e2d76dfbe6c52bf650c5a0efb881c19b83af0cbbccc258
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.18

Release files / fib_python_payment_sdk-0.4.0-py3-none-any.whl

Download URL fib_python_payment_sdk-0.4.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d8ce4d0622841ef55fe503a320afbe8a68109afe69432c3c5340b5c08aab4dd
BLAKE2b-256 checksum
How to use checksums
836865e29e1b71a8451c9b06e7960f8cca36b5b389ba426bb2d08c2e355b1517
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.18

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page