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()
|
||||
Reference in New Issue
Block a user