Skip to main content

CPTPayment SDK for Python

Project description

cptpayment

Official CPTPayment SDK for Python

Installation

pip install cptpayment

Or install from source:

pip install -e .

Quick Start

from cpt import CPTPayment

cpt = CPTPayment('your-api-key')

# Test connection
auth = cpt.auth_test()
print(f"Store ID: {auth['store_id']}")

# Create an order
order = cpt.create_order(
    order_id='ORDER_123',
    price_amount=29.99,
    price_currency='USD',
    title='Product Name',
    description='Product description',
    success_url='https://yourstore.com/success',
    cancel_url='https://yourstore.com/cancel',
)

# Get checkout URL for redirect
checkout_url = cpt.get_checkout_url(order['order_id'], order['store_id'])
# Redirect user to: checkout_url

API Reference

Constructor

cpt = CPTPayment(
    api_key='your-api-key',
    base_url='https://api.cptpayment.com'  # optional
)

Methods

auth_test()

Test API connection and get store info.

auth = cpt.auth_test()
# Returns: {'status', 'store_id', 'mode', 'credits'}

create_order(...)

Create an order on CPTPayment.

order = cpt.create_order(
    order_id='ORDER_123',
    price_amount=29.99,
    price_currency='USD',
    success_url='https://yourstore.com/success',
    cancel_url='https://yourstore.com/cancel',
    purchaser_email='customer@example.com',  # optional
    description='Order description',          # optional
    title='Order title',                      # optional
)
# Returns: {'order_id', 'store_id', 'status', 'invoice', 'payment_url'}

get_order_status(order_id)

Get order status.

status = cpt.get_order_status('ORDER_123')
# Returns: {'order_id', 'status', 'invoice'}

get_checkout_url(order_id, store_id)

Generate checkout URL for redirect flow.

url = cpt.get_checkout_url('ORDER_123', 42)
# Returns: 'https://cptpayment.com/checkout/?plugins=1&order_id=ORDER_123&store_id=42'

verify_webhook(payload, signature)

Verify webhook signature.

is_valid = cpt.verify_webhook(request.json, request.headers.get('X-Signature'))

Advanced Methods (Custom UI)

get_wallets(order_id, store_id, reservation_id=None)

Get available wallets for an order.

create_invoice(...)

Create an invoice after wallet selection.

get_invoice_status(invoice_id)

Get invoice status for polling.

Error Handling

from cpt import CPTPayment, CPTError, CPTAuthError

try:
    order = cpt.create_order(...)
except CPTAuthError:
    print('Invalid API key')
except CPTError as e:
    print(f'API Error: {e.message} (status: {e.status_code})')

Flask Example

from flask import Flask, request, jsonify
from cpt import CPTPayment
import os

app = Flask(__name__)
cpt = CPTPayment(os.environ['CPT_API_KEY'])

@app.route('/checkout', methods=['POST'])
def checkout():
    data = request.json

    order = cpt.create_order(
        order_id=f"ORDER_{data['product_id']}",
        price_amount=data['price'],
        price_currency='USD',
        title=data['product_name'],
        success_url='http://localhost:5000/success',
        cancel_url='http://localhost:5000/cancel',
    )

    checkout_url = cpt.get_checkout_url(order['order_id'], order['store_id'])
    return jsonify({'checkout_url': checkout_url})

@app.route('/webhook', methods=['POST'])
def webhook():
    payload = request.json

    if payload.get('status') == 'paid':
        print(f"Payment confirmed for order: {payload.get('order_id')}")
        # Fulfill order here

    return jsonify({'status': 'received'})

License

MIT

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

cptpayment-1.0.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

cptpayment-1.0.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file cptpayment-1.0.0.tar.gz.

File metadata

  • Download URL: cptpayment-1.0.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for cptpayment-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4d815efcf5c05d73b39f57ee7feb3087dcf457703c36493c74ed56607a7a6f37
MD5 0793001474dfff4d470f49955cc42640
BLAKE2b-256 4ae3f53bdc9c460d71377c61b6976f18e73e66248722ac591402d99525f3f0cc

See more details on using hashes here.

File details

Details for the file cptpayment-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cptpayment-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for cptpayment-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 194236c44f374cf0fc97f75a9cecabf5da4f415156f0a6d6653b4ffaa15f3bc2
MD5 82f0e41e6a0067eea77dd56ce930c1d7
BLAKE2b-256 643ece3f64c9d9e41bb3c3d99831dd4cb2640007f4c40208c16b818c9f529a51

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