Sha256: cdcde64cf8d29abfb1708b5c18b67eaf56f2adba8f3eddb746712d198f2169b3

Contents?: true

Size: 765 Bytes

Versions: 2

Compression:

Stored size: 765 Bytes

Contents

module WebToPayController  
  module ClassMethods
    def webtopay(*actions)
      options = actions.any? ? { only: actions } : {}
      before_filter :webtopay, options
      
      attr_reader :webtopay_response
    end
  end
  
  def self.included(controller)
    controller.extend(ClassMethods)
  end
  
  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_expected_params(webtopay_params)
    {}
  end

  def webtopay_failed_validation_response(api_response)
    raise api_response.errors.first
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
webtopay-1.6.1 lib/webtopay_controller.rb
webtopay-1.6.0 lib/webtopay_controller.rb