Moip v2 Ruby SDK

Build Status Code Climate Test Coverage

O jeito mais simples e rápido de integrar o Moip a sua aplicação Ruby

Instalação

Adicione a seguinte linha no seu Gemfile:

gem "moip2"

Configurando sua autenticação

  • Autenticando por BasicAuth ruby auth = Moip2::Auth::Basic.new("TOKEN", "SECRET")
  • Autenticando por OAuth ruby auth = Moip2::Auth::OAuth.new("TOKEN_OAUTH")

Após deifinir o tipo de autenticação, é necessário gerar o client, informando em qual environment você quer executar suas ações:

client = Moip2::Client.new(:sandbox/:production, auth)

Agora você pode instanciar a Api:

api = Moip2::Api.new(client)

Criando um Pedido

Agora basta criar o pedido:

order = api.order.create(
    {
        own_id: "ruby_sdk_1",
        items: [
          {
            product: "Nome do produto",
            quantity: 1,
            detail: "Mais info...",
            price: 1000
          }
        ],
        customer: {
          own_id: "ruby_sdk_customer_1",
          fullname: "Jose da Silva",
          email: "[email protected]",
          birthdate: "1988-12-30",
          tax_document: { number: "33333333333", type: "CPF" },
          phone: { country_code: "55", area_code: "11", number: "66778899" },
          shipping_address: 
            {
              street: "Avenida Faria Lima",
              street_number: 2927,
              complement: 8,
              district: "Itaim",
              city: "Sao Paulo",
              state: "SP",
              country: "BRA",
              zip_code: "01234000"
            }
        }
    }
)

Criando um pagamento

Cartão de crédito

api.payment.create(order.id,
    {
        installment_count: 1,
        funding_instrument: {
            method: "CREDIT_CARD",
            credit_card: {
                expiration_month: 04,
                expiration_year: 18,
                number: "4012001038443335",
                cvc: "123",
                holder: {
                    fullname: "Jose Portador da Silva",
                    birthdate: "1988-10-10",
                    tax_document: {
                        type: "CPF",
                        number: "22222222222"
                },
                    phone: {
                        country_code: "55",
                        area_code: "11",
                        number: "55667788"
                    }
                }
            }
        }
    }
)

Boleto

api.payment.create(
    {
        funding_instrument: {
            method: "BOLETO",
            boleto: {
                expiration_date: "2015-09-30",
                instruction_lines: {
                    first: "Primeira linha do boleto",
                    second: "Segunda linha do boleto",
                    third: "Terceira linha do boleto"
                  },
                logo_uri: "https://"
            }
        }
    }
)

Documentação

Documentação oficial

Licença

The MIT License