Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
A JavaScript library to interface with Pagar.me's API, it works in the browser and with Node.js.
The documentation can be found in our JSDocs
This library covers all your needs for integrating with Pagar.me, providing:
First, install it:
yarn add pagarme
Or using npm:
npm install pagarme
Pagar.me's JavaScript library can be used in three ways:
Import like usual:
import pagarme from 'pagarme'
also works using require
:
const pagarme = require('pagarme')
Import the browser build:
import pagarme from 'pagarme/browser'
also works using require
:
const pagarme = require('pagarme/browser')
You can also use the latest release from our CDN and import the build directly in your HTML:
<script src="https://assets.pagar.me/pagarme-js/4.11/pagarme.min.js" />
The library will be available as the global variable pagarme
.
This library provides a promise based interface for all functions. Before you can use the library, you need to provide authentication details which will be used through API calls.
For a detailed documentation, see our JSDocs.
All of Pagar.me's REST API endpoints are covered in the client
object. Every
function call issued to client
will return a Promise
which represents and
manages the result's lifecycle.
connect
When you call connect
, a Promise
which resolves to a client
or an
error will be returned. If an authentication error happens, you can catch
the error with the Promise
interface:
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))
As the entire library is based on promises, you can also use ES6 generators with every call to make code more procedural:
import pagarme from 'pagarme'
let client
try {
client = yield pagarme.client.connect({
email: 'user@email.com',
password: '123456'
})
} catch (err) {
console.log('Authentication error')
}
try {
const transactions = yield client.transactions.all()
console.log(transactions)
} catch (err) {
console.log('Error fetching transactions')
}
The downside of this approach is that you need to handle errors using try/catch.
Pagar.me authorizes clients in various fashions. This library handles all available authentication strategies:
import pagarme from 'pagarme'
pagarme.client.connect({ api_key: 'ak_test_y7jk294ynbzf93' })
.then(client => client.transactions.all())
.then(transactions => console.log(transactions))
:warning: Never use API keys in the browser, you should use encryption keys instead.
import pagarme from 'pagarme'
const card = {
card_number: '4111111111111111',
card_holder_name: 'abc',
card_expiration_date: '1225',
card_cvv: '123',
}
pagarme.client.connect({ encryption_key: 'ek_test_y7jk294ynbzf93' })
.then(client => client.security.encrypt(card))
.then(card_hash => console.log(card_hash))
import pagarme from 'pagarme'
pagarme.client.connect({ email: 'user@email.com', password: '123456' })
.then(client => client.transactions.all())
.then(transactions => console.log(transactions))
To build the library, use npm start
.
dist
directory.browser
directory.To run the library tests, use npm test
.
To run tests, you need to export
API_KEY
environment variable with your API key. When submitting a PR, Travis will already have it exported.
Community contributions are essential for keeping this library great. We simply can't access the huge number of platforms and myriad configurations for running it, so if you find any problems, feel free to open an issue.
Be sure to provide at least the following information on the issue:
We provide source maps to ease debugging. Use them whenever possible when providing stack traces as it will make digging onto the issue easier.
The MIT License (MIT)
Copyright (c) 2017 Pagar.me Pagamentos S/A
FAQs
A JavaScript library to interface with Pagar.me API
The npm package pagarme receives a total of 3,037 weekly downloads. As such, pagarme popularity was classified as popular.
We found that pagarme demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 25 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.