lib/webtopay_controller.rb in webtopay-1.2.1 vs lib/webtopay_controller.rb in webtopay-1.6.0

- old
+ new

@@ -1,35 +1,30 @@ module WebToPayController module ClassMethods def webtopay(*actions) - before_filter :webtopay_check - write_inheritable_array(:actions, actions) + options = actions.any? ? { only: actions } : {} + before_filter :webtopay, options attr_reader :webtopay_response end end def self.included(controller) controller.extend(ClassMethods) end - protected - - def webtopay_required? - (self.class.read_inheritable_attribute(:actions) || []).include?(action_name.to_sym) + def webtopay + api_response = WebToPay::Response.new( params.slice(:data, :ss1, :ss2) ) + expected_params = webtopay_expected_params( api_response.query_params.clone ) + if not api_response.valid?(expected_params) + webtopay_failed_validation_response(api_response) + end end - def webtopay_check - if webtopay_required? - begin - - @webtopay_response = WebToPay::Api.check_response(request.query_string, { - :projectid => WebToPay.config.project_id, - :sign_password => WebToPay.config.sign_password - }) - - rescue WebToPay::Exception => e - render :text => e.message, :status => 500 - end - end + def webtopay_expected_params(webtopay_params) + {} + end + + def webtopay_failed_validation_response(api_response) + raise api_response.errors.first end end