Prerequisites
- A Macropay account with an organization
- Python 3.9+
- An Organization Access Token
We recommend using the Sandbox environment for this guide
so you can test without processing real payments.
Step 1: Install the SDK
Step 2: Initialize the Client
Step 3: Create a Checkout Session
Create a product in the dashboard first, then generate a checkout session programmatically:Step 4: Handle Webhooks
Set up a webhook endpoint to process payment events. Here is a complete FastAPI example with signature verification:Step 5: Query Orders and Subscriptions
Once payments are flowing, query your data:Step 6: Test with Sandbox
- Create a checkout session and open the returned URL
- Use the test card
4242 4242 4242 4242with any future expiry and any CVC - Complete the purchase
- Verify the webhook fires in your terminal
- Replace your sandbox access token with a production token
- Change
server="sandbox"toserver="production"(or remove it entirely) - Update your webhook endpoint URL to your production domain
- API base URL changes from
sandbox-api.macropay.comtoapi.macropay.com
What’s Next?
AI/LLM Billing
Bill customers based on AI model usage
Webhook Events
See all available webhook event types
Python SDK Reference
Full SDK documentation
Customer Portal
Let customers manage their subscriptions