shoppe-paytrail 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +6 -0
- data/config/locales/en.yml +10 -0
- data/lib/shoppe/paytrail.rb +19 -0
- data/lib/shoppe/paytrail/engine.rb +17 -0
- data/lib/shoppe/paytrail/order_extensions.rb +56 -0
- data/lib/shoppe/paytrail/version.rb +5 -0
- data/shoppe-paytrail.gemspec +25 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b5503c2288a0c6714f5f790f4ff22430cd878fbb
|
4
|
+
data.tar.gz: f6b5189bfe98a6314b0b3133ff037aba358e5f81
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4426a04e590594ce30f650372f7153c91b501dccbc74efa575d6706ec97a3ef7c8f3bde4974cf38d0533d00b5645d76455a8b091c58c766c49258addf1333bea
|
7
|
+
data.tar.gz: 081b57336aab615b0fe68906fd2f1aadabf256c5f3e84203725feb03ef0015430f8298af5dcd19ee020514b0abf7478f655089f227fdae76d01b85c978689889
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Joakim Antman
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Paytrail module for Shoppe
|
2
|
+
|
3
|
+
Integrate Paytrail to your Shoppe application, with ease.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'shoppe-paytrail'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
## Example Payment handling
|
18
|
+
|
19
|
+
````ruby
|
20
|
+
class PaymentsController < ApplicationController
|
21
|
+
before_action(only: [:paytrail, :paytrail_ok, :paytrail_error, :paytrail_notification]) { Shoppe::Paytrail.configure }
|
22
|
+
|
23
|
+
def paytrail
|
24
|
+
redirect_to current_order.redirect_to_paytrail(payments_paytrail_ok_url, payments_paytrail_error_url, payments_paytrail_notification_url)
|
25
|
+
end
|
26
|
+
|
27
|
+
def paytrail_ok
|
28
|
+
redirect_to root_path and return unless current_order.confirming?
|
29
|
+
|
30
|
+
paytrail_order = Shoppe::Order.find(params['ORDER_NUMBER'])
|
31
|
+
paytrail_order.handle_paytrail_payment(params, false)
|
32
|
+
paytrail_order.confirm!
|
33
|
+
|
34
|
+
clear_current_order
|
35
|
+
|
36
|
+
respond_to do |wants|
|
37
|
+
wants.html { redirect_to root_path, notice: 'Your order has now been completed!' }
|
38
|
+
end
|
39
|
+
rescue => e
|
40
|
+
redirect_to root_path, alert: 'There was an error while completing the payment'
|
41
|
+
end
|
42
|
+
|
43
|
+
def paytrail_error
|
44
|
+
redirect_to root_path, alert: 'The payment process was aborted'
|
45
|
+
end
|
46
|
+
|
47
|
+
def paytrail_notification
|
48
|
+
paytrail_order = Shoppe::Order.find(params['ORDER_NUMBER'])
|
49
|
+
paytrail_order.handle_paytrail_payment(params, true)
|
50
|
+
render :text => ""
|
51
|
+
end
|
52
|
+
end
|
53
|
+
````
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/anakinj/shoppe-paytrail.
|
58
|
+
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'paytrail-client'
|
2
|
+
require 'shoppe/paytrail/version'
|
3
|
+
require 'shoppe/paytrail/order_extensions'
|
4
|
+
require 'shoppe/paytrail/engine'
|
5
|
+
|
6
|
+
module Shoppe::Paytrail
|
7
|
+
class << self
|
8
|
+
def setup
|
9
|
+
Shoppe.add_settings_group :paytrail, [:paytrail_merchant_id, :paytrail_merchant_secret]
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure
|
13
|
+
PaytrailClient.configuration do |config|
|
14
|
+
config.merchant_id = Shoppe.settings.paytrail_merchant_id
|
15
|
+
config.merchant_secret = Shoppe.settings.paytrail_merchant_secret
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Shoppe
|
2
|
+
module Paytrail
|
3
|
+
class Engine < Rails::Engine
|
4
|
+
config.before_initialize do
|
5
|
+
config.i18n.load_path += Dir["#{config.root}/config/locales/**/*.yml"]
|
6
|
+
end
|
7
|
+
|
8
|
+
initializer 'shoppe.paytrail.initializer' do
|
9
|
+
Shoppe::Paytrail.setup
|
10
|
+
end
|
11
|
+
|
12
|
+
config.to_prepare do
|
13
|
+
Shoppe::Order.send :include, Shoppe::Paytrail::OrderExtensions
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Shoppe
|
2
|
+
module Paytrail
|
3
|
+
module OrderExtensions
|
4
|
+
def redirect_to_paytrail(success_url, failure_url, notification_url)
|
5
|
+
response = PaytrailClient::Payment.create(order_number: number,
|
6
|
+
currency: 'EUR',
|
7
|
+
locale: resolve_locale,
|
8
|
+
url_set: {
|
9
|
+
success: success_url,
|
10
|
+
failure: failure_url,
|
11
|
+
notification: notification_url
|
12
|
+
},
|
13
|
+
price: format('%.2f', total))
|
14
|
+
|
15
|
+
response['url']
|
16
|
+
rescue
|
17
|
+
raise Shoppe::Errors::PaymentDeclined
|
18
|
+
end
|
19
|
+
|
20
|
+
def handle_paytrail_payment(params, confirmed = false)
|
21
|
+
PaytrailClient::Payment.verify_payment!(params['ORDER_NUMBER'],
|
22
|
+
params['TIMESTAMP'],
|
23
|
+
params['PAID'],
|
24
|
+
params['METHOD'],
|
25
|
+
params['RETURN_AUTHCODE'])
|
26
|
+
|
27
|
+
payment = payments.find_by(reference: params['ORDER_NUMBER'])
|
28
|
+
|
29
|
+
if payment.nil?
|
30
|
+
payments.create(amount: total,
|
31
|
+
reference: params['ORDER_NUMBER'],
|
32
|
+
method: 'Paytrail',
|
33
|
+
refundable: false,
|
34
|
+
confirmed: confirmed)
|
35
|
+
else
|
36
|
+
payment.update_attribute(:confirmed, confirmed)
|
37
|
+
end
|
38
|
+
|
39
|
+
save!
|
40
|
+
rescue
|
41
|
+
raise Shoppe::Errors::PaymentDeclined, 'Could not verify Paytrail payment'
|
42
|
+
end
|
43
|
+
|
44
|
+
def resolve_locale
|
45
|
+
case I18n.locale
|
46
|
+
when :fi
|
47
|
+
'fi_FI'
|
48
|
+
when :sv
|
49
|
+
'sv_SE'
|
50
|
+
else
|
51
|
+
'en_US'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'shoppe/paytrail/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'shoppe-paytrail'
|
8
|
+
spec.version = Shoppe::Paytrail::VERSION
|
9
|
+
spec.authors = ['Joakim Antman']
|
10
|
+
spec.email = ['antmanj@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Shoppe module for handling Paytrail integration'
|
13
|
+
spec.homepage = 'https://github.com/anakinj/shoppe-paytrail'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_dependency 'shoppe', '> 1', '< 2'
|
20
|
+
spec.add_dependency 'paytrail-client', '~> 0.1'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shoppe-paytrail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joakim Antman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: shoppe
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: paytrail-client
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.1'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0.1'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.11'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.11'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '10.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.0'
|
89
|
+
description:
|
90
|
+
email:
|
91
|
+
- antmanj@gmail.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- ".gitignore"
|
97
|
+
- ".rspec"
|
98
|
+
- ".travis.yml"
|
99
|
+
- Gemfile
|
100
|
+
- LICENSE.txt
|
101
|
+
- README.md
|
102
|
+
- Rakefile
|
103
|
+
- config/locales/en.yml
|
104
|
+
- lib/shoppe/paytrail.rb
|
105
|
+
- lib/shoppe/paytrail/engine.rb
|
106
|
+
- lib/shoppe/paytrail/order_extensions.rb
|
107
|
+
- lib/shoppe/paytrail/version.rb
|
108
|
+
- shoppe-paytrail.gemspec
|
109
|
+
homepage: https://github.com/anakinj/shoppe-paytrail
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.4.6
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Shoppe module for handling Paytrail integration
|
133
|
+
test_files: []
|