Exemplos

Veja alguns exemplos de requisições

#Pedido com Checkout Moip

Você pode crair um pedido utilizando o checkout Moip. Dessa forma seu cliente será redirecionado para uma página Moip no momento da compra. Se preferir usar seu próprio checkout você não deve usar o atributo checkoutPreferences

{  
   "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-SB5W39JUOLUV"
   },
   
   "checkoutPreferences":{  
      "redirectUrls":{  
         "urlSuccess": "http://www.lojaexemplo.com.br/compraFeita",
         "urlFailure": "http://www.lojaexemplo.com.br/error"
      },
      "installments":[  
         {  
            "quantity":[1,12]
         }
      ]
   },
   "receivers": [
    {
      "type": "SECONDARY",
      "feePayor": true,
      "moipAccount": {
        "id": "MPA-E3C8493A06AE"
      },
      "amount": {
        "percentual": 15
      }
    }
  ]
}
#
# 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-SB5W39JUOLUV'
  },

  checkoutPreferences: {
    redirectUrls: {
      urlSuccess: 'http://www.lojaexemplo.com.br/compraFeita',
      urlFailure: 'http://www.lojaexemplo.com.br/error'
    },
    installments: [
      {
        quantity: [2, 2],
        addition: 1000
      }
    ]
  },
  receivers: [
    {
      type: 'SECONDARY',
      feePayor: true,
      moipAccount: {
        id: 'MPA-E3C8493A06AE'
      },
      amount: {
        percentual: 15
      }
    }
  ]
)
/**
 * 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-SB5W39JUOLUV")
    ->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: '1521656695',
    amount: {
        currency: 'BRL',
        subtotals: {
            shipping: 1500
        }
    },
    items: [{
        product: 'Descrição do pedido',
        quantity: 1,
        detail: 'Mais info...',
        price: 9500
    }],
    customer: {
        ownId: 'id_cliente',
        fullname: 'Eduardo Garcia',
        email: '[email protected]',
        birthDate: '1988-12-30',
        taxDocument: {
            type: 'CPF',
            number: '59929091092'
          checkoutPreferences:{  
      redirectUrls:{  
         urlSuccess: 'http://www.lojaexemplo.com.br/compraFeita',
         urlFailure: 'http://www.lojaexemplo.com.br/error'
        },
        phone: {
            countryCode: '55',
            areaCode: '11',
            number: '22355576'
        },
        shippingAddress: {
            street: 'Avenida Faria Lima',
            streetNumber: 500,
            complement: 10,
            district: 'Itaim Bibi',
            city: 'Sao Paulo',
            state: 'SP',
            country: 'BRA',
            zipCode: '01234500'
        },
  receivers: [
    {
      type: 'SECONDARY',
      feePayor: true,
      moipAccount: {
        id: 'MPA-E3C8493A06AE'
      },
      amount: {
        percentual: 30
      }
    }
  ]
}
}).then((response) => {
    console.log(response.body)
}).catch((err) => {
    console.log(err)
})

#Pedido com Novo Cliente

Se você quiser usar o nosso checkout você conseguirá fazer isso através desta requisição:

{
  "ownId": "id_pedido",
  "amount": {
    "currency": "BRL",
    "subtotals": {
      "shipping": 1000
    }
  },
  "items": [
    {
      "product": "Descrição do pedido",
      "category": "CLOTHING",
      "quantity": 1,
      "detail": "Mais info...",
      "price": 12000
    }
  ],
  "customer": {
    "ownId": "id_cliente",
    "fullname": "Eduardo Garcia",
    "email": "[email protected]",
    "birthDate": "1988-12-30",
    "taxDocument": {
      "type": "CPF",
      "number": "59929091092"
    },
    "phone": {
      "countryCode": "55",
      "areaCode": "11",
      "number": "22355576"
    },
    "shippingAddress": {
      "street": "Avenida Faria Lima",
      "streetNumber": 654,
      "complement": 12,
      "district": "Jardim Paulistano",
      "city": "Sao Paulo",
      "state": "SP",
      "country": "BRA",
      "zipCode": "01451000"
    }
  },
  "receivers": [
    {
      "type": "SECONDARY",
      "feePayor": true,
      "moipAccount": {
        "id": "MPA-E3C8493A06AE"
      },
      "amount": {
        "percentual": 30
      }
    }
  ]
}
#
# Este exemplo usa a SDK do Moip de Ruby, disponível
# em: https://github.com/moip/moip-sdk-ruby
#

order = api.order.create(
  ownId: "id_pedido",
  amount: {
    currency: "BRL",
    subtotals: {
      shipping: 1000,
    },
  },
  items: [
    {
      product: "Descrição do pedido",
      category: "CLOTHING",
      quantity: 1,
      detail: "Mais info...",
      price: 12000,
    },
  ],
  customer: {
    ownId: "id_cliente",
    fullname: "Eduardo Garcia",
    email: "[email protected]",
    birthDate: "1988-12-30",
    taxDocument: {
      type: "CPF",
      number: "59929091092",
    },
    phone: {
      countryCode: "55",
      areaCode: "11",
      number: "22355576",
    },
    shippingAddress: {
      street: "Avenida 23 de Maio",
      streetNumber: "654",
      complement: "12",
      district: "Centro",
      city: "Sao Paulo",
      state: "SP",
      country: "BRA",
      zipCode: "01244500",
    },
  },
  receivers: [
    {
      type: "SECONDARY",
      feePayor: true,
      moipAccount: {
        id: "MPA-E3C8493A06AE",
      },
      amount: {
        percentual: 30,
      },
    },
  ],
)
/**
 * 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("id_pedido")
    ->addItem("Descrição do pedido", 1, "Mais info...", 12000)
    ->setShippingAmount(1000)->setAddition(0)->setDiscount(0)
    ->setCustomer($moip->customers()->setOwnId("id_cliente")
        ->setFullname("Eduardo Garcia")
        ->setEmail("[email protected]")
        ->setBirthDate("1988-12-30")
        ->setTaxDocument("59929091092")
        ->setPhone(11, 22355576)
        ->addAddress("SHIPPING",
            "Avenida 23 de Maio", 654,
            "Centro", "Sao Paulo", "SP",
            "01244500", 12))
    ->addReceiver("MPA-E3C8493A06AE", "SECONDARY", 0, 30, true)
    ->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: '1521656695',
    amount: {
        currency: 'BRL',
        subtotals: {
            shipping: 1000
        }
    },
    items: [{
        product: 'Descrição do pedido',
        quantity: 1,
        detail: 'Mais info...',
        price: 12000
    }],
    customer: {
        ownId: 'id_cliente',
        fullname: 'Eduardo Garcia',
        email: '[email protected]',
        birthDate: '1988-12-30',
        taxDocument: {
            type: 'CPF',
            number: '59929091092'
        },
        phone: {
            countryCode: '55',
            areaCode: '11',
            number: '22355576'
        },
        shippingAddress: {
            street: 'Avenida 23 de Maio',
            streetNumber: 654,
            complement: 12,
            district: 'Centro',
            city: 'Sao Paulo',
            state: 'SP',
            country: 'BRA',
            zipCode: '01244500'
        }
    }
}).then((response) => {
    console.log(response.body)
}).catch((err) => {
    console.log(err)
})

#Pedido com Cliente Existente

Criando um pedido passando o ID de um cliente já existente

{  
   "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-SB5W39JUOLUV"
   },
   "receivers": [
    {
      "type": "SECONDARY",
      "feePayor": true,
      "moipAccount": {
        "id": "MPA-E3C8493A06AE"
      },
      "amount": {
        "percentual": 15
      }
    }
  ]
}
#
# Este exemplo usa a SDK 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 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 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 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({
    own_id: '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)
})