gestpay 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +4 -0
- data/gestpay.gemspec +29 -0
- data/lib/gestpay.rb +22 -0
- data/lib/gestpay/configuration.rb +34 -0
- data/lib/gestpay/digest.rb +41 -0
- data/lib/gestpay/error.rb +7 -0
- data/lib/gestpay/error/failed_digest.rb +19 -0
- data/lib/gestpay/error/verify_visa.rb +15 -0
- data/lib/gestpay/gateway.rb +49 -0
- data/lib/gestpay/result.rb +10 -0
- data/lib/gestpay/result/base.rb +25 -0
- data/lib/gestpay/result/decrypt.rb +6 -0
- data/lib/gestpay/result/encrypt.rb +9 -0
- data/lib/gestpay/result/payment.rb +13 -0
- data/lib/gestpay/result/token_request.rb +9 -0
- data/lib/gestpay/version.rb +3 -0
- data/spec/fixtures/gestpay_cassettes/decrypt_ko.yml +224 -0
- data/spec/fixtures/gestpay_cassettes/decrypt_ok.yml +171 -0
- data/spec/fixtures/gestpay_cassettes/encrypt_ko.yml +169 -0
- data/spec/fixtures/gestpay_cassettes/encrypt_ok.yml +170 -0
- data/spec/fixtures/gestpay_cassettes/payment_ko.yml +397 -0
- data/spec/fixtures/gestpay_cassettes/payment_ok.yml +395 -0
- data/spec/fixtures/gestpay_cassettes/payment_token.yml +397 -0
- data/spec/fixtures/gestpay_cassettes/payment_visa.yml +395 -0
- data/spec/fixtures/gestpay_cassettes/request_token_ko.yml +400 -0
- data/spec/fixtures/gestpay_cassettes/request_token_ok.yml +399 -0
- data/spec/lib/gestpay/digest_spec.rb +72 -0
- data/spec/lib/gestpay/gateway_spec.rb +110 -0
- data/spec/spec_helper.rb +30 -0
- metadata +192 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: baa4e9609baa08d89ff8f3e4b50a22e68e2027e1
|
4
|
+
data.tar.gz: b070856652f23fe654c167677bda404cabf00cd2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c543332f7bb4e87608873b90ce6d35aa6498b76d50614f4296459bec39b0bb758c2cd51287f462cbf1e41d3046bd66f0489a86aeda6392bf25ff9037ea2323ca
|
7
|
+
data.tar.gz: 3ac232d167c96b36874bb050e229060884d49b5a194b1e0aceb8081064a96248ae68f756f6337ec5582376b55934625a19ee40594cb7514ed72372f523289edc
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
Gemfile.lock
|
15
|
+
|
16
|
+
# YARD artifacts
|
17
|
+
.yardoc
|
18
|
+
_yardoc
|
19
|
+
doc/
|
20
|
+
|
21
|
+
# RVM helpers
|
22
|
+
.ruby-version
|
23
|
+
.ruby-gemset
|
24
|
+
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'savon', '~> 2.2.0'
|
4
|
+
gem 'activesupport', '~> 3.2.13'
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
# gem 'factory_girl', '~> 4.2.0'
|
8
|
+
gem 'webmock', "~> 1.9.0"
|
9
|
+
gem 'vcr', "~> 2.4.0"
|
10
|
+
# gem 'turn'
|
11
|
+
gem 'rake'
|
12
|
+
gem 'rspec', "~> 2.13.0"
|
13
|
+
gem 'pry'
|
14
|
+
end
|
15
|
+
|
16
|
+
# Specify your gem's dependencies in gestpay.gemspec
|
17
|
+
gemspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Alessandro Mencarini
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Gestpay
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/momitians/gestpay.png?branch=master)](https://travis-ci.org/momitians/gestpay)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/momitians/gestpay.png)](https://codeclimate.com/github/momitians/gestpay)
|
5
|
+
|
6
|
+
Service wrapper for BancaSella Gestpay interface.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'gestpay'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install gestpay
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
You can setup the gem in a Rails project using an initializer like this:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Gestpay.setup do |config|
|
28
|
+
config.account = 'GESPAY12345'
|
29
|
+
config.environment = :test # default, change it to :production when ready
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
or using an export:
|
34
|
+
|
35
|
+
```shell
|
36
|
+
export GESTPAY_ACCOUNT=GESPAY12345
|
37
|
+
export GESTPAY_ENVIRONMENT=test
|
38
|
+
```
|
39
|
+
|
40
|
+
You then have two different classes: `Gestpay::Digest` will help with the Crypt/Decrypt web service, while `Gestpay::Gateway` with the server-to-server webservice operations.
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
49
|
+
|
50
|
+
## Licence
|
51
|
+
|
52
|
+
Released under the [MIT License](http://www.opensource.org/licenses/MIT). © 2013 [Momit S.r.l.](http://momit.it/)
|
data/Rakefile
ADDED
data/gestpay.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gestpay/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gestpay"
|
8
|
+
spec.version = Gestpay::VERSION
|
9
|
+
spec.authors = ["Alessandro Mencarini", "Maurizio de Magnis"]
|
10
|
+
spec.email = ["a.mencarini@freegoweb.it", "maurizio.demagnis@gmail.com"]
|
11
|
+
spec.description = %q{GestPay services wrapper}
|
12
|
+
spec.summary = %q{The gem will help with BancaSella payment webservices}
|
13
|
+
spec.homepage = "http://momitians.github.io/gestpay"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "savon", "~> 2.2.0"
|
22
|
+
spec.add_dependency "activesupport", "~> 3.2.13"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec", "~> 2.13.0"
|
27
|
+
spec.add_development_dependency "vcr", "~> 2.4.0"
|
28
|
+
spec.add_development_dependency "webmock", "~> 1.9.0"
|
29
|
+
end
|
data/lib/gestpay.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'savon'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
|
4
|
+
require "gestpay/version"
|
5
|
+
require "gestpay/digest"
|
6
|
+
require "gestpay/gateway"
|
7
|
+
require "gestpay/configuration"
|
8
|
+
require "gestpay/result"
|
9
|
+
|
10
|
+
require "gestpay/error"
|
11
|
+
|
12
|
+
module Gestpay
|
13
|
+
|
14
|
+
def self.setup
|
15
|
+
yield self.config
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.config
|
19
|
+
@config ||= Configuration.new
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Gestpay
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
CURRENCY_MAPPING = {
|
5
|
+
'EUR' => '242',
|
6
|
+
'ITL' => '18',
|
7
|
+
'BRL' => '234',
|
8
|
+
'USD' => '1',
|
9
|
+
'JPY' => '71',
|
10
|
+
'HKD' => '103'
|
11
|
+
}
|
12
|
+
|
13
|
+
LANGUAGE_MAPPING = {
|
14
|
+
'ITA' => '1'
|
15
|
+
}
|
16
|
+
|
17
|
+
attr_accessor :environment, :account, :currency, :language
|
18
|
+
def initialize
|
19
|
+
@environment = ENV['GESTPAY_ENVIRONMENT'] || :test
|
20
|
+
@account = ENV['GESTPAY_ACCOUNT']
|
21
|
+
@currency = 'EUR'
|
22
|
+
@language = 'ITA'
|
23
|
+
end
|
24
|
+
|
25
|
+
def currency_code
|
26
|
+
CURRENCY_MAPPING[@currency]
|
27
|
+
end
|
28
|
+
|
29
|
+
def language_code
|
30
|
+
LANGUAGE_MAPPING[@language]
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Gestpay
|
2
|
+
class Digest
|
3
|
+
|
4
|
+
URL = {
|
5
|
+
:test => 'https://testecomm.sella.it/gestpay/gestpayws/WSCryptDecrypt.asmx?WSDL',
|
6
|
+
:production => 'https://ecomms2s.sella.it/gestpay/gestpayws/WSCryptDecrypt.asmx?WSDL'
|
7
|
+
}
|
8
|
+
|
9
|
+
def config
|
10
|
+
Gestpay.config
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_accessor :client
|
14
|
+
def initialize
|
15
|
+
# SOAP Client operations:
|
16
|
+
# => [:encrypt, :decrypt]
|
17
|
+
@client = Savon.client(:wsdl => URL[Gestpay.config.environment])
|
18
|
+
end
|
19
|
+
|
20
|
+
def soap_options(data)
|
21
|
+
{
|
22
|
+
:message => {
|
23
|
+
:shop_login => config.account
|
24
|
+
}.merge(data)
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def encrypt(data)
|
29
|
+
response = @client.call(:encrypt, soap_options(data))
|
30
|
+
response_content = response.body[:encrypt_response][:encrypt_result][:gest_pay_crypt_decrypt]
|
31
|
+
Result::Encrypt.new(response_content)
|
32
|
+
end
|
33
|
+
|
34
|
+
def decrypt(string)
|
35
|
+
response = @client.call(:decrypt, soap_options({'CryptedString' => string}))
|
36
|
+
response_content = response.body[:decrypt_response][:decrypt_result][:gest_pay_crypt_decrypt]
|
37
|
+
Result::Decrypt.new(response_content)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Gestpay
|
2
|
+
module Error
|
3
|
+
class FailedDigest < StandardError
|
4
|
+
|
5
|
+
attr_reader :code, :description
|
6
|
+
|
7
|
+
def initialize(code, description)
|
8
|
+
@code, @description = code, description
|
9
|
+
end
|
10
|
+
|
11
|
+
def message
|
12
|
+
string = "Error #{code}"
|
13
|
+
string << ": #{description}" if !description.blank?
|
14
|
+
string
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Gestpay
|
2
|
+
module Error
|
3
|
+
class VerifyVisa < StandardError
|
4
|
+
|
5
|
+
attr_reader :result, :crypted_response, :transaction_key
|
6
|
+
|
7
|
+
def initialize(info)
|
8
|
+
@transaction_key = info[:transaction_key]
|
9
|
+
@result = info[:vb_v][:vb_v_buyer]
|
10
|
+
@crypted_response = info[:vb_v][:vb_v_risp]
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Gestpay
|
2
|
+
class Gateway
|
3
|
+
|
4
|
+
URL = {
|
5
|
+
:test => 'https://testecomm.sella.it/gestpay/gestpayws/WSs2s.asmx?WSDL',
|
6
|
+
:production => 'https://ecomms2s.sella.it/gestpay/gestpayws/WSs2s.asmx?WSDL'
|
7
|
+
}
|
8
|
+
|
9
|
+
def config
|
10
|
+
Gestpay.config
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_accessor :client
|
14
|
+
def initialize
|
15
|
+
# SOAP Client operations:
|
16
|
+
# => [:call_refund_s2_s, :call_read_trx_s2_s, :call_pagam_s2_s, :call_delete_s2_s, :call_settle_s2_s, :call_verifycard_s2_s, :call_check_carta_s2_s, :call_renounce, :call_request_token_s2_s, :call_delete_token_s2_s]
|
17
|
+
@client = Savon.client(:wsdl => URL[Gestpay.config.environment])
|
18
|
+
end
|
19
|
+
|
20
|
+
def soap_options(data)
|
21
|
+
{
|
22
|
+
:message => {
|
23
|
+
:shop_login => config.account,
|
24
|
+
:uic_code => config.currency_code,
|
25
|
+
:language_id => config.language_code
|
26
|
+
}.merge(data)
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def payment(data)
|
31
|
+
# Custom info must be enabled on Gestpay backoffice interface, by adding new parameters
|
32
|
+
data[:custom_info] = data[:custom_info].to_query.gsub('&', '*P1*') if data[:custom_info]
|
33
|
+
response = @client.call(:call_pagam_s2_s, soap_options(data))
|
34
|
+
response_content = response.body[:call_pagam_s2_s_response][:call_pagam_s2_s_result][:gest_pay_s2_s]
|
35
|
+
Result::Payment.new(response_content)
|
36
|
+
end
|
37
|
+
|
38
|
+
def request_token(data, verify=true)
|
39
|
+
opts = {
|
40
|
+
:request_token => 'MASKEDPAN',
|
41
|
+
:with_auth => verify ? 'Y' : 'N'
|
42
|
+
}
|
43
|
+
response = @client.call(:call_request_token_s2_s, soap_options(data.merge(opts)))
|
44
|
+
response_content = response.body[:call_request_token_s2_s_response][:call_request_token_s2_s_result][:gest_pay_s2_s]
|
45
|
+
Result::TokenRequest.new(response_content)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Gestpay
|
2
|
+
module Result
|
3
|
+
class Base
|
4
|
+
|
5
|
+
attr_reader :data
|
6
|
+
|
7
|
+
def initialize(data)
|
8
|
+
@data = data
|
9
|
+
end
|
10
|
+
|
11
|
+
def success?
|
12
|
+
transaction_result == 'OK'
|
13
|
+
end
|
14
|
+
|
15
|
+
def error
|
16
|
+
"Error #{ error_code }: #{ error_description }" if error_code
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(method_name, *args)
|
20
|
+
data.has_key?(method_name) ? data[method_name] : super
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|