pagantis-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +58 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +9 -0
- data/lib/pagantis-rails.rb +9 -0
- data/lib/pagantis-rails/helper.rb +65 -0
- data/lib/pagantis-rails/version.rb +5 -0
- data/pagantis-rails.gemspec +24 -0
- data/spec/helper_spec.rb +42 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dc3704efd782fd2edf709bca474f48621b151a71
|
4
|
+
data.tar.gz: fab5a6e757214a35099267e80ca80f92a26cd547
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f3a2fa8fab207affdd7389c6e91618091b842d6402df86cf678875e11c46b860763a002d27f5e08f6cd6e5e2bf04352f0db373af391a6c73ef6fd970216c6cce
|
7
|
+
data.tar.gz: e492cd5836ff38e1c89087231d07374f7c1db7a3cd1825bee270a076401c582b4d320ffefd1dbcb12df2aaaa57a04922f60801f3fe53f7fd59b219f7819e3322
|
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
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
|
+
|
15
|
+
# YARD artifacts
|
16
|
+
.yardoc
|
17
|
+
_yardoc
|
18
|
+
doc/
|
19
|
+
|
20
|
+
# Platform dependent
|
21
|
+
.DS_Store
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/dgilperez/pagantis-ruby.git
|
3
|
+
revision: 2002111426c18017d65656e4f3942751e5e3c9f9
|
4
|
+
specs:
|
5
|
+
pagantis-ruby (0.1.0)
|
6
|
+
activeresource (>= 3.2, < 4.2.0)
|
7
|
+
|
8
|
+
PATH
|
9
|
+
remote: .
|
10
|
+
specs:
|
11
|
+
pagantis-rails (0.0.1)
|
12
|
+
|
13
|
+
GEM
|
14
|
+
remote: https://rubygems.org/
|
15
|
+
specs:
|
16
|
+
activemodel (4.0.4)
|
17
|
+
activesupport (= 4.0.4)
|
18
|
+
builder (~> 3.1.0)
|
19
|
+
activeresource (4.0.0)
|
20
|
+
activemodel (~> 4.0)
|
21
|
+
activesupport (~> 4.0)
|
22
|
+
rails-observers (~> 0.1.1)
|
23
|
+
activesupport (4.0.4)
|
24
|
+
i18n (~> 0.6, >= 0.6.9)
|
25
|
+
minitest (~> 4.2)
|
26
|
+
multi_json (~> 1.3)
|
27
|
+
thread_safe (~> 0.1)
|
28
|
+
tzinfo (~> 0.3.37)
|
29
|
+
atomic (1.1.16)
|
30
|
+
builder (3.1.4)
|
31
|
+
diff-lcs (1.2.5)
|
32
|
+
i18n (0.6.9)
|
33
|
+
minitest (4.7.5)
|
34
|
+
multi_json (1.9.2)
|
35
|
+
rails-observers (0.1.2)
|
36
|
+
activemodel (~> 4.0)
|
37
|
+
rake (10.2.0)
|
38
|
+
rspec (2.14.1)
|
39
|
+
rspec-core (~> 2.14.0)
|
40
|
+
rspec-expectations (~> 2.14.0)
|
41
|
+
rspec-mocks (~> 2.14.0)
|
42
|
+
rspec-core (2.14.8)
|
43
|
+
rspec-expectations (2.14.5)
|
44
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
45
|
+
rspec-mocks (2.14.6)
|
46
|
+
thread_safe (0.3.1)
|
47
|
+
atomic (>= 1.1.7, < 2)
|
48
|
+
tzinfo (0.3.39)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
bundler (~> 1.3)
|
55
|
+
pagantis-rails!
|
56
|
+
pagantis-ruby (~> 0.1)!
|
57
|
+
rake
|
58
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 David Gil
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 David Gil
|
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,29 @@
|
|
1
|
+
# Pagantis::Rails
|
2
|
+
|
3
|
+
Rails wrapper for [pagantis-ruby](http://github.com/pagantis/pagantis-ruby) library.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'pagantis-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install pagantis-rails
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module Pagantis
|
2
|
+
module Rails
|
3
|
+
# Using this helper you can easily create a form of any flavour in Railsy
|
4
|
+
# environments. In the example we are using Rails and HAML
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# - helper = Pagantis::Helper.new(args ...)
|
9
|
+
# = form_for helper, as: :helper, url: "https://psp.pagantis.com/2/sale", method: "post" do |f|
|
10
|
+
# = f.hidden_field :operation
|
11
|
+
# = f.hidden_field :account_id
|
12
|
+
# = f.hidden_field :signature
|
13
|
+
# = f.text_field :order_id
|
14
|
+
# = f.text_field :auth_method
|
15
|
+
# = f.text_field :amount
|
16
|
+
# = f.text_field :currency
|
17
|
+
# = f.text_field :description
|
18
|
+
# = f.text_field :ok_url
|
19
|
+
# = f.text_field :nok_url
|
20
|
+
# = f.submit 'Pay'
|
21
|
+
class Helper
|
22
|
+
attr_reader :operation, :order_id, :auth_method, :amount, :currency, :description,
|
23
|
+
:ok_url, :nok_url, :account_id, :signature
|
24
|
+
|
25
|
+
def initialize(args = {})
|
26
|
+
@operation = args.fetch(:operation) { nil } # empty operation equals single charge
|
27
|
+
@order_id = args.fetch(:order_id)
|
28
|
+
@amount = args.fetch(:amount)
|
29
|
+
@currency = parse_currency args.fetch(:currency)
|
30
|
+
@description = args.fetch(:description) { "" }
|
31
|
+
@ok_url = args.fetch(:ok_url)
|
32
|
+
@nok_url = args.fetch(:nok_url)
|
33
|
+
@account_id = args.fetch(:account_id)
|
34
|
+
|
35
|
+
if subscription?
|
36
|
+
@plan_id = args.fetch(:plan_id)
|
37
|
+
@user_id = args.fetch(:user_id)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def subscription?
|
42
|
+
@operation == "SUBSCRIPTION"
|
43
|
+
end
|
44
|
+
|
45
|
+
def auth_method
|
46
|
+
"SHA1"
|
47
|
+
end
|
48
|
+
|
49
|
+
def signature
|
50
|
+
str = @account_id + @order_id + @amount.to_s + @currency + auth_method + @ok_url + @nok_url
|
51
|
+
Digest::SHA1.hexdigest str
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def parse_currency(currency)
|
57
|
+
if %w(EUR USD GBP).include? currency
|
58
|
+
currency
|
59
|
+
else
|
60
|
+
fail ArgumentError
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pagantis-rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pagantis-rails"
|
8
|
+
spec.version = Pagantis::Rails::VERSION
|
9
|
+
spec.authors = ["David Gil"]
|
10
|
+
spec.email = ["dgilperez@gmail.com"]
|
11
|
+
spec.description = %q{Rails wrapper for pagantis-ruby library.}
|
12
|
+
spec.summary = %q{Pagantis API On Rails}
|
13
|
+
spec.homepage = ""
|
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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
data/spec/helper_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "pagantis-rails/helper"
|
2
|
+
|
3
|
+
describe Pagantis::Rails::Helper do
|
4
|
+
let(:valid_arguments) {
|
5
|
+
{ order_id: 'ABCD',
|
6
|
+
amount: '1299',
|
7
|
+
currency: "EUR",
|
8
|
+
description: "One euro item",
|
9
|
+
ok_url: "http://example.com/ok",
|
10
|
+
nok_url: "http://example.com/nok",
|
11
|
+
account_id: '1234'
|
12
|
+
}
|
13
|
+
}
|
14
|
+
let(:invalid_arguments) {
|
15
|
+
valid_arguments.reject { |k,v| k == :amount }
|
16
|
+
}
|
17
|
+
|
18
|
+
context "initialization" do
|
19
|
+
it "should take a few mandatory params on initialization" do
|
20
|
+
expect {
|
21
|
+
Pagantis::Rails::Helper.new(valid_arguments)
|
22
|
+
}.not_to raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should take a few mandatory params on initialization" do
|
26
|
+
expect {
|
27
|
+
Pagantis::Rails::Helper.new(invalid_arguments)
|
28
|
+
}.to raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should take a few mandatory params on initialization" do
|
32
|
+
expect {
|
33
|
+
Pagantis::Rails::Helper.new(valid_arguments.merge(currency: "YEN"))
|
34
|
+
}.to raise_error ArgumentError
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should calculate a signature" do
|
39
|
+
helper = Pagantis::Rails::Helper.new(valid_arguments)
|
40
|
+
helper.signature.should == 'db698919260d01ad2e78d1274c041bd97c23cbb8'
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pagantis-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Gil
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Rails wrapper for pagantis-ruby library.
|
56
|
+
email:
|
57
|
+
- dgilperez@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- LICENSE
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/pagantis-rails.rb
|
70
|
+
- lib/pagantis-rails/helper.rb
|
71
|
+
- lib/pagantis-rails/version.rb
|
72
|
+
- pagantis-rails.gemspec
|
73
|
+
- spec/helper_spec.rb
|
74
|
+
homepage: ''
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.1.8
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Pagantis API On Rails
|
98
|
+
test_files:
|
99
|
+
- spec/helper_spec.rb
|