digistore24 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f18a71470dbbfe186cffdc587c8c85677e38929045d4d942bbd9c25dfccbef54
4
+ data.tar.gz: f911ca74a16b8cd3221eaf71332e0683b2062c03c4735eb3214ff43237e6c1ee
5
+ SHA512:
6
+ metadata.gz: 694e0b7bafdbef4fad569d62e59910de4dd86df878b28836a65d35bff63cdd805144e0bc3a3d02ba817b7f717d7733f51075bd0a5ff3ec458e5f516e3b8e76e8
7
+ data.tar.gz: 5254b4d65f449beeb8909dc6ecb075ca8ba7bef34feb5597404759e2a5a1bb9b2fa424199133630dd45fc0e34a0aca2a24031cf508c9775c38afde3ac6e8dc84
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
@@ -0,0 +1,4 @@
1
+ ---
2
+ UncommunicativeModuleName:
3
+ accept:
4
+ - Digistore24
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,3 @@
1
+ Metrics/LineLength:
2
+ Exclude:
3
+ - *.gemspec
@@ -0,0 +1,9 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5
7
+ - 2.2
8
+ script:
9
+ - bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in digistore24.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Henning Vogt
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.
@@ -0,0 +1,52 @@
1
+ # Digistore24
2
+ [![Build Status](https://travis-ci.org/henvo/digistore24.svg?branch=master)](https://travis-ci.org/henvo/digistore24)
3
+
4
+ Digistore24 IPN integration library for rails and other web applications.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'digistore24'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install digistore24
21
+
22
+ ## Usage
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ ## Configuration
27
+
28
+ You can configure this gem by running:
29
+
30
+ ``` ruby
31
+ Digistore24.configure |config|
32
+ config.passphrase = 'xxxxx'
33
+ end
34
+ ```
35
+
36
+ You can define any key here. But you have to provide at least:
37
+
38
+ * `passphrase` The IPN passphrase
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/henvo/digistore24.
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "digistore24"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'digistore24/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'digistore24'
8
+ spec.version = Digistore24::VERSION
9
+ spec.authors = ['Henning Vogt']
10
+ spec.email = ['git@henvo.de']
11
+
12
+ spec.summary = 'Digistore24 IPN integration library for rails and ' \
13
+ 'other web applications.'
14
+ spec.homepage = 'https://github.com/henvo/digistore24'
15
+ spec.license = 'MIT'
16
+
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = spec.homepage
22
+ else
23
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
24
+ 'public gem pushes.'
25
+ end
26
+
27
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
+ `git ls-files -z`.split("\x0")
29
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = 'exe'
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ['lib']
34
+
35
+ spec.add_dependency 'recursive-open-struct', '~> 1.1'
36
+
37
+ spec.add_development_dependency 'bundler', '~> 1.17'
38
+ spec.add_development_dependency 'rake', '~> 10.0'
39
+ spec.add_development_dependency 'rspec', '~> 3.0'
40
+ spec.add_development_dependency 'simplecov', '~> 0.16.1'
41
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'recursive_open_struct'
4
+
5
+ require 'digistore24/version'
6
+ require 'digistore24/notification'
7
+
8
+ # The main module for all Digistore24 related models and methods.
9
+ module Digistore24
10
+ class << self
11
+ attr_writer :configuration
12
+
13
+ # Returns the gem wide configuration.
14
+ #
15
+ # @return [RecursiveOpenStruct]
16
+ def configuration
17
+ @configuration ||= RecursiveOpenStruct.new
18
+ end
19
+
20
+ # Configure the gem wide configuration object.
21
+ # There are currently no regulations on what to store inside this object
22
+ # - any key is allowed.
23
+ #
24
+ # @example:
25
+ # Digistore24.configure do |config|
26
+ # config.passphrase = 'xxxxx'
27
+ # end
28
+ def configure
29
+ yield(configuration)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+
5
+ module Digistore24
6
+ # A basic NotificationError that implies that there is an error.
7
+ class NotificationError < StandardError; end
8
+
9
+ # The main notification class which represents an Instant Payment
10
+ # Notification (IPN).
11
+ class Notification
12
+ attr_reader :payload
13
+
14
+ # Initialize the notification.
15
+ #
16
+ # @param params [Hash] The request parameters from Digistore24.
17
+ # @return [Notification]
18
+ def initialize(params)
19
+ @payload = RecursiveOpenStruct.new(params)
20
+ end
21
+
22
+ # Calculate SHA512 signature for payload.
23
+ #
24
+ # @return [String] The signature.
25
+ def signature
26
+ # Remove 'sha_sign' key from request params and concatenate all
27
+ # key value pairs
28
+ params = payload.to_h
29
+ .reject { |key, value| key == :sha_sign }.sort
30
+ .map { | key, value| "#{key}=#{value}#{passphrase}" }.join
31
+
32
+ # Calculate SHA512 and upcase all letters, since Digistore will
33
+ # also return upcased letters in the signature.
34
+ Digest::SHA512.hexdigest(params).upcase
35
+ end
36
+
37
+ # Checks if the provided sha_sign is valid.
38
+ #
39
+ # @return [Booleand] The answer
40
+ def valid?
41
+ # If payload does not contain the sha_sign definitely return false.
42
+ return false unless payload.sha_sign
43
+
44
+ signature == payload.sha_sign
45
+ end
46
+
47
+ # Checks the request parameters signature and raises an error if it
48
+ # does not equal to the calculated signature.
49
+ #
50
+ # @return [NilClass]
51
+ # @raise [Digistore24::NotificationError]
52
+ def validate!
53
+ return if valid?
54
+ raise NotificationError, 'Request signature invalid!'
55
+ end
56
+
57
+ def to_h
58
+ payload.to_h
59
+ end
60
+ alias_method :to_hash, :to_h
61
+
62
+
63
+ private
64
+
65
+ # Return the passphrase from the global configuration.
66
+ #
67
+ # @return [String] The passphrase
68
+ def passphrase
69
+ Digistore24.configuration.passphrase
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Digistore24
4
+ VERSION = '0.1.0'.freeze
5
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: digistore24
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Henning Vogt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: recursive-open-struct
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.16.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.16.1
83
+ description:
84
+ email:
85
+ - git@henvo.de
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".reek.yml"
92
+ - ".rspec"
93
+ - ".rubocop.yml"
94
+ - ".travis.yml"
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - digistore24.gemspec
103
+ - lib/digistore24.rb
104
+ - lib/digistore24/notification.rb
105
+ - lib/digistore24/version.rb
106
+ homepage: https://github.com/henvo/digistore24
107
+ licenses:
108
+ - MIT
109
+ metadata:
110
+ allowed_push_host: https://rubygems.org
111
+ homepage_uri: https://github.com/henvo/digistore24
112
+ source_code_uri: https://github.com/henvo/digistore24
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.7.6
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Digistore24 IPN integration library for rails and other web applications.
133
+ test_files: []