pagarme-connect

0.1.4 • Public • Published

Pagar.me Connect

A JavaScript library to interface with Pagar.me API, works on browser and on Node.js.


API Docs

This library provides a Promise based interface for all calls. Before you can use the library to call Pagar.me API, you need to provide authentication details which will be used through API calls.

Authorization

Pagar.me can authorize clients in various fashions. This library handles all available authentication strategies via connect function.

  • Using API key:
import pagarme from 'pagarme'
 
pagarme.client.connect({ apiKey: 'ak_test_y7jk294ynbzf93' })
  .then(client => client.transactions.all())
  .then(transactions => console.log(transactions))
  • Using encryption key:
import pagarme from 'pagarme'
 
pagarme.client.connect({ encryptionKey: 'ek_test_y7jk294ynbzf93' })
  .then(client => client.transactions.all())
  .then(transactions => console.log(transactions))
  • Using email and password:
import pagarme from 'pagarme'
 
pagarme.client.connect({ email: 'user@email.com', password: '123456' })
  .then(client => client.transactions.all())
  .then(transactions => console.log(transactions))

Using connect

When you call connect, a Promise which resolves to a client or an error will be returned. If a login, API key or encryption key authentication error happen, you can catch the error with the Promise:

import pagarme from 'pagarme'
 
pagarme.client.connect({ email: 'user@email.com', password: '123456' })
  .then(client => client.transactions.all())
  .then(transactions => console.log(transactions))
  .catch(error => console.error(error))

When using email and password authentication, you can also provide a callback which will be invoked in case of a session expiration:

import pagarme from 'pagarme'
 
function onExpire (session) {
  console.log('Session expired!')
}
 
pagarme.client.connect({ email: 'user@email.com', password: '123456', onExpire })
  .then(client => client.transactions.all())
  .then(transactions => console.log(transactions))
  .catch(error => console.error(error))

Client API Reference

Most of Pagar.me REST API endpoints are covered in client object. Every function call issued to client will return a Promise which represent and manage the result's lifecycle.

Transactions

client.transactions.all

Return all transactions.

client.transactions.find(transactionId)

Find transactions with the given ID.

client.transactions.refund(transactionId)

Refund the transaction with the given ID.

Building

To build the library, use npm start. The result is produced inside build directory.

Testing

To run library's tests, use npm test

Readme

Keywords

none

Package Sidebar

Install

npm i pagarme-connect

Weekly Downloads

11

Version

0.1.4

License

ISC

Last publish

Collaborators

  • pagarme-opensource
  • matheusvellone
  • marquinhoalm
  • zignd
  • prifight
  • gabrielpagarme
  • magnomoreira
  • andre.lsilva
  • cigoli
  • davidsmedeiros
  • gabilleone
  • geraldofada-pagarme
  • asamedeirospagarme
  • rpsantos1987
  • danielponde
  • jonasnt17
  • nathaliacrelier
  • bruno.mduarte