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
Npm:
npm install moip-sdk-node --save
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.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)
})
moip.customer.getOne(customerId)
.then((response) => {
console.log(response)
})
.catch((err) => {
console.log(err)
})
// 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)
})
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)
})
moip.customer.removeCreditCard(creditcardId)
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
moip.customer.getAll()
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
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)
})
moip.order.getOne('ORD-SFGB23X8WAVQ')
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
// 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)
})
moip.order.getAll()
.then((response) => {
console.log(response)
}).then((err) => {
console.log(err)
})
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)
})
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)
})
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)
})
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)
})
moip.payment.preAuthorizationCapture('PAY-6PYBC8E93M2L')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
moip.payment.preAuthorizationCancel('PAY-6PYBC8E93M2L')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
moip.escrow.release('ECW-6SCRX0LE4PPW')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
moip.payment.getOne('PAY-6PYBC8E93M2L')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
moip.payment.refunds.create('PAY-3GALBSZIUSBE')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
moip.payment.refunds.create('PAY-3GALBSZIUSBE', {
amount: 100
}).then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
moip.order.refunds.create('ORD-4GALBSZIUSBE')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
moip.refund.get('REF-1HI7RBLWH0CZ')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
moip.payment.refunds.get('PAY-3GALBSZIUSBE')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
moip.order.refunds.get('ORD-4GALBSZIUSBE')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
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)
})
moip.notification.getOne('NPR-1231231231')
.then((response) => {
console.log(response.body)
})
moip.notification.remove('NPR-1231231231')
.then((response) => {
console.log(response)
})
moip.notification.getAll()
.then((response) => {
console.log(response.body)
})
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)
})
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)
})
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)
})
moip.multiorder.getOne('MOR-NUU8VMJ0QPUP')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
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)
})
moip.multipayment.getOne('MPY-6W6DILA4BZ1X')
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
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)
})
moip.account.getOne(accountId)
.then((response) => {
console.log(response.body)
})
.catch((err) => {
console.log(err)
})
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')
})
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)
})
moip.bankAccount.getOne(bankAccountId)
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
moip.bankAccount.getAll(moipAccountId)
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
moip.bankAccount.remove(bankAccountId)
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
moip.balance.getOne()
.then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
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)
})
moip.transfer.getOne(transferId)
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
moip.transfer.getAll()
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
moip.webhook.getOne(webhookId)
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
//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)
})
moip.webhook.getAll()
.then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
Simulating different payment statuses
Have any question? Join us on Slack!