easypay 0.0.3 → 0.0.4

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.
data/README.markdown ADDED
@@ -0,0 +1,57 @@
1
+ Easypay
2
+ =========
3
+
4
+ _Easypay_ is a Ruby client for [Easypay](http://www.easypay.pt/) payment platform that allows payments with credit cards and (MB references to Portugal)
5
+
6
+ Installation
7
+ ------------
8
+
9
+ OK. First, you need to talk with people from Easypay to get your credentials!
10
+
11
+ Now, let's install the gem via Rubygems:
12
+
13
+ $ gem install easypay
14
+
15
+ Or in your Gemfile:
16
+
17
+ $ gem 'easypay'
18
+
19
+ After bundle:
20
+
21
+ $ rails generate easypay
22
+
23
+ Check on your initializers folder for easypay.rb and change the parameters:
24
+
25
+ ```ruby
26
+ config.cin = 'CIN provided by Easypay'
27
+ config.user = 'USER provided by Easypay'
28
+ config.entity = 'Entity provided by Easypay'
29
+ config.code = 'Code is needed only if you don't have validation by IP Address (Configure on Easypay Backoffice)'
30
+ ```
31
+
32
+ Usage
33
+ -----
34
+
35
+ Start Easypay call:
36
+
37
+ ```ruby
38
+ Easypay::Client.new
39
+ ```
40
+
41
+ If you don't configure your easypay.rb with these params, you can start your object like this:
42
+
43
+ ```ruby
44
+ Easypay::Client.new(:easypay_cin => xxxx,
45
+ :easypay_entity => xxxx,
46
+ :easypay_user => xxxx,
47
+ :easypay_code => xxxx,
48
+ :easypay_ref_type => xxx,
49
+ :easypay_country => xxxx)
50
+ ```
51
+
52
+ In order to get one payment reference:
53
+
54
+ ```ruby
55
+ Easypay::Client.new.create_reference('token_you_generate', 'value_of_payment', 'client_language', 'client_name', 'client_mobile', 'client_email')
56
+ ```
57
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -0,0 +1,63 @@
1
+ module Easypay
2
+ class NotificationsController < ApplicationController
3
+
4
+ unloadable
5
+
6
+ before_filter :register_notification
7
+
8
+ def simple_notification
9
+ # c=PT&e=10611&r=810302231&v=7&l=PT&t_key=
10
+ @payment_reference = PaymentReference.find_by_ep_reference_and_ep_value(params[:r], params[:v])
11
+ # preciso de por os dados da morada do cliente, NIF etc
12
+ respond_to do |format|
13
+ format.xml
14
+ end
15
+ end
16
+
17
+ def notification_to_forward
18
+ # e=10611&r=810302231&v=7&s=ok&k=C36D4995CBF3574ADD8664BA26514181C9EA8737&t_key=CCCSOKCSO
19
+ payment_reference = PaymentReference.find_by_ep_reference_and_ep_key(params[:r], params[:t_key])
20
+
21
+ if params[:s].starts_with? "ok" and params[:k].present?
22
+ payment_reference.update_attribute(:o_key, params[:k]) unless payment_reference.nil?
23
+
24
+ payment_detail = Easypay::Client.new.request_payment(params[:e], params[:r], params[:v], params[:k])
25
+
26
+ payment_reference.update_attributes(:ep_last_status => payment_detail[:ep_status],
27
+ :ep_message => payment_detail[:ep_message]) unless payment_reference.nil?
28
+ end
29
+
30
+ redirect_to payment_redirect_url(:status => params[:s], :ep_key => params[:t_key])
31
+ end
32
+
33
+ def notification_from_payment
34
+ #ep_cin=8103&ep_user=OUTITUDE&ep_doc=TESTOUTITUDE0088690520120712152503
35
+ payment_detail = Easypay::Client.new.get_payment_detail("", params[:ep_doc])
36
+
37
+ payment_reference = PaymentReference.find_by_ep_reference_and_ep_key(payment_detail[:ep_reference], payment_detail[:t_key])
38
+
39
+ payment_reference.update_attributes(:ep_doc => payment_detail[:ep_doc],
40
+ :ep_payment_type => payment_detail[:ep_payment_type],
41
+ :ep_value_fixed => payment_detail[:ep_value_fixed],
42
+ :ep_value_var => payment_detail[:ep_value_var],
43
+ :ep_value_tax => payment_detail[:ep_value_tax],
44
+ :ep_value_transf => payment_detail[:ep_value_transf],
45
+ :ep_date_transf => payment_detail[:ep_date_transf],
46
+ :ep_date_read => payment_detail[:ep_date_read],
47
+ :ep_status_read => payment_detail[:ep_status_read],
48
+ :o_obs => payment_detail[:o_obs],
49
+ :ep_date => payment_detail[:ep_date],
50
+ :ep_status => 'finalized') unless payment_reference.nil?
51
+
52
+ respond_to do |format|
53
+ format.xml
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def register_notification
60
+ Easypay::Log.create(:request_type => "Notification", :request_url => request.fullpath, :request_remote_ip => request.remote_ip)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,12 @@
1
+ module Easypay
2
+ class PaymentsController < ApplicationController
3
+ def complete
4
+ # After payment success
5
+ @key = params[:ep_key]
6
+ @status = params[:status]
7
+ respond_to do |format|
8
+ format.html
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ module Easypay
2
+ class Log < ActiveRecord::Base
3
+ self.table_name = 'easypay_logs'
4
+
5
+ attr_accessible :request_type, :request_url, :request_remote_ip, :raw
6
+
7
+ end
8
+ end
@@ -0,0 +1,66 @@
1
+ module Easypay
2
+ class PaymentReference < ActiveRecord::Base
3
+ self.table_name = 'easypay_payment_references'
4
+
5
+ attr_protected
6
+
7
+ def process(object)
8
+ @object = object
9
+
10
+ if compliant?
11
+ self.update_attributes(handle_model_methods)
12
+
13
+ payment_reference = Easypay::Client.new.create_reference(self)
14
+
15
+ self.update_attributes( :ep_message => payment_reference[:ep_message],
16
+ :ep_reference => payment_reference[:ep_reference],
17
+ :ep_cin => payment_reference[:ep_cin],
18
+ :ep_user => payment_reference[:ep_user],
19
+ :ep_entity => payment_reference[:ep_entity],
20
+ :ep_link => payment_reference[:payment_link],
21
+ :ep_last_status => payment_reference[:ep_status],
22
+ :request_log => payment_reference[:raw])
23
+
24
+ return payment_reference
25
+ else
26
+ nil
27
+ end
28
+ end
29
+
30
+ protected
31
+
32
+ def handle_model_methods
33
+ attributes = {}
34
+ model_attributes.each do |attribute_name, method_name|
35
+ if @object.respond_to? method_name
36
+ attributes[attribute_name] = @object.send(method_name)
37
+ elsif !attribute_name.to_s.match("ep_key").nil?
38
+ attributes[attribute_name] = method_name
39
+ end
40
+ end
41
+ return attributes
42
+ end
43
+
44
+ def model_attributes
45
+ {
46
+ :payable_id => @object.easypay_options[:payable_id],
47
+ :ep_key => generate_ep_key,
48
+ :ep_value => @object.easypay_options[:ep_value],
49
+ :ep_language => @object.easypay_options[:ep_language],
50
+ :o_name => @object.easypay_options[:o_name],
51
+ :o_description => @object.easypay_options[:o_description],
52
+ :o_obs => @object.easypay_options[:o_obs],
53
+ :o_email => @object.easypay_options[:o_email],
54
+ :o_mobile => @object.easypay_options[:o_mobile]
55
+ }
56
+ end
57
+
58
+ def compliant?
59
+ !(@object.send(@object.easypay_options[:ep_language]).blank? && @object.send(@object.easypay_options[:ep_value]).blank?)
60
+ end
61
+
62
+ def generate_ep_key
63
+ Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{@object.easypay_options[:ep_value]}--#{@object.easypay_options[:ep_language]}--")[8..32]
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,4 @@
1
+ xml.instruct! :xml, :version => "1.0", :encoding => "ISO-8859-1"
2
+ xml.get_detail do
3
+ xml.ep_status "ok"
4
+ end
@@ -0,0 +1,44 @@
1
+ xml.instruct! :xml, :version => "1.0", :encoding => "ISO-8859-1"
2
+ xml.get_detail do
3
+ if @payment_reference.nil?
4
+ xml.ep_status "err"
5
+ xml.ep_message "error mensage"
6
+ xml.ep_entity "x1"
7
+ xml.ep_ref "x2"
8
+ xml.ep_value "x3"
9
+ else
10
+ xml.ep_status "ok"
11
+ xml.ep_message "success message"
12
+ xml.ep_entity @payment_reference.ep_entity
13
+ xml.ep_reference @payment_reference.ep_reference
14
+ xml.ep_value @payment_reference.ep_value
15
+ xml.t_key @payment_reference.ep_key
16
+ xml.order_info do
17
+ xml.total_taxes "100.00"
18
+ xml.total_including_taxes @payment_reference.ep_value
19
+
20
+ xml.bill_fiscal_number "PT123456789"
21
+ xml.bill_name "Billing Test Name"
22
+ xml.bill_address_1 "Billing address line 1"
23
+ xml.bill_address_2 "Billing address line 2"
24
+ xml.bill_city "Billing city"
25
+ xml.bill_zip_code "Billing zip code"
26
+ xml.bill_country "Billing country"
27
+
28
+ xml.ship_fiscal_number "PT123456789"
29
+ xml.shipp_name "Shipping Test Name"
30
+ xml.shipp_address_1 "Shipping address line 1"
31
+ xml.shipp_address_2 "Shipping address line 2"
32
+ xml.shipp_city "Shipping city"
33
+ xml.shipp_zip_code "Shipping zip code"
34
+ xml.shipp_country "Shipping coutry"
35
+ end
36
+ xml.order_detail do
37
+ xml.item do
38
+ xml.item_description "description of item 1"
39
+ xml.item_quantity "5"
40
+ xml.item_total @payment_reference.ep_value
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,11 @@
1
+ <%if @status.starts_with? "ok"%>
2
+ <h2>Payment</h2>
3
+ <%else%>
4
+ <h2>Payment Error</h2>
5
+ <%end%>
6
+ <div>
7
+ Status : <%=@status.to_s%>
8
+ </div>
9
+ <div>
10
+ Key : <%=@key.to_s%>
11
+ </div>
data/config/routes.rb CHANGED
@@ -1,12 +1,8 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
- mount_at = Easypay::Engine.config.mount_at
4
-
5
- match mount_at => 'easypay/clients#index'
3
+ match Easypay::Engine.config.easypay_notification_path => 'easypay/notifications#simple_notification'
4
+ match Easypay::Engine.config.easypay_forward_path => 'easypay/notifications#notification_to_forward'
5
+ match Easypay::Engine.config.easypay_payment_path => 'easypay/notifications#notification_from_payment'
6
+ match Easypay::Engine.config.redirect_after_payment_path => 'easypay/payments#complete', :as => :payment_redirect
6
7
 
7
- resources :clients, :only => [ :index ],
8
- :controller => "easypay/clients",
9
- :path_prefix => mount_at,
10
- :name_prefix => "easypay_"
11
-
12
8
  end
data/easypay.gemspec CHANGED
@@ -3,15 +3,13 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "easypay"
6
- s.version = "0.0.3"
6
+ s.version = "0.0.4"
7
7
  s.authors = ["Guilherme Pereira"]
8
8
  s.email = ["guiferrpereira@gmail.com"]
9
9
  s.homepage = ""
10
10
  s.summary = %q{This Gem provides connection to easypay API}
11
11
  s.description = %q{This Gem provides connection to easypay API, that allow you to use credit cards and MB references to Portugal}
12
- s.extra_rdoc_files = [
13
- "README.rdoc"
14
- ]
12
+ s.extra_rdoc_files = ["README.markdown"]
15
13
 
16
14
  s.rubyforge_project = "easypay"
17
15
 
@@ -0,0 +1,45 @@
1
+ module Easypay
2
+ module ActsAsPayable
3
+
4
+ ## Define ModelMethods
5
+ module Base
6
+ def self.included(klass)
7
+ klass.class_eval do
8
+ extend Config
9
+ end
10
+ end
11
+
12
+ module Config
13
+ def acts_as_payable args = {}
14
+ has_many :payment_references, :class_name => 'Easypay::PaymentReference', :foreign_key => "payable_id"
15
+
16
+ define_method "easypay_options" do
17
+ {
18
+ :payable_id => args[:id] || "id",
19
+ :ep_value => args[:value] || "value",
20
+ :ep_language => args[:language] || "language",
21
+ :o_name => args[:name] || "name",
22
+ :o_description => args[:description] || "description",
23
+ :o_obs => args[:obs] || "obs",
24
+ :o_email => args[:email] || "email",
25
+ :o_mobile => args[:mobile] || "mobile"
26
+ }
27
+ end
28
+
29
+ include Easypay::ActsAsPayable::Base::InstanceMethods
30
+ end
31
+ end
32
+
33
+ module InstanceMethods
34
+
35
+ def create_payment_reference
36
+ Easypay::PaymentReference.new.process(self)
37
+ end
38
+
39
+ end # InstanceMethods
40
+ end
41
+
42
+ end
43
+ end
44
+
45
+ ::ActiveRecord::Base.send :include, Easypay::ActsAsPayable::Base
@@ -9,14 +9,14 @@ module Easypay
9
9
  end
10
10
 
11
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. ######"
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
13
  end
14
14
 
15
15
  # This method is available inside application_controller but it is not being
16
16
  # automatically executed. Notice the before_filter line above that is automatically
17
17
  # executing the first method.
18
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 ######"
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
20
  end
21
21
  end
22
22
  end
data/lib/easypay.rb CHANGED
@@ -6,4 +6,5 @@ module Easypay
6
6
  require 'engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
7
7
  require 'application_controller'
8
8
  require 'easypay/client'
9
+ require 'acts_as_payable/base'
9
10
  end
@@ -32,35 +32,39 @@ module Easypay
32
32
 
33
33
  # API methods
34
34
 
35
- def create_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, client_observation=nil, item_description=nil)
36
+ def create_reference(object)
37
+
36
38
  get "01BG",
37
- :t_key => token,
38
- :t_value => value,
39
- :ep_language => lang.upcase,
40
- :o_name => client_name.nil? ? "" : URI.escape(client_name),
41
- :o_mobile => client_mobile.nil? ? "" : client_mobile,
42
- :o_email => client_email.nil? ? "" : URI.escape(client_email)
39
+ :t_key => object.ep_key,
40
+ :t_value => object.ep_value,
41
+ :ep_language => object.ep_language.upcase,
42
+ :o_name => object.o_name.nil? ? "" : URI.escape(object.o_name),
43
+ :o_description => object.o_description.nil? ? "" : URI.escape(object.o_description),
44
+ :o_obs => object.o_obs.nil? ? "" : URI.escape(object.o_obs),
45
+ :o_mobile => object.o_mobile.nil? ? "" : object.o_mobile,
46
+ :o_email => object.o_email.nil? ? "" : URI.escape(object.o_email)
43
47
  # :ep_rec => "yes", # Reccurrence stuff
44
48
  # :ep_rec_freq => recurrence,
45
49
  # :ep_rec_url => url_notification_cc
46
50
  end
47
51
 
48
- def get_payment_detail(ep_key,ep_doc)
52
+ def get_payment_detail(ep_key, ep_doc)
49
53
  get "03AG",
50
54
  :ep_key => ep_key,
51
55
  :ep_doc => ep_doc
52
56
  end
53
57
 
54
- def get_payment_listings(type="last", detail=10, format="xml")
58
+ def get_payment_list(type="last", detail=10, format="xml")
55
59
  get "040BG1",
56
60
  :o_list_type => type,
57
61
  :o_ini => detail,
58
62
  :type => format
59
63
  end
60
64
 
61
- def request_single_payment(reference, value, identifier)
65
+ def request_payment(entity, reference, value, identifier)
62
66
  get "05AG",
63
- :e => @easypay_entity,
67
+ :e => entity,
64
68
  :r => reference,
65
69
  :v => value,
66
70
  :k => identifier
@@ -116,11 +120,13 @@ module Easypay
116
120
  response = create_http.get(url, nil)
117
121
 
118
122
  result = { :endpoint => EASYPAY_SERVICE_URL, :url => url, :raw => response.body }
119
-
123
+
124
+ Easypay::Log.create(:request_type => "Request", :request_url => "#{EASYPAY_SERVICE_URL}#{url}", :raw => response.body)
125
+
120
126
  return parse_content(result)
121
127
 
122
128
  rescue Exception => ex
123
- return { :success => false, :error => ex.message }
129
+ return { :success => false, :ep_message => ex.message }
124
130
  end
125
131
  end
126
132
 
@@ -128,14 +134,37 @@ module Easypay
128
134
  doc = Nokogiri::XML(result[:raw])
129
135
 
130
136
  if doc.at("ep_status").nil? or !doc.at("ep_status").text.starts_with? "ok"
131
- result[:error] = doc.at("ep_message").nil? ? "Invalid xml format" : doc.at("ep_message").text
137
+ result[:ep_message] = doc.at("ep_message").nil? ? "Invalid xml format" : doc.at("ep_message").text
132
138
  result[:success] = false
133
139
  else
134
- result[:payment_link] = doc.at("ep_link").text unless doc.at("ep_link").nil?
135
- result[:reference] = doc.at("ep_reference").text unless doc.at("ep_reference").nil?
140
+ result[:ep_message] = doc.at("ep_message").nil? ? "Success" : doc.at("ep_message").text
136
141
  result[:success] = true
142
+ result[:payment_link] = doc.at("ep_link").text unless doc.at("ep_link").nil?
143
+ result[:ep_reference] = doc.at("ep_reference").text unless doc.at("ep_reference").nil?
137
144
  end
138
145
 
146
+ result[:ep_status] = doc.at("ep_status").text unless doc.at("ep_status").nil?
147
+ result[:ep_cin] = doc.at("ep_cin").text unless doc.at("ep_cin").nil?
148
+ result[:ep_user] = doc.at("ep_user").text unless doc.at("ep_user").nil?
149
+ result[:ep_entity] = doc.at("ep_entity").text unless doc.at("ep_entity").nil?
150
+
151
+
152
+ result[:t_key] = doc.at("t_key").text unless doc.at("t_key").nil?
153
+ result[:ep_doc] = doc.at("ep_doc").text unless doc.at("ep_doc").nil?
154
+ result[:ep_payment_type] = doc.at("ep_payment_type").text unless doc.at("ep_payment_type").nil?
155
+ result[:ep_value] = doc.at("ep_value").text unless doc.at("ep_value").nil?
156
+ result[:ep_value_fixed] = doc.at("ep_value_fixed").text unless doc.at("ep_value_fixed").nil?
157
+ result[:ep_value_var] = doc.at("ep_value_var").text unless doc.at("ep_value_var").nil?
158
+ result[:ep_value_tax] = doc.at("ep_value_tax").text unless doc.at("ep_value_tax").nil?
159
+ result[:ep_value_transf] = doc.at("ep_value_transf").text unless doc.at("ep_value_transf").nil?
160
+ result[:ep_date_transf] = doc.at("ep_date_transf").text unless doc.at("ep_date_transf").nil?
161
+ result[:ep_date_read] = doc.at("ep_date_read").text unless doc.at("ep_date_read").nil?
162
+ result[:ep_status_read] = doc.at("ep_status_read").text unless doc.at("ep_status_read").nil?
163
+ result[:o_obs] = doc.at("o_obs").text unless doc.at("o_obs").nil?
164
+ result[:o_email] = doc.at("o_email").text unless doc.at("o_email").nil?
165
+ result[:o_mobile] = doc.at("o_mobile").text unless doc.at("o_mobile").nil?
166
+ result[:ep_date] = doc.at("ep_date").text unless doc.at("ep_date").nil?
167
+
139
168
  return result
140
169
  end
141
170
  end
data/lib/engine.rb CHANGED
@@ -7,8 +7,14 @@ module Easypay
7
7
  class Engine < Rails::Engine
8
8
 
9
9
  # Config defaults
10
- config.widget_factory_name = "default factory name"
11
- config.mount_at = '/'
10
+ config.easypay_notification_path = '/easypay/notifications.:format'
11
+ config.easypay_forward_path = '/easypay/forwards.:format'
12
+ config.easypay_payment_path = '/easypay/payments.:format'
13
+ config.redirect_after_payment_path = '/easypay/completed'
14
+ config.cin = 'cin provided by Easypay'
15
+ config.user = 'user provided by Easypay'
16
+ config.entity = 'entity provided by Easypay'
17
+ config.code = ''
12
18
 
13
19
  # Load rake tasks
14
20
  rake_tasks do
@@ -18,8 +24,11 @@ module Easypay
18
24
  # Check the gem config
19
25
  initializer "check config" do |app|
20
26
 
21
- # make sure mount_at ends with trailing slash
22
- config.mount_at += '/' unless config.mount_at.last == '/'
27
+ # make sure all routes end with trailing slash
28
+ config.easypay_notification_path += '/' unless config.easypay_notification_path.last == '/'
29
+ config.easypay_forward_path += '/' unless config.easypay_forward_path.last == '/'
30
+ config.easypay_payment_path += '/' unless config.easypay_payment_path.last == '/'
31
+ config.redirect_after_payment_path += '/' unless config.redirect_after_payment_path.last == '/'
23
32
  end
24
33
 
25
34
  initializer "static assets" do |app|
@@ -15,29 +15,10 @@ class EasypayGenerator < Rails::Generators::Base
15
15
  "%.3d" % (current_migration_number(dirname) + 1)
16
16
  end
17
17
  end
18
-
19
-
20
- # Every method that is declared below will be automatically executed when the generator is run
21
18
 
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
19
+ def create_migration_file
20
+ migration_template 'migration.rb', 'db/migrate/create_easypay_tables.rb'
21
+ end
41
22
 
42
23
  def copy_initializer_file
43
24
  copy_file 'initializer.rb', 'config/initializers/easypay.rb'
@@ -1,7 +1,10 @@
1
1
  module Easypay
2
2
  class Engine < Rails::Engine
3
3
 
4
- config.mount_at = '/easypay'
4
+ config.easypay_notification_path = '/easypay/notifications.:format'
5
+ config.easypay_forward_path = '/easypay/forwards.:format'
6
+ config.easypay_payment_path = '/easypay/payments.:format'
7
+ config.redirect_after_payment_path = '/easypay/completed'
5
8
  config.cin = 'cin provided by Easypay'
6
9
  config.user = 'user provided by Easypay'
7
10
  config.entity = 'entity provided by Easypay'
@@ -0,0 +1,58 @@
1
+ class CreateEasypayTables < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :easypay_payment_references, :force => true do |t|
4
+ t.integer :payable_id
5
+ t.string :ep_key
6
+ t.string :ep_doc
7
+ t.string :ep_cin
8
+ t.string :ep_user
9
+ t.string :ep_language
10
+ t.timestamp :ep_date
11
+ t.string :ep_status, :default => 'pending'
12
+ t.string :ep_entity
13
+ t.string :ep_reference
14
+ t.decimal :ep_value
15
+ t.string :ep_payment_type
16
+ t.decimal :ep_value_fixed, :precision => 16, :scale => 2
17
+ t.decimal :ep_value_var, :precision => 16, :scale => 2
18
+ t.decimal :ep_value_tax, :precision => 16, :scale => 2
19
+ t.decimal :ep_value_transf, :precision => 16, :scale => 2
20
+ t.timestamp :ep_date_transf
21
+ t.timestamp :ep_date_read
22
+ t.string :ep_status_read
23
+ t.string :ep_invoice_number
24
+ t.string :ep_transf_number
25
+ t.text :ep_message
26
+ t.text :request_log
27
+ t.string :ep_last_status
28
+ t.text :ep_link
29
+
30
+ t.string :o_key
31
+ t.string :o_name
32
+ t.string :o_description
33
+ t.text :o_obs
34
+ t.string :o_email
35
+ t.string :o_mobile
36
+
37
+ t.timestamps
38
+ end
39
+
40
+ create_table :easypay_logs, :force => true do |t|
41
+ t.string :request_type
42
+ t.string :request_remote_ip
43
+ t.text :request_url
44
+ t.text :raw
45
+
46
+ t.timestamps
47
+ end
48
+
49
+ add_index :easypay_payment_references, :payable_id
50
+ add_index :easypay_payment_references, :ep_key, :unique => true
51
+ add_index :easypay_payment_references, :ep_doc, :unique => true
52
+ end
53
+
54
+ def self.down
55
+ drop_table :easypay_payment_references
56
+ drop_table :easypay_requests
57
+ end
58
+ end
@@ -0,0 +1,8 @@
1
+ namespace :easypay do
2
+
3
+ desc "example gem rake task"
4
+ task :report => :environment do
5
+ puts "you just ran the example gem rake task"
6
+ end
7
+
8
+ 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: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Guilherme Pereira
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-07-08 00:00:00 Z
18
+ date: 2012-07-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: nokogiri
@@ -39,17 +39,23 @@ executables: []
39
39
  extensions: []
40
40
 
41
41
  extra_rdoc_files:
42
- - README.rdoc
42
+ - README.markdown
43
43
  files:
44
44
  - .gitignore
45
45
  - Gemfile
46
- - README.rdoc
46
+ - README.markdown
47
47
  - Rakefile
48
48
  - VERSION
49
- - app/controllers/easypay/clients_controller.rb
50
- - app/views/easypay/clients/index.xml.builder
49
+ - app/controllers/easypay/notifications_controller.rb
50
+ - app/controllers/easypay/payments_controller.rb
51
+ - app/models/easypay/log.rb
52
+ - app/models/easypay/payment_reference.rb
53
+ - app/views/easypay/notifications/notification_from_mb_payment.xml.builder
54
+ - app/views/easypay/notifications/simple_notification.xml.builder
55
+ - app/views/easypay/payments/complete.html.erb
51
56
  - config/routes.rb
52
57
  - easypay.gemspec
58
+ - lib/acts_as_payable/base.rb
53
59
  - lib/application_controller.rb
54
60
  - lib/application_helper.rb
55
61
  - lib/easypay.rb
@@ -57,6 +63,8 @@ files:
57
63
  - lib/engine.rb
58
64
  - lib/rails/generators/easypay/easypay_generator.rb
59
65
  - lib/rails/generators/easypay/templates/initializer.rb
66
+ - lib/rails/generators/easypay/templates/migration.rb
67
+ - lib/rails/railties/tasks.rake
60
68
  homepage: ""
61
69
  licenses: []
62
70
 
data/README.rdoc DELETED
@@ -1,40 +0,0 @@
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
-
@@ -1,18 +0,0 @@
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
@@ -1,10 +0,0 @@
1
- xml.instruct! :xml, :version => "1.0", :encoding => "ISO-8859-1"
2
- xml.get_detail do
3
- xml.ep_status "ok0"
4
- xml.ep_message " "
5
- xml.ep_entity @atts[:ep_entity]
6
- xml.ep_reference @atts[:ep_reference]
7
- xml.ep_value @atts[:ep_value]
8
- xml.ep_key 12345
9
- xml.ep_d( :PT => "" , :EN => "" , :ES => "" , :v => "" )
10
- end