einvoice 0.2.0 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d40d662bce05b0f05bff5b9b980a27abb5a1bb47
4
- data.tar.gz: 43edf9033179b4475711025ba4a240e8fe2b116f
3
+ metadata.gz: e81da9d745a37edf6cd7d91ba444787a1ffd70fe
4
+ data.tar.gz: 5d3cbbd481ff54fb6b2ac53831d33a7f102864da
5
5
  SHA512:
6
- metadata.gz: 80e76b8fd5a68e4c8c28547751d1f67a2c372b07912bba3ec2768143b73988a88024d17b30e3c9b2d41ed6d383542eb56d36b83ed395e9c49c6706917f79bbad
7
- data.tar.gz: 283626dbf581277a1993eef18c6ffad7e666901219df18cd4cb4b031a93ecbb2b8087a48fe1f1488dccae634f254d9ec7b98f25f05f1384c65d04e74eaff0cb1
6
+ metadata.gz: b65eefa4b53987624bf1e242aa8321ed0ebef2af343ebb791a26d6630b9065604c97c66016162f12f36ed216c7d43a206b30d18b304bcca717a230277aa705e8
7
+ data.tar.gz: 933d45a596c8264294b582db2868d618097e62a647ab1fd0fa5c1d67078a0168844780cf70192ffef58b932f2506158f3c5bf3db1e32cb4b9a29ef9f9f3d6c3a
data/README.md CHANGED
@@ -3,18 +3,20 @@
3
3
  [![Code Climate](https://codeclimate.com/github/abookyun/einvoice/badges/gpa.svg)](https://codeclimate.com/github/abookyun/einvoice)
4
4
  [![Test Coverage](https://codeclimate.com/github/abookyun/einvoice/badges/coverage.svg)](https://codeclimate.com/github/abookyun/einvoice/coverage)
5
5
 
6
+ ## What's Einvoice
7
+
6
8
  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
9
 
8
10
  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
11
 
10
12
  * Manage e-invoices
11
- * New an e-invoice
13
+ * Issue an e-invoice
12
14
  * Return an e-invoice
13
15
  * Invalidate an e-invoice
14
16
  * List e-invoices
15
- * ...
17
+ * Others
16
18
 
17
- So that, we need a API wrapper to manage and access the APIs.
19
+ Therefore, we need a API wrapper to manage and access the APIs.
18
20
 
19
21
  ## Installation
20
22
 
@@ -34,7 +36,87 @@ Or install it yourself as:
34
36
 
35
37
  ## Usage
36
38
 
37
- TODO: Write usage instructions here
39
+ Assume one of your customer just make an `@order` including all transaction info for your `@product`. After created the order you're ready to issue this invoice.
40
+
41
+ ### 1. Setup initializer with credentials
42
+
43
+ ```ruby
44
+ Einvoice.configure do |setup|
45
+ setup.endpoint = ENV['EINVOICE_ENDPOINT']
46
+ setup.client_id = ENV['EINVOICE_CLIENT_ID']
47
+ setup.client_secret = ENV['EINVOICE_CLIENT_SECRET']
48
+ setup.format = "xml"
49
+ end
50
+ ```
51
+
52
+ ### 2. Create method for produce payload correspond to issuing action needs
53
+
54
+ ```ruby
55
+ def invoice_payload(order)
56
+ {
57
+ data_number: "#{order.data_number}",
58
+ data_date: "#{order.created_at}",
59
+ seller_id: "#{order.product.seller_id}",
60
+ buyer_name: "#{order.buyer_name}",
61
+ buyer_id: "#{order.buyer_id}",
62
+ customs_clearance_mark: "#{order.customs_clearance_mark}",
63
+ invoice_type: "#{order.invoice_type}",
64
+ donate_mark: "#{order.donate_mark}"
65
+ carrier_type: "#{order.carrier_type}",
66
+ carrier_id1: "#{order.carrier_id1}",
67
+ carrier_id2: "#{order.carrier_id2}",
68
+ print_mark: "#{order.print_invoice}",
69
+ n_p_o_b_a_n: "#{order.n_p_o_b_a_n}",
70
+ random_number: "#{order.random_number}",
71
+ invoice_item: order.items.each_with_index.map do |item, index|
72
+ {
73
+ sequence_number: "#{index}"
74
+ description: "#{order.product.description}",
75
+ quantity: "#{item.quantity}",
76
+ unit_price: "#{item.unit_price}",
77
+ amount: "#{item.quantity * item.unit_price}",
78
+ }
79
+ end,
80
+ sales_amount: "#{order.sales_amount}",
81
+ free_tax_sales_amount: "#{order.free_tax_sales_amount}",
82
+ zero_tax_sales_amount: "#{order.zero_tax_sales_amount}",
83
+ tax_type: "#{order.tax_type}",
84
+ tax_rate: "#{order.tax_rate}",
85
+ tax_amount: "#{order.tax_amount}",
86
+ total_amount: "#{order.total_amount}",
87
+ contact: {
88
+ name: "#{order.user.name}",
89
+ address: "#{order.user.address}"
90
+ t_e_l: "#{order.user.mobile}"
91
+ email: "#{order.user.email}"
92
+ }
93
+ }
94
+ end
95
+ ```
96
+
97
+ ### 3. Initialize Einvoice::Client with your provider and fire the action
98
+
99
+ ```ruby
100
+ client = Einvoice::Client.new(Einvoice::Neweb::Provider.new)
101
+ client.issue(invoice_payload)
102
+ ```
103
+
104
+ See [More Providers docs]()
105
+
106
+ ### 4. Handle Einvoice::Result object
107
+
108
+ ```ruby
109
+ result = client.issue(invoice_payload)
110
+ # => Einvoice::Result
111
+
112
+ if result.success?
113
+ logger.info "Issue invoice for #{order.id} is successful."
114
+ else
115
+ logger.info "Issue invoice for #{order.id} is failed with #{result.errors}."
116
+ end
117
+ ```
118
+
119
+ See [Einvoice::Result](https://github.com/abookyun/einvoice/blob/master/lib/einvoice/result.rb)
38
120
 
39
121
  ## Development
40
122
 
@@ -44,7 +126,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
44
126
 
45
127
  ## Contributing
46
128
 
47
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/einvoice.
129
+ Bug reports and pull requests are welcome on GitHub at https://github.com/abookyun/einvoice.
48
130
 
49
131
 
50
132
  ## License
data/bin/console CHANGED
@@ -10,5 +10,5 @@ require "einvoice"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
14
- IRB.start
13
+ require "pry"
14
+ Pry.start
data/lib/einvoice.rb CHANGED
@@ -4,7 +4,6 @@ require "einvoice/client"
4
4
  require "einvoice/configuration"
5
5
  require "einvoice/connection"
6
6
  require "einvoice/provider"
7
- require "einvoice/response"
8
7
  require "einvoice/result"
9
8
  require "einvoice/utils"
10
9
  require "einvoice/version"
@@ -6,8 +6,8 @@ module Einvoice
6
6
  @provider = provider
7
7
  end
8
8
 
9
- def issue(payload)
10
- provider.issue(payload)
9
+ def issue(payload, options = {})
10
+ provider.issue(payload, options)
11
11
  end
12
12
  end
13
13
  end
@@ -7,11 +7,13 @@ module Einvoice
7
7
  :client_id,
8
8
  :client_secret,
9
9
  :format,
10
+ :endpoint_url
10
11
  ].freeze
11
12
 
12
13
  DEFAULT_CLIENT_ID = nil
13
14
  DEFAULT_CLIENT_SECRET = nil
14
15
  DEFAULT_ENDPOINT = "".freeze
16
+ DEFAULT_ENDPOINT_URL = nil
15
17
  DEFAULT_FORMAT = ""
16
18
 
17
19
  attr_accessor *VALID_OPTIONS_KEYS
@@ -31,9 +33,10 @@ module Einvoice
31
33
  end
32
34
 
33
35
  def reset
34
- self.endpoint = DEFAULT_ENDPOINT
35
36
  self.client_id = DEFAULT_CLIENT_ID
36
37
  self.client_secret = DEFAULT_CLIENT_SECRET
38
+ self.endpoint = DEFAULT_ENDPOINT
39
+ self.endpoint_url = DEFAULT_ENDPOINT_URL
37
40
  self.format = DEFAULT_FORMAT
38
41
  end
39
42
  end
@@ -12,7 +12,7 @@ module Einvoice
12
12
  }
13
13
 
14
14
  ::Faraday::Connection.new(options) do |connection|
15
- connection.request :digest, client_secret
15
+ connection.request :digest_neweb, client_secret
16
16
  connection.request :url_encoded
17
17
 
18
18
  # Parser
@@ -1,9 +1,6 @@
1
1
  require "active_model"
2
2
 
3
- require "einvoice/neweb/validator/carrier_id1_validator"
4
- require "einvoice/neweb/validator/carrier_id2_validator"
5
- require "einvoice/neweb/validator/customs_clearance_mark_validator"
6
- require "einvoice/neweb/validator/print_mark_validator"
3
+ require "einvoice/neweb/validator/invoice_validator"
7
4
 
8
5
  module Einvoice
9
6
  module Neweb
@@ -14,6 +11,8 @@ module Einvoice
14
11
  include ActiveModel::Serialization
15
12
  include ActiveModel::Serializers::JSON
16
13
 
14
+ include Einvoice::Neweb::Validator
15
+
17
16
  def attributes=(hash)
18
17
  @invoice_item ||= []
19
18
  hash.each do |key, value|
@@ -12,7 +12,7 @@ module Einvoice
12
12
 
13
13
  validates :project_no, length: { maximum: 64 }
14
14
  validates :purchase_no, length: { maximum: 64 }
15
- validates :stamp_duty_flag, length: { maximum: 1 }
15
+ validates :stamp_duty_flag, length: { is: 1 }
16
16
  end
17
17
  end
18
18
  end
@@ -2,11 +2,7 @@ module Einvoice
2
2
  module Neweb
3
3
  module Model
4
4
  class Invoice < Base
5
- include Einvoice::Validator::Neweb
6
-
7
5
  VALID_OPTIONS_KEYS = [
8
- :data_number,
9
- :data_date,
10
6
  :seller_id,
11
7
  :buyer_name,
12
8
  :buyer_id,
@@ -33,29 +29,31 @@ module Einvoice
33
29
 
34
30
  attr_accessor *VALID_OPTIONS_KEYS
35
31
 
36
- validates :data_number, presence: true, length: { maximum: 20 }
37
- validates :data_date, presence: true, length: { maximum: 10 }, format: { with: /\A\d{4}\/\d{2}\/\d{2}\z/ }
38
32
  validates :seller_id, presence: true, length: { maximum: 10 }
39
- validates :buyer_name, presence: true, length: { maximum: 60 }
33
+ validates :buyer_name, presence: true, length: { maximum: 60 }, buyer_name: true
40
34
  validates :buyer_id, presence: true, length: { maximum: 10 }
41
- validates :customs_clearance_mark, length: { maximum: 1 }, format: { with: /[01]/ }, customs_clearance_mark: true, allow_blank: true
42
- validates :invoice_type, presence: true, length: { maximum: 2 }, format: { with: /07|08/ }
43
- validates :donate_mark, presence: true, length: { maximum: 1 }, format: { with: /[01]/ }
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
44
38
  validates :carrier_type, length: { maximum: 6 }, format: { with: /[a-zA-Z]{2}\d{4}/ }, allow_blank: true
45
39
  validates :carrier_id1, length: { maximum: 64 }, carrier_id1: true, allow_blank: true
46
40
  validates :carrier_id2, length: { maximum: 64 }, carrier_id2: true, allow_blank: true
47
- validates :print_mark, presence: true, length: { maximum: 1 }, format: { with: /[YN]/ }, print_mark: true
41
+ validates :print_mark, presence: true, length: { is: 1 }, inclusion: { in: %w(Y N) }, print_mark: true
48
42
  validates :n_p_o_b_a_n, length: { maximum: 10 }
49
- validates :random_number, length: { maximum: 4 }
43
+ validates :random_number, length: { is: 4 }, allow_blank: true
50
44
  validates :invoice_item, presence: true
51
45
  validates :sales_amount, presence: true, length: { maximum: 12 }, numericality: { greater_than_or_equal_to: 0 }
52
46
  validates :free_tax_sales_amount, presence: true, length: { maximum: 12 }, numericality: { greater_than_or_equal_to: 0 }
53
47
  validates :zero_tax_sales_amount, presence: true, length: { maximum: 12 }, numericality: { greater_than_or_equal_to: 0 }
54
- validates :tax_type, presence: true, length: { maximum: 1 }
48
+ validates :tax_type, presence: true, length: { is: 1 }, inclusion: { in: %w(1 2 3 4 9) }
55
49
  validates :tax_rate, presence: true, length: { maximum: 6 }
56
50
  validates :tax_amount, presence: true, length: { maximum: 12 }, numericality: { greater_than_or_equal_to: 0 }
57
51
  validates :total_amount, presence: true, length: { maximum: 12 }, numericality: { greater_than_or_equal_to: 0 }
58
52
  validates :contact, presence: true
53
+
54
+ def initialize
55
+ raise NotImplementedError, "You should initialize with subclasses"
56
+ end
59
57
  end
60
58
  end
61
59
  end
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,18 @@
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
@@ -5,29 +5,40 @@ require "einvoice/neweb/model/contact"
5
5
  require "einvoice/neweb/model/customer_defined"
6
6
  require "einvoice/neweb/model/invoice_item"
7
7
  require "einvoice/neweb/model/invoice"
8
+ require "einvoice/neweb/model/pre_invoice"
9
+ require "einvoice/neweb/model/seller_invoice"
10
+
11
+ require "einvoice/neweb/result"
8
12
 
9
13
  module Einvoice
10
14
  module Neweb
11
15
  class Provider < Einvoice::Provider
12
16
  include Einvoice::Utils
13
17
 
14
- def issue(payload)
15
- invoice = Einvoice::Neweb::Model::Invoice.new
18
+ def issue(payload, options)
19
+ case options[:type]
20
+ when :seller_invoice
21
+ action = "IN_SellerInvoiceS.action"
22
+ invoice = Einvoice::Neweb::Model::SellerInvoice.new
23
+ else
24
+ action = "IN_PreInvoiceS.action"
25
+ invoice = Einvoice::Neweb::Model::PreInvoice.new
26
+ end
27
+
16
28
  invoice.from_json(payload.to_json)
17
29
 
18
30
  if invoice.valid?
19
- action = "IN_PreInvoiceS.action"
20
31
  response = connection.post do |request|
21
- request.url endpoint + action
32
+ request.url endpoint_url || endpoint + action
22
33
  request.body = {
23
34
  storecode: client_id,
24
- xmldata: encode_xml(wrap(serialize(invoice)))
35
+ xmldata: encode_xml(camelize(wrap(serialize(invoice))))
25
36
  }
26
37
  end.body
27
38
 
28
- Einvoice::Result.new(Einvoice::NewebResponse.new(response))
39
+ Einvoice::Neweb::Result.new(response)
29
40
  else
30
- Einvoice::Result.new(Einvoice::NewebResponse.new(response))
41
+ Einvoice::Neweb::Result.new(invoice.errors)
31
42
  end
32
43
  end
33
44
  end
@@ -0,0 +1,24 @@
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.fetch("Result").fetch("Invoice", {}) || response.fetch("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
+ response && response.fetch("Result", {}) do |data|
18
+ data["statcode"] == "0000" ? true : false
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,46 @@
1
+ module Einvoice
2
+ module Neweb
3
+ module Validator
4
+ class BuyerNameValidator < ActiveModel::EachValidator
5
+ def validate_each(record, attribute, value)
6
+ if record.buyer_id.to_s == "0000000000" &&
7
+ value.present? && (value.ascii_only? ? value.size > 4 : value.size > 2)
8
+ record.errors.add attribute, options[:message] || :invalid
9
+ end
10
+ end
11
+ end
12
+
13
+ class DonateMarkValidator < ActiveModel::EachValidator
14
+ def validate_each(record, attribute, value)
15
+ if value == "1" && record.n_p_o_b_a_n.blank?
16
+ record.errors.add attribute, options[:message] || :invalid
17
+ end
18
+ end
19
+ end
20
+
21
+ class CarrierId1Validator < ActiveModel::EachValidator
22
+ def validate_each(record, attribute, value)
23
+ if (record.print_mark.to_s == "Y" && value.present?) || (record.print_mark.to_s == "N" && value.blank?)
24
+ record.errors.add attribute, options[:message] || :invalid
25
+ end
26
+ end
27
+ end
28
+
29
+ class CarrierId2Validator < ActiveModel::EachValidator
30
+ def validate_each(record, attribute, value)
31
+ if (record.print_mark.to_s == "Y" && value.present?) || (record.print_mark.to_s == "N" && value.blank?)
32
+ record.errors.add attribute, options[:message] || :invalid
33
+ end
34
+ end
35
+ end
36
+
37
+ class PrintMarkValidator < ActiveModel::EachValidator
38
+ def validate_each(record, attribute, value)
39
+ if value == "Y" && (record.carrier_id1.present? || record.carrier_id2.present? || record.donate_mark == "Y")
40
+ record.errors.add attribute, options[:message] || :invalid
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -7,11 +7,11 @@ module Einvoice
7
7
  end
8
8
 
9
9
  def errors
10
- response.errors unless success?
10
+ raise NotImplementedError, 'You must initialize one of Einvoice::Response subclasses then use it.'
11
11
  end
12
12
 
13
13
  def success?
14
- response.success?
14
+ raise NotImplementedError, 'You must initialize one of Einvoice::Response subclasses then use it.'
15
15
  end
16
16
  end
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module Einvoice
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.8"
3
3
  end
@@ -19,4 +19,4 @@ module Faraday
19
19
  end
20
20
  end
21
21
 
22
- Faraday::Request.register_middleware digest: Faraday::Request::DigestNeweb
22
+ Faraday::Request.register_middleware digest_neweb: Faraday::Request::DigestNeweb
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: 0.2.0
4
+ version: 0.2.8
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-01-14 00:00:00.000000000 Z
11
+ date: 2016-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -204,13 +204,12 @@ files:
204
204
  - lib/einvoice/neweb/model/customer_defined.rb
205
205
  - lib/einvoice/neweb/model/invoice.rb
206
206
  - lib/einvoice/neweb/model/invoice_item.rb
207
+ - lib/einvoice/neweb/model/pre_invoice.rb
208
+ - lib/einvoice/neweb/model/seller_invoice.rb
207
209
  - lib/einvoice/neweb/provider.rb
208
- - lib/einvoice/neweb/validator/carrier_id1_validator.rb
209
- - lib/einvoice/neweb/validator/carrier_id2_validator.rb
210
- - lib/einvoice/neweb/validator/customs_clearance_mark_validator.rb
211
- - lib/einvoice/neweb/validator/print_mark_validator.rb
210
+ - lib/einvoice/neweb/result.rb
211
+ - lib/einvoice/neweb/validator/invoice_validator.rb
212
212
  - lib/einvoice/provider.rb
213
- - lib/einvoice/response.rb
214
213
  - lib/einvoice/result.rb
215
214
  - lib/einvoice/utils.rb
216
215
  - lib/einvoice/version.rb
@@ -1,13 +0,0 @@
1
- module Einvoice
2
- module Validator
3
- module Neweb
4
- class CarrierId1Validator < ActiveModel::EachValidator
5
- def validate_each(record, attribute, value)
6
- if (record.print_mark.to_s == "Y" && value.present?) || (record.print_mark.to_s == "N" && value.blank?)
7
- record.errors.add attribute, options[:message] || :invalid
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module Einvoice
2
- module Validator
3
- module Neweb
4
- class CarrierId2Validator < ActiveModel::EachValidator
5
- def validate_each(record, attribute, value)
6
- if (record.print_mark.to_s == "Y" && value.present?) || (record.print_mark.to_s == "N" && value.blank?)
7
- record.errors.add attribute, options[:message] || :invalid
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module Einvoice
2
- module Validator
3
- module Neweb
4
- class CustomsClearanceMarkValidator < ActiveModel::EachValidator
5
- def validate_each(record, attribute, value)
6
- if record.tax_rate.present? && record.tax_rate.to_i.zero? && value.blank?
7
- record.errors.add attribute, options[:message] || :invalid
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module Einvoice
2
- module Validator
3
- module Neweb
4
- class PrintMarkValidator < ActiveModel::EachValidator
5
- def validate_each(record, attribute, value)
6
- if value == "Y" && (record.carrier_id1.present? || record.carrier_id2.present? || record.donate_mark == "Y")
7
- record.errors.add attribute, options[:message] || :invalid
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,39 +0,0 @@
1
- module Einvoice
2
- class Response
3
- attr_reader :response
4
-
5
- def initialize(response = nil)
6
- @response = response
7
- end
8
-
9
- def errors
10
- raise NotImplementedError, 'You must initialize one of Einvoice::Response subclasses then use it.'
11
- end
12
-
13
- def success?
14
- raise NotImplementedError, 'You must initialize one of Einvoice::Response subclasses then use it.'
15
- end
16
- end
17
-
18
- class NewebResponse < Response
19
- def errors
20
- if response.is_a? ActiveModel::Errors
21
- response.full_messages.join('; ')
22
- else
23
- response && response.fetch("Result", {}) do |data|
24
- "#{data["statcode"]}: #{data["statdesc"]}"
25
- end
26
- end
27
- end
28
-
29
- def success?
30
- if response.is_a? ActiveModel::Errors
31
- false
32
- elsif response && response.fetch("Result", {})["statdesc"] == "0000"
33
- true
34
- else
35
- false
36
- end
37
- end
38
- end
39
- end