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 cptpayment 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 cptpayment 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 cptpayment 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cptpayment-1.0.1.tar.gz.
File metadata
- Download URL: cptpayment-1.0.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fa6c1ff64f4319598f908666fd250ca8dd9efd7e00b2821b95216bb84bdf7f6
|
|
| MD5 |
169694bdbc187a9eac79fe4f32e48edc
|
|
| BLAKE2b-256 |
dc0b3e928587f517e5a5cca968f81c4925a16881cf8d24d2c1560c88b168691a
|
File details
Details for the file cptpayment-1.0.1-py3-none-any.whl.
File metadata
- Download URL: cptpayment-1.0.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
990f2087541db87887d22a77283d69df01d5bdd7cc5f42b24457d5b2a4d55ee7
|
|
| MD5 |
631f8d8969d6250d763fdfde67bffa3a
|
|
| BLAKE2b-256 |
8fa1196cd0bb1c6a6b2636442f6aca22e63407bd185510b6a6429f9f1402fc4c
|