Veja alguns exemplos de requisições
#Criar pedido com Checkout Moip
Se você quiser usar o nosso checkout você conseguirá fazer isso através desta requisição:
{
"ownId":"meu_id_order",
"amount":{
"currency":"BRL",
"subtotals":{
"shipping":1500
}
},
"items":[
{
"product":"Nome do produto",
"category":"APPAREL_AND_ACCESSORIES",
"subcategory":"CLOTHING",
"quantity":1,
"detail":"Camiseta estampada branca",
"price":9500
}
],
"customer":{
"id":"CUS-87HFA3QCEKO7"
},
"checkoutPreferences":{
"redirectUrls":{
"urlSuccess": "http://www.lojaexemplo.com.br/compraFeita",
"urlFailure": "http://www.lojaexemplo.com.br/error"
},
"installments":[
{
"quantity":[1,6]
}
]
}
}
#
# Este exemplo usa a SDK do Moip de Ruby, disponível
# em: https://github.com/moip/moip-sdk-ruby
#
order = api.order.create({
ownId: 'meu_id_order',
amount: {
currency: 'BRL',
subtotals: {
shipping: 1500
}
},
items: [
{
product: 'Nome do produto',
category: 'APPAREL_AND_ACCESSORIES',
subcategory: 'CLOTHING',
quantity: 1,
detail: 'Camiseta estampada branca',
price: 9500
}
],
customer: {
id: 'CUS-87HFA3QCEKO7'
},
checkoutPreferences: {
redirectUrls: {
urlSuccess: 'http://www.lojaexemplo.com.br/compraFeita',
urlFailure: 'http://www.lojaexemplo.com.br/error'
},
installments: [
{
quantity: [2,2],
addition: 1000
}
]
}
})
/**
* Este exemplo usa a SDK do Moip de Java, disponível
* em: https://github.com/moip/moip-sdk-java
*/
Map<String, Object> subtotals = payloadFactory(
value("shipping", 15000)
);
Map<String, Object> amount = payloadFactory(
value("currency", "BRL"),
value("subtotals", subtotals)
);
Map<String, Object> product = payloadFactory(
value("product", "Product 1 Description"),
value("category", "TOYS_AND_GAMES"),
value("quantity", 2),
value("detail", "Anakin's Light Saber"),
value("price", 100000000)
);
List items = new ArrayList();
items.add(product);
Map<String, Object> redirectUrls = payloadFactory(
value("urlSuccess", "https://urlSuccess.com"),
value("urlFailure", "https://urlFailure.com")
);
List installments = new ArrayList();
installments.add(1); // min allowed installment
installments.add(5); // max allowed installment
Map<String, Object> installments = payloadFactory(
value("quantity", installments)
);
Map<String, Object> checkoutPreferences = payloadFactory(
value("redirectUrls", redirectUrls),
value("installments", installments)
);
Map<String, Object> customer = payloadFactory(
value("id", "CUS-XXOBPZ80QLYP")
);
Map<String, Object> order = payloadFactory(
value("ownId", "order_own_id"),
value("amount", amount),
value("items", items),
value("checkoutPreferences", checkoutPreferences),
value("customer", customer)
);
Map<String, Object> responseCreation = Moip.API.orders().create(order, setup);
<?php
/**
* Este exemplo usa a SDK do Moip de PHP, disponível
* em: https://github.com/moip/moip-sdk-php
*/
$order = $moip->orders()->setOwnId("meu_id_order")
->addItem("Nome do produto",1, "Camiseta estampada branca", 9500)
->setShippingAmount(1500)->setAddition(0)->setDiscount(0)
->addInstallmentCheckoutPreferences([2, 2], 0, 1000)
->setUrlSuccess("http://www.lojaexemplo.com.br/compraFeita")
->setUrlFailure("http://www.lojaexemplo.com.br/error")
->setCustomerId("CUS-87HFA3QCEKO7")
->create();
print_r($order);
/**
* Este exemplo usa a SDK do Moip de Node, disponível
* em: https://github.com/moip/moip-sdk-node
*/
const moip = require('moip-sdk-node').default({
accessToken: 'your-access-token',
production: false
})
moip.order.create({
ownId: 'identificador_pedido',
amount: {
currency: 'BRL',
subtotals: {
shipping: 1000
}
},
items: [{
product: 'Descrição do pedido',
quantity: 1,
detail: 'Mais info...',
price: 1000
}],
customer:{
id: 'CUS-87HFA3QCEKO7'
},
checkoutPreferences: {
redirectUrls: {
urlSuccess: 'http://www.lojaexemplo.com.br/compraFeita',
urlFailure: 'http://www.lojaexemplo.com.br/error'
},
installments: [
{
quantity: [2,2],
addition: 1000
}
]
}
}).then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
#Criar pedido com um novo cliente
Criando um pedido e cadastrando um novo cliente na mesma requisição:
{
"ownId": "identificador_pedido",
"amount": {
"currency": "BRL",
"subtotals": {
"shipping": 1500
}
},
"items": [
{
"product": "Câmera fotográfica",
"category": "CAMERAS",
"quantity": 1,
"detail": "Câmera fotográfica, modelo CM54296, cor preta",
"price": 100000
}
],
"customer": {
"ownId": "identificador_cliente",
"fullname": "Rafael Pereira",
"email": "[email protected]",
"birthDate": "1980-05-15",
"taxDocument": {
"type": "CPF",
"number": "57390209674"
},
"phone": {
"countryCode": "55",
"areaCode": "11",
"number": "88763546"
},
"shippingAddress": {
"street": "Avenida Brigadeiro Faria Lima",
"streetNumber": 123,
"complement": 321,
"district": "Jardim Paulistano",
"city": "Sao Paulo",
"state": "SP",
"country": "BRA",
"zipCode": "01451000"
}
}
}
#
# Este exemplo usa a SDK do Moip de Ruby, disponível
# em: https://github.com/moip/moip-sdk-ruby
#
order = api.order.create({
ownId: 'identificador_pedido',
amount: {
currency: 'BRL',
subtotals: {
shipping: 1500
}
},
items: [
{
product: 'Câmera fotográfica',
category: 'CAMERAS',
quantity: 1,
detail: 'Câmera fotográfica, modelo CM54296, cor preta',
price: 100000
}
],
customer: {
ownId: 'identificador_cliente',
fullname: 'Rafael Pereira',
email: '[email protected]',
birthDate: '1980-05-15',
taxDocument: {
type: 'CPF',
number: '57390209674'
},
phone: {
countryCode: '55',
areaCode: '11',
number: '88763546'
},
shippingAddress: {
street: 'Avenida 23 de Maio',
streetNumber: 654,
complement: 12,
district: 'Centro',
city: 'Sao Paulo',
state: 'SP',
country: 'BRA',
zipCode: '01244500'
}
}
})
/**
* Este exemplo usa a SDK do Moip de Java, disponível
* em: https://github.com/moip/moip-sdk-java
*/
Map<String, Object> subtotals = payloadFactory(
value("shipping", 15000)
);
Map<String, Object> amount = payloadFactory(
value("currency", "BRL"),
value("subtotals", subtotals)
);
Map<String, Object> product1 = payloadFactory(
value("product", "Product 1 Description"),
value("category", "TOYS_AND_GAMES"),
value("quantity", 2),
value("detail", "Anakin's Light Saber"),
value("price", 100000000)
);
Map<String, Object> product2 = payloadFactory(
value("product", "Product 2 Description"),
value("category", "SCIENCE_AND_LABORATORY"),
value("quantity", 5),
value("detail", "Pym particles"),
value("price", 2450000000)
);
List items = new ArrayList();
items.add(product1);
items.add(product2);
Map<String, Object> taxDocument = payloadFactory(
value("type", "CPF"),
value("number", "10013390023")
);
Map<String, Object> phone = payloadFactory(
value("countryCode", "55"),
value("areaCode", "11"),
value("number", "22226842")
);
Map<String, Object> shippingAddress = payloadFactory(
value("city", "Sao Paulo"),
value("district", "Itaim BiBi"),
value("street", "Av. Brigadeiro Faria Lima"),
value("streetNumber", "3064"),
value("state", "SP"),
value("country", "BRA"),
value("zipCode", "01451001")
);
Map<String, Object> customer = payloadFactory(
value("ownId", "customer_own_id"),
value("fullname", "Customer Full Name"),
value("email", "[email protected]"),
value("birthDate", "1980-5-10"),
value("taxDocument", taxDocument),
value("phone", phone),
value("shippingAddress", shippingAddress)
);
Map<String, Object> order = payloadFactory(
value("ownId", "order_own_id"),
value("amount", amount),
value("items", items),
value("customer", customer)
);
Map<String, Object> responseCreation = Moip.API.orders().create(order, setup);
<?php
/**
* Este exemplo usa a SDK do Moip de PHP, disponível
* em: https://github.com/moip/moip-sdk-php
*/
$order = $moip->orders()->setOwnId("identificador_pedido")
->addItem("Câmera fotográfica",1, "Câmera fotográfica, modelo CM54296, cor preta", 100000)
->setShippingAmount(1500)->setAddition(0)->setDiscount(0)
->setCustomer($moip->customers()->setOwnId("identificador_cliente")
->setFullname("Rafael Pereira")
->setEmail("[email protected]")
->setBirthDate("1980-05-15")
->setTaxDocument("57390209674")
->setPhone(11, 88763546)
->addAddress("SHIPPING",
"Avenida 23 de Maio", 654,
"Centro", "Sao Paulo", "SP",
"01244500", 12))
->create();
print_r($order);
/**
* Este exemplo usa a SDK do Moip de Node, disponível
* em: https://github.com/moip/moip-sdk-node
*/
const moip = require('moip-sdk-node').default({
accessToken: 'your-access-token',
production: false
})
moip.order.create({
ownId: 'identificador_pedido',
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)
})
var body = new OrderRequest
{
OwnId = "id_pedido",
Amount = new Amount
{
Currency = "BRL",
Subtotals = new Subtotals
{
Shipping = 1000
}
},
Items = new List<Item>
{
new Item
{
Product = "Descrição do pedido",
Category = "VIDEO_GAME_SOFTWARE",
Quantity = 1,
Detail = "Mais info...",
Price = 22000
}
},
Customer = new Customer
{
OwnId = "meu_id_customer_002",
FullName = "Maria Oliveira",
Email = "[email protected]",
BirthDate = "1980-5-10",
TaxDocument = new Taxdocument
{
Type = "CPF",
Number = "22288866644"
},
Phone = new Phone
{
CountryCode = "55",
AreaCode = "11",
Number = "55552266"
},
ShippingAddress = new Shippingaddress
{
City = "São Paulo",
Complement = "10",
District = "Itaim Bibi",
Street = "Avenida Faria Lima",
StreetNumber = "500",
ZipCode = "01234000",
State = "SP",
Country = "BRA"
}
}
var result = await WC.Order.Create(body);
#Criar pedido com cliente existente
Criando um pedido passando o ID de um cliente já existente
{
"ownId": "identificador_pedido",
"amount": {
"currency": "BRL",
"subtotals": {
"shipping": 1500
}
},
"items": [
{
"product": "Câmera fotográfica",
"category": "CAMERAS",
"quantity": 1,
"detail": "Câmera fotográfica, modelo CM54296, cor preta",
"price": 100000
}
],
"customer": {
"id": "CUS-OQSQ7IWL229E"
}
}
#
# Este exemplo usa a SDK do Moip de Ruby, disponível
# em: https://github.com/moip/moip-sdk-ruby
#
order = api.order.create({
ownId: 'identificador_pedido',
amount: {
currency: 'BRL',
subtotals: {
shipping: 1500
}
},
items: [
{
product: 'Câmera fotográfica',
category: 'CAMERAS',
quantity: 1,
detail: 'Câmera fotográfica, modelo CM54296, cor preta',
price: 100000
}
],
customer: {
id: 'CUS-OQSQ7IWL229E'
}
})
/**
* Este exemplo usa a SDK do Moip de Java, disponível
* em: https://github.com/moip/moip-sdk-java
*/
Map<String, Object> subtotals = payloadFactory(
value("shipping", 15000)
);
Map<String, Object> amount = payloadFactory(
value("currency", "BRL"),
value("subtotals", subtotals)
);
Map<String, Object> product1 = payloadFactory(
value("product", "Product 1 Description"),
value("category", "TOYS_AND_GAMES"),
value("quantity", 2),
value("detail", "Anakin's Light Saber"),
value("price", 100000000)
);
Map<String, Object> product2 = payloadFactory(
value("product", "Product 2 Description"),
value("category", "SCIENCE_AND_LABORATORY"),
value("quantity", 5),
value("detail", "Pym particles"),
value("price", 2450000000)
);
List items = new ArrayList();
items.add(product1);
items.add(product2);
Map<String, Object> customer = payloadFactory(
value("id", "CUS-XXOBPZ80QLYP")
);
Map<String, Object> order = payloadFactory(
value("ownId", "order_own_id"),
value("amount", amount),
value("items", items),
value("customer", customer)
);
Map<String, Object> responseCreation = Moip.API.orders().create(order, setup);
<?php
/**
* Este exemplo usa a SDK do Moip de PHP, disponível
* em: https://github.com/moip/moip-sdk-php
*/
$order = $moip->orders()->setOwnId("meu_id_order")
->addItem("Descrição do pedido",1, "Camiseta estampada branca", 9500)
->setShippingAmount(1500)->setAddition(0)->setDiscount(0)
->setCustomerId("CUS-87HFA3QCEKO7")
->create();
print_r($order);
/**
* Este exemplo usa a SDK do Moip de Node, disponível
* em: https://github.com/moip/moip-sdk-node
*/
const moip = require('moip-sdk-node').default({
accessToken: 'your-access-token',
production: false
})
moip.order.create({
ownId: 'identificador_pedido',
amount: {
currency: 'BRL',
subtotals: {
shipping: 1000
}
},
items: [{
product: 'Descrição do pedido',
quantity: 1,
detail: 'Mais info...',
price: 1000
}],
customer: {
id: 'CUS-OQSQ7IWL229E'
}
}).then((response) => {
console.log(response.body)
}).catch((err) => {
console.log(err)
})
var body = new OrderRequest
{
OwnId = "id_pedido",
Amount = new Amount
{
Currency = "BRL",
Subtotals = new Subtotals
{
Shipping = 1000
}
},
Items = new List<Item>
{
new Item
{
Product = "Descrição do pedido",
Category = "VIDEO_GAME_SOFTWARE",
Quantity = 1,
Detail = "Mais info...",
Price = 22000
}
},
Customer = new Customer
{
Id = "CUS-7AKU0VORZ2D4"
}
};
var result = await WC.Order.Create(body);