Class: WebToPay::Response
- Inherits:
-
Object
- Object
- WebToPay::Response
- Defined in:
- lib/webtopay/response.rb
Constant Summary collapse
- PREFIX =
"wp_"
- SPECS_BY_TYPE =
{ # Array structure: # * name – request item name. # * maxlen – max allowed value for item. # * required – is this item is required in response. # * mustcheck – this item must be checked by user. # * isresponse – if false, item must not be included in response array. # * regexp – regexp to test item value. makro: [ [ :projectid, 11, true, true, true, /^\d+$/ ], [ :orderid, 40, false, false, true, '' ], [ :lang, 3, false, false, true, /^[a-z]{3}$/i ], [ :amount, 11, false, false, true, /^\d+$/ ], [ :currency, 3, false, false, true, /^[a-z]{3}$/i ], [ :payment, 20, false, false, true, '' ], [ :country, 2, false, false, true, /^[a-z]{2}$/i ], [ :paytext, 0, false, false, true, '' ], [ :ss2, 0, true, false, true, '' ], [ :ss1, 0, false, false, true, '' ], [ :name, 255, false, false, true, '' ], [ :surename, 255, false, false, true, '' ], [ :status, 255, false, false, true, '' ], [ :error, 20, false, false, true, '' ], [ :test, 1, false, false, true, /^[01]$/ ], [ :p_email, 0, false, false, true, '' ], [ :payamount, 0, false, false, true, '' ], [ :paycurrency, 0, false, false, true, '' ], [ :version, 9, true, false, true, /^\d+\.\d+$/ ], [ :sign_password, 255, false, true, false, '' ] ], # Specification array for mikro response. # # Array structure: # * name – request item name. # * maxlen – max allowed value for item. # * required – is this item is required in data. # * mustcheck – this item must be checked by user. # * isresponse – if false, item must not be included in response array. # * regexp – regexp to test item value. mikro: [ [ :to, 0, true, false, true, '' ], [ :sms, 0, true, false, true, '' ], [ :from, 0, true, false, true, '' ], [ :operator, 0, true, false, true, '' ], [ :amount, 0, true, false, true, '' ], [ :currency, 0, true, false, true, '' ], [ :country, 0, true, false, true, '' ], [ :id, 0, true, false, true, '' ], [ :_ss2, 0, true, false, true, '' ], [ :_ss1, 0, true, false, true, '' ], [ :test, 0, true, false, true, '' ], [ :key, 0, true, false, true, '' ], #[ :version, 9, true, false, true, /^\d+\.\d+$/ ] ] }
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#ss1 ⇒ Object
Returns the value of attribute ss1.
-
#ss2 ⇒ Object
Returns the value of attribute ss2.
-
#user_data ⇒ Object
readonly
Returns the value of attribute user_data.
Instance Method Summary collapse
-
#initialize(params, user_params = {}) ⇒ Response
constructor
A new instance of Response.
- #makro? ⇒ Boolean
- #mikro? ⇒ Boolean
- #query_params ⇒ Object
- #specs ⇒ Object
- #type ⇒ Object
- #valid?(params = {}) ⇒ Boolean
- #validate!(params = {}) ⇒ Object
Constructor Details
#initialize(params, user_params = {}) ⇒ Response
Returns a new instance of Response.
63 64 65 66 67 68 69 70 |
# File 'lib/webtopay/response.rb', line 63 def initialize(params, user_params = {}) params.each_pair do |field, value| self.public_send("#{field}=", value) end @sign_password = user_params[:sign_password] || WebToPay.config.sign_password @project_id = user_params[:projectid] || WebToPay.config.project_id @errors = [] end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
61 62 63 |
# File 'lib/webtopay/response.rb', line 61 def data @data end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
60 61 62 |
# File 'lib/webtopay/response.rb', line 60 def errors @errors end |
#project_id ⇒ Object (readonly)
Returns the value of attribute project_id.
60 61 62 |
# File 'lib/webtopay/response.rb', line 60 def project_id @project_id end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
60 61 62 |
# File 'lib/webtopay/response.rb', line 60 def query @query end |
#ss1 ⇒ Object
Returns the value of attribute ss1.
61 62 63 |
# File 'lib/webtopay/response.rb', line 61 def ss1 @ss1 end |
#ss2 ⇒ Object
Returns the value of attribute ss2.
61 62 63 |
# File 'lib/webtopay/response.rb', line 61 def ss2 @ss2 end |
#user_data ⇒ Object (readonly)
Returns the value of attribute user_data.
60 61 62 |
# File 'lib/webtopay/response.rb', line 60 def user_data @user_data end |
Instance Method Details
#makro? ⇒ Boolean
123 124 125 |
# File 'lib/webtopay/response.rb', line 123 def makro? type == :makro end |
#mikro? ⇒ Boolean
119 120 121 |
# File 'lib/webtopay/response.rb', line 119 def mikro? type == :mikro end |
#query_params ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/webtopay/response.rb', line 79 def query_params @query_params ||= begin params = CGI::parse(query) params.each_pair do |key, value| params[key] = value.first end params.merge(ss1: ss1, ss2: ss2).with_indifferent_access end end |
#specs ⇒ Object
115 116 117 |
# File 'lib/webtopay/response.rb', line 115 def specs SPECS_BY_TYPE[type] end |
#type ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/webtopay/response.rb', line 107 def type @type ||= if query_params[:to] && query_params[:from] && query_params[:sms] && query_params[:projectid].nil? :mikro else :makro end end |
#valid?(params = {}) ⇒ Boolean
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/webtopay/response.rb', line 89 def valid?(params = {}) @errors = [] params = { projectid: @project_id }.merge(params) valid = custom_params_valid?(params) valid &&= ss1_valid? valid &&= all_required_fields_included? valid &&= no_blacklisted_fields_included? valid &&= payment_status_valid? valid end |
#validate!(params = {}) ⇒ Object
103 104 105 |
# File 'lib/webtopay/response.rb', line 103 def validate!(params = {}) raise errors.first unless valid?(params) end |