Skip to content

Commit

Permalink
Upgraded providers to support new Ipizza implementation.
Browse files Browse the repository at this point in the history
* Added support for iPizza services (`1011`, `1012`, `4011` and `4012`). Read more form [Estonian Banking Association webpage](http://pangaliit.ee/et/arveldused/pangalingi-spetsifikatsioon)
* Changed MAC calculation in case of UTF-8 encoding to support new iPizza protocol.
* Added supported encodings to Provider model
* Added 'transaction_time' attribute to `Ipizza::Payment` object (parsed value of the `VK_T_DATETIME` field).
* Removed support for iPizza services (`1001`, `1002`, `4001` and `4002`).
* Added new provider: LHV Bank.
* Authentication request response method `authentication_info` returns now `Ipizza::Authentication` object instead of string.
* Bump version to 2.0.0

Closes Voog#6
  • Loading branch information
tanelj committed Feb 3, 2015
1 parent 1cd9bf4 commit 6d7567c
Show file tree
Hide file tree
Showing 70 changed files with 1,081 additions and 638 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
pkg
pkg
.ruby-gemset
.ruby-version
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## v2.0.0

* Added support for iPizza services (`1011`, `1012`, `4011` and `4012`). Read more form [Estonian Banking Association webpage](http://pangaliit.ee/et/arveldused/pangalingi-spetsifikatsioon)
* Changed MAC calculation in case of UTF-8 encoding to support new iPizza protocol.
* Added supported encodings to Provider model (`UTF-8` (default), `ISO-8859-1` and `WINDOWS-1257`).
* Added 'transaction_time' attribute to `Ipizza::Payment` object (parsed value of the `VK_T_DATETIME` field).
* Removed support for iPizza services (`1001`, `1002`, `4001` and `4002`).
* Added new provider: LHV Bank.
* Authentication request response method `authentication_info` returns now `Ipizza::Authentication` object instead of string.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
source "http://rubygems.org"
source 'http://rubygems.org'
gemspec
30 changes: 16 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
PATH
remote: .
specs:
ipizza (1.0.0)
ipizza (2.0.0)

GEM
remote: http://rubygems.org/
specs:
coderay (1.0.8)
coderay (1.1.0)
diff-lcs (1.1.3)
guard (1.6.1)
formatador (0.2.5)
guard (1.7.0)
formatador (>= 0.2.4)
listen (>= 0.6.0)
lumberjack (>= 1.0.2)
pry (>= 0.9.10)
thor (>= 0.14.6)
guard-rspec (1.1.0)
guard-rspec (1.2.1)
guard (>= 1.1)
listen (0.7.1)
lumberjack (1.0.2)
method_source (0.8.1)
pry (0.9.10)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.3.1)
listen (0.7.3)
lumberjack (1.0.9)
method_source (0.8.2)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rake (10.3.1)
rb-fsevent (0.9.1)
rb-fsevent (0.9.4)
rspec (2.9.0)
rspec-core (~> 2.9.0)
rspec-expectations (~> 2.9.0)
Expand All @@ -32,8 +34,8 @@ GEM
rspec-expectations (2.9.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.9.0)
slop (3.3.3)
thor (0.16.0)
slop (3.6.0)
thor (0.19.1)

PLATFORMS
ruby
Expand Down
4 changes: 2 additions & 2 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
guard 'rspec', :version => 2, :cli => "--color", :bundler => true, :all_on_start => false, :all_after_pass => false, :keep_failed => true, :notification => false do
watch('spec/spec_helper.rb') { "spec" }
guard 'rspec', version: 2, cli: '--color', bundler: true, all_on_start: false, all_after_pass: false, keep_failed: true, notification: false do
watch('spec/spec_helper.rb') { 'spec' }
watch(%r{^spec/.+_spec\.rb})
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
end
18 changes: 11 additions & 7 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Implements iPizza protocol to communicate with Estonian Banks.

Gem implements support for iPizza services (`1011`, `1012`, `4011` and `4012`) that are supported by members of the Estonian Banking Association [since October 2014](http://pangaliit.ee/et/arveldused/pangalingi-spetsifikatsioon).

If you need to use this gem with old iPizza services implementations (`1001`, `1002`, `4001` and `4002`), use 1.0.0 version of this gem (NB! support for these services will end on 31 December 2015).

# Usage

Add gem dependency in your `Gemfile` and install the gem:
Expand Down Expand Up @@ -46,9 +50,7 @@ At any time, configuration can be modified with `Ipizza::Config.configure` block
# relatively to YAML file
file_cert: ./certificates/bank_public.crt
snd_id: dealer
encoding: ISO-8859-4

Please note that currently only ISO-8859-4 encoding is supported with Swedbank. UTF-8 works well with other payment providers.
encoding: UTF-8

## Payment requests

Expand All @@ -75,14 +77,16 @@ Please note that currently only ISO-8859-4 encoding is supported with Swedbank.

This library currently works with four Estonian Banks. Here are their respective interface specifications:

* [Swedbank](https://www.swedbank.ee/static/pdf/business/d2d/paymentcollection/info_banklink_techspec_est.pdf)
* [Swedbank](https://www.swedbank.ee/business/cash/ecommerce/banklink/description?language=EST)
* [SEB](http://www.seb.ee/ari/maksete-kogumine/maksete-kogumine-internetis/tehniline-spetsifikatsioon)
* [Sampo](http://www.sampopank.ee/et/14732.html)
* [Krediidipank](http://www.krediidipank.ee/business/settlements/bank-link/tehniline_kirjeldus.pdf)
* [Nordea](http://www.nordea.ee/Teenused+ärikliendile/E-lahendused/787802.html)
* [Danske Bank](http://www.danskebank.ee/et/14732.html)
* [Krediidipank](http://www.krediidipank.ee/business/settlements/bank-link/index.html)
* [LHV Bank](https://www.lhv.ee/pangateenused/pangalink/)
* [Nordea](http://www.nordea.ee/Teenused+%C3%A4rikliendile/Igap%C3%A4evapangandus/Maksete+kogumine/E-makse/1562142.html) (*uses SOLO protocol*)

# Helpful links

* [pangalink.net](https://pangalink.net/et/info)
* [Repository](http://github.com/priithaamer/ipizza)
* [Issue tracker](http://github.com/priithaamer/ipizza/issues)

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Bundler::GemHelper.install_tasks

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
18 changes: 9 additions & 9 deletions ipizza.gemspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "ipizza/version"
$:.push File.expand_path('../lib', __FILE__)
require 'ipizza/version'

Gem::Specification.new do |s|
s.name = "ipizza"
s.name = 'ipizza'
s.version = Ipizza::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Priit Haamer"]
s.email = ["[email protected]"]
s.homepage = "http://github.com/priithaamer/ipizza"
s.summary = %q{Implements iPizza protocol to communicate with Estonian Banks}
s.description = %q{Simplifies generating payment requests and parsing responses from banks when using iPizza protocol.}
s.authors = ['Priit Haamer']
s.email = ['[email protected]']
s.homepage = 'https://github.com/Voog/ipizza'
s.summary = 'Implements iPizza protocol to communicate with Estonian Banks'
s.description = 'Simplifies generating payment requests and parsing responses from banks when using iPizza protocol.'

s.add_development_dependency 'rspec', '~> 2.9.0'
s.add_development_dependency 'guard-rspec'
Expand All @@ -20,5 +20,5 @@ Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.require_paths = ['lib']
end
3 changes: 3 additions & 0 deletions lib/ipizza.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
require 'ipizza/response'
require 'ipizza/payment_request'
require 'ipizza/payment_response'
require 'ipizza/authentication'
require 'ipizza/authentication_request'
require 'ipizza/authentication_response'
require 'ipizza/provider'
require 'ipizza/provider/base'
require 'ipizza/provider/lhv'
require 'ipizza/provider/swedbank'
require 'ipizza/provider/seb'
require 'ipizza/provider/sampo'
Expand Down
15 changes: 15 additions & 0 deletions lib/ipizza/authentication.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Ipizza
class Authentication

attr_accessor :provider, :user, :message_time, :sender_id, :receiver_id, :user_name, :user_id, :country, :other, :authentication_identifier, :request_identifier

def initialize(attribs = {})
attribs.each do |key, value|
if self.respond_to?("#{key.to_s}=".to_sym)
v = key.to_sym == :message_time && value.is_a?(String) ? Time.parse(value) : value
self.send("#{key.to_s}=".to_sym, v)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/ipizza/authentication_request.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Ipizza
class AuthenticationRequest < Ipizza::Request
end
end
end
31 changes: 22 additions & 9 deletions lib/ipizza/authentication_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,36 @@ module Ipizza
class AuthenticationResponse < Ipizza::Response

def success?
return ['3002'].include?(@params['VK_SERVICE'])
%w(3012 3013).include?(@params['VK_SERVICE'])
end

def valid?
return @valid
end

def authentication_info
@params['VK_INFO']
@valid
end

def info_social_security_id
/ISIK:([^;.]+)/i.match(@params['VK_INFO'])[1] if @params['VK_INFO']
authentication_info.user_id
end

def info_name
/NIMI:([^;.]+)/.match(@params['VK_INFO'])[1] if @params['VK_INFO']
authentication_info.user_name
end

def authentication_info
@authentication_info ||= Ipizza::Authentication.new(
provider: @params['VK_SND_ID'],
user: @params['VK_USER'],
message_time: @params['VK_DATETIME'],
sender_id: @params['VK_SND_ID'],
receiver_id: @params['VK_REC_ID'],
user_name: @params['VK_USER_NAME'],
user_id: @params['VK_USER_ID'],
country: @params['VK_COUNTRY'],
other: @params['VK_OTHER'],
authentication_identifier: @params['VK_TOKEN'],
request_identifier: @params['VK_RID'],
nonce: @params['VK_NONCE']
)
end
end
end
end
6 changes: 3 additions & 3 deletions lib/ipizza/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def configure
end

def method_missing(m, *args)
if /^(swedbank|seb|sampo|krediidipank|nordea)_(.*)=$/ =~ m.to_s
if /^(lhv|swedbank|seb|sampo|krediidipank|nordea)_(.*)=$/ =~ m.to_s
clz = Ipizza::Provider.const_get($1.capitalize)
key = $2
value = args.first
Expand All @@ -45,13 +45,13 @@ def method_missing(m, *args)
private

def load_certificate(file_path)
if File.exists?(file_path)
if File.exist?(file_path)
file_path
else
file_path = File.expand_path(File.join(certs_root, file_path))
end

if File.exists?(file_path)
if File.exist?(file_path)
file_path
else
raise "Could not load certificate from file '#{file_path}'"
Expand Down
8 changes: 4 additions & 4 deletions lib/ipizza/payment.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module Ipizza
class Payment

attr_accessor :stamp, :amount, :currency, :refnum, :receiver_account, :receiver_name, :sender_account, :sender_name, :message, :transaction_id
attr_accessor :provider, :stamp, :amount, :currency, :refnum, :receiver_account, :receiver_name, :sender_account, :sender_name, :message, :transaction_id, :transaction_time

def initialize(attribs = {})
attribs.each do |key, value|
if self.respond_to?("#{key.to_s}=".to_sym)
self.send("#{key.to_s}=".to_sym, value)
v = key.to_sym == :transaction_time && value.is_a?(String) ? Time.parse(value) : value
self.send("#{key.to_s}=".to_sym, v)
end
end
end

end
end
end
2 changes: 1 addition & 1 deletion lib/ipizza/payment_request.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Ipizza
class PaymentRequest < Ipizza::Request
end
end
end
22 changes: 15 additions & 7 deletions lib/ipizza/payment_response.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
class Ipizza::PaymentResponse < Ipizza::Response

def success?
return ['1101'].include?(@params['VK_SERVICE'])
%w(1111).include?(@params['VK_SERVICE'])
end

def valid?
return @valid
@valid
end

def automatic_message?
@params['VK_AUTO'] and @params['VK_AUTO'] == 'Y'
@params['VK_AUTO'] == 'Y'
end

def payment_info
@payment_info ||= Ipizza::Payment.new(
:stamp => @params['VK_STAMP'], :amount => @params['VK_AMOUNT'], :currency => @params['VK_CURR'],
:refnum => @params['VK_REF'], :message => @params['VK_MSG'], :transaction_id => @params['VK_T_NO'],
:receiver_account => @params['VK_REC_ACC'], :receiver_name => @params['VK_REC_NAME'],
:sender_account => @params['VK_SND_ACC'], :sender_name => @params['VK_SND_NAME']
provider: @params['VK_SND_ID'],
stamp: @params['VK_STAMP'],
amount: @params['VK_AMOUNT'],
currency: @params['VK_CURR'],
refnum: @params['VK_REF'],
message: @params['VK_MSG'],
transaction_id: @params['VK_T_NO'],
receiver_account: @params['VK_REC_ACC'],
receiver_name: @params['VK_REC_NAME'],
sender_account: @params['VK_SND_ACC'],
sender_name: @params['VK_SND_NAME'],
transaction_time: @params['VK_T_DATETIME']
)
end
end
20 changes: 8 additions & 12 deletions lib/ipizza/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,20 @@ module Provider
class << self
def get(provider_name)
case provider_name.downcase
when 'swedbank'
when 'lhv'
Ipizza::Provider::Lhv.new
when 'swedbank', 'hp'
Ipizza::Provider::Swedbank.new
when 'hp'
Ipizza::Provider::Swedbank.new
when 'eyp'
Ipizza::Provider::Seb.new
when 'seb'
when 'eyp', 'seb'
Ipizza::Provider::Seb.new
when 'sampo'
when 'sampo', 'sampopank', 'danske'
Ipizza::Provider::Sampo.new
when 'sampopank'
Ipizza::Provider::Sampo.new
when 'krep'
Ipizza::Provider::Krediidipank.new
when 'krediidipank'
when 'krep', 'krediidipank'
Ipizza::Provider::Krediidipank.new
when 'nordea'
Ipizza::Provider::Nordea.new
else
Ipizza::Provider::Base.new
end
end
end
Expand Down
Loading

0 comments on commit 6d7567c

Please sign in to comment.