
Security News
rv Is a New Rust-Powered Ruby Version Manager Inspired by Python's uv
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
@transvoucher/sdk
Advanced tools
Official TypeScript/JavaScript SDK for TransVoucher payment processing API
Official TypeScript/JavaScript SDK for the TransVoucher payment processing API.
Install the SDK using npm:
npm install @transvoucher/sdk
Or using yarn:
yarn add @transvoucher/sdk
import TransVoucher from '@transvoucher/sdk';
// Initialize for sandbox
const client = TransVoucher.sandbox('your-api-key');
// Or for production
const client = TransVoucher.production('your-api-key');
// Create a payment
const payment = await client.payments.create({
amount: 100.00,
currency: 'USD',
title: 'Test Payment', // Required - title of the payment link
description: 'Test payment', // Optional
reference_id: 'ORDER-123', // Optional
multiple_use: false, // Optional
customer_details: { // Optional
full_name: 'John Doe', // Required if customer_details is provided
email: 'customer@example.com', // Optional
phone: '+1234567890', // Optional
}
});
console.log('Payment created:', payment.id);
console.log('Payment URL:', payment.payment_url);
import { TransVoucher } from '@transvoucher/sdk';
const client = new TransVoucher({
apiKey: 'your-api-key',
environment: 'sandbox', // or 'production'
timeout: 30000 // optional, default is 30000ms
});
// Start with sandbox
const client = TransVoucher.sandbox('your-api-key');
// Switch to production
client.switchEnvironment('production');
// Check current environment
if (client.isProduction()) {
console.log('Running in production mode');
}
const payment = await client.payments.create({
// Required fields
amount: 100.00,
currency: 'USD',
title: 'Product Purchase', // Required - title of the payment link
// Optional fields
description: 'Order payment', // Optional - description of the payment
reference_id: 'order-123', // Optional - your reference ID
multiple_use: false, // Optional - whether the payment link can be used multiple times
expires_at: '2025-12-31T23:59:59Z', // Optional - when the payment link expires
// Customer details (optional)
customer_details: {
// learn more about this at: https://transvoucher.com/api-documentation#pre_fill
full_name: 'John Doe', // Required if customer_details is provided
id: 'cust_123', // Optional - Customer's unique identifier
email: 'customer@example.com', // Optional
phone: '+1333999999', // Optional
date_of_birth: '1992-12-21', // Optional - YYYY-MM-DD format
country_of_residence: 'US', // Optional - ISO country code
state_of_residence: 'NY' // Optional - Required for US customers
// if you want to prefill card information
card_country_code: 'US',
card_city: 'Montana',
card_state_code: 'MT',
card_post_code: '12345',
card_street: 'Street 123',
},
// Metadata (optional)
metadata: {
// Optional - use this to identify the customer or payment session
// This data will be returned in webhooks and API responses
order_id: '123',
user_id: '456',
session_id: '789'
}
});
// Helper methods for payment status
if (client.payments.isCompleted(payment)) {
console.log('Payment is completed');
} else if (client.payments.isPending(payment)) {
console.log('Payment is pending');
} else if (client.payments.isFailed(payment)) {
console.log('Payment has failed');
} else if (client.payments.isExpired(payment)) {
console.log('Payment has expired');
}
const payment = await client.payments.getStatus(123); // Note: payment ID is now a number
console.log('Status:', payment.status);
console.log('Amount:', payment.amount);
console.log('Transaction ID:', payment.transaction_id);
console.log('Customer Commission:', payment.customer_commission_percentage);
console.log('Multiple Use:', payment.multiple_use);
const result = await client.payments.list({
page: 1,
per_page: 10,
status: 'completed',
currency: 'USD',
from_date: '2024-01-01',
to_date: '2024-12-31',
customer_email: 'customer@example.com'
});
console.log('Payments:', result.payments);
console.log('Total:', result.meta.total);
const payment = await client.payments.getByReference('order-123');
if (payment) {
console.log('Found payment:', payment.id);
}
import { WebhookUtils } from '@transvoucher/sdk';
const isValid = WebhookUtils.verifySignature(
payload, // string or Buffer
signature, // from X-TransVoucher-Signature header
'your-webhook-secret'
);
const result = WebhookUtils.parseEvent(
payload,
signature,
'your-webhook-secret'
);
if (result.isValid && result.event) {
console.log('Event type:', result.event.type);
console.log('Payment data:', result.event.data);
} else {
console.error('Invalid webhook:', result.error);
}
const handler = WebhookUtils.createHandler('your-webhook-secret', {
'payment_intent.succeeded': async (event) => {
console.log('Payment completed:', event.data.id);
// Handle successful payment
},
'payment_intent.failed': async (event) => {
console.log('Payment failed:', event.data.id);
// Handle failed payment
}
});
// Use in your webhook endpoint
app.post('/webhook', async (req, res) => {
try {
const signature = req.headers['x-transvoucher-signature'];
await handler(req.body, signature);
res.status(200).send('OK');
} catch (error) {
console.error('Webhook error:', error);
res.status(400).send('Bad Request');
}
});
The SDK provides specific error types for different scenarios:
import {
TransVoucherError,
ValidationError,
AuthenticationError,
ApiError,
NetworkError
} from '@transvoucher/sdk';
try {
const payment = await client.payments.create({
amount: 100,
currency: 'USD'
});
} catch (error) {
if (error instanceof ValidationError) {
console.log('Validation errors:', error.errors);
} else if (error instanceof AuthenticationError) {
console.log('Authentication failed');
} else if (error instanceof ApiError) {
console.log('API error:', error.message);
console.log('Status code:', error.statusCode);
} else if (error instanceof NetworkError) {
console.log('Network error:', error.message);
} else {
console.log('Unknown error:', error);
}
}
The SDK is written in TypeScript and provides full type definitions:
import { Payment, PaymentStatus, CreatePaymentRequest } from '@transvoucher/sdk';
const paymentData: CreatePaymentRequest = {
amount: 100.00,
currency: 'USD',
description: 'Test payment'
};
const payment: Payment = await client.payments.create(paymentData);
const status: PaymentStatus = payment.status;
import express from 'express';
import { WebhookUtils } from '@transvoucher/sdk';
const app = express();
// Middleware to capture raw body for signature verification
app.use('/webhook', express.raw({ type: 'application/json' }));
app.post('/webhook', async (req, res) => {
try {
const signature = req.headers['x-transvoucher-signature'] as string;
const secret = process.env.TRANSVOUCHER_WEBHOOK_SECRET!;
const result = WebhookUtils.parseEvent(req.body, signature, secret);
if (!result.isValid || !result.event) {
return res.status(400).json({ error: result.error });
}
// Handle the event
switch (result.event.type) {
case 'payment_intent.succeeded':
console.log('Payment completed:', result.event.data.id);
break;
case 'payment_intent.failed':
console.log('Payment failed:', result.event.data.id);
break;
default:
console.log('Unhandled event:', result.event.type);
}
res.status(200).json({ received: true });
} catch (error) {
console.error('Webhook error:', error);
res.status(500).json({ error: 'Internal server error' });
}
});
pending
- Payment is awaiting processingprocessing
- Payment is being processedcompleted
- Payment has been successfully completedfailed
- Payment has failedexpired
- Payment has expiredcancelled
- Payment has been cancelledpayment_intent.created
- Payment intent was createdpayment_intent.processing
- Payment attempt was startedpayment_intent.succeeded
- Payment attempt was completed successfullypayment_intent.failed
- Payment intent failedpayment_intent.cancelled
- Payment intent was cancelledpayment_intent.expired
- Payment intent expiredWe welcome contributions! Please see our Contributing Guide for details.
This SDK is released under the MIT License. See LICENSE for details.
FAQs
Official TypeScript/JavaScript SDK for TransVoucher payment processing API
The npm package @transvoucher/sdk receives a total of 17 weekly downloads. As such, @transvoucher/sdk popularity was classified as not popular.
We found that @transvoucher/sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.