Developer Quickstart
Get started with OwnPay API integration in 5 minutes.
Step 1: Generate Your API Key
- Log in to your OwnPay admin panel
- Go to Developers (or your profile → Developer Hub)
- Click Generate API Key
- Choose Full Access (or Read-Only for testing)
- Copy both the Public Key and Secret Key - you'll need them
Your keys look like:
Public Key: op_live_abc123xyz...
Secret Key: op_secret_def456...Keep Keys Safe
Never commit API keys to git. Use environment variables instead:
OWNPAY_PUBLIC_KEY=op_live_...
OWNPAY_SECRET_KEY=op_secret_...Step 2: Choose Your SDK
PHP Developers
composer require ownpay/php-sdkThen in your code:
use OwnPay\SDK\Client;
$client = new Client(
publicKey: $_ENV['OWNPAY_PUBLIC_KEY'],
secretKey: $_ENV['OWNPAY_SECRET_KEY'],
baseUrl: 'https://yourdomain.com/api/v1'
);
// Create a payment
$payment = $client->payments()->create([
'amount' => 5000, // in cents (50.00)
'currency' => 'USD',
'customer_email' => '[email protected]',
'description' => 'Order #123'
]);
echo "Payment ID: " . $payment['id'];Full guide: PHP SDK →
Node.js Developers
npm install ownpayThen in your code:
import OwnPay from 'ownpay';
const ownpay = new OwnPay({
publicKey: process.env.OWNPAY_PUBLIC_KEY,
secretKey: process.env.OWNPAY_SECRET_KEY,
baseUrl: 'https://yourdomain.com/api/v1'
});
// Create a payment
const payment = await ownpay.payments.create({
amount: 5000, // in cents (50.00)
currency: 'USD',
customer_email: '[email protected]',
description: 'Order #123'
});
console.log('Payment ID:', payment.id);Full guide: Node.js SDK →
Other Languages (cURL)
curl -X POST https://yourdomain.com/api/v1/payments \
-H "Authorization: Bearer op_live_xxx..." \
-H "Content-Type: application/json" \
-d '{
"amount": 5000,
"currency": "USD",
"customer_email": "[email protected]",
"description": "Order #123"
}'Step 3: Create Your First Payment
After creating a payment, you get back:
{
"success": true,
"data": {
"id": "pay_abc123...",
"amount": 5000,
"currency": "USD",
"status": "pending",
"checkout_url": "https://yourdomain.com/checkout/pay_abc123",
"customer_email": "[email protected]"
}
}The checkout_url is where your customer makes the payment.
Step 4: Handle Webhooks
When your customer completes a payment, OwnPay sends a webhook to your endpoint.
Configure Your Webhook Endpoint
- Go to Developers → Webhook Settings
- Enter your endpoint URL:
https://yourapp.com/webhooks/ownpay - Copy the Webhook Signing Secret
- Click Save
Receive and Verify Webhook Events
PHP Example:
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_OWNPAY_SIGNATURE'] ?? '';
$secret = $_ENV['OWNPAY_WEBHOOK_SECRET'];
// Verify the signature
$expectedSignature = hash_hmac('sha256', $payload, $secret);
if (!hash_equals($expectedSignature, $signature)) {
http_response_code(401);
exit('Unauthorized');
}
// Parse the event
$event = json_decode($payload, true);
// Handle the event
if ($event['type'] === 'payment.completed') {
$paymentId = $event['data']['id'];
$amount = $event['data']['amount'];
// Update your database, send confirmation email, etc.
updateOrder($paymentId, 'completed');
}
http_response_code(200);Node.js Example:
import crypto from 'crypto';
app.post('/webhooks/ownpay', express.json(), (req, res) => {
const payload = JSON.stringify(req.body);
const signature = req.headers['x-ownpay-signature'];
const secret = process.env.OWNPAY_WEBHOOK_SECRET;
// Verify the signature
const expectedSignature = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
if (signature !== expectedSignature) {
return res.status(401).json({ error: 'Unauthorized' });
}
// Handle the event
const { type, data } = req.body;
if (type === 'payment.completed') {
updateOrder(data.id, 'completed');
}
res.json({ success: true });
});Full guide: Webhooks →
Step 5: Test Your Integration
Development / Sandbox Mode
- In your admin panel, go to Gateways
- Set the gateway to Test Mode
- Use test card numbers like
4111 1111 1111 1111 - No real charges occur
Test Card Numbers
| Card Type | Number | Outcome |
|---|---|---|
| Visa | 4111 1111 1111 1111 | Success |
| Mastercard | 5555 5555 5555 4444 | Success |
| Amex | 3782 822463 10005 | Success |
| Declined | 4000 0000 0000 0002 | Failure |
Webhook Testing
Use tools like:
- Webhook.cool - Temporary webhook URL for testing
- Hookbin - Inspect webhook payloads
- ngrok - Expose local server to the internet
Common Tasks
Get Payment Status
$payment = $client->payments()->get('pay_abc123');
echo $payment['status']; // 'pending', 'completed', 'failed'List Transactions
$transactions = $client->transactions()->list([
'limit' => 50,
'offset' => 0
]);Create a Payment Link
$link = $client->paymentLinks()->create([
'amount' => 5000,
'currency' => 'USD',
'description' => 'Product Name',
'expires_at' => date('Y-m-d H:i:s', strtotime('+30 days'))
]);
echo "Share this link: " . $link['url'];Next Steps
- Full PHP SDK Guide → - Complete API reference for PHP
- Full Node.js SDK Guide → - Complete API reference for Node.js
- Webhook Events → - All webhook event types
- Build a Plugin → - Extend OwnPay with plugins
- API Error Codes → - Error handling reference
API Quick Reference
| Endpoint | Method | Purpose |
|---|---|---|
/payments | POST | Create a payment |
/payments/{id} | GET | Get payment details |
/transactions | GET | List transactions |
/payment-links | POST | Create a payment link |
/webhooks/verify | POST | Verify webhook signature |
Full API reference: docs.ownpay.org
Troubleshooting
"Invalid API key" error → Verify your key is correct and hasn't expired. Regenerate if needed.
Webhook not being received → Check your firewall/security groups. OwnPay connects from your server IP.
Payment shows "pending" forever → Check that your cron job is running: php public/index.php cron
CORS errors → This is expected. Always make API calls from your backend, not the browser.
Need more help? → Check Troubleshooting or open an issue on GitHub.
Finished? Celebrate! 🎉 You've successfully integrated OwnPay.