diff --git a/lib/simplepay/helpers/notification_helper.rb b/lib/simplepay/helpers/notification_helper.rb index 2e2d435..3098859 100644 --- a/lib/simplepay/helpers/notification_helper.rb +++ b/lib/simplepay/helpers/notification_helper.rb @@ -3,11 +3,40 @@ module Simplepay module Helpers + ## + # Adds a +valid_simplepay_request?+ method to your ActionControllers. + # + # In order to use this, you should just directly hand your +params+ into + # the method: + # + # class FooController < ApplicationController + # + # def receive_ipn + # if valid_simplepay_request?(params) + # ... record something useful ... + # else + # ... maybe log a bad request? ... + # end + # end + # + # end + # module NotificationHelper protected + ## + # Authenticates the incoming request by validating the +signature+ + # provided. + # + # (from within your controller) + # def receive_ipn + # if valid_simplepay_request?(params) + # ... + # end + # end + # def valid_simplepay_request?(request_hash) hash = request_hash.symbolize_keys signature = hash.delete(:signature) || '' diff --git a/lib/simplepay/helpers/rails_helper.rb b/lib/simplepay/helpers/rails_helper.rb index a27733e..bf2f529 100644 --- a/lib/simplepay/helpers/rails_helper.rb +++ b/lib/simplepay/helpers/rails_helper.rb @@ -3,8 +3,23 @@ module Simplepay module Helpers + ## + # Adds helpers to your views for generating the correct HTML FORMs and + # valid signatures. + # module RailsHelper + ## + # This is the general interface for generating your Simple Pay service + # forms. See Simplepay::Services for available services and information + # specific to each. + # + # === Example + # + # (in your view) + # + # <%= simplepay_form_for(:service_name, {:attr => 'foo'}) %> + # def simplepay_form_for(service_name, attributes = {}) service = get_simplepay_service(service_name) service.form(attributes) @@ -14,7 +29,7 @@ def simplepay_form_for(service_name, attributes = {}) private - def get_simplepay_service(name) + def get_simplepay_service(name) #:nodoc: service = "Simplepay::Services::#{name.to_s.camelize}".constantize service.new end