bcash 0.5.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.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +8 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +61 -0
- data/Rakefile +1 -0
- data/bcash.gemspec +30 -0
- data/lib/bcash.rb +13 -0
- data/lib/bcash/form_bcash.html.haml +6 -0
- data/lib/bcash/item.rb +29 -0
- data/lib/bcash/package.rb +35 -0
- data/lib/bcash/payment.rb +29 -0
- data/lib/bcash/version.rb +3 -0
- data/spec/bcash/item_spec.rb +21 -0
- data/spec/bcash/package_spec.rb +18 -0
- data/spec/bcash/payment_spec.rb +46 -0
- data/spec/spec_helper.rb +2 -0
- metadata +156 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Matheus Caceres
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Bcash
|
2
|
+
|
3
|
+
Integração com Bcash(antigo Pagamento Digital)
|
4
|
+
|
5
|
+
## Como usar
|
6
|
+
|
7
|
+
# Criando um item
|
8
|
+
|
9
|
+
items = []
|
10
|
+
items << Bcash::Item.new({id: 1, description: 'teste', amount: 2, price: 30.0})
|
11
|
+
|
12
|
+
Você pode criar quando itens for necessários para enviar para o Bcash
|
13
|
+
|
14
|
+
# Criando um pacote
|
15
|
+
|
16
|
+
Com os itens criados, crie um pacote para o envio
|
17
|
+
|
18
|
+
package = Package.create(items)
|
19
|
+
|
20
|
+
No pacote você pode alterar o valor do frete e o tipo de integração do Bcash
|
21
|
+
|
22
|
+
Package.create(items, 30.0, BCASH::PAD)
|
23
|
+
|
24
|
+
# Gerando pagamento
|
25
|
+
|
26
|
+
Crie um pagamento
|
27
|
+
|
28
|
+
payment = Bcash::Payment.new(package, {:email_loja => 'test@test.com'})
|
29
|
+
|
30
|
+
Podemos colocar nas opções uma url de retorno para o Bcash voltar ao site desejado.
|
31
|
+
|
32
|
+
Bcash::Payment.new(package, {:email_loja => 'test@test.com', :url_retorno => 'http://www.teste.com.br'})
|
33
|
+
|
34
|
+
Você pode encontrar todas as opções no [site do bcash](https://www.bcash.com.br/desenvolvedores/integracao-loja-online.html) e procure por campos opcionais
|
35
|
+
|
36
|
+
# Gerando formulário
|
37
|
+
|
38
|
+
payment.html
|
39
|
+
|
40
|
+
Você terá o formulário pronto para envio, você também pode alterar o input do de envio para a maneira que desejar
|
41
|
+
|
42
|
+
payment.html{tag_content('button', 'Pagar!')}
|
43
|
+
|
44
|
+
## Instalação
|
45
|
+
|
46
|
+
Adicione ao seu Gemfile:
|
47
|
+
|
48
|
+
gem 'bcash'
|
49
|
+
|
50
|
+
E execute:
|
51
|
+
|
52
|
+
$ bundle
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork
|
57
|
+
2. Cria seu branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit suas mudanças (`git commit -am 'Add some feature'`)
|
59
|
+
4. Envie o branch (`git push origin my-new-feature`)
|
60
|
+
5. Rode os testes
|
61
|
+
6. Cria um novo Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bcash.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bcash/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bcash"
|
8
|
+
spec.version = Bcash::VERSION
|
9
|
+
spec.authors = ["Matheus Caceres"]
|
10
|
+
spec.email = ["matheuscaceres@gmail.com"]
|
11
|
+
spec.description = %q{Integration with BCash}
|
12
|
+
spec.summary = %q{Integration with BCash}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activemodel"
|
22
|
+
spec.add_dependency "rest-client"
|
23
|
+
spec.add_dependency "haml"
|
24
|
+
spec.add_dependency "nokogiri"
|
25
|
+
spec.add_dependency "actionpack"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
end
|
data/lib/bcash.rb
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
%form{:action => "https://www.bcash.com.br/checkout/pay/", :name => "bcash", :method => "post"}
|
2
|
+
-options.each do |key, value|
|
3
|
+
%input{:name => key.to_s, :type => "hidden", :value => value.to_s}
|
4
|
+
-package.items.each do |key, value|
|
5
|
+
%input{:name => key.to_s, :type => "hidden", :value => value.to_s}
|
6
|
+
=button_html
|
data/lib/bcash/item.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Bcash
|
2
|
+
class Item
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
attr_accessor :id, :description, :amount, :price, :integration, :shipping_cost
|
6
|
+
|
7
|
+
validates_presence_of :id, :description, :amount, :price
|
8
|
+
validate :quantity_amount
|
9
|
+
|
10
|
+
def initialize(attributes={})
|
11
|
+
@id = attributes[:id]
|
12
|
+
@description = attributes[:description]
|
13
|
+
@amount = attributes[:amount]
|
14
|
+
@price = attributes[:price]
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def description
|
19
|
+
@description[0..254] if @description.present?
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def quantity_amount
|
25
|
+
errors.add(:quantity, " must be a number between 1 and 99999999999") if @quantity.present? && (@quantity == 0 || @quantity.to_s !~ /^\d{1,11}$/)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Bcash
|
2
|
+
|
3
|
+
class Package
|
4
|
+
|
5
|
+
attr_accessor :integration, :shipping_cost, :items
|
6
|
+
|
7
|
+
def initialize(items, shipping_cost, integration)
|
8
|
+
@items = items
|
9
|
+
@shipping_cost = shipping_cost
|
10
|
+
@integration = integration
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def create(items, shipping_cost = 0, integration = Bcash::PAD)
|
16
|
+
items_humanize_bcash = {}
|
17
|
+
|
18
|
+
items.each_with_index do |item, index|
|
19
|
+
amount_to_post = index + 1
|
20
|
+
|
21
|
+
items_humanize_bcash[:"produto_codigo_#{amount_to_post}"] = item.id
|
22
|
+
items_humanize_bcash[:"produto_descricao_#{amount_to_post}"] = item.description
|
23
|
+
items_humanize_bcash[:"produto_qtde_#{amount_to_post}"] = item.amount
|
24
|
+
items_humanize_bcash[:"produto_valor_#{amount_to_post}"] = item.price
|
25
|
+
end
|
26
|
+
|
27
|
+
items_humanize_bcash[:tipo_integracao] = integration
|
28
|
+
items_humanize_bcash[:frete] = shipping_cost
|
29
|
+
|
30
|
+
Package.new(items_humanize_bcash, items_humanize_bcash[:frete], items_humanize_bcash[:tipo_integracao])
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Bcash
|
2
|
+
class Payment
|
3
|
+
include ActionView::Helpers::TagHelper
|
4
|
+
include ActiveModel::Validations
|
5
|
+
|
6
|
+
attr_accessor :package, :options
|
7
|
+
attr_reader :email
|
8
|
+
|
9
|
+
validates_presence_of :email
|
10
|
+
|
11
|
+
def initialize(package, options = {})
|
12
|
+
@package = package
|
13
|
+
@options = options
|
14
|
+
@email = @options[:email_loja]
|
15
|
+
end
|
16
|
+
|
17
|
+
def html
|
18
|
+
form_content = File.open(File.join(File.dirname(__FILE__), 'form_bcash.html.haml')).read
|
19
|
+
|
20
|
+
if block_given?
|
21
|
+
button_html = yield
|
22
|
+
else
|
23
|
+
button_html = content_tag('button', 'Pagar com Bcash!', type: "submit")
|
24
|
+
end
|
25
|
+
|
26
|
+
Haml::Engine.new(form_content).render(nil, package: self.package, options: self.options, button_html: button_html)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
valid_attributes = {
|
4
|
+
id: 1,
|
5
|
+
description: "Description a item.",
|
6
|
+
amount: 2,
|
7
|
+
price: 200.00,
|
8
|
+
}
|
9
|
+
|
10
|
+
describe Bcash::Item do
|
11
|
+
|
12
|
+
it "should be a valid item" do
|
13
|
+
Bcash::Item.new(valid_attributes).should be_valid
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be return description with at 255 caracters" do
|
17
|
+
item = Bcash::Item.new(valid_attributes.merge(valid_attributes.merge(description: 'A' * 300)))
|
18
|
+
item.description.size.should == 255
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
items = [
|
4
|
+
Bcash::Item.new(id: 1, description: 'Test', amount: 2, price: 10.00),
|
5
|
+
Bcash::Item.new(id: 3, description: 'Another test', amount: 5, price: 40.00),
|
6
|
+
]
|
7
|
+
|
8
|
+
posts = {
|
9
|
+
produto_codigo_1: items[0].id, produto_descricao_1: items[0].description, produto_qtde_1: items[0].amount, produto_valor_1: items[0].price,
|
10
|
+
produto_codigo_2: items[1].id, produto_descricao_2: items[1].description, produto_qtde_2: items[1].amount, produto_valor_2: items[1].price,
|
11
|
+
}
|
12
|
+
describe Bcash::Package do
|
13
|
+
subject {Bcash::Package.create(items)}
|
14
|
+
|
15
|
+
it "should return 8 items humanize with bcash" do
|
16
|
+
subject.items.should include(posts)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
items = [
|
4
|
+
Bcash::Item.new(id: 1, description: 'Test', amount: 2, price: 10.00),
|
5
|
+
Bcash::Item.new(id: 3, description: 'Another test', amount: 5, price: 40.00),
|
6
|
+
]
|
7
|
+
|
8
|
+
package = Bcash::Package.create(items)
|
9
|
+
|
10
|
+
describe Bcash::Payment do
|
11
|
+
describe "Invalid package" do
|
12
|
+
subject{Bcash::Payment.new(package)}
|
13
|
+
|
14
|
+
it "should be invalid" do
|
15
|
+
subject.should_not be_valid
|
16
|
+
end
|
17
|
+
end
|
18
|
+
describe "With valid package" do
|
19
|
+
subject {Bcash::Payment.new(package, {email_loja: 'test@test.com', url_retorno: 'http://www.test.com'})}
|
20
|
+
|
21
|
+
it "should return a form" do
|
22
|
+
subject.html.should match(/^<form/)
|
23
|
+
subject.html.should match(/<button/)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return html with block button" do
|
27
|
+
subject.html{"<input type='submit' />"}.should match(/<input\ type=\'submit\'/)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should has inputs" do
|
31
|
+
form_bcash = Nokogiri::HTML(subject.html)
|
32
|
+
form_bcash.at('input[@name="email_loja"]')['value'].should == 'test@test.com'
|
33
|
+
form_bcash.at('input[@name="url_retorno"]')['value'].should == 'http://www.test.com'
|
34
|
+
form_bcash.at('input[@name="frete"]')['value'].should == '0'
|
35
|
+
form_bcash.at('input[@name="tipo_integracao"]')['value'].should == 'PAD'
|
36
|
+
form_bcash.at('input[@name="produto_codigo_1"]')['value'].should == '1'
|
37
|
+
form_bcash.at('input[@name="produto_descricao_1"]')['value'].should == 'Test'
|
38
|
+
form_bcash.at('input[@name="produto_qtde_1"]')['value'].should == '2'
|
39
|
+
form_bcash.at('input[@name="produto_valor_1"]')['value'].should == '10.0'
|
40
|
+
form_bcash.at('input[@name="produto_codigo_2"]')['value'].should == '3'
|
41
|
+
form_bcash.at('input[@name="produto_descricao_2"]')['value'].should == 'Another test'
|
42
|
+
form_bcash.at('input[@name="produto_qtde_2"]')['value'].should == '5'
|
43
|
+
form_bcash.at('input[@name="produto_valor_2"]')['value'].should == '40.0'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bcash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matheus Caceres
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activemodel
|
16
|
+
requirement: &70359646914460 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70359646914460
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rest-client
|
27
|
+
requirement: &70359646912380 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70359646912380
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: haml
|
38
|
+
requirement: &70359646911320 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70359646911320
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: nokogiri
|
49
|
+
requirement: &70359646910360 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70359646910360
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: actionpack
|
60
|
+
requirement: &70359646908740 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70359646908740
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: &70359646921820 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.3'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70359646921820
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rspec
|
82
|
+
requirement: &70359646920260 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70359646920260
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rake
|
93
|
+
requirement: &70359646918580 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70359646918580
|
102
|
+
description: Integration with BCash
|
103
|
+
email:
|
104
|
+
- matheuscaceres@gmail.com
|
105
|
+
executables: []
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files: []
|
108
|
+
files:
|
109
|
+
- .gitignore
|
110
|
+
- .rspec
|
111
|
+
- Gemfile
|
112
|
+
- Guardfile
|
113
|
+
- LICENSE.txt
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- bcash.gemspec
|
117
|
+
- lib/bcash.rb
|
118
|
+
- lib/bcash/form_bcash.html.haml
|
119
|
+
- lib/bcash/item.rb
|
120
|
+
- lib/bcash/package.rb
|
121
|
+
- lib/bcash/payment.rb
|
122
|
+
- lib/bcash/version.rb
|
123
|
+
- spec/bcash/item_spec.rb
|
124
|
+
- spec/bcash/package_spec.rb
|
125
|
+
- spec/bcash/payment_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
homepage: ''
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ! '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 1.8.10
|
149
|
+
signing_key:
|
150
|
+
specification_version: 3
|
151
|
+
summary: Integration with BCash
|
152
|
+
test_files:
|
153
|
+
- spec/bcash/item_spec.rb
|
154
|
+
- spec/bcash/package_spec.rb
|
155
|
+
- spec/bcash/payment_spec.rb
|
156
|
+
- spec/spec_helper.rb
|