FuturaPay Payment Gateway Integration Guide for Core Python

This guide provides step-by-step instructions on integrating the FuturaPay payment gateway using Python. You will learn how to initialize a payment request using FuturaPay's SDK and process transactions.


 

Prerequisites

  1. Python Installation: Ensure you have Python installed on your system.
  2. FuturaPay SDK: You should have the FuturaPay SDK package installed. If not, install it using:
  3. Merchant Credentials: Obtain the following details from your FuturaPay account:
    • MerchantKey: Your unique merchant key.
    • apiKey: The API key provided for accessing FuturaPay services.
    • siteID: The site ID associated with your FuturaPay account.

Installation

Install the FuturaPay SDK if you haven’t already done so:

pip install Futurapay

 

Integration Steps

Step 1: Setting Up Your Merchant Details

You need to define your merchant credentials. These include merchant_key, api_key, and site_id.

# Merchant details
merchant_key = "YOUR_MERCHANT_KEY" # Replace with your actual Merchant Key
site_id = "YOUR_SITE_ID"           # Replace with your actual Site ID
api_key = "YOUR_API_KEY"           # Replace with your actual API Key

Step 2: Creating the Payment Payload

The payment payload contains the details of the transaction. Below is an example of how to set up a payment payload:

from random import randint
payment_payload = {
    "currency": "XAF",                             # The currency code for the transaction
    "amount": "50000",                             # Transaction amount
    "customer_transaction_id": randint(10000000, 99999999), # Unique ID for each transaction
    "country_code": "CM",                          # Country code (e.g., 'CM' for Cameroon)
    "customer_first_name": "Tanmoy",               # Customer's first name
    "customer_last_name": "Sharma",                # Customer's last name
    "customer_phone": "8617821668",                # Customer's phone number
    "customer_email": "rohitk.techexactly@gmail.com" # Customer's email address
}

 

Step 3: Initializing the FuturaPay Payment

Once you have the merchant details and payment payload set up, you can initialize a payment request.

from Futurapay import FuturaPay
# Initialize FuturaPay
futurapay = FuturaPay(
    merchant_key=merchant_key,
    api_key=api_key,
    site_id=site_id
)
# Make a payment request
futurapay.initialize(payment_payload=payment_payload)

 


 

Example Code

Here is a complete example demonstrating how to integrate the FuturaPay payment gateway:

from Futurapay import FuturaPay
from random import randint
# Payment payload
payment_payload = {
    "currency": "XAF",
    "amount": "50000",
    "customer_transaction_id": randint(10000000, 99999999),
    "country_code": "CM",
    "customer_first_name": "Tanmoy",
    "customer_last_name": "Sharma",
    "customer_phone": "8617821668",
    "customer_email": "rohitk.techexactly@gmail.com"
}
# Merchant details
merchant_key = "YOUR_MERCHANT_KEY"
site_id = "YOUR_SITE_ID"
api_key = "YOUR_API_KEY"
# Initialize FuturaPay
futurapay = FuturaPay(
    merchant_key=merchant_key,
    api_key=api_key,
    site_id=site_id
)
# Make a payment request
futurapay.set_env("sandbox")  #when you have go in live update thie parameter with "live"
futurapay.set_type("withdraw") #you change the parameter according the requirement lke "deposit" or "withdraw"
response = futurapay.initialize(payment_payload=payment_payload)


 

Important Notes

  • Keep Your API Credentials Secure: Do not share your merchant_key, api_key, or site_id publicly.
  • Error Handling: Make sure to handle any exceptions or errors during the payment initialization process.
  • Transaction ID: Each transaction should have a unique customer_transaction_id to avoid conflicts.

Payment Payload Parameters

ParameterTypeDescription
currencyStringCurrency code for the transaction, e.g., XAF.
amountStringThe amount to be charged.
customer_transaction_idIntegerA unique ID for the customer's transaction.
country_codeStringThe ISO country code, e.g., CM for Cameroon.
customer_first_nameStringThe customer's first name.
customer_last_nameStringThe customer's last name.
customer_phoneStringThe customer's phone number.
customer_emailStringThe customer's email address.

 

Merchant Details

You will need the following details:

  • MerchantKey: Your unique merchant key assigned by FuturaPay.
  • apiKey: The API key for accessing FuturaPay's services.
  • siteID: The site ID associated with your FuturaPay account.

 


 

FuturaPay Payment Gateway Integration – Django

This documentation guides you through integrating the FuturaPay payment gateway in a Django project. The integration involves using the FuturaPay SDK to initialize payments with merchant_key, api_key, site_id, and the transaction payload.

 

Prerequisites

  1. Python Installation: Ensure you have Python installed on your system.
  2. FuturaPay SDK: You should have the FuturaPay SDK package installed. If not, install it using:
  3. Merchant Credentials: Obtain the following details from your FuturaPay account:
    • MerchantKey: Your unique merchant key.
    • apiKey: The API key provided for accessing FuturaPay services.
    • siteID: The site ID associated with your FuturaPay account.

 

Step-by-Step Implementation

 

1. Install Necessary Libraries

Ensure that the FuturaPay SDK is installed in your project. You can install it via pip (replace futurapay with the actual package name if necessary):

pip install futurapay

 

2. Django Project Setup

Make sure your Django project is correctly set up, with the necessary apps created.

 

3. Update settings.py with FuturaPay Credentials

In your settings.py, define your FuturaPay credentials.

# settings.py

FUTURAPAY_MERCHANT_KEY = "TMXXXXXXXXXXXXXXXX"  # Replace with your Merchant Key
FUTURAPAY_API_KEY = "apiKey66a33e22470a2"  # Replace with your API Key
FUTURAPAY_SITE_ID = "831206409"  # Replace with your Site ID

 

4. Create a View for Processing Payments

In one of your Django apps, create a view to handle the payment process. In this view, you will set up the payment payload and call the FuturaPay SDK.

# views.py

from django.conf import settings
from django.http import JsonResponse
from Futurapay import FuturaPay
from random import randint

def process_payment(request):
    # Payment payload
    payment_payload = {
        "currency": "XAF",
        "amount": "50000",
        "customer_transaction_id": randint(10000000, 99999999),
        "country_code": "CM",
        "customer_first_name": "Tanmoy",
        "customer_last_name": "Sharma",
        "customer_phone": "8617821668",
        "customer_email": "rohitk.techexactly@gmail.com",
    }

    # Merchant details from settings.py
    merchant_key = settings.FUTURAPAY_MERCHANT_KEY
    api_key = settings.FUTURAPAY_API_KEY
    site_id = settings.FUTURAPAY_SITE_ID


    # Initialize FuturaPay
    futurapay = FuturaPay(merchant_key=merchant_key, api_key=api_key, site_id=site_id)

    # Process the payment
    try:
    	futurapay.set_env("sandbox")  #when you have go in live update thie parameter with "live"
		futurapay.set_type("withdraw") #you change the parameter according the requirement lke "deposit" or "withdraw"
        response = futurapay.initialize(payment_payload=payment_payload)
        return JsonResponse({"status": "success", "data": response})
    except Exception as e:
        return JsonResponse({"status": "error", "message": str(e)})

 

5. Create a URL for the Payment View

Add a URL pattern in urls.py to map the payment view.

# urls.py

from django.urls import path
from .views import process_payment

urlpatterns = [
    path('process-payment/', process_payment, name='process_payment'),
]

 

6. Example Frontend Payment Form

You can create a simple form in your frontend that submits to the process_payment view. Here’s a basic example using HTML.

<form action="/process-payment/" method="post">
    {% csrf_token %}
    <button type="submit">Pay Now</button>
</form>

 

7. Complete Example

Here is the complete integration:

In settings.py:

 FUTURAPAY_MERCHANT_KEY = "TMXXXXXXXXXXXXXXXX"
 FUTURAPAY_API_KEY = "apiKey66a33e22470a2"
 FUTURAPAY_SITE_ID = "831206409"

 

In views.py:

 from django.conf import settings
 from django.http import JsonResponse
 from Futurapay import FuturaPay
 from random import randint

 def process_payment(request):
     payment_payload = {
         "currency": "XAF",
         "amount": "50000",
         "customer_transaction_id": randint(10000000, 99999999),
         "country_code": "CM",
         "customer_first_name": "Tanmoy",
         "customer_last_name": "Sharma",
         "customer_phone": "8617821668",
         "customer_email": "rohitk.techexactly@gmail.com",
     }

     merchant_key = settings.FUTURAPAY_MERCHANT_KEY
     api_key = settings.FUTURAPAY_API_KEY
     site_id = settings.FUTURAPAY_SITE_ID

     futurapay = FuturaPay(merchant_key=merchant_key, api_key=api_key, site_id=site_id)

     try:
   		 futurapay.set_env("sandbox")  #when you have go in live update thie parameter with "live"
		 futurapay.set_type("withdraw") #you change the parameter according the requirement lke "deposit" or "withdraw"
         response = futurapay.initialize(payment_payload=payment_payload)
         return JsonResponse({"status": "success", "data": response})
     except Exception as e:
         return JsonResponse({"status": "error", "message": str(e)})

 

In urls.py:

 from django.urls import path
 from .views import process_payment

 urlpatterns = [
     path('process-payment/', process_payment, name='process_payment'),
 ]

 

HTML Form:

 <form action="/process-payment/" method="post">
     {% csrf_token %}
     <button type="submit">Pay Now</button>
 </form>

 

Payload Parameters

  • currency: Transaction currency.
  • amount: Amount to charge in the smallest unit.
  • customer_transaction_id: Unique transaction ID.
  • country_code: Customer's country code.
  • customer_first_name: First name of the customer.
  • customer_last_name: Last name of the customer.
  • customer_phone: Phone number of the customer.
  • customer_email: Email address of the customer.

 

Merchant Credentials

  • merchant_key: Unique key provided to the merchant.
  • api_key: API key associated with FuturaPay.
  • site_id: Identifier for your site.