FetcherPay Python SDK
Project description
FetcherPay Python SDK
Official Python SDK for the FetcherPay API — One API. Every Rail.
Installation
pip install fetcherpay
Quick Start
from fetcherpay import FetcherPay
client = FetcherPay(
api_key='fp_test_your_key',
environment='sandbox' # or 'production'
)
# Create a payment
payment = client.payments.create(
amount=10000, # $100.00 in cents
currency='USD',
source={'payment_method_id': 'pm_123'},
destination={'payment_method_id': 'pm_456'},
rail='auto' # Auto-select optimal rail
)
print(payment['id'], payment['status'])
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
api_key |
str | required | Your FetcherPay API key |
environment |
str | 'sandbox' | 'sandbox' or 'production' |
base_url |
str | auto | Override base URL |
timeout |
int | 30 | Request timeout (seconds) |
API Reference
Payments
# Create payment
payment = client.payments.create(
amount=10000,
source={'payment_method_id': 'pm_123'},
destination={'payment_method_id': 'pm_456'},
idempotency_key='unique-key'
)
# Retrieve payment
payment = client.payments.retrieve('pay_xxx')
# List payments
payments = client.payments.list(limit=10)
# Cancel payment
client.payments.cancel('pay_xxx', reason='Customer request')
# Refund payment
client.payments.refund('pay_xxx', amount=5000, reason='Partial refund')
Ledger
# List accounts
accounts = client.ledger.list_accounts()
# Get account balance
account = client.ledger.retrieve_account('la_xxx')
print(account['balance']['available'])
# List entries
entries = client.ledger.list_entries(account_id='la_xxx')
Payment Methods
# Create bank account
pm = client.payment_methods.create(
type='bank_account',
bank_account={
'account_number': '000123456789',
'routing_number': '011000015',
'account_type': 'checking'
}
)
# List payment methods
methods = client.payment_methods.list()
Webhooks
# Create webhook endpoint
webhook = client.webhooks.create(
url='https://your-app.com/webhooks',
events=['payment.settled', 'payment.failed']
)
# Verify webhook signature
is_valid = client.verify_webhook_signature(
payload,
signature, # from X-FetcherPay-Signature header
webhook['secret']
)
Error Handling
from fetcherpay import (
FetcherPayError,
AuthenticationError,
ValidationError,
NotFoundError
)
try:
client.payments.create(...)
except AuthenticationError:
print('Invalid API key')
except ValidationError as e:
print(f'Validation failed: {e.param}')
except FetcherPayError as e:
print(f'API error: {e.type} ({e.status_code})')
Webhook Verification
import json
# In your webhook handler
def handle_webhook(request):
payload = request.body
signature = request.headers.get('X-FetcherPay-Signature')
secret = 'whsec_your_webhook_secret'
if client.verify_webhook_signature(payload, signature, secret):
event = json.loads(payload)
if event['type'] == 'payment.settled':
handle_payment_settled(event['data'])
return 'OK', 200
else:
return 'Invalid signature', 401
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
fetcherpay-1.0.0.tar.gz
(8.3 kB
view details)
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 fetcherpay-1.0.0.tar.gz.
File metadata
- Download URL: fetcherpay-1.0.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b075be4e8db2ecaab57a77c0d8197fd2d9ce1a7ea974c33d9baa7b63f8417d08
|
|
| MD5 |
f05d573414325435b1c042d131ad2c6c
|
|
| BLAKE2b-256 |
a249be98a4eb0859b743eb0334db8f36d6ba7cf836f42b361ae658d132d21ac1
|
File details
Details for the file fetcherpay-1.0.0-py3-none-any.whl.
File metadata
- Download URL: fetcherpay-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1877cf833b323e3e1458cceeef2f635c786142b6a620ae621681fe482d0a6919
|
|
| MD5 |
4b60f049a7743bc5d6d47c377b544d7c
|
|
| BLAKE2b-256 |
81244906cd8d788817da251c1dfaa663099777efbaabdbaa2794f1d54fb0d863
|