easypay 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ == Overview
2
+
3
+ This gem enables connection with Easypay API (www.easypay.pt)
4
+
5
+ Installation:
6
+
7
+ In your gemfile:
8
+
9
+ * gem 'easypay'
10
+
11
+ After bundle:
12
+
13
+ * rails generate easypay
14
+
15
+ Check on your initializers folder for easypay.rb and change the parameters:
16
+
17
+ * config.cin = CIN provided by Easypay
18
+ * config.user = USER provided by Easypay
19
+ * config.entity = Entity provided by Easypay
20
+ * config.code = Code is needed only if you don't have validation by IP Address (Configure on Easypay Backoffice)
21
+
22
+ Usage:
23
+
24
+ Start Easypay call:
25
+
26
+ * Easypay::Client.new
27
+
28
+ If you don't configure your easypay.rb with these params, you can start your object like this:
29
+
30
+ * Easypay::Client.new(:easypay_cin => xxxx,
31
+ :easypay_entity => xxxx,
32
+ :easypay_user => xxxx,
33
+ :easypay_code => xxxx,
34
+ :easypay_ref_type => xxx,
35
+ :easypay_country => xxxx)
36
+
37
+
38
+ In order to get one payment reference:
39
+ * Easypay::Client.new.create_reference('token_you_generate', 'value_of_payment', 'client_language', 'client_name', 'client_mobile', 'client_email')
40
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.3
@@ -0,0 +1,18 @@
1
+ module Easypay
2
+ class ClientsController < ApplicationController
3
+
4
+ unloadable
5
+
6
+ def index
7
+ @atts = params
8
+
9
+ @atts[:ep_entity] = params[:e]
10
+ @atts[:ep_reference] = params[:r]
11
+ @atts[:ep_value] = params[:v]
12
+
13
+ respond_to do |format|
14
+ format.xml #{ render :xml => render_to_string(:template => 'easypay/notify.xml.builder', :layout => false), :content_type => 'plain/text'}
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ Rails.application.routes.draw do
2
+
3
+ mount_at = Easypay::Engine.config.mount_at
4
+
5
+ match mount_at => 'easypay/clients#index'
6
+
7
+ resources :clients, :only => [ :index ],
8
+ :controller => "easypay/clients",
9
+ :path_prefix => mount_at,
10
+ :name_prefix => "easypay_"
11
+
12
+ end
@@ -1,20 +1,24 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "easypay/version"
4
3
 
5
4
  Gem::Specification.new do |s|
6
5
  s.name = "easypay"
7
- s.version = Easypay::VERSION
6
+ s.version = "0.0.3"
8
7
  s.authors = ["Guilherme Pereira"]
9
8
  s.email = ["guiferrpereira@gmail.com"]
10
9
  s.homepage = ""
11
10
  s.summary = %q{This Gem provides connection to easypay API}
12
11
  s.description = %q{This Gem provides connection to easypay API, that allow you to use credit cards and MB references to Portugal}
13
-
12
+ s.extra_rdoc_files = [
13
+ "README.rdoc"
14
+ ]
15
+
14
16
  s.rubyforge_project = "easypay"
15
-
17
+
18
+ s.add_dependency('nokogiri')
19
+
16
20
  s.files = `git ls-files`.split("\n")
17
21
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
22
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
23
  s.require_paths = ["lib"]
20
- end
24
+ end
@@ -0,0 +1,24 @@
1
+ module Easypay
2
+ ## Define ControllerMethods
3
+ module Controller
4
+ ## this one manages the usual self.included, klass_eval stuff
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ before_filter :test_controller_instance_method
9
+ end
10
+
11
+ def test_controller_instance_method
12
+ puts "###### This text is coming from an application_controller before_filter that is being declared and triggered from inside the engine. This before_filter is automatically integrated in when the engine is installed into an app. Look inside lib/application_controller.rb to find it. ######"
13
+ end
14
+
15
+ # This method is available inside application_controller but it is not being
16
+ # automatically executed. Notice the before_filter line above that is automatically
17
+ # executing the first method.
18
+ def second_controller_instance_method
19
+ puts "###### This method is not automatically run inside application_controller, but it is available inside application_controller. To see this example add 'before_filter :second_controller_instance_method' at the top of your app's application_controller.rb ######"
20
+ end
21
+ end
22
+ end
23
+
24
+ ::ActionController::Base.send :include, Easypay::Controller
@@ -0,0 +1,7 @@
1
+ module ApplicationHelper
2
+
3
+ def app_wide_helper_method
4
+ "this output is from an app-wide helper method that is declared within the gem"
5
+ end
6
+
7
+ end
@@ -1,3 +1,9 @@
1
- require "easypay/version"
2
- require "easypay/client"
3
- require "easypay/config/routes"
1
+ module Easypay
2
+ require 'net/http'
3
+ require 'net/https'
4
+ require 'nokogiri'
5
+
6
+ require 'engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
7
+ require 'application_controller'
8
+ require 'easypay/client'
9
+ end
@@ -6,26 +6,33 @@ module Easypay
6
6
  def initialize *params
7
7
  if params.first.is_a?(Hash)
8
8
  hash_options = params.first
9
- @easypay_cin = hash_options[:easypay_cin]
10
- @easypay_user = hash_options[:easypay_user]
11
- @easypay_entity = hash_options[:easypay_entity]
12
- @easypay_code = hash_options[:easypay_code]
9
+ @easypay_cin = hash_options[:easypay_cin] || Easypay::Engine.config.cin
10
+ @easypay_user = hash_options[:easypay_user] || Easypay::Engine.config.user
11
+ @easypay_entity = hash_options[:easypay_entity] || Easypay::Engine.config.entity
12
+ @easypay_code = hash_options[:easypay_code] || Easypay::Engine.config.code
13
13
  @easypay_ref_type = hash_options[:easypay_ref_type] || "auto"
14
14
  @easypay_country = hash_options[:easypay_country] || "PT"
15
15
  elsif params.first
16
16
  puts "* warning: the method Easypay::Client.new(ep_cin, ep_user, ep_entity) is deprecated, use Easypay::Client.new(:easypay_cin => 'cin', :easypay_user => 'user', :easypay_entity => 'entity')"
17
- @easypay_cin = params.shift
18
- @easypay_user = params.shift
19
- @easypay_entity = params.shift
20
- @easypay_code = params.shift
17
+ @easypay_cin = params.shift || Easypay::Engine.config.cin
18
+ @easypay_user = params.shift || Easypay::Engine.config.user
19
+ @easypay_entity = params.shift || Easypay::Engine.config.entity
20
+ @easypay_code = params.shift || Easypay::Engine.config.code
21
21
  @easypay_ref_type = params.shift || "auto"
22
22
  @easypay_country = params.shift || "PT"
23
+ else
24
+ @easypay_cin = Easypay::Engine.config.cin
25
+ @easypay_user = Easypay::Engine.config.user
26
+ @easypay_entity = Easypay::Engine.config.entity
27
+ @easypay_code = Easypay::Engine.config.code
28
+ @easypay_ref_type = "auto"
29
+ @easypay_country = "PT"
23
30
  end
24
31
  end
25
32
 
26
33
  # API methods
27
34
 
28
- def create_client_reference(token, value, lang, client_name=nil, client_mobile=nil, client_email=nil)
35
+ def create_reference(token, value, lang, client_name=nil, client_mobile=nil, client_email=nil)
29
36
  get "01BG",
30
37
  :t_key => token,
31
38
  :t_value => value,
@@ -0,0 +1,30 @@
1
+ require 'easypay'
2
+ require 'rails'
3
+ require 'action_controller'
4
+ require 'application_helper'
5
+
6
+ module Easypay
7
+ class Engine < Rails::Engine
8
+
9
+ # Config defaults
10
+ config.widget_factory_name = "default factory name"
11
+ config.mount_at = '/'
12
+
13
+ # Load rake tasks
14
+ rake_tasks do
15
+ load File.join(File.dirname(__FILE__), 'rails/railties/tasks.rake')
16
+ end
17
+
18
+ # Check the gem config
19
+ initializer "check config" do |app|
20
+
21
+ # make sure mount_at ends with trailing slash
22
+ config.mount_at += '/' unless config.mount_at.last == '/'
23
+ end
24
+
25
+ initializer "static assets" do |app|
26
+ app.middleware.use ::ActionDispatch::Static, "#{root}/public"
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,76 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ class EasypayGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+
7
+ def self.source_root
8
+ File.join(File.dirname(__FILE__), 'templates')
9
+ end
10
+
11
+ def self.next_migration_number(dirname) #:nodoc:
12
+ if ActiveRecord::Base.timestamped_migrations
13
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
14
+ else
15
+ "%.3d" % (current_migration_number(dirname) + 1)
16
+ end
17
+ end
18
+
19
+
20
+ # Every method that is declared below will be automatically executed when the generator is run
21
+
22
+ # def create_migration_file
23
+ # f = File.open File.join(File.dirname(__FILE__), 'templates', 'schema.rb')
24
+ # schema = f.read; f.close
25
+ #
26
+ # schema.gsub!(/ActiveRecord::Schema.*\n/, '')
27
+ # schema.gsub!(/^end\n*$/, '')
28
+ #
29
+ # f = File.open File.join(File.dirname(__FILE__), 'templates', 'migration.rb')
30
+ # migration = f.read; f.close
31
+ # migration.gsub!(/SCHEMA_AUTO_INSERTED_HERE/, schema)
32
+ #
33
+ # tmp = File.open "tmp/~migration_ready.rb", "w"
34
+ # tmp.write migration
35
+ # tmp.close
36
+ #
37
+ # migration_template '../../../tmp/~migration_ready.rb',
38
+ # 'db/migrate/create_easypay_tables.rb'
39
+ # remove_file 'tmp/~migration_ready.rb'
40
+ # end
41
+
42
+ def copy_initializer_file
43
+ copy_file 'initializer.rb', 'config/initializers/easypay.rb'
44
+ end
45
+
46
+ # def update_application_template
47
+ # f = File.open "app/views/layouts/application.html.erb"
48
+ # layout = f.read; f.close
49
+ #
50
+ # if layout =~ /<%=[ ]+yield[ ]+%>/
51
+ # print " \e[1m\e[34mquestion\e[0m Your layouts/application.html.erb layout currently has the line <%= yield %>. This gem needs to change this line to <%= content_for?(:content) ? yield(:content) : yield %> to support its nested layouts. This change should not affect any of your existing layouts or views. Is this okay? [y/n] "
52
+ # begin
53
+ # answer = gets.chomp
54
+ # end while not answer =~ /[yn]/i
55
+ #
56
+ # if answer =~ /y/i
57
+ #
58
+ # layout.gsub!(/<%=[ ]+yield[ ]+%>/, '<%= content_for?(:content) ? yield(:content) : yield %>')
59
+ #
60
+ # tmp_real_path = File.expand_path("tmp/~application.html.erb")
61
+ #
62
+ # tmp = File.open tmp_real_path, "w"
63
+ # tmp.write layout; tmp.close
64
+ #
65
+ # remove_file 'app/views/layouts/application.html.erb'
66
+ # copy_file tmp_real_path, 'app/views/layouts/application.html.erb'
67
+ # remove_file tmp_real_path
68
+ # end
69
+ # elsif layout =~ /<%=[ ]+content_for\?\(:content\) \? yield\(:content\) : yield[ ]+%>/
70
+ # puts " \e[1m\e[33mskipping\e[0m layouts/application.html.erb modification is already done."
71
+ # else
72
+ # puts " \e[1m\e[31mconflict\e[0m The gem is confused by your layouts/application.html.erb. It does not contain the default line <%= yield %>, you may need to make manual changes to get this gem's nested layouts working. Visit ###### for details."
73
+ # end
74
+ # end
75
+
76
+ end
@@ -0,0 +1,12 @@
1
+ module Easypay
2
+ class Engine < Rails::Engine
3
+
4
+ config.mount_at = '/easypay'
5
+ config.cin = 'cin provided by Easypay'
6
+ config.user = 'user provided by Easypay'
7
+ config.entity = 'entity provided by Easypay'
8
+ # Code is needed only if you don't have validation by IP Address
9
+ config.code = ''
10
+
11
+ end
12
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easypay
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Guilherme Pereira
@@ -15,9 +15,22 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-07-06 00:00:00 Z
19
- dependencies: []
20
-
18
+ date: 2012-07-08 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: nokogiri
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
21
34
  description: This Gem provides connection to easypay API, that allow you to use credit cards and MB references to Portugal
22
35
  email:
23
36
  - guiferrpereira@gmail.com
@@ -25,20 +38,25 @@ executables: []
25
38
 
26
39
  extensions: []
27
40
 
28
- extra_rdoc_files: []
29
-
41
+ extra_rdoc_files:
42
+ - README.rdoc
30
43
  files:
31
44
  - .gitignore
32
45
  - Gemfile
33
- - README
46
+ - README.rdoc
34
47
  - Rakefile
48
+ - VERSION
49
+ - app/controllers/easypay/clients_controller.rb
50
+ - app/views/easypay/clients/index.xml.builder
51
+ - config/routes.rb
35
52
  - easypay.gemspec
53
+ - lib/application_controller.rb
54
+ - lib/application_helper.rb
36
55
  - lib/easypay.rb
37
56
  - lib/easypay/client.rb
38
- - lib/easypay/config/routes.rb
39
- - lib/easypay/controllers/client_controller.rb
40
- - lib/easypay/version.rb
41
- - lib/easypay/views/notify.xml.builder
57
+ - lib/engine.rb
58
+ - lib/rails/generators/easypay/easypay_generator.rb
59
+ - lib/rails/generators/easypay/templates/initializer.rb
42
60
  homepage: ""
43
61
  licenses: []
44
62
 
data/README DELETED
@@ -1,8 +0,0 @@
1
- = Easypay -- Client for Easypay API
2
-
3
- = Installing Easypay
4
-
5
- == Installing the Gem
6
- $ gem install easypay
7
-
8
- == Usage
@@ -1,3 +0,0 @@
1
- Rails.application.routes.draw do
2
- match 'easypay.:format' => 'client#notify'
3
- end
@@ -1,16 +0,0 @@
1
- class ClientController < ApplicationController
2
-
3
- def notify
4
-
5
-
6
- @atts = params
7
-
8
- @atts[:ep_entity] = params[:e]
9
- @atts[:ep_reference] = params[:r]
10
- @atts[:ep_value] = params[:v]
11
-
12
- respond_to do |format|
13
- format.xml #{ render :xml => render_to_string(:template => 'easypay/notify.xml.builder', :layout => false), :content_type => 'plain/text'}
14
- end
15
- end
16
- end
@@ -1,3 +0,0 @@
1
- module Easypay
2
- VERSION = "0.0.2"
3
- end