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:'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'
}
}).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
constqueryObj={
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:'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'
}
}
}).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
constobjQuery={
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',
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.