npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vindi-payments

v0.3.2

Published

Vindi SDK Typescript library for Vindi Payments only

Downloads

19

Readme

Vindi TypeScript Library

TypeScript License: ISC Build Status Beta

A TypeScript library for interacting with the Vindi API to create transactions using various payment methods such as Pix, CreditCard, and BankSlip. This project is currently in beta. Feel free to contribute and report any issues you encounter.

Installation

npm install vindi-payments

Usage

import { VindiClient } from 'vindi-payments';

Initializing the Client

const isSandbox = true;
const vindiClient = new VindiClient(isSandbox);

// Initialize the transaction request
vindiClient.initialize('SEU_TOKEN_AQUI');

Fingerpint

To Generate the Fingerprint, it's necessary to have the DOM loaded (in beta)

// Generate fingerprint
vindiClient.generateFingerprint(document);

Setting Up the Customer

//Name, email, cpf, date of birthday (DD/MM/YYYY)
vindiClient.addCustomer('João das Neves', '[email protected]', '50235335142', '01/01/1990');

//H = Home (Landline), M = Mobile
vindiClient.addContact('H', '1133221122');
vindiClient.addContact('M', '11999999999');

//Postcode, Street, Number, Complement, Neighborhood, City, Region
vindiClient.addBillingAddress('17000-000', 'Av Esmeralda', '1001', 'Apartamento 3', 'Jd Esmeralda', 'Marilia', 'SP');
vindiClient.addShippingAddress('01001-010', 'Avenida do Centro', '99', 'Sala 602', 'Centro', 'São Paulo', 'SP');

Adding Products

vindiClient.addProduct(
  'Camiseta de Teste', //Description
  '1', // Quantity
  '119.00', // Price Unit
  'C01', // Code
  'SK-0001', // SKU
  'Informação Extra', //Extra
  '0', //Weight
);

Setting transaction Details

vindiClient.addTransactionDetails(
  '127.0.0.1', //IP
  'Sedex', //Shipping Description
  '12', //ShippingPrice
  'http://www.loja.com.br/notificacao', //Notification URL
  'FREE', // Free
  'MY-ORDER-NUMBER'
);

//Estimated Delivery Date
vindiClient.addEstimatedDate('02/04/2025');

Payment Examples

Pix

async function createPixTransaction() {
  try {
    const response = await vindiClient.createPixTransaction();
    console.log('Pix Transaction:', response);
  } catch (error) {
    console.log(error);;
  }
}

createPixTransaction();

Credit Card

async function createCreditCardTransaction() {
  try {
    const response = await vindiClient.createCreditCardTransaction(
      'JOAO DAS NEVES',
      '4111111111111111',
      '01',
      '2030',
      '644',
      '1'
    );
    console.log('Credit Card Transaction:', response);
  } catch (error) {
    console.log(error);;
  }
}

createCreditCardTransaction();

BankSlip

const paymentBankSlip = new Payment();
vindiClient.setPayment(paymentBankSlip);

async function createBankSlipTransaction() {
  try {
    const response = await vindiClient.createBankSlipTransaction();
    console.log('Bank Slip Transaction:', response);
  } catch (error) {
    console.log(error);;
  }
}

createBankSlipTransaction();

BankSlipPix

const paymentBankSlipPix = new Payment();
vindiClient.setPayment(paymentBankSlipPix);

async function createBankSlipPixTransaction() {
  try {
    const response = await vindiClient.createBankSlipPixTransaction();
    console.log('Bank Slip ìx Transaction:', response);
  } catch (error) {
    console.log(error);;
  }
}

createBankSlipPixTransaction();

CheckoutCartRedirect

To use the Vindi's checkout, you'll need a different initialization


const vindiClient = new VindiClient(true);
vindiClient.initializeCart(apiKey);

vindiClient.addProduct(
  'Camiseta de Teste', //Description
  '1', // Quantity
  '119.00', // Price Unit
  'C01', // Code
  'SK-0001', // SKU
  'Informação Extra', //Extra
  '0', //Weight
);

//Mandatory fields
vindiClient.setCartDetails(
  '01001000', //Sender post code (mandatory for Vindi)
  '1000-01', //Order Number
  'https://minha.loja/notificacao', //URL Notification
  '10', //Price Additional
  '8', //Price Discount 
);

//Optional Fields
vindiClient.getCartRequest().setUrlSuccess('https://minha.loja/success'); //Payment Confirmed
vindiClient.getCartRequest().setUrlProcess('https://minha.loja/process'); //Waiting Payment
vindiClient.getCartRequest().setUrlCancel('https://minha.loja/cancel'); //Canceled

async function createCartTransaction() {
  try {
    const response = await vindiClient.createCartTransaction();
    console.log('Cart Transaction:', response);
  } catch (error) {
    console.log(error);
  }
}

createCartTransaction();

Tracking Code

async function addTrackingCode(transactionId: string, trackingCode: string) {
  try {
    const response = await vindiClient.addTrackingCode(transactionId, trackingCode);
    console.log('Tracking Code Added:', response);
  } catch (error) {
    console.log(error);;
  }
}

addTrackingCode('transaction-id', 'tracking-code');

Querying a transaction

async function queryTransaction(transactionId: string) {
  try {
    const response = await vindiClient.queryTransaction(transactionId);
    console.log('Transaction Details:', response);
  } catch (error) {
    console.log(error);;
  }
}

queryTransaction('transaction-id');

Error Handling

public handleError(error: any): void {
  console.error('Error:', error.message);
  if (error.response) {
    console.error('Response data:', error.response.data);
  }
}