Exemplos

Veja alguns exemplos de requisições

#Criando 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({
    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) 
})
var body = new CustomerRequest
{
    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"
    }
};

#Criando cliente + cartão de crédito

Cadastrando um cliente já com um cartão de crédito vinculado à sua conta.

{  
   "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":"São Paulo",
      "district":"Jardim Paulistano",
      "street":"Avenida 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'
   },
   funding_instrument: {  
      method: 'CREDIT_CARD', 
      credit_card: {  
         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);
/**
* 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({
    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'
    },
    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"
              }
           }
        }
     }
}).then((response) => {
    console.log(response.body) 
}).catch((err) => {
    console.log(err) 
})
var body = new CustomerRequest
{
    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"
    },
    FundingInstrument = new Fundinginstrument
    {
        Method = "CREDIT_CARD",
        CreditCard = new Creditcard
        {
            ExpirationMonth = "06",
            ExpirationYear = "22",
            Number = "6362970000457013",
            Cvc = "123",
            Holder = new Holder
            {
                FullName = "Maria Oliveira",
                BirthDate = "1988-12-30",
                TaxDocument = new Taxdocument
                {
                    Type = "CPF",
                    Number = "33333333333"
                },
                BillingAddress = new Billingaddress
                {
                    City = "Rio de Janeiro",
                    District = "Copacabana",
                    Street = "Rua Raimundo Corrêa",
                    StreetNumber = "1200",
                    ZipCode = "05246200",
                    State = "SP",
                    Country = "BRA"
                },
                Phone = new Phone
                {
                    CountryCode = "55",
                    AreaCode = "11",
                    Number = "66778899"
                }
            }
        }
    }
};
var result = await WC.Customer.Create(body);