O jeito mais simples e rápido de integrar o Moip a sua aplicação Node
[Em desenvolvimento - Não utilize em Produção] Módulo Node.js para integração com a API Moip v2 e assinaturas
Índice
Npm:
npm install moip-sdk-node --save
var moip = require('moip-sdk-node')({
token: 'SEU_TOKEN',
key: 'SUA_CHAVE',
production: false // false para utilizar Sandbox e true para Production. Default: false
})
moip.customer.create({
fullname: 'Jose Silva',
email: 'jose_silva0@email.com',
birthDate: '1988-12-30',
taxDocument: {
type: 'CPF',
number: '22222222222'
},
phone: {
countryCode: '55',
areaCode: '11',
number: '66778899'
},
shippingAddress: {
city: 'Sao Paulo',
complement: '8',
district: 'Itaim',
street: 'Avenida Faria Lima',
streetNumber: '2927',
zipCode: '01234000',
state: 'SP',
country: 'BRA'
}
}, function(error, body, response) {
if (error) {
console.log(error)
} else {
console.log(body)
}
})
moip.customer.getOne('CUS-MXAZ45AZ15U1', function(error, body, response) {
if (error) {
console.log(error)
} else {
console.log(body)
}
})
moip.order.create({
amount: {
currency: 'BRL',
subtotals: {
shipping: 1000
}
},
items: [{
product: 'Descrição do pedido',
quantity: 1,
detail: 'Mais info...',
price: 1000
}],
customer: {
fullname: 'Jose Silva',
email: 'jose_silva0@email.com',
birthDate: '1988-12-30',
taxDocument: {
type: 'CPF',
number: '22222222222'
},
phone: {
countryCode: '55',
areaCode: '11',
number: '66778899'
},
shippingAddress: {
street: 'Avenida Faria Lima',
streetNumber: 2927,
complement: 8,
district: 'Itaim',
city: 'Sao Paulo',
state: 'SP',
country: 'BRA',
zipCode: '01234000'
}
}
}, function(error, body, response) {
if (error) {
console.log(error)
} else {
console.log(body)
}
})
moip.order.getOne('ORD-SFGB23X8WAVQ', function(error, body, response) {
if (error) {
console.log(error)
} else {
console.log(body)
}
})
moip.order.getAll(function(error, body, response) {
if (error) {
console.log(error)
} else {
console.log(body)
}
})
moip.payment.create('ORD-SFGB23X8WAVQ', {
{
installmentCount: 1,
fundingInstrument: {
method: 'CREDIT_CARD',
creditCard: {
hash: 'HASH -- gerado do carto a partir de sua chave pública',
holder: {
fullname: 'Jose Santos',
birthdate: '1980-01-02',
taxDocument: {
type: 'CPF',
number: '12345679891'
},
phone: {
countryCode: '55',
areaCode: '11',
number: '25112511'
}
}
}
}
}
}, function(error, body, response) {
if (error) {
console.log(error)
} else {
console.log(body)
}
})
moip.payment.create('ORD-SFGB23X8WAVQ', {
{
installmentCount: 1,
fundingInstrument: {
method: 'CREDIT_CARD',
funding_instrument: {
method: "BOLETO",
boleto: {
expiration_date: "2017-09-30",
instruction_lines: {
first: "Primeira linha do boleto",
second: "Segunda linha do boleto",
third: "Terceira linha do boleto"
},
logo_uri: "https://sualoja.com.br/logo.jpg"
}
}
}
}
}, function(error, body, response) {
if (error) {
console.log(error)
} else {
console.log(body)
}
})
moip.payment.getOne('PAY-6PYBC8E93M2L', function(error, body, response) {
if (error) {
console.log(error)
} else {
console.log(body)
}
})
moip.connect.createApp({
name: 'Appz',
description: 'Appz test',
site: 'https://www.Appztest.com',
redirectUri: 'https://www.Appztest.com/get'
}, function(error, body, response) {
if (error) {
console.log(error)
} else {
console.log(body)
}
})
moip.notification.create({
events: [
'ORDER.*',
'PAYMENT.AUTHORIZED',
'PAYMENT.CANCELLED'
],
target: 'https://requestb.in/17ndz451',
media: 'WEBHOOK'
}, function(error, body, response) {
if (error) {
console.log(error)
} else {
console.log(body)
}
})
moip.notification.getOne('NPR-1231231231', function(error, body, response) {
if (error) {
console.log(error)
} else {
console.log(body)
}
})
moip.notification.delete('NPR-1231231231', function(error, response) {
if (error) {
console.log(error)
} else {
console.log(response)
}
})
moip.notification.getAll(function(error, body, response) {
if (error) {
console.log(error)
} else {
console.log(body)
}
})
Documentação oficial Assinaturas