lolita-bank-link 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +20 -0
- data/Rakefile +12 -0
- data/app/controllers/lolita_bank_link/application_controller.rb +7 -0
- data/app/controllers/lolita_bank_link/transactions_controller.rb +89 -0
- data/app/helpers/lolita_bank_link/application_helper.rb +11 -0
- data/app/models/lolita_bank_link/transaction.rb +39 -0
- data/app/views/lolita_bank_link/payment_form.html.erb +15 -0
- data/app/views/lolita_bank_link/test/fake_server.html.erb +16 -0
- data/config/locales/en-US.yml +3 -0
- data/config/locales/en.yml +3 -0
- data/config/locales/lv.yml +3 -0
- data/config/routes.rb +6 -0
- data/lib/generators/lolita_bank_link/USAGE +4 -0
- data/lib/generators/lolita_bank_link/lolita_bank_link_generator.rb +12 -0
- data/lib/generators/lolita_bank_link/templates/bank_link_transactions.erb +32 -0
- data/lib/lolita-bank-link.rb +29 -0
- data/lib/lolita-bank-link/bank_link.rb +36 -0
- data/lib/lolita-bank-link/billing.rb +41 -0
- data/lib/lolita-bank-link/crypt.rb +51 -0
- data/lib/lolita-bank-link/custom_logger.rb +8 -0
- data/lib/lolita-bank-link/engine.rb +5 -0
- data/lib/lolita-bank-link/request.rb +44 -0
- data/lib/lolita-bank-link/response.rb +75 -0
- data/lib/lolita-bank-link/version.rb +3 -0
- metadata +181 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 48939bf625644b80d0aecc5ad96eb7dda954430f
|
4
|
+
data.tar.gz: 412a56c74ecb15586d20e8df5319bdfd59df0f7c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea58e6a71c8e619a40481c9c7cfa92e539c14102847192bc8354ade2f251cc7574a294243ac2fd6dddc5ebede70cda2abc5125a5a23681818591a78d8e771788
|
7
|
+
data.tar.gz: e51112cefd619632ff78ad09c68620b3567b9800b04ccdaf73ee57df8dc23e48d004a6b047a1f86553fb2321c269ca122494f1988da471aa4670eed716ecea71
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
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.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# LolitaBankLink
|
2
|
+
|
3
|
+
SWEDBANK plugin for Lolita
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Add to your Gemfile `gem "lolita-bank-link"`
|
8
|
+
To use with Rails `< 4.0` add also `gem "strong_parameters"`
|
9
|
+
|
10
|
+
Then run generator `rails g lolita_bank_link`
|
11
|
+
|
12
|
+
To setup your paymentable object see `spec/dummy/app/models/reservation.rb`
|
13
|
+
|
14
|
+
## ENV variables
|
15
|
+
|
16
|
+
BANK_LINK_PRIVATE_KEY: ~/production/shared/config/keyfile.key
|
17
|
+
BANK_LINK_BANK_CERTIFICATE: ~/production/shared/config/bank_link_cert.pem
|
18
|
+
BANK_LINK_SENDER: TEST
|
19
|
+
BANK_LINK_URL: https://ib.swedbank.lv/banklink
|
20
|
+
BANK_LINK_LANG: LAT
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
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
|
+
|
8
|
+
require "rspec/core/rake_task"
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
10
|
+
|
11
|
+
task :default => :spec
|
12
|
+
Bundler::GemHelper.install_tasks
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module LolitaBankLink
|
2
|
+
class TransactionsController < LolitaBankLink::ApplicationController
|
3
|
+
before_filter :is_ssl_required
|
4
|
+
before_filter :set_active_payment, :check_valid_payment, only: :checkout
|
5
|
+
|
6
|
+
def checkout
|
7
|
+
transaction = LolitaBankLink::Transaction.add(@payment, request)
|
8
|
+
@payment_request = LolitaBankLink::Request.new(@payment, transaction)
|
9
|
+
render "lolita_bank_link/payment_form"
|
10
|
+
ensure
|
11
|
+
if @payment && @payment_request
|
12
|
+
LolitaBankLink.logger.info("[#{session_id}][#{@payment.id}][checkout] #{@payment_request.build_form_data}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# This action is called twice
|
17
|
+
# - after client returns from BankLink server
|
18
|
+
# - bank sends another confirmation and add's VK_AUTO=Y to params
|
19
|
+
def answer
|
20
|
+
response = LolitaBankLink::Response.new(response_params)
|
21
|
+
if response.update_transaction
|
22
|
+
if bank_auto_response?
|
23
|
+
render nothing: true
|
24
|
+
else
|
25
|
+
redirect_to response.return_path
|
26
|
+
end
|
27
|
+
else
|
28
|
+
LolitaBankLink.logger.error("[#{session_id}][#{response.paymentable_id}][answer] #{response.error}")
|
29
|
+
render text: I18n.t("bank_link.wrong_request"), status: 400
|
30
|
+
end
|
31
|
+
ensure
|
32
|
+
if response
|
33
|
+
LolitaBankLink.logger.info("[#{session_id}][#{response.paymentable_id}][answer] #{response.params}")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def bank_auto_response?
|
40
|
+
params["VK_AUTO"] == "Y"
|
41
|
+
end
|
42
|
+
|
43
|
+
# returns current payment instance from session
|
44
|
+
def set_active_payment
|
45
|
+
if session && session[:payment_data]
|
46
|
+
@payment ||= session[:payment_data][:billing_class].constantize.find(session[:payment_data][:billing_id])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# payment should not be paid
|
51
|
+
def check_valid_payment
|
52
|
+
if @payment && @payment.paid?
|
53
|
+
render text: I18n.t("bank_link.wrong_request"), status: 400
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# forces SSL in production mode if available
|
58
|
+
def is_ssl_required
|
59
|
+
ssl_required(:answer, :checkout) if defined?(ssl_required)
|
60
|
+
end
|
61
|
+
|
62
|
+
def response_params
|
63
|
+
params.permit("VK_T_NO",
|
64
|
+
"VK_SND_NAME",
|
65
|
+
"VK_REF",
|
66
|
+
"VK_REC_ID",
|
67
|
+
"VK_SND_ACC",
|
68
|
+
"VK_STAMP",
|
69
|
+
"VK_T_DATE",
|
70
|
+
"VK_AMOUNT",
|
71
|
+
"VK_REC_NAME",
|
72
|
+
"VK_SERVICE",
|
73
|
+
"VK_LANG",
|
74
|
+
"VK_AUTO",
|
75
|
+
"VK_MSG",
|
76
|
+
"VK_ENCODING",
|
77
|
+
"VK_VERSION",
|
78
|
+
"VK_SND_ID",
|
79
|
+
"VK_CURR",
|
80
|
+
"VK_REC_ACC",
|
81
|
+
"VK_MAC")
|
82
|
+
end
|
83
|
+
|
84
|
+
def session_id
|
85
|
+
request.session_options[:id]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module LolitaBankLink
|
2
|
+
module ApplicationHelper
|
3
|
+
include Rails.application.routes.url_helpers
|
4
|
+
|
5
|
+
def render_bank_link_form_data payment_request
|
6
|
+
payment_request.build_form_data(return: answer_bank_link_url(protocol: 'https')).collect do |key, value|
|
7
|
+
hidden_field_tag("VK_#{key.to_s.upcase}", value, id: nil )
|
8
|
+
end.join
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "ipaddr"
|
2
|
+
# Available statuses
|
3
|
+
# processing, completed, failed
|
4
|
+
module LolitaBankLink
|
5
|
+
class Transaction < ActiveRecord::Base
|
6
|
+
self.table_name = "bank_link_transactions"
|
7
|
+
belongs_to :paymentable, polymorphic: true
|
8
|
+
after_save :touch_paymentable
|
9
|
+
default_scope -> { order(:id) }
|
10
|
+
validates_associated :paymentable
|
11
|
+
|
12
|
+
def ip
|
13
|
+
IPAddr.new(self[:ip], Socket::AF_INET).to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def ip=(x)
|
17
|
+
self[:ip] = IPAddr.new(x).to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
# add new transaction in Checkout
|
22
|
+
def add payment, request
|
23
|
+
LolitaBankLink::Transaction.create!(
|
24
|
+
status: "processing",
|
25
|
+
paymentable_id: payment.id,
|
26
|
+
paymentable_type: payment.class.to_s,
|
27
|
+
ip: request.remote_ip
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# trigger "bank_link_trx_saved" on our paymentable model
|
35
|
+
def touch_paymentable
|
36
|
+
paymentable.bank_link_trx_saved(self) if paymentable
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<title>BankLink payment</title>
|
5
|
+
</head>
|
6
|
+
<body>
|
7
|
+
<form method="POST" name="bank_link_form" action="<%= LolitaBankLink.url %>">
|
8
|
+
<%= raw render_bank_link_form_data(@payment_request) %>
|
9
|
+
<button type="submit" id="submit_button" name="submit" style="display:none;"></button>
|
10
|
+
</form>
|
11
|
+
<script type="text/javascript">
|
12
|
+
document.getElementById("submit_button").click();
|
13
|
+
</script>
|
14
|
+
</body>
|
15
|
+
</html>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
|
5
|
+
<style type="text/css">
|
6
|
+
body { font-family: Verdana, sans-serif; text-align: center;}
|
7
|
+
h1 { text-transform: uppercase; font-size: 22px; color: #cd0a0a; text-shadow: #ccc 3px 3px 3px;}
|
8
|
+
</style>
|
9
|
+
</head>
|
10
|
+
<h1>This is fake Bank Link aka Swedbank server</h1>
|
11
|
+
|
12
|
+
<form action="" method="post">
|
13
|
+
<button type="button" onclick="window.location.href='/bank_link_test/fake_success';">Respond as success</button> |
|
14
|
+
<button type="button" onclick="window.location.href='/bank_link_test/fake_failure';">Respond as failure</button>
|
15
|
+
</form>
|
16
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
get "/bank_link/checkout" => "lolita_bank_link/transactions#checkout", as: "checkout_bank_link"
|
3
|
+
get "/bank_link/answer" => "lolita_bank_link/transactions#answer", as: "answer_bank_link"
|
4
|
+
post "/bank_link/answer" => "lolita_bank_link/transactions#answer"
|
5
|
+
get "/bank_link/test/:action" => "lolita_bank_link/test"
|
6
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class LolitaBankLinkGenerator < Rails::Generator::Base
|
2
|
+
def initialize(runtime_args, runtime_options = {})
|
3
|
+
super
|
4
|
+
usage if @args.first == "help"
|
5
|
+
end
|
6
|
+
|
7
|
+
def manifest
|
8
|
+
record do |m|
|
9
|
+
m.migration_template "bank_link_transactions.erb", "db/migrate", :migration_file_name => "create_bank_link_transactions"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class CreateBankLinkTransactions < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :bank_link_transactions do |t|
|
4
|
+
t.string :status, default: "processing"
|
5
|
+
t.references :paymentable, polymorphic: true
|
6
|
+
t.string :ip, length: 10
|
7
|
+
t.string :service
|
8
|
+
t.string :version
|
9
|
+
t.string :snd_id
|
10
|
+
t.string :rec_id
|
11
|
+
t.string :stamp
|
12
|
+
t.string :t_no
|
13
|
+
t.string :amount
|
14
|
+
t.string :curr
|
15
|
+
t.string :rec_acc
|
16
|
+
t.string :rec_name
|
17
|
+
t.string :snd_acc
|
18
|
+
t.string :snd_name
|
19
|
+
t.string :ref
|
20
|
+
t.string :msg
|
21
|
+
t.string :t_date
|
22
|
+
|
23
|
+
t.timestamps
|
24
|
+
end
|
25
|
+
|
26
|
+
add_index :bank_link_transactions, [:paymentable_type, :paymentable_id]
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.down
|
30
|
+
drop_table :bank_link_transactions
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "digest/md5"
|
2
|
+
require "openssl"
|
3
|
+
require "lolita-bank-link/custom_logger"
|
4
|
+
require "lolita-bank-link/engine"
|
5
|
+
require "lolita-bank-link/version"
|
6
|
+
require "lolita-bank-link/bank_link"
|
7
|
+
require "lolita-bank-link/request"
|
8
|
+
require "lolita-bank-link/response"
|
9
|
+
require "lolita-bank-link/crypt"
|
10
|
+
require "lolita-bank-link/billing"
|
11
|
+
|
12
|
+
module LolitaBankLink
|
13
|
+
mattr_accessor :custom_logger
|
14
|
+
|
15
|
+
def self.logger
|
16
|
+
unless @logger
|
17
|
+
@logger = custom_logger ? custom_logger : default_logger
|
18
|
+
end
|
19
|
+
@logger
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def self.default_logger
|
25
|
+
logger = Logger.new(Rails.root.join('log', 'lolita_bank_link.log'))
|
26
|
+
logger.formatter = LolitaBankLink::LogFormatter.new
|
27
|
+
logger
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module LolitaBankLink
|
2
|
+
class << self
|
3
|
+
def private_key
|
4
|
+
ENV["BANK_LINK_PRIVATE_KEY"]
|
5
|
+
end
|
6
|
+
|
7
|
+
def bank_certificate
|
8
|
+
ENV["BANK_LINK_CERTIFICATE"]
|
9
|
+
end
|
10
|
+
|
11
|
+
def sender
|
12
|
+
ENV["BANK_LINK_SENDER"]
|
13
|
+
end
|
14
|
+
|
15
|
+
def url
|
16
|
+
ENV["BANK_LINK_URL"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def lang
|
20
|
+
ENV["BANK_LINK_LANG"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def required_params_by_service(service)
|
24
|
+
required_fields = nil
|
25
|
+
if service=='1002'
|
26
|
+
required_fields = [:service,:version,:snd_id,:stamp,:amount,:curr,:ref,:msg]
|
27
|
+
elsif service=='1101'
|
28
|
+
required_fields = [:service,:version,:snd_id,:rec_id,:stamp,:t_no,:amount,:curr,:rec_acc,:rec_name,:snd_acc,:snd_name,:ref,:msg,:t_date]
|
29
|
+
elsif service=='1901'
|
30
|
+
required_fields = [:service,:version,:snd_id,:rec_id,:stamp,:ref,:msg]
|
31
|
+
end
|
32
|
+
required_fields
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module LolitaBankLink
|
2
|
+
module Billing
|
3
|
+
def self.included(base)
|
4
|
+
base.has_many :bank_link_transactions, as: :paymentable, class_name: "LolitaBankLink::Transaction", dependent: :destroy
|
5
|
+
base.class_eval do
|
6
|
+
|
7
|
+
# Payment description
|
8
|
+
def description
|
9
|
+
raise NotImplementedError, 'Redefine this method in your billing model.'
|
10
|
+
end
|
11
|
+
|
12
|
+
# Price of payment in cents
|
13
|
+
def price
|
14
|
+
raise NotImplementedError, 'Redefine this method in your billing model.'
|
15
|
+
end
|
16
|
+
|
17
|
+
# Currency as 3 letter code as in ISO 4217
|
18
|
+
def currency
|
19
|
+
raise NotImplementedError, 'Redefine this method in your billing model.'
|
20
|
+
end
|
21
|
+
|
22
|
+
def bank_link_trx_saved trx
|
23
|
+
raise NotImplementedError, "Redefine this method in your billing model."
|
24
|
+
end
|
25
|
+
|
26
|
+
def bank_link_return_path
|
27
|
+
raise NotImplementedError, 'This should be inplemented on your paymentable class'
|
28
|
+
end
|
29
|
+
|
30
|
+
# Add this to your paid? method along with other payment methods
|
31
|
+
# Example:
|
32
|
+
# def paid?
|
33
|
+
# bank_link_paid? || first_data_paid?
|
34
|
+
# end
|
35
|
+
def bank_link_paid?
|
36
|
+
self.bank_link_transactions.where(status: "completed").count >= 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module LolitaBankLink
|
2
|
+
class Crypt
|
3
|
+
attr_reader :public_key, :private_key, :digest
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@private_key = read_private_key(LolitaBankLink.private_key)
|
7
|
+
@public_key = extract_public_key(LolitaBankLink.bank_certificate)
|
8
|
+
@digest = OpenSSL::Digest::SHA1.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def sign message
|
12
|
+
Base64::encode64(private_key.sign(digest, message)).rstrip
|
13
|
+
end
|
14
|
+
|
15
|
+
def verify_mac_signature(params, signature)
|
16
|
+
mac = prepair_mac_string(params,params[:service])
|
17
|
+
verify(mac, signature)
|
18
|
+
end
|
19
|
+
|
20
|
+
def calc_mac_signature(params, service = '1002')
|
21
|
+
mac = prepair_mac_string(params,service)
|
22
|
+
enc_mac = self.sign(mac)
|
23
|
+
enc_mac
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def verify message, signature_base64
|
29
|
+
decoded_signature = Base64::decode64(signature_base64)
|
30
|
+
public_key.verify(digest, decoded_signature, message)
|
31
|
+
end
|
32
|
+
|
33
|
+
def prepair_mac_string(post, service)
|
34
|
+
required_fields = LolitaBankLink.required_params_by_service(service)
|
35
|
+
mac = ""
|
36
|
+
required_fields.each{|field|
|
37
|
+
post[field] = post[field].to_s.strip
|
38
|
+
mac += post[field].to_s.chars.count.to_s.rjust(3,'0') + post[field].to_s
|
39
|
+
}
|
40
|
+
mac
|
41
|
+
end
|
42
|
+
|
43
|
+
def read_private_key key_path
|
44
|
+
OpenSSL::PKey::RSA.new File.read(key_path)
|
45
|
+
end
|
46
|
+
|
47
|
+
def extract_public_key cert_path
|
48
|
+
OpenSSL::X509::Certificate.new(File.read(cert_path).gsub(/ /, '')).public_key
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module LolitaBankLink
|
2
|
+
class Request
|
3
|
+
attr_reader :crypt, :payment, :transaction
|
4
|
+
|
5
|
+
def initialize payment, transaction
|
6
|
+
@transaction = transaction
|
7
|
+
@payment = payment
|
8
|
+
@crypt = LolitaBankLink::Crypt.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def build_form_data(data = {})
|
12
|
+
data[:stamp] = self.payment.id
|
13
|
+
data[:ref] = self.transaction.id
|
14
|
+
data[:snd_id] = LolitaBankLink.sender
|
15
|
+
data[:amount] = amount(self.payment.price)
|
16
|
+
data[:curr] = self.payment.currency
|
17
|
+
data[:msg] = self.payment.description
|
18
|
+
prepare_for_banklink(data)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def prepare_for_banklink(data = {})
|
24
|
+
data[:service] = "1002"
|
25
|
+
data[:version] = "008"
|
26
|
+
data[:mac] = self.crypt.calc_mac_signature(data)
|
27
|
+
data[:lang] = data[:lang] || LolitaBankLink.lang
|
28
|
+
data[:encoding] = data[:encoding] || "UTF-8"
|
29
|
+
data
|
30
|
+
end
|
31
|
+
|
32
|
+
def amount(money)
|
33
|
+
return nil if money.nil?
|
34
|
+
cents = money.respond_to?(:cents) ? money.cents : money
|
35
|
+
|
36
|
+
if money.is_a?(String) || cents.to_i < 0
|
37
|
+
raise ArgumentError, "money amount must be either a Money object or a positive integer in cents."
|
38
|
+
end
|
39
|
+
|
40
|
+
sprintf("%.2f", cents.to_f / 100)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module LolitaBankLink
|
2
|
+
class Response
|
3
|
+
attr_reader :params, :required_params, :crypt, :signature
|
4
|
+
attr_accessor :error
|
5
|
+
|
6
|
+
def initialize params
|
7
|
+
@params = read_required_params(params)
|
8
|
+
@signature = read_signature(params)
|
9
|
+
@crypt = LolitaBankLink::Crypt.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def update_transaction
|
13
|
+
if valid?
|
14
|
+
new_status = completed? ? "completed" : "failed"
|
15
|
+
transaction.update_attributes!(params.merge(status: new_status))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def completed?
|
20
|
+
self.params[:service].to_i == 1101
|
21
|
+
end
|
22
|
+
|
23
|
+
def valid?
|
24
|
+
if self.params[:rec_id] != LolitaBankLink.sender
|
25
|
+
self.error = "Wrong sender" and return false
|
26
|
+
elsif !self.crypt.verify_mac_signature(self.params,self.signature)
|
27
|
+
self.error = "Wrong signature" and return false
|
28
|
+
elsif transaction.status.to_sym != :processing
|
29
|
+
self.error = "Transaction has wrong status: #{transaction.status}"
|
30
|
+
end
|
31
|
+
self.error.blank?
|
32
|
+
end
|
33
|
+
|
34
|
+
def transaction
|
35
|
+
@trx ||= LolitaBankLink::Transaction.where(id: params[:ref]).first
|
36
|
+
end
|
37
|
+
|
38
|
+
def return_path
|
39
|
+
transaction.paymentable.bank_link_return_path
|
40
|
+
end
|
41
|
+
|
42
|
+
def paymentable_id
|
43
|
+
transaction && transaction.paymentable_id
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def read_signature(params)
|
49
|
+
params["VK_MAC"].blank? ? "" : params["VK_MAC"]
|
50
|
+
end
|
51
|
+
|
52
|
+
def read_required_params(param_hash)
|
53
|
+
req_params = {}
|
54
|
+
if param_hash["VK_SERVICE"].nil?
|
55
|
+
self.error = "BankLinkGateway reading post service not set"
|
56
|
+
else
|
57
|
+
req_list = LolitaBankLink.required_params_by_service(param_hash["VK_SERVICE"])
|
58
|
+
if req_list.nil?
|
59
|
+
self.error = "BankLinkGateway unknown service posted #{param_hash["VK_SERVICE"]}"
|
60
|
+
else
|
61
|
+
req_list.each{|item|
|
62
|
+
value = param_hash["VK_"+item.to_s.upcase]
|
63
|
+
if value.nil?
|
64
|
+
self.error = "BankLinkGateway a required param #{"VK_"+item.to_s.upcase} from post for signature check is not available for service: #{param_hash["VK_SERVICE"]}"
|
65
|
+
else
|
66
|
+
req_params[item] = value.to_s
|
67
|
+
end
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
req_params
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lolita-bank-link
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gatis Tomsons
|
8
|
+
- ITHouse
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-04-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 3.2.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 3.2.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: sqlite3
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.3'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.3'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec-rails
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.14.0
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.14.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: webmock
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: fabrication
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '2.1'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '2.1'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: database_cleaner
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.2.0
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 1.2.0
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: simplecov
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 0.8.2
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 0.8.2
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: pry-byebug
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 1.3.1
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 1.3.1
|
126
|
+
description: BankLink payment plugin using ActiveMerchant for use with Lolita CMS
|
127
|
+
email:
|
128
|
+
- info@ithouse.lv
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- MIT-LICENSE
|
134
|
+
- README.md
|
135
|
+
- Rakefile
|
136
|
+
- app/controllers/lolita_bank_link/application_controller.rb
|
137
|
+
- app/controllers/lolita_bank_link/transactions_controller.rb
|
138
|
+
- app/helpers/lolita_bank_link/application_helper.rb
|
139
|
+
- app/models/lolita_bank_link/transaction.rb
|
140
|
+
- app/views/lolita_bank_link/payment_form.html.erb
|
141
|
+
- app/views/lolita_bank_link/test/fake_server.html.erb
|
142
|
+
- config/locales/en-US.yml
|
143
|
+
- config/locales/en.yml
|
144
|
+
- config/locales/lv.yml
|
145
|
+
- config/routes.rb
|
146
|
+
- lib/generators/lolita_bank_link/USAGE
|
147
|
+
- lib/generators/lolita_bank_link/lolita_bank_link_generator.rb
|
148
|
+
- lib/generators/lolita_bank_link/templates/bank_link_transactions.erb
|
149
|
+
- lib/lolita-bank-link.rb
|
150
|
+
- lib/lolita-bank-link/bank_link.rb
|
151
|
+
- lib/lolita-bank-link/billing.rb
|
152
|
+
- lib/lolita-bank-link/crypt.rb
|
153
|
+
- lib/lolita-bank-link/custom_logger.rb
|
154
|
+
- lib/lolita-bank-link/engine.rb
|
155
|
+
- lib/lolita-bank-link/request.rb
|
156
|
+
- lib/lolita-bank-link/response.rb
|
157
|
+
- lib/lolita-bank-link/version.rb
|
158
|
+
homepage: http://github.com/ithouse/lolita-bank-link
|
159
|
+
licenses: []
|
160
|
+
metadata: {}
|
161
|
+
post_install_message:
|
162
|
+
rdoc_options: []
|
163
|
+
require_paths:
|
164
|
+
- lib
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
requirements: []
|
176
|
+
rubyforge_project:
|
177
|
+
rubygems_version: 2.2.0
|
178
|
+
signing_key:
|
179
|
+
specification_version: 4
|
180
|
+
summary: BankLink payment plugin for Lolita
|
181
|
+
test_files: []
|