0.0.2 • Published 8 years ago

pagarme-nodejs v0.0.2

Weekly downloads
1
License
ISC
Repository
-
Last release
8 years ago

pagarme-nodejs

Pagarme SDK for NodeJs. With this library we can manage transactions and subscriptions through Pagarme API. Other resources will be implemented soon.

Install

$ npm install pagarme-nodejs

Initialize Pagarme with your api key

var Pagarme = require('pagarme-nodejs');
var pagarme = new Pagarme('<YOUR_API_KEY>');

or in ES6:

import Pagarme from 'pagarme-nodejs';
const pagarme = new Pagarme('<YOUR_API_KEY>');

Transaction

Create

const customer = {
  name: 'Bill Gates',
  document_number: '14546943530',
  email: 'billgates@email.com',
  address: {
    street: 'Cody Ridge Road',
    street_number: '45',
    complementary: 'Apt 402',
    neighborhood: 'Prineville',
    zipcode: '40159350',
  },
  phone: {
    ddd: '11',
    number: '99992222',
  },
  sex: 'M',
  born_at: new Date(1955, 9, 28),
};

pagarme.Transaction.new({
  customer,
  payment_method: 'credit_card',
  card_hash: '<CARD_HASH>',
  amount: 2000,
  metadata: {
    um: 1,
    dois: 2,
  },
}).then(console.log).catch(console.log);

Find by id

pagarme.Transaction.findById(12345).then(console.log).catch(console.log);

All Transactions

const page = 1;
const count = 10;
pagarme.Transaction.all(page, count).then(console.log).catch(console.log);

Subscription

Create

const customer = {
  name: 'Bill Gates',
  document_number: '14546943530',
  email: 'billgates@email.com',
  address: {
    street: 'Cody Ridge Road',
    street_number: '45',
    complementary: 'Apt 402',
    neighborhood: 'Prineville',
    zipcode: '40159350',
  },
  phone: {
    ddd: '11',
    number: '99992222',
  },
  sex: 'M',
  born_at: new Date(1955, 9, 28),
};

pagarme.Subscription.new({
  customer,
  plan_id: 12345,
  card_hash: '<CARD_HASH>',
  metadata: {
    um: 1,
    dois: 2,
  },
}).then(console.log).catch(console.log);

Find by id

pagarme.Subscription.findById(12345).then(console.log).catch(console.log);

All Subscriptions

const page = 1;
const count = 10;
pagarme.Subscription.all(page, count).then(console.log).catch(console.log);