Classy Pay Client

raw JSON →
1.1.4 verified Thu Apr 23 auth: no javascript abandoned

The `classy-pay-client` package provides a simple CommonJS-based client for interacting with the Classy Pay API. Its current and only stable version is 1.1.4, last published over seven years ago, indicating it is no longer actively maintained. The library utilizes a factory pattern for initialization, requiring an API URL, timeout, authentication token, and secret. It exposes methods for standard HTTP operations like GET, POST, PUT, and DELETE through callback-based functions, lacking modern features such as Promises or ESM support. This package is specifically designed for integration with the Classy Pay service and is likely used in legacy Node.js environments.

error TypeError: PayClient is not a function
cause The `require('classy-pay-client')` returns a factory function that must be immediately invoked with configuration.
fix
Call the factory function: const PayClient = require('classy-pay-client')({ apiUrl: '...', token: '...', secret: '...' });
error Error: Missing configuration option: token
cause The client initialization object is missing required configuration properties like `token`, `secret`, or `apiUrl`.
fix
Ensure the configuration object passed to require('classy-pay-client') includes apiUrl, token, and secret.
error ReferenceError: PayClient is not defined
cause Attempting to use ES module `import` syntax instead of CommonJS `require` for an older package that does not support ESM.
fix
Replace import PayClient from 'classy-pay-client'; with const PayClient = require('classy-pay-client')({ ... });
breaking The `del` method is a JavaScript reserved keyword. While the client exports `del`, using it directly as an object property might lead to syntax errors in strict mode or certain environments. It's generally safer to use `client['del'](...)` if encountering issues.
fix Access the `del` method using bracket notation: `PayClient['del'](appId, resource, callback)` to avoid potential keyword conflicts.
gotcha This package exclusively uses a CommonJS module syntax (`require`) and callback-based APIs. It does not natively support ES Modules (`import`) or modern Promise-based async/await patterns, which can lead to integration challenges in contemporary Node.js applications.
fix For ESM projects, consider a wrapper function that returns a Promise or migrate to a more modern API client. For CJS projects, ensure all usage adheres to the callback pattern.
gotcha The `classy-pay-client` package has not been updated in over seven years (last published 2017). This means it likely contains outdated dependencies with potential security vulnerabilities and may not be compatible with newer Node.js versions or API changes in Classy Pay itself.
fix Before using in production, thoroughly audit the package's dependencies for known vulnerabilities. Consider if an alternative or a direct API integration is more appropriate for long-term maintenance and security.
gotcha Configuration parameters like `apiUrl`, `token`, and `secret` are passed directly into the factory function. Hardcoding these values is insecure. They should always be sourced from environment variables or a secure configuration management system.
fix Always use `process.env.YOUR_VARIABLE` for sensitive information and API URLs, providing fallback defaults for development environments.
npm install classy-pay-client
yarn add classy-pay-client
pnpm add classy-pay-client

Demonstrates initializing the PayClient and making a GET request to fetch a transaction, followed by a POST request to create a new transaction, using callback patterns.

const PayClient = require('classy-pay-client')({
  apiUrl: process.env.CLASSY_PAY_API_URL || 'https://pay.classy.org',
  timeout: parseInt(process.env.CLASSY_PAY_TIMEOUT || '10000', 10),
  token: process.env.CLASSY_PAY_TOKEN || 'YOUR_PAY_TOKEN',
  secret: process.env.CLASSY_PAY_SECRET || 'YOUR_PAY_SECRET'
});

const appId = 0; // Replace with your actual application ID

PayClient.get(appId, '/transaction/1', (error, result) => {
  if (error) {
    console.error('Error fetching transaction:', error);
    // Handle specific error codes if necessary
    if (error.statusCode === 404) {
      console.log('Transaction not found.');
    }
  } else {
    console.log('Fetched transaction:', result);
  }
});

PayClient.post(appId, '/transactions', { amount: 1000, currency: 'USD' }, (error, result) => {
  if (error) {
    console.error('Error creating transaction:', error);
  } else {
    console.log('Created transaction:', result);
  }
});