Step-by-step guides to integrate Davspay into your application
Get started with Davspay in under 10 minutes. This guide will walk you through creating your first payment integration.
Sign up for a Davspay account at dashboard.davspaysolution.com. You'll receive instant access to your test API keys.
Navigate to Settings → API Keys in your dashboard. You'll see two sets of keys:
Install the Davspay SDK for your preferred language:
# Node.js npm install @davspay/node-sdk # Python pip install davspay # PHP composer require davspay/sdk
Initialize the SDK and create a payment:
const Davspay = require('@davspay/node-sdk');
// Initialize with your test API key
const davspay = new Davspay({
apiKey: 'test_your_key_here',
environment: 'sandbox'
});
// Create a payment
const payment = await davspay.payments.create({
amount: 100000, // ₹1000 in paise
currency: 'INR',
customer: {
email: 'customer@example.com',
phone: '+919876543210',
name: 'John Doe'
},
description: 'Test Payment',
callback_url: 'https://yoursite.com/callback'
});
// Redirect customer to payment URL
console.log(payment.payment_url);After payment, the customer will be redirected to your callback_url with payment status:
app.get('/callback', async (req, res) => {
const { payment_id, status } = req.query;
// Verify payment status from our server
const payment = await davspay.payments.retrieve(payment_id);
if (payment.status === 'captured') {
// Payment successful - update your database
res.send('Payment successful!');
} else {
// Payment failed or pending
res.send('Payment failed or pending');
}
});Webhooks allow you to receive real-time notifications about payment events. This is the recommended way to handle payment confirmations.
In your Davspay dashboard, go to Settings → Webhooks and add your webhook endpoint URL. This should be a POST endpoint on your server that can receive JSON payloads.
Create an endpoint to receive webhook notifications:
const express = require('express');
const app = express();
app.post('/webhooks/davspay',
express.json(),
async (req, res) => {
// Get signature from headers
const signature = req.headers['x-davspay-signature'];
// Verify webhook signature
const isValid = davspay.webhooks.verify(
req.body,
signature,
process.env.WEBHOOK_SECRET
);
if (!isValid) {
return res.status(400).send('Invalid signature');
}
// Process webhook event
const { event, data } = req.body;
switch (event) {
case 'payment.captured':
// Payment successful
await handleSuccessfulPayment(data);
break;
case 'payment.failed':
// Payment failed
await handleFailedPayment(data);
break;
case 'refund.completed':
// Refund processed
await handleRefund(data);
break;
}
// Return 200 to acknowledge receipt
res.status(200).send('OK');
}
);Use the webhook testing tool in your dashboard to send test events to your endpoint. This helps you verify your integration before going live.
Before going live, make sure you've completed these essential steps: