einvoice 1.1.1 → 1.2.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.
@@ -10,7 +10,7 @@ module Einvoice
10
10
  raise NotImplementedError, 'You must initialize one of Einvoice::Response subclasses then use it.'
11
11
  end
12
12
 
13
- def success?
13
+ def successful?
14
14
  raise NotImplementedError, 'You must initialize one of Einvoice::Response subclasses then use it.'
15
15
  end
16
16
 
@@ -84,7 +84,7 @@ module Einvoice
84
84
 
85
85
  # Type I R G
86
86
  validates :donate, presence: true, length: { is: 1 }, if: proc { %w(I R G).include?(self.type) && self.buyerUn.blank? && self.paperPrintMode.to_i == 0 }
87
- validates :donationUnit, presence: true, length: { maximum: 10 }, if: proc { %w(I R G).include?(self.type) && self.donate == 'Y' }
87
+ validates :donationUnit, presence: true, length: { maximum: 10 }, donationUnit: true, if: proc { %w(I R G).include?(self.type) && self.donate == 'Y' }
88
88
  validates :carrierId, presence: true, length: { maximum: 64 }, if: proc { %w(I R G).include?(self.type) && self.paperPrintMode.to_i == 0 && self.donate == 'N' }
89
89
  validates :carrierIdHidden, presence: true, length: { maximum: 64 }, if: proc { %w(I R G).include?(self.type) && self.paperPrintMode.to_i == 0 && self.donate == 'N' }
90
90
  validates :receiverName, allow_blank: true, length: { maximum: 30 }, if: proc { %w(I R G).include?(self.type) }
@@ -125,7 +125,6 @@ module Einvoice
125
125
  }
126
126
  ).get do |request|
127
127
  request.url endpoint_url || endpoint + "/DEFAULTAPI/get/getInvoiceContent"
128
-
129
128
  request.params[:v] = encrypted_params(payload)
130
129
  end.body
131
130
 
@@ -33,6 +33,16 @@ module Einvoice
33
33
  end
34
34
  end
35
35
 
36
+ class DonationUnitValidator < ActiveModel::EachValidator
37
+ def validate_each(record, attribute, value)
38
+ units = JSON.parse(File.read("lib/einvoice/donation_unit_list.json"))
39
+
40
+ unless units[value]
41
+ record.errors.add attribute, options[:message] || :invalid
42
+ end
43
+ end
44
+ end
45
+
36
46
  class ItemListValidator < ActiveModel::EachValidator
37
47
  def validate_each(record, attribtue, value)
38
48
  if %w(A G H).include?(record.type) && record.itemList.map(&:itemExclude).map(&:blank?).reduce(&:|)
@@ -1,3 +1,3 @@
1
1
  module Einvoice
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: einvoice
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Yun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-25 00:00:00.000000000 Z
11
+ date: 2016-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -229,18 +229,7 @@ files:
229
229
  - lib/einvoice/client.rb
230
230
  - lib/einvoice/configuration.rb
231
231
  - lib/einvoice/connection.rb
232
- - lib/einvoice/neweb/model/base.rb
233
- - lib/einvoice/neweb/model/contact.rb
234
- - lib/einvoice/neweb/model/customer_defined.rb
235
- - lib/einvoice/neweb/model/invoice.rb
236
- - lib/einvoice/neweb/model/invoice_item.rb
237
- - lib/einvoice/neweb/model/pre_invoice.rb
238
- - lib/einvoice/neweb/model/query.rb
239
- - lib/einvoice/neweb/model/seller_invoice.rb
240
- - lib/einvoice/neweb/provider.rb
241
- - lib/einvoice/neweb/result.rb
242
- - lib/einvoice/neweb/validator/invoice_item_validator.rb
243
- - lib/einvoice/neweb/validator/invoice_validator.rb
232
+ - lib/einvoice/donation_unit_list.json
244
233
  - lib/einvoice/provider.rb
245
234
  - lib/einvoice/result.rb
246
235
  - lib/einvoice/tradevan/model/base.rb
@@ -252,7 +241,6 @@ files:
252
241
  - lib/einvoice/tradevan/validator/issue_data_validator.rb
253
242
  - lib/einvoice/utils.rb
254
243
  - lib/einvoice/version.rb
255
- - lib/faraday/request/digest_neweb.rb
256
244
  - lib/faraday/response/decode_tradevan.rb
257
245
  homepage: https://github.com/abookyun/einvoice
258
246
  licenses:
@@ -1,39 +0,0 @@
1
- require "active_model"
2
-
3
- require "einvoice/neweb/validator/invoice_validator"
4
- require "einvoice/neweb/validator/invoice_item_validator"
5
-
6
- module Einvoice
7
- module Neweb
8
- module Model
9
- class Base
10
- include ActiveModel::Model
11
- include ActiveModel::Validations
12
- include ActiveModel::Serialization
13
- include ActiveModel::Serializers::JSON
14
-
15
- include Einvoice::Neweb::Validator
16
-
17
- def attributes=(hash)
18
- @invoice_item ||= []
19
- hash.each do |key, value|
20
- case key.to_sym
21
- when :invoice_item
22
- value.each { |v| @invoice_item << InvoiceItem.new(v) }
23
- when :contact
24
- @contact = Contact.new(value)
25
- when :customer_defined
26
- @customer_defined = CustomerDefined.new(value)
27
- else
28
- send("#{key}=", value)
29
- end
30
- end
31
- end
32
-
33
- def attributes
34
- instance_values
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,21 +0,0 @@
1
- module Einvoice
2
- module Neweb
3
- module Model
4
- class Contact < Base
5
- VALID_OPTIONS_KEYS = [
6
- :name,
7
- :address,
8
- :t_e_l,
9
- :email
10
- ].freeze
11
-
12
- attr_accessor *VALID_OPTIONS_KEYS
13
-
14
- validates :name, presence: true, length: { maximum: 64 }
15
- validates :address, presence: true, length: { maximum: 128 }
16
- validates :t_e_l, length: { maximum: 64 }
17
- validates :email, length: { maximum: 512 }
18
- end
19
- end
20
- end
21
- end
@@ -1,19 +0,0 @@
1
- module Einvoice
2
- module Neweb
3
- module Model
4
- class CustomerDefined < Base
5
- VALID_OPTIONS_KEYS = [
6
- :project_no,
7
- :purchase_no,
8
- :stamp_duty_flag
9
- ].freeze
10
-
11
- attr_accessor *VALID_OPTIONS_KEYS
12
-
13
- validates :project_no, length: { maximum: 64 }
14
- validates :purchase_no, length: { maximum: 64 }
15
- validates :stamp_duty_flag, length: { is: 1 }
16
- end
17
- end
18
- end
19
- end
@@ -1,70 +0,0 @@
1
- module Einvoice
2
- module Neweb
3
- module Model
4
- class Invoice < Base
5
- VALID_OPTIONS_KEYS = [
6
- :seller_id,
7
- :buyer_name,
8
- :buyer_id,
9
- :customs_clearance_mark,
10
- :invoice_type,
11
- :donate_mark,
12
- :carrier_type,
13
- :carrier_id1,
14
- :carrier_id2,
15
- :print_mark,
16
- :n_p_o_b_a_n,
17
- :random_number,
18
- :invoice_item,
19
- :sales_amount,
20
- :free_tax_sales_amount,
21
- :zero_tax_sales_amount,
22
- :tax_type,
23
- :tax_rate,
24
- :tax_amount,
25
- :total_amount,
26
- :contact,
27
- :customer_defined
28
- ].freeze
29
-
30
- attr_accessor *VALID_OPTIONS_KEYS
31
-
32
- validates :seller_id, presence: true, length: { maximum: 10 }
33
- validates :buyer_name, presence: true, length: { maximum: 60 }, buyer_name: true
34
- validates :buyer_id, presence: true, length: { maximum: 10 }
35
- validates :customs_clearance_mark, length: { maximum: 1 }, inclusion: { in: %w(1 2) }, allow_blank: true
36
- validates :invoice_type, presence: true, length: { is: 2 }, inclusion: { in: %w(07 08) }
37
- validates :donate_mark, presence: true, length: { is: 1 }, inclusion: { in: %w(0 1) }, donate_mark: true
38
- validates :carrier_type, length: { maximum: 6 }, format: { with: /[a-zA-Z]{2}\d{4}/ }, allow_blank: true
39
- validates :carrier_id1, length: { maximum: 64 }, carrier_id1: true, allow_blank: true
40
- validates :carrier_id2, length: { maximum: 64 }, carrier_id2: true, allow_blank: true
41
- validates :print_mark, presence: true, length: { is: 1 }, inclusion: { in: %w(Y N) }, print_mark: true
42
- validates :n_p_o_b_a_n, length: { maximum: 10 }
43
- validates :random_number, length: { is: 4 }, allow_blank: true
44
- validates :invoice_item, presence: true
45
- validates :sales_amount, presence: true, length: { maximum: 12 }, numericality: { greater_than_or_equal_to: 0 }
46
- validates :free_tax_sales_amount, presence: true, length: { maximum: 12 }, numericality: { greater_than_or_equal_to: 0 }
47
- validates :zero_tax_sales_amount, presence: true, length: { maximum: 12 }, numericality: { greater_than_or_equal_to: 0 }
48
- validates :tax_type, presence: true, length: { is: 1 }, inclusion: { in: %w(1 2 3 4 9) }
49
- validates :tax_rate, presence: true, length: { maximum: 6 }
50
- validates :tax_amount, presence: true, length: { maximum: 12 }, numericality: { greater_than_or_equal_to: 0 }
51
- validates :total_amount, presence: true, length: { maximum: 12 }, numericality: { greater_than_or_equal_to: 0 }, total_amount: true
52
- validates :contact, presence: true
53
-
54
- def initialize
55
- raise NotImplementedError, "You should initialize with subclasses"
56
- end
57
-
58
- def payload
59
- serializable_hash(except: [:errors, :validation_context], include: [:invoice_item, :contact, :customer_defined])
60
- end
61
-
62
- def wrapped_payload
63
- { invoice_root:
64
- { invoice: payload }
65
- }
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,27 +0,0 @@
1
- module Einvoice
2
- module Neweb
3
- module Model
4
- class InvoiceItem < Base
5
- VALID_OPTIONS_KEYS = [
6
- :description,
7
- :quantity,
8
- :unit,
9
- :unit_price,
10
- :amount,
11
- :sequence_number,
12
- :remark
13
- ].freeze
14
-
15
- attr_accessor *VALID_OPTIONS_KEYS
16
-
17
- validates :description, presence: true, length: { maximum: 256 }
18
- validates :quantity, presence: true, length: { maximum: 17 }, quantity: true
19
- validates :unit, length: { maximum: 6 }
20
- validates :unit_price, presence: true, length: { maximum: 17 }, unit_price: true
21
- validates :amount, presence: true, length: { maximum: 17 }, amount: true
22
- validates :sequence_number, presence: true, length: { maximum: 3 }, format: { with: /\A[1-9]|[1-9][0-9]|[1-9][0-9][0-9]\Z/ }
23
- validates :remark, length: { maximum: 40 }
24
- end
25
- end
26
- end
27
- end
@@ -1,18 +0,0 @@
1
- module Einvoice
2
- module Neweb
3
- module Model
4
- class PreInvoice < Invoice
5
- TYPE_SPECIFIC_KEYS = [:data_number, :data_date]
6
-
7
- attr_accessor *TYPE_SPECIFIC_KEYS
8
-
9
- validates :data_number, presence: true, length: { maximum: 20 }
10
- validates :data_date, presence: true, length: { maximum: 10 }, format: { with: /\A\d{4}\/\d{2}\/\d{2}\Z/ }
11
-
12
- def initialize
13
- # overwritten
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,43 +0,0 @@
1
- module Einvoice
2
- module Neweb
3
- module Model
4
- class Query < Base
5
- VALID_OPTIONS_KEYS = [
6
- :invoice_date_time_s,
7
- :invoice_date_time_e,
8
- :data_number_s,
9
- :data_number_e,
10
- :sync_status_update
11
- ].freeze
12
-
13
- attr_accessor *VALID_OPTIONS_KEYS
14
-
15
- validates :invoice_date_time_s, presence: true, length: { maximum: 14 }, format: { with: /\A\d{4}\d{2}\d{2}\d{2}\d{2}\Z/ }
16
- validates :invoice_date_time_e, presence: true, length: { maximum: 14 }, format: { with: /\A\d{4}\d{2}\d{2}\d{2}\d{2}\Z/ }
17
- validates :data_number_s, presence: true, length: { maximum: 20 }
18
- validates :data_number_e, presence: true, length: { maximum: 20 }
19
- validates :sync_status_update, presence: true, length: { maximum: 1 }
20
-
21
- def initialize
22
- # overwritten
23
- end
24
-
25
- def attributes=(hash)
26
- hash.each do |key, value|
27
- send("#{key}=", value)
28
- end
29
- end
30
-
31
- def payload
32
- serializable_hash(except: [:errors, :validation_context])
33
- end
34
-
35
- def wrapped_payload
36
- { invoice_map_root:
37
- { invoice_map: payload }
38
- }
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,18 +0,0 @@
1
- module Einvoice
2
- module Neweb
3
- module Model
4
- class SellerInvoice < Invoice
5
- TYPE_SPECIFIC_KEYS = [:invoice_number, :invoice_date]
6
-
7
- attr_accessor *TYPE_SPECIFIC_KEYS
8
-
9
- validates :invoice_number, presence: true, length: { maximum: 20 }
10
- validates :invoice_date, presence: true, length: { maximum: 10 }, format: { with: /\A\d{4}\/\d{2}\/\d{2}\Z/ }
11
-
12
- def initialize
13
- # overwritten
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,67 +0,0 @@
1
- require "einvoice/utils"
2
-
3
- require "einvoice/neweb/model/base"
4
- require "einvoice/neweb/model/contact"
5
- require "einvoice/neweb/model/customer_defined"
6
- require "einvoice/neweb/model/invoice_item"
7
- require "einvoice/neweb/model/invoice"
8
- require "einvoice/neweb/model/pre_invoice"
9
- require "einvoice/neweb/model/seller_invoice"
10
- require "einvoice/neweb/model/query"
11
-
12
- require "einvoice/neweb/result"
13
-
14
- module Einvoice
15
- module Neweb
16
- class Provider < Einvoice::Provider
17
- include Einvoice::Utils
18
-
19
- def issue(payload, options = {})
20
- case options[:type]
21
- when :seller_invoice
22
- action = "IN_SellerInvoiceS.action"
23
- invoice = Einvoice::Neweb::Model::SellerInvoice.new
24
- else
25
- action = "IN_PreInvoiceS.action"
26
- invoice = Einvoice::Neweb::Model::PreInvoice.new
27
- end
28
-
29
- invoice.from_json(payload.to_json)
30
-
31
- if invoice.valid?
32
- response = connection.post do |request|
33
- request.url endpoint_url || endpoint + action
34
- request.body = {
35
- storecode: client_id,
36
- xmldata: encode_xml(camelize(invoice.wrapped_payload))
37
- }
38
- end.body
39
-
40
- Einvoice::Neweb::Result.new(response)
41
- else
42
- Einvoice::Neweb::Result.new(invoice.errors)
43
- end
44
- end
45
-
46
- def query(payload, options = {})
47
- action = "IN_InvoiceMapS.action"
48
- query = Einvoice::Neweb::Model::Query.new
49
- query.from_json(payload.to_json)
50
-
51
- if query.valid?
52
- response = connection.post do |request|
53
- request.url endpoint_url || endpoint + action
54
- request.body = {
55
- storecode: client_id,
56
- xmldata: encode_xml(camelize(query.wrapped_payload))
57
- }
58
- end.body
59
-
60
- Einvoice::Neweb::Result.new(response)
61
- else
62
- Einvoice::Neweb::Result.new(query.errors)
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,32 +0,0 @@
1
- module Einvoice
2
- module Neweb
3
- class Result < Einvoice::Result
4
- def errors
5
- if response.is_a? ActiveModel::Errors
6
- response.full_messages.join('; ')
7
- else
8
- data = response && (response["Result"]["Invoice"] || response["Result"])
9
- data["statcode"] == "0000" ? nil : "#{data["statcode"]}: #{data["statdesc"]}" if data
10
- end
11
- end
12
-
13
- def success?
14
- if response.is_a? ActiveModel::Errors
15
- false
16
- else
17
- data = response && (response["Result"]["Invoice"] || response["Result"])
18
- data["statcode"] == "0000" if data
19
- end
20
- end
21
-
22
- def data
23
- if response.is_a? ActiveModel::Errors
24
- nil
25
- else
26
- data = response && (response["Result"]["Invoice"] || response["Result"])
27
- data["InvoiceMapRoot"] if data["statcode"] == "0000"
28
- end
29
- end
30
- end
31
- end
32
- end