Skip to content

Nucleus-Inc/moip-sdk-node

 
 

Repository files navigation

Moip SDK Node

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

Build Status js-standard-style

Índice

Instalação

Npm:

npm install moip-sdk-node --save

Configurando a autenticação

Por BasicAuth

var moip = require('moip-sdk-node')({
    token: 'SEU_TOKEN',
    key: 'SUA_CHAVE',
     production: false // false para utilizar Sandbox e true para Production. Default: false
})

Clientes

Criação

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

Consulta

moip.customer.getOne('CUS-MXAZ45AZ15U1', function(error, body, response) {
    if (error) {
        console.log(error)
    } else {
        console.log(body) 
    }
})

Pedidos

Criação

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

Consulta

Pedido Específico

moip.order.getOne('ORD-SFGB23X8WAVQ', function(error, body, response) {
    if (error) {
        console.log(error)
    } else {
        console.log(body) 
    }
})

Todos os Pedidos

Sem Filtro
moip.order.getAll(function(error, body, response) {
    if (error) {
        console.log(error)
    } else {
        console.log(body) 
    }
})

Pagamentos

Criação

Cartão de Crédito

Com Hash
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) 
    }
})

Com Boleto

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

Consulta

moip.payment.getOne('PAY-6PYBC8E93M2L', function(error, body, response) {
    if (error) {
        console.log(error)
    } else {
        console.log(body) 
    }
})

Moip Connect

Criação de App

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

Preferências de notificação

Criação

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

Consulta

moip.notification.getOne('NPR-1231231231', function(error, body, response) {
    if (error) {
        console.log(error)
    } else {
        console.log(body) 
    }
})

Exclusão

moip.notification.delete('NPR-1231231231', function(error, response) {
    if (error) {
        console.log(error)
    } else {
        console.log(response) 
    }
})

Listagem

moip.notification.getAll(function(error, body, response) {
    if (error) {
        console.log(error)
    } else {
        console.log(body) 
    }
})

Referência API

Documentação oficial v2

Documentação oficial Assinaturas

Links Úteis

Número de cartões para teste

Simulando diferentes estados de pagamento

Guia para assinaturas

Licença

The MIT License

About

[Em desenvolvimento] Módulo Node.js para integração com API Moip v2

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%