bcash 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +37 -6
- data/bcash.gemspec +1 -0
- data/lib/bcash.rb +4 -0
- data/lib/bcash/errors/empty_attributes.rb +11 -0
- data/lib/bcash/transaction.rb +71 -0
- data/lib/bcash/version.rb +1 -1
- data/spec/bcash/transaction_spec.rb +47 -0
- data/spec/response/transaction_200.xml +59 -0
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 801325959c92ee9e5d5795658eb4e0f7e20568ba
|
4
|
+
data.tar.gz: 3927d49e6662d8e7964583e9df49016e61be5a78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e52e56b8fc9aa8adf903244286d9a40ebffdee0c7222993fe2db2644af46789200b69b4bc956bcf20d3d0b1a014c2f2414fce56298ce8819f5216de334cbc705
|
7
|
+
data.tar.gz: b8388333f01ef83cbe1c14767ad59592dfa25bf193f5fcb91d44a8e112ab89f3aec780186e3716db6abf063ebf7c1fff1fed5e39ea041e5b36a7f1e0ea353091
|
data/README.md
CHANGED
@@ -48,6 +48,42 @@ Você terá o formulário pronto para envio, você também pode alterar o input
|
|
48
48
|
|
49
49
|
payment.html{tag_content('button', 'Pagar!')}
|
50
50
|
|
51
|
+
# Retorno automático
|
52
|
+
|
53
|
+
Se você utilizou a opção de url de retorno, você pode capturar o POST enviado pelo Bcash
|
54
|
+
|
55
|
+
notification = Bcash::Notification(params)
|
56
|
+
notification.id_transacao
|
57
|
+
|
58
|
+
Você pode visualizar todos os parametros na [página de desenvolvimento do bcash](https://www.bcash.com.br/desenvolvedores/integracao-retorno-automatico-loja-online.html).
|
59
|
+
|
60
|
+
## Verificar transação
|
61
|
+
|
62
|
+
Você pode visualizar as transações, consultado o status do seu pedido, para isso obtenha a chave de acesso
|
63
|
+
|
64
|
+
Logue em sua conta no site do bcash -> Ferramentas -> Sua chave acesso
|
65
|
+
|
66
|
+
Com a chave de acesso podemos utilizar a classe transação de duas maneiras
|
67
|
+
|
68
|
+
transaction = Bcash::Transaction.new(email, token, id_transacao, id_pedido)
|
69
|
+
transaction.get
|
70
|
+
|
71
|
+
Ou
|
72
|
+
|
73
|
+
transaction = Bcash::Transaction.new
|
74
|
+
transaction.email = 'teste@teste.com.br'
|
75
|
+
transaction.token = '1234567890'
|
76
|
+
transaction.id_transaction = '123'
|
77
|
+
transaction.id_order = '1234'
|
78
|
+
transaction.get
|
79
|
+
|
80
|
+
Agora você tem todos os parametros para consulta
|
81
|
+
|
82
|
+
transaction.id_transacao
|
83
|
+
transaction.status
|
84
|
+
|
85
|
+
Você pode ver todos HTTP code e parametros de retorno no [manual de transação](https://www.bcash.com.br/site/manual/Bcash_Manual_Integracao_Consultar_Dados_Transacao.pdf).
|
86
|
+
|
51
87
|
## Instalação
|
52
88
|
|
53
89
|
Adicione ao seu Gemfile:
|
@@ -58,12 +94,7 @@ E execute:
|
|
58
94
|
|
59
95
|
$ bundle
|
60
96
|
|
61
|
-
##
|
62
|
-
|
63
|
-
* Criar classe para retorno automatico
|
64
|
-
* Verificar status do pedido
|
65
|
-
|
66
|
-
## Contributing
|
97
|
+
## Contribuindo
|
67
98
|
|
68
99
|
1. Fork
|
69
100
|
2. Cria seu branch (`git checkout -b my-new-feature`)
|
data/bcash.gemspec
CHANGED
data/lib/bcash.rb
CHANGED
@@ -2,12 +2,16 @@ require "active_model"
|
|
2
2
|
require "haml"
|
3
3
|
require "action_view"
|
4
4
|
require "nokogiri"
|
5
|
+
require "rest-client"
|
5
6
|
|
6
7
|
require "bcash/version"
|
7
8
|
require "bcash/item"
|
8
9
|
require "bcash/package"
|
9
10
|
require "bcash/payment"
|
10
11
|
require "bcash/notification"
|
12
|
+
require "bcash/transaction"
|
13
|
+
|
14
|
+
require "bcash/errors/empty_attributes.rb"
|
11
15
|
|
12
16
|
module Bcash
|
13
17
|
PAD = "PAD"
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module Bcash
|
4
|
+
class Transaction
|
5
|
+
attr_accessor :email, :token, :id_transaction, :id_order
|
6
|
+
attr_reader :items
|
7
|
+
|
8
|
+
def initialize(email = nil, token = nil, id_transaction = nil, id_order = nil)
|
9
|
+
@email = email
|
10
|
+
@token = token
|
11
|
+
@id_transaction = id_transaction
|
12
|
+
@id_order = id_order
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def get
|
17
|
+
transaction = Nokogiri::XML(get_transaction_url)
|
18
|
+
self.instance_variables.each{|variable| raise Bcash::Errors::EmptyAttributes.new if self.instance_variable_get(variable).nil?}
|
19
|
+
|
20
|
+
create_transaction_attrs(transaction)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def get_transaction_url
|
26
|
+
url = 'https://www.pagamentodigital.com.br/transacao/consulta'
|
27
|
+
|
28
|
+
RestClient.post(url, params, headers).to_str
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_transaction_attrs(transaction)
|
32
|
+
transaction.xpath("//transacao/*").each do |node|
|
33
|
+
next if node.name == "pedidos"
|
34
|
+
self.instance_variable_set "@#{node.name}", node.text
|
35
|
+
|
36
|
+
self.class.class_eval do
|
37
|
+
attr_reader node.name
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
@items = transaction.xpath("//pedidos/item").map do |item|
|
42
|
+
Item.new({
|
43
|
+
:id => item.css("codigo_produto").text,
|
44
|
+
:description => item.css("nome_produto").text,
|
45
|
+
:amount => item.css("qtde").text,
|
46
|
+
:price => item.css("valor_total").text
|
47
|
+
})
|
48
|
+
end
|
49
|
+
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def base64_bcash
|
54
|
+
Base64.strict_encode64("#{self.email}:#{self.token}")
|
55
|
+
end
|
56
|
+
|
57
|
+
def params
|
58
|
+
{
|
59
|
+
:id_transacao => @id_transaction,
|
60
|
+
:id_pedido => @id_pedido,
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def headers
|
65
|
+
{
|
66
|
+
'Authorization' => "Basic #{base64_bcash}"
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
data/lib/bcash/version.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fakeweb'
|
3
|
+
|
4
|
+
describe Bcash::Transaction do
|
5
|
+
|
6
|
+
subject{Bcash::Transaction.new}
|
7
|
+
|
8
|
+
context "its ok" do
|
9
|
+
before(:each) do
|
10
|
+
body = File.open(File.join(File.dirname(__FILE__), '..', 'response', 'transaction_200.xml')).read
|
11
|
+
FakeWeb.register_uri(:post, %r|pagamentodigital\.com\.br|, :body => body, :content_type => 'text/xml')
|
12
|
+
FakeWeb.allow_net_connect = false
|
13
|
+
|
14
|
+
subject.email = 'teste@test.com'
|
15
|
+
subject.token = '1234567890'
|
16
|
+
subject.id_transaction = '18621609'
|
17
|
+
subject.id_order = 'R415728787'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should nil in get" do
|
21
|
+
subject.get.should be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return attributes" do
|
25
|
+
subject.get
|
26
|
+
|
27
|
+
subject.id_transacao.should == '18621609'
|
28
|
+
subject.id_pedido.should == 'R415728787'
|
29
|
+
subject.valor_original.should == '0.01'
|
30
|
+
subject.items[0].id.should == "1070870205"
|
31
|
+
subject.items[0].description.should == "Ruby on Rails Bag"
|
32
|
+
subject.items[0].amount.should == "1"
|
33
|
+
subject.items[0].price.should == "0.01"
|
34
|
+
subject.items[1].id.should == "1070870206"
|
35
|
+
subject.items[1].description.should == "Ruby on Rails Bag"
|
36
|
+
subject.items[1].amount.should == "3"
|
37
|
+
subject.items[1].price.should == "10.0"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "empty attributes" do
|
42
|
+
it "should return raise EmptyAttributes" do
|
43
|
+
expect {subject.get}.to raise_error(Bcash::Errors::EmptyAttributes)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<transacao>
|
3
|
+
<id_transacao>18621609</id_transacao>
|
4
|
+
<data_transacao>21/04/2013</data_transacao>
|
5
|
+
<data_credito></data_credito>
|
6
|
+
<valor_original>0.01</valor_original>
|
7
|
+
<valor_loja>0.00</valor_loja>
|
8
|
+
<valor_total>0.00</valor_total>
|
9
|
+
<desconto_programado>0.00</desconto_programado>
|
10
|
+
<desconto>0.00</desconto>
|
11
|
+
<acrescimo>0.00</acrescimo>
|
12
|
+
<cod_meio_pagamento>0</cod_meio_pagamento>
|
13
|
+
<meio_pagamento>Não efetuado</meio_pagamento>
|
14
|
+
<parcelas>0</parcelas>
|
15
|
+
<cod_status>1</cod_status>
|
16
|
+
<status>Em andamento</status>
|
17
|
+
<data_alteracao_status>00/00/0000 00:00:00</data_alteracao_status>
|
18
|
+
<cliente_razao_social></cliente_razao_social>
|
19
|
+
<cliente_nome_fantasia></cliente_nome_fantasia>
|
20
|
+
<cliente_nome></cliente_nome>
|
21
|
+
<cliente_email>matheus@grupo-audax.com</cliente_email>
|
22
|
+
<cliente_rg></cliente_rg>
|
23
|
+
<cliente_data_emissao_rg></cliente_data_emissao_rg>
|
24
|
+
<cliente_orgao_emissor_rg></cliente_orgao_emissor_rg>
|
25
|
+
<cliente_estado_emissor_rg></cliente_estado_emissor_rg>
|
26
|
+
<cliente_cnpj></cliente_cnpj>
|
27
|
+
<cliente_cpf></cliente_cpf>
|
28
|
+
<cliente_sexo></cliente_sexo>
|
29
|
+
<cliente_data_nascimento></cliente_data_nascimento>
|
30
|
+
<cliente_telefone></cliente_telefone>
|
31
|
+
<cliente_endereco></cliente_endereco>
|
32
|
+
<cliente_complemento></cliente_complemento>
|
33
|
+
<cliente_bairro></cliente_bairro>
|
34
|
+
<cliente_cidade></cliente_cidade>
|
35
|
+
<cliente_estado></cliente_estado>
|
36
|
+
<cliente_cep></cliente_cep>
|
37
|
+
<frete>0.00</frete>
|
38
|
+
<tipo_frete></tipo_frete>
|
39
|
+
<id_pedido>R415728787</id_pedido>
|
40
|
+
<free></free>
|
41
|
+
<email_vendedor>matheuscaceres@gmail.com</email_vendedor>
|
42
|
+
<pedidos>
|
43
|
+
<item>
|
44
|
+
<codigo_produto>1070870205</codigo_produto>
|
45
|
+
<nome_produto>Ruby on Rails Bag</nome_produto>
|
46
|
+
<qtde>1</qtde>
|
47
|
+
<valor_total>0.01</valor_total>
|
48
|
+
<extra></extra>
|
49
|
+
</item>
|
50
|
+
<item>
|
51
|
+
<codigo_produto>1070870206</codigo_produto>
|
52
|
+
<nome_produto>Ruby on Rails Bag</nome_produto>
|
53
|
+
<qtde>3</qtde>
|
54
|
+
<valor_total>10.0</valor_total>
|
55
|
+
<extra></extra>
|
56
|
+
</item>
|
57
|
+
</pedidos>
|
58
|
+
</transacao>
|
59
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matheus Caceres
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ! '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: fakeweb
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description: Integration with BCash
|
126
140
|
email:
|
127
141
|
- matheuscaceres@gmail.com
|
@@ -138,16 +152,20 @@ files:
|
|
138
152
|
- Rakefile
|
139
153
|
- bcash.gemspec
|
140
154
|
- lib/bcash.rb
|
155
|
+
- lib/bcash/errors/empty_attributes.rb
|
141
156
|
- lib/bcash/form_bcash.html.haml
|
142
157
|
- lib/bcash/item.rb
|
143
158
|
- lib/bcash/notification.rb
|
144
159
|
- lib/bcash/package.rb
|
145
160
|
- lib/bcash/payment.rb
|
161
|
+
- lib/bcash/transaction.rb
|
146
162
|
- lib/bcash/version.rb
|
147
163
|
- spec/bcash/item_spec.rb
|
148
164
|
- spec/bcash/notification_spec.rb
|
149
165
|
- spec/bcash/package_spec.rb
|
150
166
|
- spec/bcash/payment_spec.rb
|
167
|
+
- spec/bcash/transaction_spec.rb
|
168
|
+
- spec/response/transaction_200.xml
|
151
169
|
- spec/spec_helper.rb
|
152
170
|
homepage: ''
|
153
171
|
licenses:
|
@@ -178,4 +196,6 @@ test_files:
|
|
178
196
|
- spec/bcash/notification_spec.rb
|
179
197
|
- spec/bcash/package_spec.rb
|
180
198
|
- spec/bcash/payment_spec.rb
|
199
|
+
- spec/bcash/transaction_spec.rb
|
200
|
+
- spec/response/transaction_200.xml
|
181
201
|
- spec/spec_helper.rb
|