Skip to main content

NETOPIA Payments Python SDK for integration with the NETOPIA Payments API v2.

Project description

NETOPIA SDK Publish

NETOPIA Payments Python SDK

The NETOPIA Payments Python SDK provides seamless integration with the NETOPIA Payments API v2. It allows developers to handle payments, IPN verification, and status retrieval efficiently within their Python applications.


Table of Contents


Dependencies

  • requests
  • pyjwt

Features

  • Start a payment with customer details, products, and billing/shipping data.
  • Retrieve the status of an order.
  • Verify 3D Secure authentications.
  • Validate IPNs (Instant Payment Notifications) for order updates.
  • Compatible with both Sandbox and Live environments.

Installation

You can install the SDK from PyPI Test or PyPI, or by cloning this repository.:

Install the SDK from the PyPI Test repository (unstable, only for test purpose):

pip install -i https://test.pypi.org/simple/ netopia-sdk

Install the SDK from the PyPI repository (recommended):

pip install netopia-sdk

Alternatively, clone this repository and install the dependencies:

git clone https://github.com/netopiapayments/python-sdk
pip install -r requirements.txt

You can also add the SDK to your project by copying the netopia_sdk folder to your project directory.


Getting Started

Initialization

from netopia_sdk.config import Config
from netopia_sdk.client import PaymentClient
from netopia_sdk.payment import PaymentService

config = Config(
    api_key="your-api-key",
    pos_signature="your-pos-signature",
    is_live=False,  # True = production, False = sandbox
    notify_url="https://yourdomain.com/ipn",
    redirect_url="https://yourdomain.com/redirect",
    public_key_str="-----BEGIN PUBLIC KEY-----....-----END PUBLIC KEY-----",
    pos_signature_set=["your-pos-signature"],
)

client = PaymentClient(config)
payment_service = PaymentService(client)

Configuration

The Config class contains the following fields:

Field Type Required Description
api_key string Yes API key generated in NETOPIA's admin panel
pos_signature string Yes POS Signature for your NETOPIA account
is_live bool No Whether to use the live environment or sandbox
notify_url string Yes The URL where IPNs (order updates) will be sent
redirect_url string Yes The URL to redirect the customer after payment
public_key_str string Yes RSA public key provided by NETOPIA for verification
pos_signature_set list Yes List of allowed POS Signatures

API Reference

PaymentService Methods

StartPayment

Initiates a payment transaction.

from netopia_sdk.requests.models import (
    StartPaymentRequest, ConfigData, PaymentData, PaymentOptions, Instrument,
    OrderData, BillingData, ProductsData,
)

start_payment_request = StartPaymentRequest(
    config=ConfigData(
        emailTemplate="default",
        emailSubject="Order Confirmation",
        cancelUrl="https://yourdomain.com/cancel",
        notifyUrl=config.notify_url,
        redirectUrl=config.redirect_url,
        language="ro",
    ),
    payment=PaymentData(
        options=PaymentOptions(installments=1, bonus=0),
        instrument=Instrument(
            type="card",
            account="4111111111111111",
            expMonth=12,
            expYear=2025,
            secretCode="123",
        ),
    ),
    order=OrderData(
        orderID="R12345",
        amount=100.0,
        currency="RON",
        description="Test Order",
        billing=BillingData(
            email="customer@example.com",
            phone="1234567890",
            firstName="John",
            lastName="Doe",
            city="Bucharest",
            country=642,
        ),
        products=[
            ProductsData(name="Product1", code="P001", category="Category1", price=100.0, vat=0),
        ],
    ),
)

response = payment_service.start_payment(start_payment_request)
print("Start Payment Response:", response)

Note: If the instrument is set to None, NETOPIA will handle the payment processing.

if the instrument is set with card details, it is mandatory for the site to implement the PCI DSS (Payment Card Industry Data Security Standard).


GetStatus

Retrieves the status of an order.

response = payment_service.get_status(ntpID="ntpID-123456", orderID="orderID-12345")
print("Order Status Response:", response)

VerifyAuth

Handles 3D Secure verification for transactions.

response = payment_service.verify_auth(
    authenticationToken="authToken123",
    ntpID="ntpID-123456",
    formData={"paRes": "paResData"},
)
print("VerifyAuth Response:", response)

IPN Verification

Validates the authenticity and integrity of IPNs.

from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route("/ipn", methods=["POST"])
def ipn_handler():
    try:
        result = payment_service.verify_ipn(request.data)
        return jsonify({"message": "IPN verified", "data": result}), 200
    except Exception as e:
        return jsonify({"error": str(e)}), 400

Error Handling

The SDK provides structured error handling with pre-defined error classes. Common errors include:

Error Name Description
MissingAPIKeyError API Key is not provided.
InvalidPublicKeyError The provided public key is invalid.
InvalidIssuerError JWT token issuer (iss) is not "NETOPIA Payments".
PayloadHashMismatchError Hash of the payload does not match sub in the JWT.
InvalidTokenError The JWT token is invalid.

Example:

try:
    response = payment_service.get_status(ntpID="ntpID-123456", orderID="orderID-12345")
except MissingAPIKeyError:
    print("API Key is missing!")
except Exception as e:
    print("An error occurred:", str(e))

Examples

To see examples in action, check out demo.py in the repository for a detailed playground.


Useful Links


License

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

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

netopia_sdk-2.1.1.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

netopia_sdk-2.1.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file netopia_sdk-2.1.1.tar.gz.

File metadata

  • Download URL: netopia_sdk-2.1.1.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for netopia_sdk-2.1.1.tar.gz
Algorithm Hash digest
SHA256 f4c7ef4e56cb9ea0c58789cd6bae7703e5aa0cac0965c6218cb87f5ab3a1be10
MD5 47ff8f219a894b2136545b1bf02080e2
BLAKE2b-256 f8f0477d4653d3033d892613868865d70ab7598bb7d8a580cdad0432ae7120e5

See more details on using hashes here.

File details

Details for the file netopia_sdk-2.1.1-py3-none-any.whl.

File metadata

  • Download URL: netopia_sdk-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for netopia_sdk-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8453ebf1ce08320aee0c4e347991d4aca0e40fdcaceedcb2067fe77e4914ac6d
MD5 a156d77f66c72ab0819a58244faaee5b
BLAKE2b-256 774dd3bb886e0928a85da44faef815dc335985448b3fbbcd834f90d42528f48d

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