easypay 0.0.1
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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README +8 -0
- data/Rakefile +1 -0
- data/easypay.gemspec +20 -0
- data/lib/easypay.rb +3 -0
- data/lib/easypay/client.rb +135 -0
- data/lib/easypay/config/routes.rb +3 -0
- data/lib/easypay/controllers/client_controller.rb +16 -0
- data/lib/easypay/version.rb +3 -0
- data/lib/easypay/views/notify.xml.builder +10 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/easypay.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "easypay/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "easypay"
|
7
|
+
s.version = Easypay::VERSION
|
8
|
+
s.authors = ["Guilherme Pereira"]
|
9
|
+
s.email = ["guiferrpereira@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{This Gem provides connection to easypay API}
|
12
|
+
s.description = %q{This Gem provides connection to easypay API, that allow you to use credit cards and MB references to Portugal}
|
13
|
+
|
14
|
+
s.rubyforge_project = "easypay"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
data/lib/easypay.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
module Easypay
|
2
|
+
class Client
|
3
|
+
|
4
|
+
EASYPAY_SERVICE_URL = Rails.env.production? ? "www.easypay.pt" : "test.easypay.pt"
|
5
|
+
|
6
|
+
def initialize *params
|
7
|
+
if params.first.is_a?(Hash)
|
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]
|
13
|
+
@easypay_ref_type = hash_options[:easypay_ref_type] || "auto"
|
14
|
+
@easypay_country = hash_options[:easypay_country] || "PT"
|
15
|
+
elsif params.first
|
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
|
21
|
+
@easypay_ref_type = params.shift || "auto"
|
22
|
+
@easypay_country = params.shift || "PT"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# API methods
|
27
|
+
|
28
|
+
def create_client_reference(token, value, lang, client_name=nil, client_mobile=nil, client_email=nil)
|
29
|
+
get "01BG",
|
30
|
+
:t_key => token,
|
31
|
+
:t_value => value,
|
32
|
+
:ep_language => lang.upcase,
|
33
|
+
:o_name => client_name.nil? ? "" : URI.escape(client_name),
|
34
|
+
:o_mobile => client_mobile.nil? ? "" : client_mobile,
|
35
|
+
:o_email => client_email.nil? ? "" : URI.escape(client_email)
|
36
|
+
# :ep_rec => "yes", # Reccurrence stuff
|
37
|
+
# :ep_rec_freq => recurrence,
|
38
|
+
# :ep_rec_url => url_notification_cc
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_payment_detail(ep_key,ep_doc)
|
42
|
+
get "03AG",
|
43
|
+
:ep_key => ep_key,
|
44
|
+
:ep_doc => ep_doc
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_payment_listings(type="last", detail=10, format="xml")
|
48
|
+
get "040BG1",
|
49
|
+
:o_list_type => type,
|
50
|
+
:o_ini => detail,
|
51
|
+
:type => format
|
52
|
+
end
|
53
|
+
|
54
|
+
def request_single_payment(reference, value, identifier)
|
55
|
+
get "05AG",
|
56
|
+
:e => @easypay_entity,
|
57
|
+
:r => reference,
|
58
|
+
:v => value,
|
59
|
+
:k => identifier
|
60
|
+
# :ep_k1 => identifier,
|
61
|
+
# :rec => "yes",
|
62
|
+
# :ep_key_rec => uid
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
protected
|
67
|
+
|
68
|
+
def create_http
|
69
|
+
if Rails.env.production?
|
70
|
+
http = Net::HTTP.new(EASYPAY_SERVICE_URL, 443)
|
71
|
+
http.use_ssl = true
|
72
|
+
else
|
73
|
+
http = Net::HTTP.new(EASYPAY_SERVICE_URL)
|
74
|
+
end
|
75
|
+
|
76
|
+
http
|
77
|
+
end
|
78
|
+
|
79
|
+
def process_args(current_args)
|
80
|
+
current_args[:ep_cin] ||= @easypay_cin
|
81
|
+
current_args[:ep_user] ||= @easypay_user
|
82
|
+
current_args[:ep_entity] ||= @easypay_entity
|
83
|
+
current_args[:ep_ref_type] ||= @easypay_ref_type
|
84
|
+
current_args[:ep_country] ||= @easypay_country
|
85
|
+
current_args[:s_code] ||= @easypay_code if current_args[:s_code].nil? and !Rails.env.production?
|
86
|
+
current_args[:ep_test] = "ok" if current_args[:ep_test].nil? and !Rails.env.production?
|
87
|
+
|
88
|
+
return current_args
|
89
|
+
end
|
90
|
+
|
91
|
+
def build_url(service_name, args)
|
92
|
+
if service_name.match("^0").nil?
|
93
|
+
url = "/_s/_#{service_name}.php?"
|
94
|
+
else
|
95
|
+
url = "/_s/api_easypay_#{service_name}.php?"
|
96
|
+
end
|
97
|
+
|
98
|
+
process_args(args).each do |key, value|
|
99
|
+
url += "#{key.to_s}=#{value.to_s}&" if value and value.present?
|
100
|
+
end
|
101
|
+
|
102
|
+
return url.chop
|
103
|
+
end
|
104
|
+
|
105
|
+
def get(service_name, args)
|
106
|
+
begin
|
107
|
+
url = build_url(service_name, args)
|
108
|
+
|
109
|
+
response = create_http.get(url, nil)
|
110
|
+
|
111
|
+
result = { :endpoint => EASYPAY_SERVICE_URL, :url => url, :raw => response.body }
|
112
|
+
|
113
|
+
return parse_content(result)
|
114
|
+
|
115
|
+
rescue Exception => ex
|
116
|
+
return { :success => false, :error => ex.message }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def parse_content(result)
|
121
|
+
doc = Nokogiri::XML(result[:raw])
|
122
|
+
|
123
|
+
if doc.at("ep_status").nil? or !doc.at("ep_status").text.starts_with? "ok"
|
124
|
+
result[:error] = doc.at("ep_message").nil? ? "Invalid xml format" : doc.at("ep_message").text
|
125
|
+
result[:success] = false
|
126
|
+
else
|
127
|
+
result[:payment_link] = doc.at("ep_link").text unless doc.at("ep_link").nil?
|
128
|
+
result[:reference] = doc.at("ep_reference").text unless doc.at("ep_reference").nil?
|
129
|
+
result[:success] = true
|
130
|
+
end
|
131
|
+
|
132
|
+
return result
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,16 @@
|
|
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
|
@@ -0,0 +1,10 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easypay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Guilherme Pereira
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-07-06 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: This Gem provides connection to easypay API, that allow you to use credit cards and MB references to Portugal
|
22
|
+
email:
|
23
|
+
- guiferrpereira@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- Gemfile
|
33
|
+
- README
|
34
|
+
- Rakefile
|
35
|
+
- easypay.gemspec
|
36
|
+
- lib/easypay.rb
|
37
|
+
- 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
|
42
|
+
homepage: ""
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: easypay
|
71
|
+
rubygems_version: 1.8.6
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: This Gem provides connection to easypay API
|
75
|
+
test_files: []
|
76
|
+
|