bot_ebill 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 907e8820ff32b25b0ea03b38fead94085d34a846be4c49d91bcb8846115b614b
4
+ data.tar.gz: fc339ef8dee4eecaff6cbaa2416228bdee8b92ab8106a7c6ed3669514a66809b
5
+ SHA512:
6
+ metadata.gz: 7535235d04c59973df3b91a448091aa3117e4ea7330a6ca74d709f2372e9f9cbe49ace79963758bbbdb06c10b2accb1c2e5d641e1a05649a9d210e5fdaadefd6
7
+ data.tar.gz: 7b2647b32fd8b1740328d868ada2430c21d27e14e5d941ba48237ad5bf867039945844d77839b65dea84a441005de12b388cef13b649e2a2421e236656effa0a
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 1.17.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at cellvinchung@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem 'simplecov', require: false
6
+ # Specify your gem's dependencies in bot_ebill.gemspec
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bot_ebill (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ docile (1.3.2)
11
+ json (2.2.0)
12
+ rake (10.5.0)
13
+ rspec (3.8.0)
14
+ rspec-core (~> 3.8.0)
15
+ rspec-expectations (~> 3.8.0)
16
+ rspec-mocks (~> 3.8.0)
17
+ rspec-core (3.8.2)
18
+ rspec-support (~> 3.8.0)
19
+ rspec-expectations (3.8.4)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.8.0)
22
+ rspec-mocks (3.8.1)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-support (3.8.2)
26
+ simplecov (0.17.0)
27
+ docile (~> 1.1)
28
+ json (>= 1.8, < 3)
29
+ simplecov-html (~> 0.10.0)
30
+ simplecov-html (0.10.2)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bot_ebill!
37
+ bundler (~> 1.17)
38
+ rake (~> 10.0)
39
+ rspec (~> 3.0)
40
+ simplecov
41
+
42
+ BUNDLED WITH
43
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 鍾劭方(Cellvin Chung)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # BotEbill
2
+
3
+ [台灣銀行電子化收款](https://www.bot.com.tw/Business/ITBusiness/Pages/ebill.aspx)Barcode內容產生器
4
+
5
+ >- 請先向台灣銀行申請電子化收款服務。
6
+ >- 不產出Barcode圖像,請搭配使用Barcode產生器,如[barby](https://github.com/toretore/barby)(ruby)、[JsBarcode](https://github.com/lindell/JsBarcode)(js)等,格式使用**code39**。
7
+
8
+ ## Installation
9
+
10
+ Gemfile 加上:
11
+
12
+ ```ruby
13
+ gem 'bot_ebill'
14
+ ```
15
+
16
+ 執行:
17
+
18
+ $ bundle
19
+
20
+ 或直接執行:
21
+
22
+ $ gem install bot_ebill
23
+
24
+ ## 使用方式
25
+
26
+ ```ruby
27
+ @barcode_text = BotEbill::BarcodeText.new(
28
+ collection_no: "代收類別",
29
+ store_no: "超商代收項目",
30
+ order_no: "自訂編號",
31
+ price: "金額"
32
+ )
33
+
34
+ #台銀條碼內容
35
+ @barcode_text.bot_text
36
+
37
+ #超商條碼內容
38
+ @barcode_text.store_text
39
+
40
+ #郵局條碼內容
41
+ @barcode_text.post_office_text
42
+ ```
43
+
44
+ ## License
45
+
46
+ [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bot_ebill"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bot_ebill.gemspec ADDED
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "bot_ebill/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bot_ebill"
8
+ spec.version = BotEbill::VERSION
9
+ spec.authors = ["鍾劭方(Cellvin Chung)"]
10
+ spec.email = ["cellvinchung@gmail.com"]
11
+
12
+ spec.summary = %q{台灣銀行電子化收款條碼資料產生器}
13
+ spec.description = %q{台灣銀行電子化收款產生台銀、超商、郵局條碼}
14
+ spec.homepage = "https://github.com/cellvinchung/bot_ebill"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/cellvinchung/bot_ebill"
24
+ spec.metadata["changelog_uri"] = "https://github.com/cellvinchung/bot_ebill"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.17"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ end
data/lib/bot_ebill.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "bot_ebill/version"
2
+ require "bot_ebill/check_code"
3
+ require "bot_ebill/barcode_text"
4
+
5
+ module BotEbill
6
+ class Error < StandardError; end
7
+
8
+ end
@@ -0,0 +1,62 @@
1
+ module BotEbill
2
+ class BarcodeText
3
+ attr_accessor :bot_text, :store_text, :post_office_text
4
+ def initialize(options)
5
+ raise ArgumentError, 'Missing required argument: collection_no.代收類別' unless options[:collection_no]
6
+ raise ArgumentError, 'Missing required argument: store_no.超商代收項目' unless options[:store_no]
7
+ raise ArgumentError, 'Missing required argument: order_no.自訂編號' unless options[:order_no]
8
+ raise ArgumentError, 'Missing required argument: price.金額' unless options[:price]
9
+
10
+ @collection_no = options[:collection_no].to_s #代收類別
11
+ @store_no = options[:store_no].to_s #超商代收項目
12
+ @order_no = options[:order_no].to_s #自訂編號
13
+ @price = options[:price] #金額
14
+
15
+ bot_check_code = BotEbill::CheckCode.bot(collection_no: @collection_no, order_no: @order_no, price: @price)
16
+
17
+ @bot_account = "#{@collection_no}#{@order_no}#{bot_check_code}" #台銀帳號
18
+ end
19
+
20
+ def bot_text #台銀條碼
21
+ [@bot_account, @price.to_s]
22
+ end
23
+
24
+ def store_text
25
+ section_1 = "999999#{@store_no}"
26
+ section_2 = @bot_account
27
+
28
+ custom_no = "1234"
29
+ full_price = @price.to_s.rjust(9, "0")
30
+ tem_section_3 = "#{custom_no}#{full_price}"
31
+
32
+ store_check_code = BotEbill::CheckCode.store(section_1, section_2, tem_section_3)
33
+
34
+ section_3 = "#{custom_no}#{store_check_code}#{full_price}"
35
+ [section_1, section_2, section_3]
36
+ end
37
+
38
+ def post_office_text
39
+ section_1 = "19834251" #固定台銀戶名
40
+
41
+ total_price = @price.to_i + post_office_fee
42
+
43
+ post_office_check_code = BotEbill::CheckCode.post_office(collection_no: @collection_no, order_no: @order_no, price: total_price)
44
+
45
+ section_2 = "#{@collection_no}#{@order_no}#{post_office_check_code}"
46
+ section_3 = total_price.to_s
47
+
48
+ [section_1, section_2, section_3]
49
+ end
50
+
51
+ private
52
+
53
+ def post_office_fee
54
+ origin_price = @price.to_i
55
+ fee = 5 if origin_price.between?(1, 95)
56
+ fee = 10 if origin_price.between?(96, 990)
57
+ fee = 15 if origin_price >= 991
58
+
59
+ fee ||= 0
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,89 @@
1
+ module BotEbill
2
+ class CheckCode
3
+
4
+ def self.bot(options)
5
+ collection_no = options[:collection_no].to_s #代收類別
6
+ order_no = options[:order_no].to_s #自訂編號
7
+ price = options[:price].to_s #金額
8
+
9
+ full_price = price.to_s.rjust(10, "0")
10
+
11
+ full_string = "#{collection_no}#{order_no}#{full_price}"
12
+ weights = [1,3,7]
13
+
14
+ full_string.split("").each_with_index.map{|element, index| element.to_i*(weights[index%3]) }.reduce(&:+)%10
15
+ end
16
+
17
+ def self.store(section_1, section_2, section_3) #超商檢核碼
18
+ numbered_section_1 = section_1.split("").map{|s| transfer_text(s)}
19
+ numbered_section_2 = section_2.split("").map{|s| transfer_text(s)}
20
+ numbered_section_3 = section_3.split("").map{|s| transfer_text(s)}
21
+
22
+ numbered_section_1_odd, numbered_section_1_even = numbered_section_1.partition.with_index { |_,i| i.even? }
23
+ numbered_section_2_odd, numbered_section_2_even = numbered_section_2.partition.with_index { |_,i| i.even? }
24
+ numbered_section_3_odd, numbered_section_3_even = numbered_section_3.partition.with_index { |_,i| i.even? }
25
+
26
+ first_sum = (numbered_section_1_odd+numbered_section_2_odd+numbered_section_3_odd).reduce(&:+)
27
+ last_sum = (numbered_section_1_even+numbered_section_2_even+numbered_section_3_even).reduce(&:+)
28
+
29
+ first_code, last_code = first_sum%11, last_sum%11
30
+ first_code = "A" if first_code == 0
31
+ first_code = "B" if first_code == 10
32
+ last_code = "X" if last_code == 0
33
+ last_code = "Y" if last_code == 10
34
+
35
+ "#{first_code}#{last_code}"
36
+ end
37
+
38
+ def self.post_office(options) #郵局檢核碼
39
+ collection_no = options[:collection_no].to_s #代收類別
40
+ order_no = options[:order_no].to_s #自訂編號
41
+ price = options[:price].to_s #金額
42
+
43
+ full_price = price.to_s.rjust(10, "0")
44
+
45
+ full_string = "#{collection_no}#{order_no}#{full_price}"
46
+ weights = [1,3,7]
47
+
48
+ code = full_string.split("").each_with_index.map{|element, index| element.to_i*(weights[index%3]) }.reduce(&:+)%10
49
+
50
+ code + 1
51
+ end
52
+
53
+ private
54
+
55
+ def self.transfer_text(text)
56
+ text_mapping = {
57
+ A: 1,
58
+ B: 2,
59
+ C: 3,
60
+ D: 4,
61
+ E: 5,
62
+ F: 6,
63
+ G: 7,
64
+ H: 8,
65
+ I: 9,
66
+ J: 1,
67
+ K: 2,
68
+ L: 3,
69
+ M: 4,
70
+ N: 5,
71
+ O: 6,
72
+ P: 7,
73
+ Q: 8,
74
+ R: 9,
75
+ S: 2,
76
+ T: 3,
77
+ U: 4,
78
+ V: 5,
79
+ W: 6,
80
+ X: 7,
81
+ Y: 8,
82
+ Z: 9
83
+ }
84
+ text = text.to_s.upcase
85
+
86
+ text.between?("A", "Z") ? text_mapping[text.to_sym] : text.to_i
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,3 @@
1
+ module BotEbill
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bot_ebill
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - 鍾劭方(Cellvin Chung)
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-30 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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: 台灣銀行電子化收款產生台銀、超商、郵局條碼
56
+ email:
57
+ - cellvinchung@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - bot_ebill.gemspec
74
+ - lib/bot_ebill.rb
75
+ - lib/bot_ebill/barcode_text.rb
76
+ - lib/bot_ebill/check_code.rb
77
+ - lib/bot_ebill/version.rb
78
+ homepage: https://github.com/cellvinchung/bot_ebill
79
+ licenses:
80
+ - MIT
81
+ metadata:
82
+ allowed_push_host: https://rubygems.org
83
+ homepage_uri: https://github.com/cellvinchung/bot_ebill
84
+ source_code_uri: https://github.com/cellvinchung/bot_ebill
85
+ changelog_uri: https://github.com/cellvinchung/bot_ebill
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubygems_version: 3.0.1
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: 台灣銀行電子化收款條碼資料產生器
105
+ test_files: []