ecconnect_rails 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.
- checksums.yaml +15 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +5 -0
- data/Rakefile +29 -0
- data/app/controllers/ecconnect_rails/application_controller.rb +4 -0
- data/app/controllers/ecconnect_rails/base_controller.rb +170 -0
- data/app/controllers/ecconnect_rails/ecconnect_payments_controller.rb +4 -0
- data/app/helpers/ecconnect_rails/application_helper.rb +29 -0
- data/app/models/ecconnect_rails/ecconnect_payment.rb +202 -0
- data/app/views/ecconnect_rails/ecconnect_payments/failure.html.erb +0 -0
- data/app/views/ecconnect_rails/ecconnect_payments/new.html.erb +5 -0
- data/app/views/ecconnect_rails/ecconnect_payments/notify.html.erb +18 -0
- data/app/views/ecconnect_rails/ecconnect_payments/show.html.erb +1 -0
- data/app/views/ecconnect_rails/ecconnect_payments/success.html.erb +0 -0
- data/config/locales/ecconnect_rails_en.yml +59 -0
- data/config/routes.rb +9 -0
- data/lib/ecconnect_rails.rb +11 -0
- data/lib/ecconnect_rails/engine.rb +5 -0
- data/lib/ecconnect_rails/version.rb +3 -0
- data/lib/tasks/ecconnect_rails_tasks.rake +4 -0
- data/spec/certs/1753970.crt +16 -0
- data/spec/certs/1753970.pem +15 -0
- data/spec/certs/test-server.cert +16 -0
- data/spec/controllers/ecconnect_payments_controller_spec.rb +170 -0
- data/spec/dummy/Gemfile +5 -0
- data/spec/dummy/Gemfile.lock +106 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/ecconnect_payments_controller.rb +32 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/test.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +65 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +31 -0
- data/spec/dummy/config/environments/production.rb +64 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/ecconnect_rails.rb +6 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +10 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/mongoid.yml +80 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/econnect_payment.rb +11 -0
- data/spec/features/ecconnect_payments_spec.rb +72 -0
- data/spec/models/ecconnect_rails/ecconnect_payment_spec.rb +51 -0
- data/spec/routing/ecconnect_rails/ecconnect_payments_routing_spec.rb +15 -0
- data/spec/spec_helper.rb +39 -0
- metadata +256 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2Q5ZTRlYmVkNjZhZmIxMGFjN2Q1Mjk0ZTgyMmMxODAyODIzNzVhOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YTNlNzMwNzE4NWNjNDQ4MzBlNzgxNDAwYTBiNzdiZmI0M2E0MGQzMg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NTA1YjUxYTM4OTVmZTZmNjcwNTA0ZTA5MTM3ZjYwM2JlNjdjNTE2ODM0YWM2
|
10
|
+
NGU2ZDkzNWJhODViZTE1NTYzMWI1OWFhYWU3Y2Q1YWQ3MzdjZDZiZjIyYTU5
|
11
|
+
NjYyY2E2M2QyODE2ODhlYjE5Y2I2MDNiYWI0MzNhN2M1ZGE3MjQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTk1NjVlODMxZjYzZjlkNDdlZTVlN2VhMTdjZWNiMmM3MjcxYjQwZjM0YWRi
|
14
|
+
N2YyNzlhODRjNTRkZjcyOTgxNmFkZDE3OWM0M2VjY2ZjNjMwNzU2NmY0Yzhm
|
15
|
+
MGRkMTg1MTMxYjdkZjIxMGQ1N2FhYTY2ODhlMzEyY2FmZGRmMzQ=
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Roman Budnikov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'EcconnectRails'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
24
|
+
require 'rspec/core'
|
25
|
+
require 'rspec/core/rake_task'
|
26
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
27
|
+
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
28
|
+
task :default => :spec
|
29
|
+
|
@@ -0,0 +1,170 @@
|
|
1
|
+
module EcconnectRails
|
2
|
+
class BaseController < ActionController::Base
|
3
|
+
respond_to :json, :html
|
4
|
+
def new
|
5
|
+
@ecconnect_payment = EcconnectRails::EcconnectPayment.new
|
6
|
+
respond_to do |format|
|
7
|
+
format.html do
|
8
|
+
render 'new'
|
9
|
+
end
|
10
|
+
format.json{ render json: @ecconnect_payment.ecconnect_json }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
@ecconnect_payment = EcconnectRails::EcconnectPayment.new params[:ecconnect_payment]
|
16
|
+
if @ecconnect_payment.save
|
17
|
+
respond_to do |format|
|
18
|
+
format.html{ redirect_to ecconnect_payment_path(@ecconnect_payment.to_param) }
|
19
|
+
format.json{ render json: @ecconnect_payment.ecconnect_json }
|
20
|
+
end
|
21
|
+
else
|
22
|
+
respond_to do |format|
|
23
|
+
format.html{ render 'new' }
|
24
|
+
format.json{ render json: @ecconnect_payment.ecconnect_json }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def show
|
30
|
+
@ecconnect_payment = EcconnectRails::EcconnectPayment.find params[:id]
|
31
|
+
respond_to do |format|
|
32
|
+
format.html do
|
33
|
+
render 'show'
|
34
|
+
end
|
35
|
+
format.json{ render json: @ecconnect_payment.ecconnect_json }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def check
|
40
|
+
@ecconnect_payment = EcconnectRails::EcconnectPayment.find params[:id]
|
41
|
+
respond_to do |format|
|
42
|
+
format.html do
|
43
|
+
render 'check'
|
44
|
+
end
|
45
|
+
format.json{ render json: @ecconnect_payment.ecconnect_json }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def failure
|
50
|
+
@ecconnect_payment = EcconnectRails::EcconnectPayment.where(order_id: params[:OrderID]).limit(1).first
|
51
|
+
@ecconnect_payment.update_by params
|
52
|
+
if @ecconnect_payment.check_signature
|
53
|
+
failure_right_signature @ecconnect_payment
|
54
|
+
failure_respond @ecconnect_payment
|
55
|
+
else
|
56
|
+
failure_wrong_signature @ecconnect_payment
|
57
|
+
wrong_signature_respond @ecconnect_payment
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def success
|
62
|
+
@ecconnect_payment = EcconnectRails::EcconnectPayment.where(order_id: params[:OrderID]).limit(1).first
|
63
|
+
@ecconnect_payment.update_by params
|
64
|
+
if @ecconnect_payment.check_signature
|
65
|
+
if @ecconnect_payment.tran_code == '000'
|
66
|
+
success_right_signature @ecconnect_payment
|
67
|
+
success_respond @ecconnect_payment
|
68
|
+
else
|
69
|
+
failure_right_signature @ecconnect_payment
|
70
|
+
failure_respond @ecconnect_payment
|
71
|
+
end
|
72
|
+
else
|
73
|
+
success_wrong_signature @ecconnect_payment
|
74
|
+
wrong_signature_respond @ecconnect_payment
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def notify
|
79
|
+
@ecconnect_payment = EcconnectRails::EcconnectPayment.where(order_id: params[:OrderID]).limit(1).first
|
80
|
+
@ecconnect_payment.update_by params
|
81
|
+
if @ecconnect_payment.check_signature
|
82
|
+
if @ecconnect_payment.tran_code == '000'
|
83
|
+
@action = 'approve'
|
84
|
+
@forward_url = forward_url_success
|
85
|
+
notify_right_signature_and_code @ecconnect_payment
|
86
|
+
notify_respond @ecconnect_payment
|
87
|
+
else
|
88
|
+
@action = 'reverse'
|
89
|
+
@reason = I18n.t "ecconnect_rails.codes.code_503"
|
90
|
+
@forward_url = forward_url_failure
|
91
|
+
notify_right_signature @ecconnect_payment
|
92
|
+
notify_respond @ecconnect_payment
|
93
|
+
end
|
94
|
+
else
|
95
|
+
@action = 'reverse'
|
96
|
+
@reason = I18n.t "ecconnect_rails.codes.code_405"
|
97
|
+
@forward_url = forward_url_failure
|
98
|
+
notify_wrong_signature @ecconnect_payment
|
99
|
+
notify_respond @ecconnect_payment
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def forward_url_success
|
106
|
+
end
|
107
|
+
|
108
|
+
def forward_url_failure
|
109
|
+
end
|
110
|
+
|
111
|
+
def notify_respond ecconnect_payment
|
112
|
+
respond_to do |format|
|
113
|
+
format.html do
|
114
|
+
render 'notify', layout: nil
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def success_respond ecconnect_payment
|
120
|
+
respond_to do |format|
|
121
|
+
format.html do
|
122
|
+
flash[:notice] = I18n.t "ecconnect_rails.success"
|
123
|
+
render 'success'
|
124
|
+
end
|
125
|
+
format.json{ render json: @ecconnect_payment.ecconnect_json }
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def failure_respond ecconnect_payment
|
130
|
+
respond_to do |format|
|
131
|
+
format.html do
|
132
|
+
flash[:error] = I18n.t "ecconnect_rails.codes.code_#{@ecconnect_payment.tran_code}"
|
133
|
+
render 'failure'
|
134
|
+
end
|
135
|
+
format.json{ render json: @ecconnect_payment.ecconnect_json }
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def wrong_signature_respond ecconnect_payment
|
140
|
+
respond_to do |format|
|
141
|
+
format.html do
|
142
|
+
flash[:error] = I18n.t "ecconnect_rails.wrong_signature"
|
143
|
+
render 'failure'
|
144
|
+
end
|
145
|
+
format.json{ render json: @ecconnect_payment.ecconnect_json }
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def success_right_signature ecconnect_payment
|
150
|
+
end
|
151
|
+
|
152
|
+
def success_wrong_signature ecconnect_payment
|
153
|
+
end
|
154
|
+
|
155
|
+
def failure_right_signature ecconnect_payment
|
156
|
+
end
|
157
|
+
|
158
|
+
def failure_wrong_signature ecconnect_payment
|
159
|
+
end
|
160
|
+
|
161
|
+
def notify_right_signature ecconnect_payment
|
162
|
+
end
|
163
|
+
|
164
|
+
def notify_right_signature_and_code ecconnect_payment
|
165
|
+
end
|
166
|
+
|
167
|
+
def notify_wrong_signature ecconnect_payment
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module EcconnectRails
|
2
|
+
module ApplicationHelper
|
3
|
+
def ecconnect_form(ecconnect_payment, options={}, &block)
|
4
|
+
id = options.fetch(:id, 'ecconnect_form')
|
5
|
+
result = ''
|
6
|
+
content_tag(:form, id: id, action: EcconnectRails.default_options[:request_url], method: :post) do
|
7
|
+
result += hidden_field_tag(:Version, 1)
|
8
|
+
result += hidden_field_tag(:MerchantID, ecconnect_payment.merchant_id) if ecconnect_payment.merchant_id
|
9
|
+
result += hidden_field_tag(:TerminalID, ecconnect_payment.terminal_id) if ecconnect_payment.terminal_id
|
10
|
+
result += hidden_field_tag(:Currency, ecconnect_payment.currency_id) if ecconnect_payment.currency_id
|
11
|
+
result += hidden_field_tag(:AltCurrency, ecconnect_payment.alt_currency_id) if ecconnect_payment.alt_currency_id
|
12
|
+
result += hidden_field_tag(:TotalAmount, ecconnect_payment.upc_amount) if ecconnect_payment.upc_amount
|
13
|
+
result += hidden_field_tag(:AltTotalAmount, ecconnect_payment.alt_amount) if ecconnect_payment.alt_amount
|
14
|
+
result += hidden_field_tag(:locale, ecconnect_payment.locale)
|
15
|
+
result += hidden_field_tag(:PurchaseTime, ecconnect_payment.purchase_time) if ecconnect_payment.purchase_time
|
16
|
+
result += hidden_field_tag(:OrderID, ecconnect_payment.order_id)
|
17
|
+
result += hidden_field_tag(:SD, ecconnect_payment.sd) if ecconnect_payment.sd
|
18
|
+
result += hidden_field_tag(:Delay, ecconnect_payment.delay) if ecconnect_payment.delay
|
19
|
+
result += hidden_field_tag(:Signature, ecconnect_payment.signature)
|
20
|
+
if block_given?
|
21
|
+
result += yield
|
22
|
+
else
|
23
|
+
result += submit_tag(I18n.t('ecconnect_rails.ecconnect_form.submit'), name: nil)
|
24
|
+
end
|
25
|
+
result.html_safe
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,202 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
require 'base64'
|
3
|
+
require 'openssl'
|
4
|
+
require 'autoinc'
|
5
|
+
module EcconnectRails
|
6
|
+
class EcconnectPayment
|
7
|
+
include Mongoid::Document
|
8
|
+
include Mongoid::Timestamps
|
9
|
+
include Mongoid::Autoinc
|
10
|
+
|
11
|
+
CURRENCY = [980, 643, 840, 978]
|
12
|
+
|
13
|
+
field :delay, type: Boolean
|
14
|
+
field :merchant_id, type: Integer
|
15
|
+
field :terminal_id, type: String
|
16
|
+
field :tran_code, type: String
|
17
|
+
field :approval_code, type: Integer
|
18
|
+
field :locale, type: String
|
19
|
+
field :proxy_pan, type: String
|
20
|
+
field :currency_id, type: Integer
|
21
|
+
field :alt_currency_id, type: Integer
|
22
|
+
field :amount, type: Float
|
23
|
+
field :alt_amount, type: Integer
|
24
|
+
field :order_id, type: Integer
|
25
|
+
field :income_signature, type: String
|
26
|
+
field :purchase_desc, type: String
|
27
|
+
field :email, type: String
|
28
|
+
field :sd, type: String
|
29
|
+
field :xid, type: String
|
30
|
+
field :rrn, type: String
|
31
|
+
|
32
|
+
increments :order_id, seed: 1
|
33
|
+
|
34
|
+
belongs_to :payer
|
35
|
+
|
36
|
+
validates :merchant_id, :terminal_id, :currency_id, :amount, presence: true
|
37
|
+
before_validation :set_terminal_id, :set_merchant_id, :set_locale, :set_currency_id
|
38
|
+
before_create :set_tran_code
|
39
|
+
|
40
|
+
def purchase_time
|
41
|
+
self.created_at.strftime("%Y%m%d%H%M%S%z") if self.created_at
|
42
|
+
end
|
43
|
+
|
44
|
+
def currency
|
45
|
+
I18n.t "ecconnect_rails.currency_#{self.currency_id}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def request_data
|
49
|
+
@request_data ||= make_request_data
|
50
|
+
end
|
51
|
+
|
52
|
+
def check_data
|
53
|
+
@check_data ||= make_check_data
|
54
|
+
end
|
55
|
+
|
56
|
+
def signature
|
57
|
+
@signature ||= sign(request_data)
|
58
|
+
end
|
59
|
+
|
60
|
+
def upc_amount
|
61
|
+
(self.amount*100).to_i
|
62
|
+
end
|
63
|
+
|
64
|
+
def code
|
65
|
+
I18n.t "ecconnect_rails.codes.code_#{self.tran_code}" if self.tran_code
|
66
|
+
end
|
67
|
+
|
68
|
+
def ecconnect_json
|
69
|
+
self.as_json(except: [:income_signature, :proxy_pan, :rrn, :sd, :xid, :approval_code], methods: [:purchase_time, :signature, :code])
|
70
|
+
end
|
71
|
+
|
72
|
+
#def check_payment
|
73
|
+
# uri = URI.parse EcconnectRails.default_options[:check_url]
|
74
|
+
# http = Net::HTTP.new uri.host, uri.port
|
75
|
+
# http.use_ssl = true
|
76
|
+
# request = Net::HTTP::Post.new uri.path
|
77
|
+
# request.set_form_data check_payment_data
|
78
|
+
# response = http.request request
|
79
|
+
#end
|
80
|
+
|
81
|
+
def check_signature
|
82
|
+
cert.public_key.verify OpenSSL::Digest::SHA1.new, Base64.decode64(self.income_signature), check_data
|
83
|
+
end
|
84
|
+
|
85
|
+
def update_by params
|
86
|
+
self.update_attributes :proxy_pan => params[:ProxyPan],
|
87
|
+
#:currency => params[:Currency],
|
88
|
+
:approval_code => params[:ApprovalCode],
|
89
|
+
#:merchant_id => params[:MerchantID],
|
90
|
+
#:order_id => params[:OrderID],
|
91
|
+
:income_signature => params[:Signature],
|
92
|
+
:rrn => params[:Rrn],
|
93
|
+
:xid => params[:XID],
|
94
|
+
:email => params[:Email],
|
95
|
+
:sd => params[:SD],
|
96
|
+
:tran_code => params[:TranCode]
|
97
|
+
#:terminal_id => params[:TerminalID],
|
98
|
+
#:total_amount => params[:TotalAmount],
|
99
|
+
#:alt_total_amount => params[:AltTotalAmount],
|
100
|
+
#:alt_currency => params[:AltCurrency]
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
private
|
105
|
+
def set_locale
|
106
|
+
self.locale = I18n.locale.to_s
|
107
|
+
end
|
108
|
+
|
109
|
+
def set_currency_id
|
110
|
+
self.currency_id = EcconnectRails.default_options[:currency_id]
|
111
|
+
end
|
112
|
+
|
113
|
+
def set_terminal_id
|
114
|
+
self.terminal_id = EcconnectRails.default_options[:terminal_id]
|
115
|
+
end
|
116
|
+
|
117
|
+
def set_merchant_id
|
118
|
+
self.merchant_id = EcconnectRails.default_options[:merchant_id]
|
119
|
+
end
|
120
|
+
|
121
|
+
def set_tran_code
|
122
|
+
self.tran_code = nil
|
123
|
+
end
|
124
|
+
|
125
|
+
#def check_payment_data
|
126
|
+
# data = {}
|
127
|
+
# data['MerchantID'] = self.merchant_id if self.merchant_id
|
128
|
+
# data['TerminalID'] = self.terminal_id if self.terminal_id
|
129
|
+
# data['TotalAmount'] = self.upc_amount if self.upc_amount
|
130
|
+
# data['AltTotalAmount'] = self.alt_amount if self.alt_amount
|
131
|
+
# data['Currency'] = self.currency_id if self.currenc_id
|
132
|
+
# data['AltCurrency'] = self.alt_currency_id if self.alt_currency_id
|
133
|
+
# data['OrderID'] = self.order_id if self.order_id
|
134
|
+
# data
|
135
|
+
#end
|
136
|
+
|
137
|
+
def sign data
|
138
|
+
Base64.encode64(pem.sign(OpenSSL::Digest::SHA1.new, data)).gsub(/\n/, '')
|
139
|
+
end
|
140
|
+
|
141
|
+
def pem
|
142
|
+
OpenSSL::PKey::RSA.new File.read EcconnectRails.default_options[:pem_path]
|
143
|
+
end
|
144
|
+
|
145
|
+
def cert
|
146
|
+
OpenSSL::X509::Certificate.new File.read EcconnectRails.default_options[:cert_path]
|
147
|
+
end
|
148
|
+
|
149
|
+
#MerchantId;TerminalId;PurchaseTime;OrderId,Delay;Xid;CurrencyId,AltCurrencyId;Amount,AltAmount;SessionData;TranCode;ApprovalCode;
|
150
|
+
def make_check_data
|
151
|
+
data = ""
|
152
|
+
data << (self.merchant_id.nil? ? "" : "#{self.merchant_id}")
|
153
|
+
data << (self.terminal_id.nil? ? ";" : ";#{self.terminal_id}")
|
154
|
+
data << ";#{self.purchase_time}"
|
155
|
+
data << ";#{self.order_id}"
|
156
|
+
data << (self.delay.nil? ? "" : ", #{self.delay}")
|
157
|
+
data << (self.xid.nil? ? ";" : ";#{self.xid}")
|
158
|
+
if self.currency_id.nil?
|
159
|
+
data << ";"
|
160
|
+
else
|
161
|
+
data << ";#{self.currency_id}"
|
162
|
+
data << (self.alt_currency_id.nil? ? "" : ", #{self.alt_currency_id}")
|
163
|
+
end
|
164
|
+
if self.amount.nil?
|
165
|
+
data << ";"
|
166
|
+
else
|
167
|
+
data << ";#{self.upc_amount}"
|
168
|
+
data << (self.alt_amount.nil? ? "" : ", #{self.alt_amount}")
|
169
|
+
end
|
170
|
+
data << (self.sd.nil? ? ";" : ";#{self.sd}")
|
171
|
+
data << (self.tran_code.nil? ? ";" : ";#{self.tran_code}")
|
172
|
+
data << (self.approval_code.nil? ? ";" : ";#{self.approval_code}")
|
173
|
+
data << ";"
|
174
|
+
data
|
175
|
+
end
|
176
|
+
|
177
|
+
#MerchantId;TerminalId;PurchaseTime;OrderId,Delay;CurrencyId,AltCurrencyId;Amount,AltAmount;SessionData(SD);
|
178
|
+
def make_request_data
|
179
|
+
data = ""
|
180
|
+
data << (self.merchant_id.nil? ? "" : "#{self.merchant_id}")
|
181
|
+
data << (self.terminal_id.nil? ? ";" : ";#{self.terminal_id}")
|
182
|
+
data << ";#{self.purchase_time}"
|
183
|
+
data << ";#{self.order_id}"
|
184
|
+
data << (self.delay.nil? ? "" : ", #{self.delay}")
|
185
|
+
if self.currency_id.nil?
|
186
|
+
data << ";"
|
187
|
+
else
|
188
|
+
data << ";#{self.currency_id}"
|
189
|
+
data << (self.alt_currency_id.nil? ? "" : ", #{self.alt_currency_id}")
|
190
|
+
end
|
191
|
+
if self.amount.nil?
|
192
|
+
data << ";"
|
193
|
+
else
|
194
|
+
data << ";#{self.upc_amount}"
|
195
|
+
data << (self.alt_amount.nil? ? "" : ", #{self.alt_amount}")
|
196
|
+
end
|
197
|
+
data << (self.sd.nil? ? ";" : "#{;self.sd}")
|
198
|
+
data << ";"
|
199
|
+
data
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|