moip-sdk-node
v1.2.4
Published
Moip v2 API wrapper
Downloads
880
Readme
Wirecard SDK Node
The easiest way and fastest way to integrate Wirecard to your Node application Node.js module to integrate Wirecard v2 and subscriptions API
Summary
- Installing
- Getting started
- Wirecard v2 Examples:
- API Reference
- Useful Links
- License
- Contributors
- Slack Community
Installing
Npm:
npm install moip-sdk-node --save
Getting started
Prerequisite - Create an app (access token)
const moip = require('moip-sdk-node').default({
accessToken: 'your-access-token',
// token: 'your-token',
// key: 'your-key',
production: false
})
If you are using import syntax:
import moipSdk from 'moip-sdk-node'
const moip = moipSdk({
accessToken: 'your-access-token',
// token: 'your-token',
// key: 'your-key',
production: false
})
To authenticate using Basic authorization, you can pass a token
and key
as an argument instead of accessToken
.
Moip v2 Examples
Customers
Create
moip.customer.create({
ownId: '1521656695',
fullname: 'Jose Silva',
email: '[email protected]',
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'
}
}).then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Get
moip.customer.getOne(customerId)
.then((response) => {
console.log(response)
})
.catch((err) => {
console.log(err)
})
Query
// query example
// See https://dev.moip.com.br/reference#filtros-de-busca
const queryObj = {
limit: 14,
offset: 0
}
moip.customer.query(queryObj)
.then((response) => {
console.log(response)
})
.catch((err) => {
console.log(err)
})
Add a credit card to a Customer
moip.customer.createCreditCard(customerId, {
method: "CREDIT_CARD",
creditCard: {
expirationMonth: "05",
expirationYear: "22",
number: "5555666677778884",
cvc: "123",
holder: {
fullname: "Jose Portador da Silva",
birthdate: "1988-12-30",
taxDocument: {
type: "CPF",
number: "33333333333"
},
phone: {
countryCode: "55",
areaCode: "11",
number: "66778899"
}
}
}
}).then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Remove a credit card from a Customer
moip.customer.removeCreditCard(creditcardId)
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
Get all
moip.customer.getAll()
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Orders
Create
moip.order.create({
ownId: '1521656695',
amount: {
currency: 'BRL',
subtotals: {
shipping: 1000
}
},
items: [{
product: 'Descrição do pedido',
quantity: 1,
detail: 'Mais info...',
price: 1000
}],
customer: {
ownId: '1521656726',
fullname: 'Jose Silva',
email: '[email protected]',
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'
}
}
}).then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Get
moip.order.getOne('ORD-SFGB23X8WAVQ')
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Query
// query example
// See https://dev.moip.com.br/reference#filtros-de-busca
const objQuery = {
limit: 15,
offset: 0,
filters: {
status: {
in: 'PAID,WAITING'
}
}
}
moip.order.query(objQuery)
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Get all
moip.order.getAll()
.then((response) => {
console.log(response)
}).then((err) => {
console.log(err)
})
Payments
Create a credit card payment (using credit card hash)
moip.payment.create('ORD-SFGB23X8WAVQ', {
installmentCount: 1,
fundingInstrument: {
method: 'CREDIT_CARD',
creditCard: {
hash: 'Credit Card HASH -> generated using the JS encryption SDK',
holder: {
fullname: 'Jose Santos',
birthdate: '1980-01-02',
taxDocument: {
type: 'CPF',
number: '12345679891'
},
phone: {
countryCode: '55',
areaCode: '11',
number: '25112511'
}
}
}
}
}).then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Create a Boleto payment
moip.payment.create('ORD-SFGB23X8WAVQ', {
installmentCount: 1,
fundingInstrument: {
method: "BOLETO",
boleto: {
expirationDate: "2017-09-30",
instructionLines: {
first: "Primeira linha do boleto",
second: "Segunda linha do boleto",
third: "Terceira linha do boleto"
},
logoUri: "https://sualoja.com.br/logo.jpg"
}
}
}).then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Create a payment with pre-authorization
To create a payment with pre-authorization you only have to add a delayCapture
attribute to any payment method (credit card, boleto or online bank debit). See the example below with a credit card payment:
moip.payment.create('ORD-SFGB23X8WAVQ', {
installmentCount: 1,
delayCapture: true,
fundingInstrument: {
method: 'CREDIT_CARD',
creditCard: {
hash: 'Credit Card HASH -> generated using the JS encryption SDK',
holder: {
fullname: 'Jose Santos',
birthdate: '1980-01-02',
taxDocument: {
type: 'CPF',
number: '12345679891'
},
phone: {
countryCode: '55',
areaCode: '11',
number: '25112511'
}
}
}
}
}).then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Create a payment with escrow
To create a payment with escrow you only have to add the node escrow
with an attribute description
:
moip.payment.create('ORD-SFGB23X8WAVQ', {
installmentCount: 1,
escrow: {
description: 'Teste escrow'
},
fundingInstrument: {
method: 'CREDIT_CARD',
creditCard: {
hash: 'Credit Card HASH -> generated using the JS encryption SDK',
holder: {
fullname: 'Jose Santos',
birthdate: '1980-01-02',
taxDocument: {
type: 'CPF',
number: '12345679891'
},
phone: {
countryCode: '55',
areaCode: '11',
number: '25112511'
}
}
}
}
}).then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Capturing a payment with pre-authorization
moip.payment.preAuthorizationCapture('PAY-6PYBC8E93M2L')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
Canceling a payment with pre-authorization
moip.payment.preAuthorizationCancel('PAY-6PYBC8E93M2L')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
Releasing the escrow
moip.escrow.release('ECW-6SCRX0LE4PPW')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
Get (details of a payment)
moip.payment.getOne('PAY-6PYBC8E93M2L')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
Refunds
Create a payment refund
moip.payment.refunds.create('PAY-3GALBSZIUSBE')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
Create a payment partial refund
moip.payment.refunds.create('PAY-3GALBSZIUSBE', {
amount: 100
}).then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
Create an order refund
moip.order.refunds.create('ORD-4GALBSZIUSBE')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
Get Refund
moip.refund.get('REF-1HI7RBLWH0CZ')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
List Payment Refunds
moip.payment.refunds.get('PAY-3GALBSZIUSBE')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
List Order Refunds
moip.order.refunds.get('ORD-4GALBSZIUSBE')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
Notification Preferences
Create
moip.notification.create({
events: [
'ORDER.*',
'PAYMENT.AUTHORIZED',
'PAYMENT.CANCELLED'
],
target: 'https://requestb.in/17ndz451',
media: 'WEBHOOK'
}).then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Get
moip.notification.getOne('NPR-1231231231')
.then((response) => {
console.log(response.body)
})
Remove
moip.notification.remove('NPR-1231231231')
.then((response) => {
console.log(response)
})
Get all
moip.notification.getAll()
.then((response) => {
console.log(response.body)
})
Wirecard Connect
Ask for OAuth permission
To ask for OAuth permission for a merchant, you need to redirect them to a page in which they will log in with their Moip credentials to authorize your access to their account.
The complete list of available scopes for permission is available in our official documentation here.
moip.connect.getAuthorizeUrl({
clientId: 'APP-XXXXXXXXXXXX',
redirectUri: 'https://url_registered.in.yourapp',
scopes: ['RECEIVE_FUNDS', 'REFUND']
}).then((url) => {
console.log(url)
}).catch((err) => {
console.log(err)
})
Generate access token OAuth
Once the merchant has given you permission, you need to generate their access token
from the code returned to your redirect_uri
.
moip.connect.generateToken({
clientId: 'APP-XXXXXXXXXXXX',
redirectUri: 'https://url_registered.in.yourapp',
clientSecret: 'the secret token returned when you created your APP',
grantType: 'authorization_code',
code: 'the code returned to your redirect_uri after seller authorized'
}).then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
Multiorder
Create Multiorder
moip.multiorder.create({
ownId: 'your_own_id',
orders: [
{
ownId: 'your_own_id',
amount: {
currency: 'BRL',
subtotals: {
shipping: 2000
}
},
items: [
{
product: 'Camisa Verde e Amarelo - Brasil',
quantity: 1,
detail: 'Seleção Brasileira',
price: 2000
}
],
customer: {
fullname: 'Joao Sousa',
email: '[email protected]',
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'
}
},
receivers: [
{
type: 'PRIMARY',
moipAccount: {
id: 'MPA-VB5OGTVPCI52'
}
}
]
},
{
ownId: 'your_own_id',
amount: {
currency: 'BRL',
subtotals: {
shipping: 3000
}
},
items: [
{
product: 'Camisa Preta - Alemanha',
quantity: 1,
detail: 'Camiseta da Copa 2014',
price: 1000
}
],
customer: {
fullname: 'Joao Sousa',
email: '[email protected]',
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'
}
},
receivers: [
{
type: 'PRIMARY',
moipAccount: {
id: 'MPA-IFYRB1HBL73Z'
}
},
{
type: 'SECONDARY',
feePayor: false,
moipAccount: {
id: 'MPA-KQB1QFWS6QNM'
},
amount: {
fixed: 55
}
}
]
}
]
})
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
Get Multiorder
moip.multiorder.getOne('MOR-NUU8VMJ0QPUP')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
Multipayment
Create Multipayment
moip.multipayment.create('MOR-NUU8VMJ0QPUP', {
installmentCount: 1,
fundingInstrument: {
method: 'CREDIT_CARD',
creditCard: {
hash: 'Credit Card HASH -> generated using the JS encryption SDK',
holder: {
fullname: 'Jose Santos',
birthdate: '1980-01-02',
taxDocument: {
type: 'CPF',
number: '12345679891'
},
phone: {
countryCode: '55',
areaCode: '11',
number: '25112511'
}
}
}
}
}).then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Get Multipayment
moip.multipayment.getOne('MPY-6W6DILA4BZ1X')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
Account
Create
moip.account.create({
email: {
address: "[email protected]"
},
person: {
name: "Runscope",
lastName: "Random 9123",
taxDocument: {
type: "CPF",
number: "123.456.798-91"
},
identityDocument: {
type : "RG",
number: "434322344",
issuer: "SSP",
issueDate: "2000-12-12"
},
birthDate: "1990-01-01",
phone: {
countryCode: "55",
areaCode: "11",
number: "965213244"
},
address: {
street: "Av. Brigadeiro Faria Lima",
streetNumber: "2927",
district: "Itaim",
zipCode: "01234-000",
city: "São Paulo",
state: "SP",
country: "BRA"
}
},
type: "MERCHANT",
transparentAccount: false
}).then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Get
moip.account.getOne(accountId)
.then((response) => {
console.log(response.body)
})
.catch((err) => {
console.log(err)
})
Check Existence
Verify if an account already exists through the e-mail
or tax document
moip.account.exists({
email: '[email protected]'
// tax_document: 880.956.367-03
}).then(() => {
console.log('If here, the account exists')
}).catch(() => {
console.log('If here, the account does not exist')
})
Bank Account
Create
moip.bankAccount.create(moipAccountId, {
bankNumber: "237",
agencyNumber: "12345",
agencyCheckNumber: "0",
accountNumber: "12345678",
accountCheckNumber: "7",
type: "CHECKING",
holder: {
taxDocument: {
type: "CPF",
number: "622.134.533-22"
},
fullname: "Demo Moip"
}
}).then((response) => {
console.log(response.body)
}).catch((response) => {
console.log(response.body)
})
Get
moip.bankAccount.getOne(bankAccountId)
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Get all
moip.bankAccount.getAll(moipAccountId)
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Remove
moip.bankAccount.remove(bankAccountId)
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
Balance
Get balance
moip.balance.getOne()
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
Transfers
Create transfer
moip.transfer.create({
amount: 500,
transferInstrument: {
method: "BANK_ACCOUNT",
bankAccount: {
type: "CHECKING",
bankNumber: 1,
agencyNumber: 1111,
agencyCheckNumber: 2,
accountNumber: 9999,
accountCheckNumber: 8,
holder: {
fullname: "Nome do Portador",
taxDocument: {
type: "CPF",
number: "22222222222"
}
}
}
}
}).then((response) => {
console.log(response.body)
}).catch((response) => {
console.log(response.body)
})
Get transfer
moip.transfer.getOne(transferId)
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Get all transfers
moip.transfer.getAll()
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Webhooks
Get
moip.webhook.getOne(webhookId)
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Query
//query example
// See https://dev.moip.com.br/reference#consultar-webhook-enviado
const queryObj = {
limit: 4,
offset: 0,
event: 'ORDER.CREATED'
resourceId: 'the_resource_id'
}
moip.webhook.query(queryObj)
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Get all
moip.webhook.getAll()
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
API Reference
Useful Links
Simulating different payment statuses
License
Contributors
Slack Community
Have any question? Join us on Slack!