Class: Cetustek::Services::ResponseHandler
- Inherits:
-
Object
- Object
- Cetustek::Services::ResponseHandler
- Defined in:
- lib/cetustek/services/response_handler.rb
Overview
Parses the CreateInvoiceV3 return value. Three shapes are possible: the Table 8 JSON object (RtnMsg=Json), the 15-character "發票號碼;隨機碼" string, or a bare Table 7 result code.
Defined Under Namespace
Classes: InvalidResponseError
Constant Summary collapse
- SUCCESS_LENGTH =
發票號碼 10 碼 + ';' + 隨機碼 4 碼
15- RESULT_MESSAGES =
Spec AVM-26-03 Table 7.
{ 'M:' => '欄位未填或格式錯誤', 'M0' => 'XML 格式錯誤', 'M1' => 'XML 格式錯誤', 'D0' => '沒有產品明細', 'D0_' => '產品編號格式錯誤', 'D1_' => '品名未填或格式錯誤', 'D2_' => '數量未填或格式錯誤', 'D3_' => '單價未填或格式錯誤', 'D4_' => '單位格式錯誤', 'D5_' => '數量*單價,其小計整數位大於 13 位', 'D999' => '明細筆數最多 9999 筆', 'S1' => '資料庫發生錯誤', 'S2' => '訂單日期超過開立日期', 'S3' => '未在申報期內', 'S4' => '未取得發票號碼', 'S5' => '發票號碼已使用完畢', 'S6' => '超過租賃張數限制', 'S7' => '訂單號碼已存在,若需重開請先作廢原發票號碼', 'S8' => '開立的總金額為負值', 'Invalid' => '無效 IP,請通知系統商' }.freeze
Instance Method Summary collapse
-
#initialize(response, invoice_data = nil, xml = nil) ⇒ ResponseHandler
constructor
A new instance of ResponseHandler.
- #process ⇒ Object
Constructor Details
#initialize(response, invoice_data = nil, xml = nil) ⇒ ResponseHandler
Returns a new instance of ResponseHandler.
41 42 43 44 45 |
# File 'lib/cetustek/services/response_handler.rb', line 41 def initialize(response, invoice_data = nil, xml = nil) @response = response @invoice_data = invoice_data @xml = xml end |
Instance Method Details
#process ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/cetustek/services/response_handler.rb', line 47 def process body = @response.body[:create_invoice_v3_response][:return].to_s.strip json = parse_json(body) return success(json_result(json)) if json && json['msg'] == 'Success' return success(string_result(body)) if json.nil? && success_string?(body) fail_with(json ? json['msg'].to_s : body) end |