Module EWS::Transaction::Validator
In: lib/ews/transaction/validator.rb

Methods

valid?  

Public Instance methods

[Source]

    # File lib/ews/transaction/validator.rb, line 30
30:       def valid?
31:         @errors = {}
32: 
33:         validate_lengths
34:         
35:         validate_mandatory_fields
36:         
37:         append_error(:transaction_type, "transaction_type must be supplied") if self.transaction_type.blank?
38:       
39:         # need to authenticate
40:         append_error(:gateway_id, "gateway_id must be supplied") if self.gateway_id.blank?
41:         append_error(:password, "password must be supplied") if self.password.blank?
42: 
43:         # ensure we've been given valid amounts
44:         append_error(:amount, "invalid amount supplied") unless valid_amount?(self.amount)
45:         append_error(:surcharge_amount, "invalid surcharge_amount supplied") unless valid_amount?(self.surcharge_amount)
46:         append_error(:tax1_amount, "invalid tax1_amount supplied") unless valid_amount?(self.tax1_amount)
47:         append_error(:tax2_amount, "invalid tax2_amount supplied") unless valid_amount?(self.tax2_amount)
48: 
49:         # ensure our amounts are within range
50:         append_error(:amount, "amount must be between 0.00 and 99999.99") unless amount_too_big?(self.amount)
51:         append_error(:surcharge_amount, "amount must be between 0.00 and 99999.99") unless amount_too_big?(self.surcharge_amount)
52:         append_error(:tax1_amount, "amount must be between 0.00 and 99999.99") unless amount_too_big?(self.tax1_amount)
53:         append_error(:tax2_amount, "amount must be between 0.00 and 99999.99") unless amount_too_big?(self.tax2_amount)
54:         
55:         # ensure our credit card information is valid
56:         append_error(:cc_number, "invalid cc_number supplied") unless valid_card_number?
57:         append_error(:cc_expiry, "invalid cc_expiry supplied") unless valid_expiry_date?
58:         
59:         @errors.empty?
60:       end

[Validate]