Class: ECpayInvoice::NotifyParamVerify
- Inherits:
-
InvoiceVerifyBase
- Object
- InvoiceVerifyBase
- ECpayInvoice::NotifyParamVerify
- Includes:
- ECpayErrorDefinition
- Defined in:
- lib/ecpay_invoice/verification.rb
Instance Method Summary collapse
-
#initialize(apiname) ⇒ NotifyParamVerify
constructor
A new instance of NotifyParamVerify.
- #verify_notify_param(params) ⇒ Object
Methods inherited from InvoiceVerifyBase
#get_all_pattern, #get_basic_params, #get_cond_param, #get_depopt_param_pattern, #get_int_param_pattern, #get_opt_param_pattern, #get_param_type, #get_special_encode_param, #get_str_param_pattern, #get_svc_url, #verify_param_by_pattern
Constructor Details
#initialize(apiname) ⇒ NotifyParamVerify
999 1000 1001 1002 1003 |
# 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 |
Instance Method Details
#verify_notify_param(params) ⇒ Object
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 |
# 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 |