class ECpayInvoice::NotifyParamVerify
Public Class Methods
new(apiname)
click to toggle source
# File lib/ecpay_invoice/verification.rb, line 999 def initialize(apiname) @inv_basic_param = self.get_basic_params(apiname).freeze @inv_conditional_param = self.get_cond_param(apiname).freeze @all_param_pattern = self.get_all_pattern(apiname).freeze end
Public Instance Methods
verify_notify_param(params)
click to toggle source
# File lib/ecpay_invoice/verification.rb, line 1005 def verify_notify_param(params) if params.is_a?(Hash) #發送發票通知預設參數要全帶 if params.has_value?(nil) raise ECpayInvalidParam, %Q{Parameter value cannot be nil} end #1. 比對欄位是否缺乏 param_diff = @inv_basic_param - params.keys() unless param_diff == [] raise ECpayInvalidParam, %Q{Lack required invoice param #{param_diff}} end #2. 比對特殊欄位值相依需求 #a Phone和NotifyMail至少一個有值 if params['Phone'].to_s.empty? and params['NotifyMail'].to_s.empty? raise ECpayInvoiceRuleViolate, "[Phone] and [NotifyMail] can not both be empty." end #b [Notify] is S [Phone] can not be empty or [Notify] is E [NotifyMail] can not be empty # If [Notify] is A [Phone] and [NotifyMail] can not both be empty if params['Notify'].to_s == 'S' if params['Phone'].to_s.empty? raise ECpayInvoiceRuleViolate, "[Phone] can not be empty when [Notify] is 'S'." end elsif params['Notify'].to_s == 'E' if params['NotifyMail'].to_s.empty? raise ECpayInvoiceRuleViolate, "[NotifyMail] can not be empty when [Notify] is 'E'." end elsif params['Notify'].to_s == 'A' if params['Phone'].to_s.empty? or params['NotifyMail'].to_s.empty? raise ECpayInvoiceRuleViolate, "[Phone] and [NotifyMail] can not be empty when [Notify] is 'A'." end else raise ECpayInvoiceRuleViolate, "Unexpected value in [Notify]." end #c [InvoiceTag] is I,II,A,AI,AW [InvoiceNo] can not be empty or [InvoiceTag] is A,AI [AllowanceNo] can not be empty if params['InvoiceTag'].to_s == 'I' or params['InvoiceTag'].to_s == 'II' or params['InvoiceTag'].to_s == 'AW' if params['InvoiceNo'].to_s.empty? raise ECpayInvoiceRuleViolate, "[InvoiceNo] can not be empty." end elsif params['InvoiceTag'].to_s == 'A' or params['InvoiceTag'].to_s == 'AI' if /^\d{16}$/.match(params['AllowanceNo']).nil? raise ECpayInvoiceRuleViolate, "[AllowanceNo] must followed by 16 number characters when [InvoiceTag] is 'A' or 'AI'." end if params['InvoiceNo'].to_s.empty? if params['AllowanceNo'].to_s.empty? raise ECpayInvoiceRuleViolate, "[InvoiceNo] and [AllowanceNo] can not be empty when [Notify] is 'A' or 'AI'." end raise ECpayInvoiceRuleViolate, "[InvoiceNo] can not be empty." end unless params['InvoiceNo'].to_s.empty? if params['AllowanceNo'].to_s.empty? raise ECpayInvoiceRuleViolate, "[AllowanceNo] can not be empty." end end else raise ECpayInvoiceRuleViolate, "Unexpected value in [InvoiceTag]." end #Verify Value pattern of each param self.verify_param_by_pattern(params, @all_param_pattern) else raise TypeError, "Recieved argument is not a hash" end end