Rack::Webmoney

Usage

You trigger an Webmoney request similar to HTTP authentication. From your app, return a “401 Unauthorized” and a “WWW-Authenticate” header with the identifier you would like to validate.

On competition, the Webmoney response is automatically verified and assigned to env["rack.webmoney.response"].

Rails 3 Example

application.rb

...
config.middleware.insert_before(Warden::Manager, Rack::Webmoney,
  :credentials => {:app_rids => { 'example.com' => 'your_site_rid' }, :site_holder_wmid => 'your_site_holder_wmid'},
  :mode => Rails.env)
...

Rack Example

MyApp = lambda { |env|
  if resp = env["rack.webmoney.response"]
    case resp.status
    when :successful
      ...
    else
      ...
  else
    [401, {"WWW-Authenticate" => 'Webmoney"}, []]
  end
}

use Rack::Webmoney, :credentials => {:app_rids => { 'example.com' => 'your_site_rid' }, :site_holder_wmid => 'your_site_holder_wmid'}, :mode => "development_OR_test_FOR_TESTING"
run MyApp

Sinatra Example

# Session needs to be before Rack::OpenID
use Rack::Session::Cookie

require 'rack/webmoney'
use Rack::Webmoney, :credentials => {:app_rids => { 'example.com' => 'your_site_rid' }, :site_holder_wmid => 'your_site_holder_wmid'}, :mode => "development_OR_test_FOR_TESTING"

get '/login' do
  erb :login
end

post '/login' do
  if resp = request.env["rack.webmoney.response"]
    if resp.status == :successful
      "Welcome: #{resp.display_identifier}"
    else
      "#{resp.status}: #{resp.message}"
    end
  else
    headers 'WWW-Authenticate' => Rack::Webmoney.build_header({})
    throw :halt, [401, 'got webmoney?']
  end
end

use_in_file_templates!

__END__

Thank for inspiration goes to:

rack-openid