einvoice 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +12 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/einvoice.gemspec +33 -0
- data/lib/einvoice.rb +15 -0
- data/lib/einvoice/api.rb +22 -0
- data/lib/einvoice/client/neweb.rb +20 -0
- data/lib/einvoice/configuration.rb +40 -0
- data/lib/einvoice/connection.rb +23 -0
- data/lib/einvoice/model/base.rb +16 -0
- data/lib/einvoice/model/contact.rb +18 -0
- data/lib/einvoice/model/customer_defined.rb +17 -0
- data/lib/einvoice/model/invoice.rb +54 -0
- data/lib/einvoice/model/invoice_item.rb +22 -0
- data/lib/einvoice/validator/carrier_id1_validator.rb +7 -0
- data/lib/einvoice/validator/carrier_id2_validator.rb +7 -0
- data/lib/einvoice/validator/customs_clearance_mark_validator.rb +7 -0
- data/lib/einvoice/validator/print_mark_validator.rb +7 -0
- data/lib/einvoice/version.rb +3 -0
- data/lib/faraday/request/digest_neweb.rb +20 -0
- data/lib/faraday/request/encode_xml.rb +52 -0
- metadata +211 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fbc9820ea32a3c3e23284e5b25de73215a5d660c
|
4
|
+
data.tar.gz: a1a78e1b0f0d7438392dd1b1724eba9fa451701d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48f85fd5e4a2437bf88e951f62af15e8bd24e7b1aabe86e88efec919d3334424bb78566d38d7a77151fadc619d08ff0669477d2769bd1739836e3da6075fbdfa
|
7
|
+
data.tar.gz: cac3cc64d46ebe7d3a879cc9603acb6d56a4f09bffb268083899b8a99971775427784f64c449a44e700c4f8465b0b33ebbe345cc1c11f5b0e4bbde1839b733c1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 David Yun
|
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,52 @@
|
|
1
|
+
# Einvoice
|
2
|
+
[![Build Status](https://travis-ci.org/abookyun/einvoice.svg?branch=master)](https://travis-ci.org/abookyun/einvoice)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/abookyun/einvoice/badges/gpa.svg)](https://codeclimate.com/github/abookyun/einvoice)
|
4
|
+
[![Test Coverage](https://codeclimate.com/github/abookyun/einvoice/badges/coverage.svg)](https://codeclimate.com/github/abookyun/einvoice/coverage)
|
5
|
+
|
6
|
+
To support the thriving e-commerce industry and lower the business costs and barriers associated with printing paper receipts, the Taiwan Executive Yuan announced plans in August 2000 to implement electronic receipts in Taiwan and launched a comprehensive project in May 2010 to promote e-invoice applications. This initiative employs innovative approaches such as allowing consumers to claim virtual receipts via multiple devices, offering automatic checking of receipt lottery numbers, and providing a variety of channels for retailers to issue receipts.
|
7
|
+
|
8
|
+
Hence, there are several e-invoice services for B2B, B2C in Taiwan as the intermediate and value-adding platform like CHT, allPay, Neweb, ..etc. They mostly provide services like below:
|
9
|
+
|
10
|
+
* Manage e-invoices
|
11
|
+
* New an e-invoice
|
12
|
+
* Return an e-invoice
|
13
|
+
* Invalidate an e-invoice
|
14
|
+
* List e-invoices
|
15
|
+
* ...
|
16
|
+
|
17
|
+
So that, we need a API wrapper to manage and access the APIs.
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'einvoice'
|
25
|
+
```
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ bundle
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install einvoice
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
TODO: Write usage instructions here
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
+
|
43
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/einvoice.
|
48
|
+
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "einvoice"
|
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
data/einvoice.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'einvoice/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "einvoice"
|
8
|
+
spec.version = Einvoice::VERSION
|
9
|
+
spec.authors = ["David Yun"]
|
10
|
+
spec.email = ["abookyun@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A API wrapper for Taiwan e-invoice services.}
|
13
|
+
spec.homepage = "https://github.com/abookyun/einvoice"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 2.0.0'
|
22
|
+
spec.add_dependency "faraday"
|
23
|
+
spec.add_dependency "faraday_middleware"
|
24
|
+
spec.add_dependency "multi_xml"
|
25
|
+
spec.add_dependency "activemodel"
|
26
|
+
spec.add_dependency "gyoku"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec"
|
31
|
+
spec.add_development_dependency "factory_girl"
|
32
|
+
spec.add_development_dependency "shoulda-matchers"
|
33
|
+
end
|
data/lib/einvoice.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "einvoice/version"
|
2
|
+
require "einvoice/configuration"
|
3
|
+
require "einvoice/connection"
|
4
|
+
require "einvoice/api"
|
5
|
+
require "einvoice/model/base"
|
6
|
+
|
7
|
+
require "einvoice/client/neweb"
|
8
|
+
require "einvoice/model/invoice"
|
9
|
+
require "einvoice/model/invoice_item"
|
10
|
+
require "einvoice/model/contact"
|
11
|
+
require "einvoice/model/customer_defined"
|
12
|
+
|
13
|
+
module Einvoice
|
14
|
+
extend Configuration
|
15
|
+
end
|
data/lib/einvoice/api.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Einvoice
|
2
|
+
class API
|
3
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
options = Einvoice.options.merge(options)
|
7
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
8
|
+
send("#{key}=", options[key])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def config
|
13
|
+
conf = {}
|
14
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
15
|
+
conf[key] = send key
|
16
|
+
end
|
17
|
+
conf
|
18
|
+
end
|
19
|
+
|
20
|
+
include Connection
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Einvoice
|
2
|
+
module Client
|
3
|
+
class Neweb < API
|
4
|
+
def initialize
|
5
|
+
connection.use Faraday::Request::UrlEncoded
|
6
|
+
connection.use Faraday::Request::DigestNeweb :neweb, client_secret
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_invoice(invoice)
|
10
|
+
connection.post do |request|
|
11
|
+
request.url "IN_PreInvoiceS.action"
|
12
|
+
request.body = {
|
13
|
+
StoreCode: client_id,
|
14
|
+
xmldata: invoice.to_json
|
15
|
+
}
|
16
|
+
end.body
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "faraday"
|
2
|
+
|
3
|
+
module Einvoice
|
4
|
+
module Configuration
|
5
|
+
VALID_OPTIONS_KEYS = [
|
6
|
+
:endpoint,
|
7
|
+
:client_id,
|
8
|
+
:client_secret,
|
9
|
+
:format,
|
10
|
+
].freeze
|
11
|
+
|
12
|
+
DEFAULT_CLIENT_ID = nil
|
13
|
+
DEFAULT_CLIENT_SECRET = nil
|
14
|
+
DEFAULT_ENDPOINT = "".freeze
|
15
|
+
DEFAULT_FORMAT = :xml
|
16
|
+
|
17
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
18
|
+
|
19
|
+
def self.extended(base)
|
20
|
+
base.reset
|
21
|
+
end
|
22
|
+
|
23
|
+
def configure
|
24
|
+
yield self
|
25
|
+
end
|
26
|
+
|
27
|
+
def options
|
28
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
29
|
+
option.merge!(key => send(key))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def reset
|
34
|
+
self.endpoint = DEFAULT_ENDPOINT
|
35
|
+
self.client_id = DEFAULT_CLIENT_ID
|
36
|
+
self.client_secret = DEFAULT_CLIENT_SECRET
|
37
|
+
self.format = DEFAULT_FORMAT
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "faraday_middleware"
|
2
|
+
|
3
|
+
module Einvoice
|
4
|
+
module Connection
|
5
|
+
private
|
6
|
+
|
7
|
+
def connection
|
8
|
+
options = {
|
9
|
+
headers: { "Accept" => "application/#{format}; charset=utf-8" },
|
10
|
+
url: endpoint
|
11
|
+
}
|
12
|
+
|
13
|
+
::Faraday::Connection.new(options) do |connection|
|
14
|
+
case format.to_s.downcase
|
15
|
+
when "xml" then connection.use Faraday::Response::ParseXml
|
16
|
+
when "json" then connection.use Faraday::Response::ParseJson
|
17
|
+
end
|
18
|
+
|
19
|
+
connection.adapter Faraday.default_adapter
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "active_model"
|
2
|
+
|
3
|
+
require "einvoice/validator/carrier_id1_validator"
|
4
|
+
require "einvoice/validator/carrier_id2_validator"
|
5
|
+
require "einvoice/validator/customs_clearance_mark_validator"
|
6
|
+
require "einvoice/validator/print_mark_validator"
|
7
|
+
|
8
|
+
module Einvoice
|
9
|
+
module Model
|
10
|
+
class Base
|
11
|
+
include ActiveModel::Model
|
12
|
+
include ActiveModel::Validations
|
13
|
+
include ActiveModel::Serialization
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Einvoice
|
2
|
+
module Model
|
3
|
+
class Contact < Einvoice::Model::Base
|
4
|
+
attr_accessor :name, :address, :t_e_l, :email
|
5
|
+
|
6
|
+
validates :name, presence: true, length: { maximum: 64 }
|
7
|
+
validates :address, presence: true, length: { maximum: 128 }
|
8
|
+
validates :t_e_l, length: { maximum: 64 }
|
9
|
+
validates :email, length: { maximum: 512 }
|
10
|
+
|
11
|
+
def initialize(attributes={})
|
12
|
+
attributes.each do |attribute, value|
|
13
|
+
instance_variable_set("@#{attribute}", value) if respond_to?(attribute.to_sym)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Einvoice
|
2
|
+
module Model
|
3
|
+
class CustomerDefined < Einvoice::Model::Base
|
4
|
+
attr_accessor :project_no, :purchase_no, :stamp_duty_flag
|
5
|
+
|
6
|
+
validates :project_no, length: { maximum: 64 }
|
7
|
+
validates :purchase_no, length: { maximum: 64 }
|
8
|
+
validates :stamp_duty_flag, length: { maximum: 1 }
|
9
|
+
|
10
|
+
def initialize(attributes={})
|
11
|
+
attributes.each do |attribute, value|
|
12
|
+
instance_variable_set("@#{attribute}", value) if respond_to?(attribute.to_sym)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Einvoice
|
2
|
+
module Model
|
3
|
+
class Invoice < Einvoice::Model::Base
|
4
|
+
attr_accessor :data_number, :data_date, :seller_id, :buyer_name,
|
5
|
+
:buyer_id, :customs_clearance_mark, :invoice_type,
|
6
|
+
:donate_mark, :carrier_type, :carrier_id1, :carrier_id2,
|
7
|
+
:print_mark, :n_p_o_b_a_n, :random_number, :invoice_items,
|
8
|
+
:sales_amount, :free_tax_sales_amount,
|
9
|
+
:zero_tax_sales_amount, :tax_type, :tax_rate, :tax_amount,
|
10
|
+
:total_amount, :contact, :customer_defined
|
11
|
+
|
12
|
+
validates :data_number, presence: true, length: { maximum: 20 }
|
13
|
+
validates :data_date, presence: true, length: { maximum: 10 }, format: { with: /\A\d{4}\/\d{2}\/\d{2}\z/ }
|
14
|
+
validates :seller_id, presence: true, length: { maximum: 10 }
|
15
|
+
validates :buyer_name, presence: true, length: { maximum: 60 }
|
16
|
+
validates :buyer_id, presence: true, length: { maximum: 10 }
|
17
|
+
validates :customs_clearance_mark, length: { maximum: 1 }, format: { with: /[01]/ }, customs_clearance_mark: true
|
18
|
+
validates :invoice_type, presence: true, length: { maximum: 2 }, format: { with: /07|08/ }
|
19
|
+
validates :donate_mark, presence: true, length: { maximum: 1 }, format: { with: /[01]/ }
|
20
|
+
validates :carrier_type, length: { maximum: 6 }, format: { with: /[a-zA-Z]{2}\d{4}/ }, allow_blank: true
|
21
|
+
validates :carrier_id1, length: { maximum: 64 }, carrier_id1: true
|
22
|
+
validates :carrier_id2, length: { maximum: 64 }, carrier_id2: true
|
23
|
+
validates :print_mark, presence: true, length: { maximum: 1 }, format: { with: /[YN]/ }, print_mark: true
|
24
|
+
validates :n_p_o_b_a_n, length: { maximum: 10 }
|
25
|
+
validates :random_number, length: { maximum: 4 }
|
26
|
+
validates :invoice_items, presence: true
|
27
|
+
validates :sales_amount, presence: true, length: { maximum: 12 }, numericality: { greater_than_or_equal_to: 0 }
|
28
|
+
validates :free_tax_sales_amount, presence: true, length: { maximum: 12 }, numericality: { greater_than_or_equal_to: 0 }
|
29
|
+
validates :zero_tax_sales_amount, presence: true, length: { maximum: 12 }, numericality: { greater_than_or_equal_to: 0 }
|
30
|
+
validates :tax_type, presence: true, length: { maximum: 1 }
|
31
|
+
validates :tax_rate, presence: true, length: { maximum: 6 }
|
32
|
+
validates :tax_amount, presence: true, length: { maximum: 12 }, numericality: { greater_than_or_equal_to: 0 }
|
33
|
+
validates :total_amount, presence: true, length: { maximum: 12 }, numericality: { greater_than_or_equal_to: 0 }
|
34
|
+
validates :contact, presence: true
|
35
|
+
validates :customer_defined, presence: true
|
36
|
+
|
37
|
+
def initialize(attributes={})
|
38
|
+
invoice_items = []
|
39
|
+
attributes.each do |attribute, value|
|
40
|
+
case attribute.to_sym
|
41
|
+
when :invoice_item
|
42
|
+
invoice_items << InvoiceItem.new(value)
|
43
|
+
when :contact
|
44
|
+
contact = Contact.new(value)
|
45
|
+
when :customer_defined
|
46
|
+
customer_defined = CustomerDefined.new(value)
|
47
|
+
else
|
48
|
+
instance_variable_set("@#{attribute}", value) if respond_to?(attribute.to_sym)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Einvoice
|
2
|
+
module Model
|
3
|
+
class InvoiceItem < Einvoice::Model::Base
|
4
|
+
attr_accessor :description, :quantity, :unit, :unit_price, :amount,
|
5
|
+
:sequence_number, :remark
|
6
|
+
|
7
|
+
validates :description, presence: true, length: { maximum: 256 }
|
8
|
+
validates :quantity, presence: true, length: { maximum: 17 }
|
9
|
+
validates :unit, length: { maximum: 6 }
|
10
|
+
validates :unit_price, presence: true, length: { maximum: 17 }
|
11
|
+
validates :amount, presence: true, length: { maximum: 17 }
|
12
|
+
validates :sequence_number, presence: true, length: { maximum: 3 }
|
13
|
+
validates :remark, length: { maximum: 40 }
|
14
|
+
|
15
|
+
def initialize(attributes={})
|
16
|
+
attributes.each do |attribute, value|
|
17
|
+
instance_variable_set("@#{attribute}", value) if respond_to?(attribute.to_sym)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class CarrierId1Validator < ActiveModel::EachValidator
|
2
|
+
def validate_each(record, attribute, value)
|
3
|
+
if (record.print_mark.to_s == "Y" && value.present?) || (record.print_mark.to_s == "N" && value.blank?)
|
4
|
+
record.errors.add attribute, options[:message] || :invalid
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class CarrierId2Validator < ActiveModel::EachValidator
|
2
|
+
def validate_each(record, attribute, value)
|
3
|
+
if (record.print_mark.to_s == "Y" && value.present?) || (record.print_mark.to_s == "N" && value.blank?)
|
4
|
+
record.errors.add attribute, options[:message] || :invalid
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class PrintMarkValidator < ActiveModel::EachValidator
|
2
|
+
def validate_each(record, attribute, value)
|
3
|
+
if value == "Y" && (record.carrier_id1.present? || record.carrier_id2.present? || record.donate_mark == "Y")
|
4
|
+
record.errors.add attribute, options[:message] || :invalid
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module FaradayMiddleware
|
4
|
+
class DigestNeweb < Faraday::Middleware
|
5
|
+
dependency do
|
6
|
+
require 'digest' unless defined?(::Digest)
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(app, secret)
|
10
|
+
super(app)
|
11
|
+
@secret = secret
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
xmldata = env[:body][:xmldata]
|
16
|
+
env[:body][:hash] = Digest::MD5.digest([xmldata, @secret])
|
17
|
+
@app.call env
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module FaradayMiddleware
|
4
|
+
# Request middleware that encodes the body as XML.
|
5
|
+
#
|
6
|
+
# Processes only requests with matching Content-type or those without a type.
|
7
|
+
# If a request doesn't have a type but has a body, it sets the Content-type
|
8
|
+
# to XML MIME-type.
|
9
|
+
#
|
10
|
+
# Doesn't try to encode bodies that already are in string form.
|
11
|
+
class EncodeXml < Faraday::Middleware
|
12
|
+
CONTENT_TYPE = 'Content-Type'.freeze
|
13
|
+
MIME_TYPE = 'application/xml'.freeze
|
14
|
+
|
15
|
+
dependency do
|
16
|
+
require 'gyoku' unless defined?(::Gyoku)
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
match_content_type(env) do |data|
|
21
|
+
env[:body] = encode data
|
22
|
+
end
|
23
|
+
@app.call env
|
24
|
+
end
|
25
|
+
|
26
|
+
def encode(data)
|
27
|
+
::Gyoku.xml(data, :key_converter => :none)
|
28
|
+
end
|
29
|
+
|
30
|
+
def match_content_type(env)
|
31
|
+
if process_request?(env)
|
32
|
+
env[:request_headers][CONTENT_TYPE] ||= MIME_TYPE
|
33
|
+
yield env[:body] unless env[:body].respond_to?(:to_str)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def process_request?(env)
|
38
|
+
type = request_type(env)
|
39
|
+
has_body?(env) and (type.empty? or type == MIME_TYPE)
|
40
|
+
end
|
41
|
+
|
42
|
+
def has_body?(env)
|
43
|
+
body = env[:body] and !(body.respond_to?(:to_str) and body.empty?)
|
44
|
+
end
|
45
|
+
|
46
|
+
def request_type(env)
|
47
|
+
type = env[:request_headers][CONTENT_TYPE].to_s
|
48
|
+
type = type.split(';', 2).first if type.index(';')
|
49
|
+
type
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: einvoice
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Yun
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: multi_xml
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activemodel
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: gyoku
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.11'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.11'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: factory_girl
|
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'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: shoulda-matchers
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description:
|
154
|
+
email:
|
155
|
+
- abookyun@gmail.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".gitignore"
|
161
|
+
- ".rspec"
|
162
|
+
- ".travis.yml"
|
163
|
+
- Gemfile
|
164
|
+
- LICENSE.txt
|
165
|
+
- README.md
|
166
|
+
- Rakefile
|
167
|
+
- bin/console
|
168
|
+
- bin/setup
|
169
|
+
- einvoice.gemspec
|
170
|
+
- lib/einvoice.rb
|
171
|
+
- lib/einvoice/api.rb
|
172
|
+
- lib/einvoice/client/neweb.rb
|
173
|
+
- lib/einvoice/configuration.rb
|
174
|
+
- lib/einvoice/connection.rb
|
175
|
+
- lib/einvoice/model/base.rb
|
176
|
+
- lib/einvoice/model/contact.rb
|
177
|
+
- lib/einvoice/model/customer_defined.rb
|
178
|
+
- lib/einvoice/model/invoice.rb
|
179
|
+
- lib/einvoice/model/invoice_item.rb
|
180
|
+
- lib/einvoice/validator/carrier_id1_validator.rb
|
181
|
+
- lib/einvoice/validator/carrier_id2_validator.rb
|
182
|
+
- lib/einvoice/validator/customs_clearance_mark_validator.rb
|
183
|
+
- lib/einvoice/validator/print_mark_validator.rb
|
184
|
+
- lib/einvoice/version.rb
|
185
|
+
- lib/faraday/request/digest_neweb.rb
|
186
|
+
- lib/faraday/request/encode_xml.rb
|
187
|
+
homepage: https://github.com/abookyun/einvoice
|
188
|
+
licenses:
|
189
|
+
- MIT
|
190
|
+
metadata: {}
|
191
|
+
post_install_message:
|
192
|
+
rdoc_options: []
|
193
|
+
require_paths:
|
194
|
+
- lib
|
195
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
196
|
+
requirements:
|
197
|
+
- - ">="
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
version: 2.0.0
|
200
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
|
+
requirements:
|
202
|
+
- - ">="
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
version: '0'
|
205
|
+
requirements: []
|
206
|
+
rubyforge_project:
|
207
|
+
rubygems_version: 2.4.5.1
|
208
|
+
signing_key:
|
209
|
+
specification_version: 4
|
210
|
+
summary: A API wrapper for Taiwan e-invoice services.
|
211
|
+
test_files: []
|