Project

ipiranga

0.0
No commit activity in last 3 years
No release in over 3 years
A simple Ipiranga Web Services Client
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3.5
~> 0.0.5

Runtime

~> 1.2.0
~> 0.4.0
 Project Readme

Ipiranga

Usage

The base class that sends requests and parse responses to the Ipiranga Web Services is Client:

wsdl_url = "https://b2bdv.ipiranga.com.br/csp/ensb2cws/cbpi.bs.participantePF.Service.CLS?WSDL=1"
ipiranga = Ipiranga::Client.new(wsdl_url: wsdl_url)

Responds to the following methods:

  • operations: List all the operations
  • #{operation}: Posts to the operation endpoint. Yields a LolSoap::Builder

PF and KM

There are two Client subclasses: PF and KM (for registering users and giving credit, respectively).

You can use them so that you don't need to specify the wsdl urls. The RAILS_ENV var is used to set the wsdl, check lib/ipiranga/clients.rb for more details.

Credentials

Ipiranga uses WSSE for security, so you need to specify your credentials:

ipiranga_pf = Ipiranga::PF.new(username: "badosu",
                               password: "pass")

Operations

Some examples for the operations of the wsdl's listed on wsdl.

Any inconsistency here is caused as consequence of the wsdl being used. The operations could be refined, but it would have a cost on flexibility.

PF - Cadastrar

Raises Ipiranga::UserAlreadyExists when the user already exists.

ipiranga_pf.cadastrar do |b|
  b.idRequisitante "badosu"
  b.nome "John"
  b.sobreNome "Doe"
  b.cpf 12345678991
  b.dataNascimento Date.parse('27/05/1986').
                        strftime("%Y-%m-%dT%H:%M:%S")
end

PF - Consultar

ipiranga_pf.consultar do |b|
  b.idRequisitante "badosu"
  b.listaCpf.cpf(listaCpfKey: 1).cpf 1234567899
  b.listaCpf.cpf(listaCpfKey: 2).cpf 3451238762
end

PF - Consultar Dados Detalhados

ipiranga_pf.consultarDadosDetalhados do |b|
  b.requisitante "badosu"
  b.cpf 1234567899
end

KM - Gerar Pedido Acumulo

Raises Ipiranga::RequestAlreadyExists if a request with the same CodigoPedido was already made.

Returns the Request Id.

ipiranga_km.post_gerarPedidoAcumulo do |b|
  b.Requisitante "badosu"
  b.CPF 1234567899
  b.CodigoPedido 2 # Generated by you
  b.Produto do |p|
    produtoKM = p.ProdutoKM
    produtoKM.IdItem 1 # 1 is ok
    produtoKM.CodigoProduto "1" # Generated by you
    produtoKM.Quantidade 1 # 1 is ok
    produtoKM.KM 100 # The quantity of credit
    produtoKM.TipoAcumulo "2" # The type of the partner
  end
end

Troubleshooting

If you need more control over the operation you can use the post_#{operation} method (or post(operation)). In this case, it returns a LolSoap::Response instance that responds to #body_hash.

The following methods and attributes may be useful:

  • wsdl: The wsdl supplied to the client, can be passed on initialization
  • soap: The LolSoap::Client being used
  • #operation(key): A LolSoap::WSDL::operation instance that describes the operation
  • #has_credentials?: Verify that the client has supplied credentials