Skip to content
This repository has been archived by the owner on Mar 19, 2023. It is now read-only.

Ruby on Rails 4 support #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 32 additions & 14 deletions README → README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,50 @@
WebToPay
===========
# WebToPay

It is a plugin which could be very useful on working with https://www.webtopay.com/ (https://www.mokejimai.lt/) billing system.
The main function of this plugin is protection against forgeries that could be done by sending required parameters to the application and getting services without paying for free.
This plugin could be integrated with both billing types - MACRO (VISA, MasterCard, banks etc.) and MICRO (SMS, phone calls etc.).
It is a gem which could be very useful on working with https://www.webtopay.com/ (https://www.mokejimai.lt/) billing system.
The main function of this gem is protection against forgeries that could be done by sending required parameters to the application and getting services without paying for free.
This gem could be integrated with both billing types - MACRO (VISA, MasterCard, banks etc.) and MICRO (SMS, phone calls etc.).

*It works with OpenSSL so be sure that you have installed all necessary libs or modules on your system.

Installation
===========
## Installation

cd your_application
./script/plugin install git://github.com/kristis/webtopay.git
Add to your gemfile:

```ruby
gem "webtopay", branch: 'rails4'
```

## Configuration

Configuration
===========
Create initializer
config/initializers/webtopay.rb

```ruby
WebToPay.configure do |config|
config.project_id = 00000
config.sign_password = 'your sign password'
end
```

Examples
===========
## Usage

Add this to your controller:
```ruby
webtopay :controller_method1, :controller_method2 ...
```

Or you can add this (it does the same as above):
```ruby
before_filter :webtopay_check, only:[:controller_method1, :controller_method2] ...
```

## Examples

These code slices will protect your controller actions, which work with webtopay.com billing, against forgeries.

****** Usage for MICRO and MACRO billing on controller:

```ruby
[........]

webtopay :activate_user, :confirm_cart # You can add here as many actions as you want
Expand All @@ -45,17 +60,20 @@ These code slices will protect your controller actions, which work with webtopay
end

[........]
```

****** You can also use helper method to generate required form for MACRO billing query:

```ruby
[........]

<% macro_form :test => 1, :orderid => 123, :amount => 2000, :payment => 'vb', :country => 'lt', :paytext => "Billing for XX at the website XXX" do %>
<% macro_form test: 1, orderid: 123, amount: 2000, payment: 'vb', :country => 'lt', :paytext => "Billing for XX at the website XXX" do %>
Select paying method: <%= select_tag(:payment, options_for_select(['', 'vb', 'hanza', 'nord', 'snoras'])) %>
<%= submit_tag "test paying" %>
<% end %>

[........]
```

* Attention!!! Be sure that you have set required option, which let sending test requests, at your webtopay.com account settings at first if you want to use test requests.
* You can add into the helper options additional parameters or remove them according to technical specifications at https://www.webtopay.com/ .
Expand Down
34 changes: 13 additions & 21 deletions lib/webtopay_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module WebToPayController
module WebToPayController
module ClassMethods
def webtopay(*actions)
before_filter :webtopay_check
write_inheritable_array(:actions, actions)
options = actions.any? ? { only: actions } : {}
before_filter :webtopay_check, options

attr_reader :webtopay_response
end
Expand All @@ -12,24 +12,16 @@ def self.included(controller)
controller.extend(ClassMethods)
end

protected

def webtopay_required?
(self.class.read_inheritable_attribute(:actions) || []).include?(action_name.to_sym)
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
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
end
28 changes: 28 additions & 0 deletions spec/dummy/README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
== README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* System dependencies

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...


Please feel free to use a different markup language if you do not plan to run
<tt>rake doc:app</tt>.
6 changes: 6 additions & 0 deletions spec/dummy/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Dummy::Application.load_tasks
Empty file.
13 changes: 13 additions & 0 deletions spec/dummy/app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require_tree .
13 changes: 13 additions & 0 deletions spec/dummy/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require_tree .
*/
5 changes: 5 additions & 0 deletions spec/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
Empty file.
11 changes: 11 additions & 0 deletions spec/dummy/app/controllers/payments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class PaymentsController < ApplicationController
webtopay :order

def index
render text: 'it\'s index'
end

def order
render text: 'ok'
end
end
2 changes: 2 additions & 0 deletions spec/dummy/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApplicationHelper
end
Empty file added spec/dummy/app/mailers/.keep
Empty file.
Empty file added spec/dummy/app/models/.keep
Empty file.
Empty file.
14 changes: 14 additions & 0 deletions spec/dummy/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy</title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>
3 changes: 3 additions & 0 deletions spec/dummy/bin/bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
4 changes: 4 additions & 0 deletions spec/dummy/bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
4 changes: 4 additions & 0 deletions spec/dummy/bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run
4 changes: 4 additions & 0 deletions spec/dummy/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
23 changes: 23 additions & 0 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require File.expand_path('../boot', __FILE__)

require 'rails/all'

Bundler.require(*Rails.groups)
require "webtopay"

module Dummy
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.

# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
end
end

5 changes: 5 additions & 0 deletions spec/dummy/config/boot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
25 changes: 25 additions & 0 deletions spec/dummy/config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000

production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
5 changes: 5 additions & 0 deletions spec/dummy/config/environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Load the Rails application.
require File.expand_path('../application', __FILE__)

# Initialize the Rails application.
Dummy::Application.initialize!
29 changes: 29 additions & 0 deletions spec/dummy/config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false

# Do not eager load code on boot.
config.eager_load = false

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

# Raise an error on page load if there are pending migrations
config.active_record.migration_error = :page_load

# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
end
Loading