Install the SDK
Install our official SDK for your language. We support Node.js, Python, and Ruby with full TypeScript definitions.
# Using npm
npm install @vydapay/sdk
# Using yarn
yarn add @vydapay/sdk
# Using pnpm
pnpm add @vydapay/sdk
Authenticate with your API key
Get your API keys from the dashboard. Use test keys (sk_test_) for development.
const Vydapay = require('@vydapay/sdk');
// Initialize with your secret key
const vydapay = new Vydapay('sk_test_abc123...');
// Or use environment variables (recommended)
const vydapay = new Vydapay(process.env.VYDAPAY_SECRET_KEY);
// TypeScript support included
import Vydapay from '@vydapay/sdk';
const vydapay: Vydapay = new Vydapay(process.env.VYDAPAY_SECRET_KEY!);
Create a cardholder
Before issuing cards, create a cardholder representing the person who will use the card.
const cardholder = await vydapay.cardholders.create({
email: 'sarah.mitchell@acme.com',
name: {
first_name: 'Sarah',
last_name: 'Mitchell'
},
phone: '+447700900123',
billing_address: {
line1: '123 Business Street',
line2: 'Floor 4',
city: 'London',
postal_code: 'EC1A 1BB',
country: 'GB'
},
metadata: {
employee_id: 'EMP-4521',
department: 'Engineering',
manager: 'john.smith@acme.com'
}
});
console.log('Created cardholder:', cardholder.id);
// Created cardholder: ch_abc123def456
Issue a virtual card
Create a virtual card with spending limits and controls. Cards are issued instantly.
const card = await vydapay.cards.create({
type: 'virtual',
currency: 'GBP',
cardholder_id: cardholder.id,
// Set a monthly spending limit of £500
spending_limit: {
amount: 50000, // Amount in pence
interval: 'monthly'
},
// Configure spending controls
spending_controls: {
allowed_categories: [
'software_services',
'office_supplies',
'advertising'
],
blocked_categories: [
'gambling',
'adult_entertainment'
],
allowed_countries: ['GB', 'IE', 'US']
},
metadata: {
purpose: 'Software subscriptions',
budget_code: 'ENG-2025-Q1'
}
});
console.log('Card created!');
console.log('Card ID:', card.id);
console.log('Last 4:', card.last_four);
console.log('Status:', card.status);
// Card created!
// Card ID: card_xyz789def456
// Last 4: 4821
// Status: active
Set up webhooks
Receive real-time notifications when transactions occur, cards are frozen, or limits are reached.
// 1. Create a webhook endpoint
const webhook = await vydapay.webhooks.create({
url: 'https://your-app.com/webhooks/vydapay',
events: [
'transaction.created',
'transaction.declined',
'card.frozen',
'spending_limit.reached'
]
});
console.log('Webhook secret:', webhook.secret);
// Store this secret securely!
// 2. Handle webhooks in your app (Express.js example)
const express = require('express');
const app = express();
app.post('/webhooks/vydapay',
express.raw({ type: 'application/json' }),
async (req, res) => {
const signature = req.headers['x-vydapay-signature'];
let event;
try {
event = vydapay.webhooks.constructEvent(
req.body,
signature,
process.env.WEBHOOK_SECRET
);
} catch (err) {
console.log('Webhook signature verification failed');
return res.status(400).send(`Webhook Error: \${err.message}`);
}
// Handle the event
switch (event.type) {
case 'transaction.created':
const transaction = event.data.object;
console.log(`New transaction: £\${transaction.amount / 100}`);
// Send notification, update your database, etc.
break;
case 'transaction.declined':
const declined = event.data.object;
console.log(`Declined: \${declined.decline_reason}`);
// Alert the cardholder
break;
case 'spending_limit.reached':
console.log('Spending limit reached!');
// Notify finance team
break;
}
res.json({ received: true });
}
);