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 aLolSoap::Builder
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.
Ipiranga uses WSSE for security, so you need to specify your credentials:
ipiranga_pf = Ipiranga::PF.new(username: "badosu",
password: "pass")
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.
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
ipiranga_pf.consultar do |b|
b.idRequisitante "badosu"
b.listaCpf.cpf(listaCpfKey: 1).cpf 1234567899
b.listaCpf.cpf(listaCpfKey: 2).cpf 3451238762
end
ipiranga_pf.consultarDadosDetalhados do |b|
b.requisitante "badosu"
b.cpf 1234567899
end
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
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 initializationsoap: TheLolSoap::Clientbeing used#operation(key): ALolSoap::WSDL::operationinstance that describes the operation#has_credentials?: Verify that the client has supplied credentials