1.0.5 • Published 5 months ago

paytor v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Paytor

npm version License: MIT

Paytor is a payment gateway integrator that simplifies the integration of multiple payment providers into your application. Currently supporting MercadoPago, with more payment gateways coming soon.

Features

  • 🔌 Easy integration with MercadoPago
  • 💳 Create one-time payments
  • 📅 Set up recurring subscriptions
  • 🔄 Unified API for multiple payment gateways
  • 🌐 Support for callbacks and redirect URLs
  • 📦 TypeScript support out of the box

Installation

npm install paytor

Usage

Initialize the Payment Manager

import { PaytorManager } from "paytor";

const paytor = new PaytorManager("YOUR_PAYTOR_ACCESS_TOKEN");

Create a Payment

// Create a one-time payment
const payment = await paytor.createPayment({
  gateway: "mercadopago",
  appIdentifier: "your-app-name",
  product: {  // You can use either product or productId
    title: "Product Name",
    quantity: 1,
    unit_price: 100,
    currency: "ARS", // Optional, defaults to account currency
  },
  // productId: "your-product-id", // Alternative to product object
  backUrls: {
    success: "https://your-domain.com/success",
    pending: "https://your-domain.com/pending",
    failure: "https://your-domain.com/failure",
  },
  callback: {
    url: "https://your-domain.com/to-do-when-accepted-payment",
    method: "POST",
  },
});

Create a Subscription

// Create a subscription
const subscription = await paytor.createSubscription({
  gateway: "mercadopago",
  appIdentifier: "your-app-id",
  product: {  // You can use either product or productId
    reason: "Premium Subscription",
    unit_price: 10,
    currency: "ARS",
    frequency: "1",
    frequency_type: "months"
  },
  // productId: "your-product-id", // Alternative to product object
  backUrl: "https://your-domain.com/subscription/callback",
  callback: {
    url: "https://your-domain.com/to-do-when-accepted-subscription",
    method: "POST",
  },
  payer_email: "customer@email.com"
});

API Reference

PaytorManager

Constructor

new PaytorManager(userAccessToken: string)

Methods

createPayment

Creates a one-time payment.

createPayment({
  gateway: string;
  appIdentifier: string;
  product?: PaymentItem;
  productId?: string;
  backUrls: {
    success?: string;
    pending?: string;
    failure?: string;
  };
  callback?: {
    method: string;
    url: string;
    body?: any;
    headers?: any;
  };
}): Promise<any>
createSubscription

Creates a recurring subscription.

createSubscription({
  gateway: string;
  appIdentifier: string;
  product?: SubscriptionItem;
  productId?: string;
  backUrl: string;
  callback?: {
    method: string;
    url: string;
    body?: any;
    headers?: any;
  };
  payer_email: string;
}): Promise<any>

Types

PaymentItem

interface PaymentItem {
  quantity: number;
  unit_price: number;
  currency?: string;
  title: string;
}

SubscriptionItem

interface SubscriptionItem {
  unit_price: number;
  currency?: string;
  reason: string;
  frequency: string;
  frequency_type: string;
}

Supported Payment Gateways

Currently supported payment gateways:

  • MercadoPago

Coming soon:

  • Stripe
  • And more...

Contributing

Contributions and feedback are welcome!

License

This project is licensed under the MIT License - see the LICENSE file for details.

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago