All Projects → pagarme → Pagarme Js

pagarme / Pagarme Js

Licence: mit
💛 Pagar.me's JavaScript API

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Pagarme Js

Laravel Stripe Webhooks
Handle Stripe webhooks in a Laravel application
Stars: ✭ 300 (-18.92%)
Mutual labels:  payments
When Dom Ready
$(document).ready() for the 21st century
Stars: ✭ 336 (-9.19%)
Mutual labels:  promise
Ws
⚠️ Deprecated - (in favour of Networking) ☁️ Elegantly connect to a JSON api. (Alamofire + Promises + JSON Parsing)
Stars: ✭ 352 (-4.86%)
Mutual labels:  promise
Express Promise Router
A lightweight wrapper for Express 4's Router that allows middleware to return promises
Stars: ✭ 309 (-16.49%)
Mutual labels:  promise
Vuejs Dialog
A lightweight, promise based alert, prompt and confirm dialog
Stars: ✭ 327 (-11.62%)
Mutual labels:  promise
Sdk Php
PHP SDK for Authorize.Net API
Stars: ✭ 343 (-7.3%)
Mutual labels:  payments
Future
Streamlined Future<Value, Error> implementation
Stars: ✭ 291 (-21.35%)
Mutual labels:  promise
Fun Task
Abstraction for managing asynchronous code in JS
Stars: ✭ 363 (-1.89%)
Mutual labels:  promise
Promise Fun
Promise packages, patterns, chat, and tutorials
Stars: ✭ 3,779 (+921.35%)
Mutual labels:  promise
Magicmusic
🎵帅气的手机端音乐播放器(vue vue-router vuex flex ...)
Stars: ✭ 350 (-5.41%)
Mutual labels:  promise
Android Card Form
A ready-made card form layout that can be included in your Android app, making it easy to accept credit and debit cards.
Stars: ✭ 310 (-16.22%)
Mutual labels:  payments
Express Promise
❤️ Middleware for easy rendering of async Query results.
Stars: ✭ 320 (-13.51%)
Mutual labels:  promise
Braintree android
Braintree SDK for Android
Stars: ✭ 343 (-7.3%)
Mutual labels:  payments
Evt
💧EventEmitter's typesafe replacement
Stars: ✭ 305 (-17.57%)
Mutual labels:  promise
Angular Admin
🔏Admin client for surmon.me blog powered by @angular and Bootstrap4
Stars: ✭ 352 (-4.86%)
Mutual labels:  promise
Promise
Ultra-performant Promise implementation in Python
Stars: ✭ 297 (-19.73%)
Mutual labels:  promise
P Iteration
Utilities that make array iteration easy when using async/await or Promises
Stars: ✭ 337 (-8.92%)
Mutual labels:  promise
Replace In File
A simple utility to quickly replace contents in one or more files
Stars: ✭ 369 (-0.27%)
Mutual labels:  promise
Braintree Web
A suite of tools for integrating Braintree in the browser
Stars: ✭ 357 (-3.51%)
Mutual labels:  payments
Rfcs
Specifications for Interledger and related protocols
Stars: ✭ 345 (-6.76%)
Mutual labels:  payments

Pagar.me JavaScript

Quality Gate Status Code Smells Coverage Maintainability Rating Security Rating

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

Description

This library covers all your needs for integrating with Pagar.me, providing:

  • A clean Promise-based interface for all endpoints in Pagarme's API
  • A fast way to generate card hashes
  • Postback signature validation
  • Documents validations (CPF, CNPJ, and others)

How to use

First, install it:

yarn add pagarme

Or using npm:

npm install pagarme

Pagar.me's JavaScript library can be used in three ways:

Node.js

Import like usual:

import pagarme from 'pagarme'

also works using require:

const pagarme = require('pagarme')

Browser (CommonJS)

Import the browser build:

import pagarme from 'pagarme/browser'

also works using require:

const pagarme = require('pagarme/browser')

Browser (Global Variable)

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.

API Docs

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.

Client API

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.

Using 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: '[email protected]', 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: '[email protected]',
    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:

Using API key:

import pagarme from 'pagarme'

pagarme.client.connect({ api_key: 'ak_test_y7jk294ynbzf93' })
  .then(client => client.transactions.all())
  .then(transactions => console.log(transactions))

⚠️ Never use API keys in the browser, you should use encryption keys instead.

Using encryption key:

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))

Using email and password:

import pagarme from 'pagarme'

pagarme.client.connect({ email: '[email protected]', password: '123456' })
  .then(client => client.transactions.all())
  .then(transactions => console.log(transactions))

Building

To build the library, use npm start.

  • Node.js build is produced inside the dist directory.
  • Browser build is produced inside the browser directory.

Testing

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.

Contributing

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:

  • Environment (e.g. Node 7, Chrome 57)
  • Operating System (e.g. iOS 10)
  • Library version (e.g. 3.0.0)

We provide source maps to ease debugging. Use them whenever possible when providing stack traces as it will make digging onto the issue easier.

License

The MIT License (MIT)
Copyright (c) 2017 Pagar.me Pagamentos S/A
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].