Quick Start
Get started with the SafePays API in just 5 minutes
Follow this guide to make your first API call and create an invoice in just a few minutes.
Get Your API Key
- Log in to your SafePays Dashboard
- Navigate to Settings → API Keys
- Click Generate New API Key
- Copy and securely store your API key
Your API key is shown only once. Store it securely and never expose it in client-side code.
Create Your First Customer
Let's create a customer profile that we can use for invoicing:
curl -X POST https://app.safepays.com/api/customer \
-H "Content-Type: application/json" \
-d '{
"api_key": "your_api_key_here",
"name": "John Doe",
"email": "john.doe@example.com",
"preferred_currency": "USD"
}'const response = await fetch('https://app.safepays.com/api/customer', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
api_key: 'your_api_key_here',
name: 'John Doe',
email: 'john.doe@example.com',
preferred_currency: 'USD'
})
});
const customer = await response.json();
console.log('Customer ID:', customer.customer.id);import requests
import json
url = 'https://app.safepays.com/api/customer'
headers = {'Content-Type': 'application/json'}
data = {
'api_key': 'your_api_key_here',
'name': 'John Doe',
'email': 'john.doe@example.com',
'preferred_currency': 'USD'
}
response = requests.post(url, headers=headers, data=json.dumps(data))
customer = response.json()
print(f"Customer ID: {customer['customer']['id']}")Save the customer.id from the response - you'll need it for the next step.
Create Your First Invoice
Now let's create an invoice for the customer:
curl -X POST "https://app.safepays.com/api/invoice?webhook=https://your-webhook-url.com/callback" \
-H "Content-Type: application/json" \
-d '{
"api_key": "your_api_key_here",
"customer_id": "550e8400-e29b-41d4-a716-446655440000",
"currency": "USD",
"items": [
{
"name": "Product A",
"qty": 2,
"price": 50.00
}
]
}'const webhookUrl = 'https://your-webhook-url.com/callback';
const response = await fetch(`https://app.safepays.com/api/invoice?webhook=${webhookUrl}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
api_key: 'your_api_key_here',
customer_id: '550e8400-e29b-41d4-a716-446655440000',
currency: 'USD',
items: [
{
name: 'Product A',
qty: 2,
price: 50.00
}
]
})
});
const invoice = await response.json();
console.log('Payment Link:', invoice.invoice.payment_link);import requests
import json
webhook_url = 'https://your-webhook-url.com/callback'
url = f'https://app.safepays.com/api/invoice?webhook={webhook_url}'
headers = {'Content-Type': 'application/json'}
data = {
'api_key': 'your_api_key_here',
'customer_id': '550e8400-e29b-41d4-a716-446655440000',
'currency': 'USD',
'items': [
{
'name': 'Product A',
'qty': 2,
'price': 50.00
}
]
}
response = requests.post(url, headers=headers, data=json.dumps(data))
invoice = response.json()
print(f"Payment Link: {invoice['invoice']['payment_link']}")The webhook URL is required and will receive notifications when the invoice status changes.
Check Invoice Status
You can check the status of your invoice at any time:
curl -X GET "https://app.safepays.com/api/invoice/660e8400-e29b-41d4-a716-446655440001?api_key=your_api_key_here"const invoiceId = '660e8400-e29b-41d4-a716-446655440001';
const apiKey = 'your_api_key_here';
const response = await fetch(`https://app.safepays.com/api/invoice/${invoiceId}?api_key=${apiKey}`);
const invoice = await response.json();
console.log('Invoice Status:', invoice.invoice.status);import requests
invoice_id = '660e8400-e29b-41d4-a716-446655440001'
api_key = 'your_api_key_here'
url = f'https://app.safepays.com/api/invoice/{invoice_id}?api_key={api_key}'
response = requests.get(url)
invoice = response.json()
print(f"Invoice Status: {invoice['invoice']['status']}")Next Steps
Congratulations! You've successfully:
- Created a customer
- Generated an invoice
- Checked the invoice status
Here's what to explore next:
- Authentication Guide - Learn about API key security
- Customer Management - Advanced customer operations
- Invoice Management - Working with invoices
- Webhook Integration - Handle real-time notifications
- Error Handling - Handle errors gracefully
Sample Integration
Here's a complete example that ties everything together:
class SafePaysAPI {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseUrl = 'https://app.safepays.com/api';
}
async createCustomer(customerData) {
const response = await fetch(`${this.baseUrl}/customer`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
api_key: this.apiKey,
...customerData
})
});
return response.json();
}
async createInvoice(invoiceData, webhookUrl) {
const response = await fetch(`${this.baseUrl}/invoice?webhook=${webhookUrl}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
api_key: this.apiKey,
...invoiceData
})
});
return response.json();
}
async getInvoiceStatus(invoiceId) {
const response = await fetch(`${this.baseUrl}/invoice/${invoiceId}?api_key=${this.apiKey}`);
return response.json();
}
}
// Usage
const api = new SafePaysAPI('your_api_key_here');
// Create customer and invoice
const customer = await api.createCustomer({
name: 'John Doe',
email: 'john.doe@example.com'
});
const invoice = await api.createInvoice({
customer_id: customer.customer.id,
amount: 100.00,
currency: 'USD'
}, 'https://your-webhook-url.com/callback');
console.log('Payment Link:', invoice.invoice.payment_link);