Initial Python SDK release v1.0.0
This commit is contained in:
51
examples/basic.py
Normal file
51
examples/basic.py
Normal file
@@ -0,0 +1,51 @@
|
||||
"""
|
||||
FetcherPay Python SDK - Basic Example
|
||||
"""
|
||||
|
||||
import os
|
||||
from fetcherpay import FetcherPay
|
||||
|
||||
# Initialize client
|
||||
client = FetcherPay(
|
||||
api_key=os.environ.get('FETCHERPAY_API_KEY', 'sandbox'),
|
||||
environment='sandbox'
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
# Create a payment
|
||||
print('Creating payment...')
|
||||
payment = client.payments.create(
|
||||
amount=10000, # $100.00 in cents
|
||||
currency='USD',
|
||||
source={'payment_method_id': 'pm_bank_123'},
|
||||
destination={'payment_method_id': 'pm_merchant_456'},
|
||||
rail='auto'
|
||||
)
|
||||
print(f'Payment created: {payment["id"]} Status: {payment["status"]}')
|
||||
|
||||
# Retrieve the payment
|
||||
print('\nRetrieving payment...')
|
||||
retrieved = client.payments.retrieve(payment['id'])
|
||||
print(f'Retrieved: {retrieved["id"]} Timeline: {len(retrieved["timeline"])} events')
|
||||
|
||||
# List payments
|
||||
print('\nListing payments...')
|
||||
payments = client.payments.list(limit=5)
|
||||
print(f'Found {len(payments["data"])} payments')
|
||||
|
||||
# List ledger accounts
|
||||
print('\nListing ledger accounts...')
|
||||
accounts = client.ledger.list_accounts()
|
||||
print(f'Found {len(accounts["data"])} accounts')
|
||||
for acc in accounts['data']:
|
||||
print(f' - {acc["name"]}: ${acc["balance"]["available"] / 100} available')
|
||||
|
||||
except Exception as e:
|
||||
print(f'Error: {e}')
|
||||
raise
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
41
examples/webhook_verification.py
Normal file
41
examples/webhook_verification.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""
|
||||
FetcherPay Python SDK - Webhook Verification Example
|
||||
"""
|
||||
|
||||
import json
|
||||
from fetcherpay import FetcherPay
|
||||
|
||||
# Initialize client
|
||||
client = FetcherPay(
|
||||
api_key='sandbox',
|
||||
environment='sandbox'
|
||||
)
|
||||
|
||||
# Example webhook payload
|
||||
payload = json.dumps({
|
||||
'id': 'evt_123',
|
||||
'type': 'payment.settled',
|
||||
'created_at': '2026-02-18T20:00:00Z',
|
||||
'data': {
|
||||
'id': 'pay_456',
|
||||
'status': 'settled',
|
||||
'amount': 10000
|
||||
}
|
||||
})
|
||||
|
||||
# Your webhook secret from the dashboard
|
||||
webhook_secret = 'whsec_your_secret_here'
|
||||
|
||||
# Simulate receiving a webhook
|
||||
signature = 'sha256=...' # From X-FetcherPay-Signature header
|
||||
|
||||
# Verify the signature
|
||||
is_valid = client.verify_webhook_signature(payload, signature, webhook_secret)
|
||||
|
||||
if is_valid:
|
||||
print('✅ Webhook signature verified')
|
||||
# Process the webhook event
|
||||
event = json.loads(payload)
|
||||
print(f'Event type: {event["type"]}')
|
||||
else:
|
||||
print('❌ Invalid webhook signature')
|
||||
Reference in New Issue
Block a user