BoletoIntermedium 0.1.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 +7 -0
- data/.gitignore +17 -0
- data/BoletoIntermedium.gemspec +35 -0
- data/Gemfile +5 -0
- data/README.md +59 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/BoletoIntermedium/boleto.rb +96 -0
- data/lib/BoletoIntermedium/configuration.rb +0 -0
- data/lib/BoletoIntermedium/version.rb +3 -0
- data/lib/BoletoIntermedium.rb +86 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 21bf9c555ae2583d29bc805d9a052a1a766bfd3f
|
4
|
+
data.tar.gz: 07ee60887d45bffb972f796ef00973eac924454d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fe13ad9210d966942c362fab7e5872aa98b2076520d349f2d3b387b0309fee9a1f0581408d229c9cb7c24c619dc9a38825be6ee54caba32cd2e46d86ffc1888f
|
7
|
+
data.tar.gz: f544ddebb454ec3d7a034f71c0ce65fc47d01b3d2469925f1fd20e41ce2a801840be635d7e2a7abbfd1eeecb0bed77e1fcee64e63d104e841bd9be2123fc4b29
|
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'BoletoIntermedium/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "BoletoIntermedium"
|
8
|
+
spec.version = BoletoIntermedium::VERSION
|
9
|
+
spec.authors = ["Gabriel Hamdan"]
|
10
|
+
spec.email = ["ghamdan.eng@gmail.com"]
|
11
|
+
spec.licenses = ['MIT']
|
12
|
+
|
13
|
+
|
14
|
+
spec.summary = "Create Bank Intermedium's payment slips in ruby"
|
15
|
+
spec.description = "This gem makes possible to generate Bank Intermedium's payment slips in ruby"
|
16
|
+
spec.homepage = "https://github.com/hamdan85/BoletoIntermedium"
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
if spec.respond_to?(:metadata)
|
21
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
22
|
+
else
|
23
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
end
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# BoletoIntermedium
|
2
|
+
|
3
|
+
This gem makes possible to generate Bank Intermedium's payment slips in ruby
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'BoletoIntermedium'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install BoletoIntermedium
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In order to generate the bank's slips, you need first to initialize the gem's module with some initial configurations:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
BoletoIntermedium.configure do |config|
|
27
|
+
config.account = "0000000" #Your account number
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
Then, you can generate the payment slips:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
boleto = Boleto.new(
|
35
|
+
payment_slip: 1, #YOUR control number (Integer)
|
36
|
+
value_in_cents: 100, #Value to be paid in cents (Integer)
|
37
|
+
due_date: Date.today #Due Date (Date)
|
38
|
+
)
|
39
|
+
```
|
40
|
+
|
41
|
+
To get the bar code:
|
42
|
+
```ruby
|
43
|
+
boleto.bar_code
|
44
|
+
```
|
45
|
+
|
46
|
+
To get the formatted digitable line:
|
47
|
+
```ruby
|
48
|
+
boleto.formatted_digitable_line
|
49
|
+
```
|
50
|
+
|
51
|
+
To get the non-formatted digitable line:
|
52
|
+
```ruby
|
53
|
+
boleto.digitable_line
|
54
|
+
```
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hamdan85/BoletoIntermedium.
|
59
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "BoletoIntermedium"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
class Boleto
|
2
|
+
include BoletoIntermedium
|
3
|
+
|
4
|
+
attr_accessor :configuration
|
5
|
+
|
6
|
+
attr_accessor :payment_slip
|
7
|
+
attr_accessor :value_in_cents
|
8
|
+
attr_accessor :due_date
|
9
|
+
|
10
|
+
attr_accessor :field1
|
11
|
+
attr_accessor :field_dv
|
12
|
+
attr_accessor :field2
|
13
|
+
attr_accessor :field_dv
|
14
|
+
attr_accessor :field3
|
15
|
+
attr_accessor :field_dv
|
16
|
+
attr_accessor :field4
|
17
|
+
attr_accessor :field5
|
18
|
+
|
19
|
+
def initialize(fields = {})
|
20
|
+
@payment_slip = fields[:payment_slip] ? fields[:payment_slip].to_s[0..6].rjust(7, '0') : '0000000'
|
21
|
+
@value_in_cents = (fields[:value_in_cents] || 0).to_s[0..9].rjust(10, '0')
|
22
|
+
@due_date = (fields[:due_date] ? BoletoIntermedium.bank_epoque(fields[:due_date]) : BoletoIntermedium.bank_epoque(Date.today + 1.week)).to_s[0..3].rjust(4, '0')
|
23
|
+
|
24
|
+
config = BoletoIntermedium.configuration
|
25
|
+
|
26
|
+
self.field1 = config.bank_code + config.currency_code + config.agency + config.product + config.wallet[0]
|
27
|
+
self.field2 = config.wallet[1] + config.system + @payment_slip
|
28
|
+
self.field3 = config.account
|
29
|
+
|
30
|
+
@field5 = @due_date + @value_in_cents
|
31
|
+
end
|
32
|
+
|
33
|
+
def field1=(str)
|
34
|
+
@field1 = str
|
35
|
+
@field1_dv = BoletoIntermedium.module_10(str).to_s
|
36
|
+
set_field_4
|
37
|
+
end
|
38
|
+
|
39
|
+
def field2=(str)
|
40
|
+
@field2 = str
|
41
|
+
@field2_dv = BoletoIntermedium.module_10(str).to_s
|
42
|
+
set_field_4
|
43
|
+
end
|
44
|
+
|
45
|
+
def field3=(str)
|
46
|
+
@field3 = str
|
47
|
+
@field3_dv = BoletoIntermedium.module_10(str).to_s
|
48
|
+
set_field_4
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_field_4
|
52
|
+
@field4 = BoletoIntermedium.module_11(bar_code_without_verifier).to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
def bar_code_without_verifier
|
56
|
+
config = BoletoIntermedium.configuration
|
57
|
+
|
58
|
+
config.bank_code +
|
59
|
+
config.currency_code +
|
60
|
+
due_date +
|
61
|
+
value_in_cents +
|
62
|
+
config.agency +
|
63
|
+
config.product +
|
64
|
+
config.wallet +
|
65
|
+
config.system +
|
66
|
+
payment_slip +
|
67
|
+
config.account
|
68
|
+
end
|
69
|
+
|
70
|
+
def bar_code
|
71
|
+
bar_code_without_verifier[0..3] + BoletoIntermedium.module_11(bar_code_without_verifier).to_s + bar_code_without_verifier[-39..-1]
|
72
|
+
end
|
73
|
+
|
74
|
+
def digitable_line
|
75
|
+
(@field1 || '') +
|
76
|
+
(@field1_dv || '') +
|
77
|
+
(@field2 || '') +
|
78
|
+
(@field2_dv || '') +
|
79
|
+
(@field3 || '') +
|
80
|
+
(@field3_dv || '') +
|
81
|
+
(@field4 || '') +
|
82
|
+
(@field5 || '')
|
83
|
+
end
|
84
|
+
|
85
|
+
def formatted_digitable_line
|
86
|
+
digitable_line[0..4] +
|
87
|
+
'.' + digitable_line[5..9] +
|
88
|
+
' ' + digitable_line[10..14] +
|
89
|
+
'.' + digitable_line[15..20] +
|
90
|
+
' ' + digitable_line[21..25] +
|
91
|
+
'.' + digitable_line[26..31] +
|
92
|
+
' ' + digitable_line[32] +
|
93
|
+
' ' + digitable_line[33..46]
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
File without changes
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require "BoletoIntermedium/version"
|
2
|
+
require "../lib/BoletoIntermedium/configuration"
|
3
|
+
require "../lib/BoletoIntermedium/boleto"
|
4
|
+
require "active_support/all"
|
5
|
+
|
6
|
+
module BoletoIntermedium
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configure
|
13
|
+
@configuration ||= Configuration.new
|
14
|
+
yield(configuration || @configuration)
|
15
|
+
@configuration
|
16
|
+
end
|
17
|
+
|
18
|
+
class Configuration
|
19
|
+
|
20
|
+
attr_reader :bank_code
|
21
|
+
attr_reader :currency_code
|
22
|
+
attr_reader :agency
|
23
|
+
attr_reader :product
|
24
|
+
attr_reader :wallet
|
25
|
+
attr_reader :system
|
26
|
+
attr_accessor :account
|
27
|
+
|
28
|
+
def initialize(fields = {})
|
29
|
+
@bank_code = '077'
|
30
|
+
@currency_code = '9'
|
31
|
+
@agency = '1'
|
32
|
+
@product = '000'
|
33
|
+
@wallet = '12'
|
34
|
+
@system = '10'
|
35
|
+
|
36
|
+
self.account = fields[:account] if fields[:account]
|
37
|
+
end
|
38
|
+
|
39
|
+
def account=(str)
|
40
|
+
@account = str.to_s[0..9].rjust(10, '0')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def self.bank_epoque(date)
|
47
|
+
(date - Date.new(1997,10,7)).to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.module_10(str)
|
51
|
+
str = str.chars.reverse
|
52
|
+
i = 2
|
53
|
+
sum = 0
|
54
|
+
res = 0
|
55
|
+
|
56
|
+
str.each do |char|
|
57
|
+
res = char.to_i * i
|
58
|
+
sum += res > 9 ? (res - 9) : res
|
59
|
+
i = i == 2 ? 1 : 2
|
60
|
+
end
|
61
|
+
|
62
|
+
if (sum % 10) == 0
|
63
|
+
0
|
64
|
+
else
|
65
|
+
10 - (sum % 10)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.module_11(str)
|
70
|
+
peso = 2
|
71
|
+
soma = 0
|
72
|
+
|
73
|
+
str = str.chars.reverse
|
74
|
+
|
75
|
+
str.each do |char|
|
76
|
+
soma += char.to_i * peso
|
77
|
+
peso = (peso == 9) ? 2 : peso + 1
|
78
|
+
end
|
79
|
+
|
80
|
+
if soma % 11 == 0
|
81
|
+
1
|
82
|
+
else
|
83
|
+
11 - (soma % 11)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: BoletoIntermedium
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gabriel Hamdan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: This gem makes possible to generate Bank Intermedium's payment slips
|
42
|
+
in ruby
|
43
|
+
email:
|
44
|
+
- ghamdan.eng@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- BoletoIntermedium.gemspec
|
51
|
+
- Gemfile
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- lib/BoletoIntermedium.rb
|
57
|
+
- lib/BoletoIntermedium/boleto.rb
|
58
|
+
- lib/BoletoIntermedium/configuration.rb
|
59
|
+
- lib/BoletoIntermedium/version.rb
|
60
|
+
homepage: https://github.com/hamdan85/BoletoIntermedium
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata:
|
64
|
+
allowed_push_host: https://rubygems.org
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.5.1
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Create Bank Intermedium's payment slips in ruby
|
85
|
+
test_files: []
|