UNPKG

@payforpress/payforpress-node-sdk

Version:

Official Node.js Server SDK for PayForPress API - An onboarding, paywall and payment solution for online media

43 lines (42 loc) 1.5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PayForPressClient = void 0; const axios_1 = __importDefault(require("axios")); class PayForPressClient { constructor(config) { this.config = config; this.client = axios_1.default.create({ baseURL: config.baseUrl || 'https://payfor.press/api/v3', headers: { 'pfp-api-key': config.apiKey, 'Content-Type': 'application/json' } }); // Add response interceptor for error handling this.client.interceptors.response.use((response) => response.data, (error) => { if (error.response) { throw error.response.data; } throw { success: false, message: error.message || 'An unexpected error occurred' }; }); } async post(endpoint, data, config) { return this.client.post(endpoint, data, config); } async get(endpoint, params, config) { return this.client.get(endpoint, { ...config, params }); } async put(endpoint, data, config) { return this.client.put(endpoint, data, config); } async delete(endpoint, config) { return this.client.delete(endpoint, config); } } exports.PayForPressClient = PayForPressClient;