Exemplos

Veja alguns exemplos de requisições

#Criar Cliente

Dados para cadastramento de um cliente.

{
  "ownId": "meu_id_customer",
  "fullname": "João Silva",
  "email": "[email protected]",
  "birthDate": "1990-10-22",
  "taxDocument": {
    "type": "CPF",
    "number": "22288866644"
  },
  "phone": {
    "countryCode": "55",
    "areaCode": "11",
    "number": "55552266"
  },
  "shippingAddress": {
    "city": "São Paulo",
    "complement": "10",
    "district": "Itaim Bibi",
    "street": "Avenida Faria Lima",
    "streetNumber": "500",
    "zipCode": "01451000",
    "state": "SP",
    "country": "BRA"
  }
}
#
# Este exemplo usa a SDK do Moip de Ruby, disponível
# em: https://github.com/moip/moip-sdk-ruby
#

customer = api.customer.create(
  ownId: "meu_id_customer",
  fullname: "João Silva",
  email: "[email protected]",
  phone: {
    areaCode: "11",
    number: "66778899",
  },
  birthDate: "1990-10-22",
  taxDocument: {
    type: "CPF",
    number: "22288866644",
  },
  shippingAddress: {
    street: "Avenida Faria Lima",
    streetNumber: "500",
    complement: "10",
    district: "Itaim Bibi",
    city: "São Paulo",
    state: "SP",
    country: "BRA",
    zipCode: "01234000",
  },
)
/**
* Este exemplo usa a SDK do Moip de Java, disponível 
* em: https://github.com/moip/moip-sdk-java
*/

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> newCustomer = Moip.API.customers().create(customer, setup);
<?php

/**
* Este exemplo usa a SDK do Moip de PHP, disponível 
* em: https://github.com/moip/moip-sdk-php
*/

try {
  $customer = $moip->customers()->setOwnId(uniqid())
    ->setFullname('João Silva')
    ->setEmail('[email protected]')
    ->setBirthDate('1990-10-22')
    ->setTaxDocument('22288866644')
    ->setPhone(11, 55552266)
    ->addAddress('SHIPPING',
      'Avenida Faria Lima', 500,
      'Itaim Bibi', 'São Paulo', 'SP',
      '01234000', 10)
    ->create();
} catch (Exception $e) {
  printf($e->__toString());
}
/**
* 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.customer.create({
    ownId: '201805251702',
    fullname: 'Jose Silva',
    email: '[email protected]',
    birthDate: '1988-12-30',
    taxDocument: {
        type: 'CPF',
        number: '22288866644'
    },
    phone: {
        countryCode: '55',
        areaCode: '11',
        number: '55552266'
    },
    shippingAddress: {
        city: 'Sao Paulo',
        complement: '10',
        district: 'Itaim Bibi',
        street: 'Avenida Faria Lima',
        streetNumber: '500',
        zipCode: '01234000',
        state: 'SP',
        country: 'BRA'
    }
}).then((response) => {
    console.log(response.body) 
}).catch((err) => {
    console.log(err) 
})

#Criar Cliente com Cartão de Crédito

Crie um cliente com um cartão de crédito cadastrado

{  
   "ownId":"meu_id_customer_002",
   "fullname":"Maria Oliveira",
   "email":"[email protected]",
   "birthDate":"1980-5-10",
   "taxDocument":{  
      "type":"CPF",
      "number":"10013390023"
   },
   "phone":{  
      "countryCode":"55",
      "areaCode":"11",
      "number":"22226842"
   },
   "shippingAddress":{  
      "city":"Sao Paulo",
      "district":"Jardim Paulistano",
      "street":"Avenida Brigadeiro Faria Lima",
      "streetNumber":"60",
      "zipCode":"01451000",
      "state":"SP",
      "country":"BRA"
   },
   "fundingInstrument":{  
      "method":"CREDIT_CARD",
      "creditCard":{  
         "expirationMonth":"06",
         "expirationYear":"22",
         "number":"6362970000457013",
         "holder":{  
            "fullname":"Maria Oliveira",
            "birthdate":"1980-05-10",
            "taxDocument":{  
               "type":"CPF",
               "number":"10013390023"
            },
            "billingAddress":{  
               "city":"Rio de Janeiro",
               "district":"Copacabana",
               "street":"Rua Raimundo Corrêa",
               "streetNumber":"1200",
               "zipCode":"05246200",
               "state":"RJ",
               "country":"BRA"
            },
            "phone":{  
               "countryCode":"55",
               "areaCode":"11",
               "number":"22226842"
            }
         }
      }
   }
}
#
# Este exemplo usa a SDK do Moip de Ruby, disponível
# em: https://github.com/moip/moip-sdk-ruby
#

customer = api.customer.create({  
   ownId: 'meu_id_customer_002', 
   fullname: 'Maria Oliveira', 
   email: '[email protected]', 
   birthDate: '1980-5-10', 
   taxDocument: {  
      type: 'CPF', 
      number: '10013390023'
   },
   phone: {  
      countryCode: '55', 
      areaCode: '11', 
      number: '22226842'
   },
   shippingAddress: {  
      city: 'Rio de Janeiro', 
      district: 'Ipanema', 
      street: 'Avenida Atlântica', 
      streetNumber: '60', 
      zipCode: '02446000', 
      state: 'RJ', 
      country: 'BRA'
   },
   fundingInstrument: {  
      method: 'CREDIT_CARD', 
      creditCard: {  
         expirationMonth: '06', 
         expirationYear: '22', 
         number: '6362970000457013', 
         cvc: '123', 
         holder: {  
            fullname: 'Maria Oliveira', 
            birthdate: '1980-05-10', 
            taxDocument: {  
               type: 'CPF', 
               number: '10013390023'
            },
            billingAddress: {  
               city: 'Rio de Janeiro', 
               district: 'Copacabana', 
               street: 'Rua Raimundo Corrêa', 
               streetNumber: '1200', 
               zipCode: '05246200', 
               state: 'RJ', 
               country: 'BRA'
            },
            phone: {  
               countryCode: '55', 
               areaCode: '11', 
               number: '22226842'
            }
         }
      }
   }
})
/**
* Este exemplo usa a SDK do Moip de Java, disponível 
* em: https://github.com/moip/moip-sdk-java
*/

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> taxDocumentHolder = payloadFactory(
    value("type", "CPF"),
    value("number", "22288866644")
);

Map<String, Object> phoneHolder = payloadFactory(
    value("countryCode", "55"),
    value("areaCode", "11"),
    value("number", "55552266")
);

Map<String, Object> holder = payloadFactory(
    value("fullname", "Test Holder Moip"),
    value("birthdate", "1990-10-22"),
    value("taxDocument", taxDocumentHolder),
    value("phone", phoneHolder)
);

Map<String, Object> creditCard = payloadFactory(
    value("expirationMonth", "05"),
    value("expirationYear", "22"),
    value("number", "4012001037141112"),
    value("cvc", "123"),
    value("holder", holder)
);

Map<String, Object> fundingInstrument = payloadFactory(
    value("method", "CREDIT_CARD"),
    value("creditCard", creditCard)
);

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),
    value("fundingInstrument", fundingInstrument)
);

Map<String, Object> newCustomer = Moip.API.customers().create(customer, setup);
<?php

/**
* Este exemplo usa a SDK do Moip de PHP, disponível 
* em: https://github.com/moip/moip-sdk-php
*/

$customer = $moip->customers()->setOwnId(meu_id_customer_002)
    ->setFullname("Maria Oliveira")
  ->setEmail("[email protected]")
  ->setBirthDate("1980-5-10")
  ->setTaxDocument("1001339023")
  ->setPhone(55, 11, 22226842)
  ->addAddress("SHIPPING",
    "Avenida Atlântica", 60,
    "Ipanema", "Rio de Janeiro", "RJ",
    "01234000")
  ->setCreditCard(6, 22, 6362970000457013, 123, $holder)
  ->create();

print_r($customer);