teligem 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d4d4c4251c71acb20e927c26adef2f19791d0abc
4
+ data.tar.gz: f58cc447814ec1f03841050572127fdca9291fc9
5
+ SHA512:
6
+ metadata.gz: 6dabd55860d22a0e85f99113a448efaa2918eaa817fe4d9d8c1199c5d9c1609b5de2010eeceefec1e2c323264b60f37b3666ae5bd154163cbef659da691f4446
7
+ data.tar.gz: 9943af1a13908ef451169a42d46230204cce6efe02d1431a5c2dcf38d9e58aaa490e11d55ac0c91bd08566825d9a31c62f13db4f242b7b3e2ae545e16e6e27f4
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,29 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ teligem (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rspec (3.3.0)
11
+ rspec-core (~> 3.3.0)
12
+ rspec-expectations (~> 3.3.0)
13
+ rspec-mocks (~> 3.3.0)
14
+ rspec-core (3.3.2)
15
+ rspec-support (~> 3.3.0)
16
+ rspec-expectations (3.3.1)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.3.0)
19
+ rspec-mocks (3.3.2)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.3.0)
22
+ rspec-support (3.3.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ rspec
29
+ teligem!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 CT2C
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.
22
+
data/README.markdown ADDED
@@ -0,0 +1,81 @@
1
+ # Teligem
2
+
3
+ Teligem allows you to integrate the notifications of the [Telipass](https://telipass.com/) solution.
4
+
5
+ ## INSTALL
6
+
7
+ In your Gemfile
8
+
9
+ ```ruby
10
+ gem 'teligem'
11
+ ```
12
+
13
+ Then run 'bundle install'
14
+
15
+ ## SETUP
16
+
17
+ ### MODEL
18
+
19
+ When a payment has been made, Telipass sends to the notification url those parameters.
20
+ Pick the ones you are interested in and put it in your payment model.
21
+
22
+ You must at least have those attributes: security_code:string, enduser_ip:string and ntu:string,
23
+ as they are used to check if the payment really comes from the Telipass plateform.
24
+
25
+ ```ruby
26
+ # Security
27
+ t.string :security_code # SecurityCode
28
+ # User Infos
29
+ t.string :enduser_ip # UserIP
30
+ t.string :enduser_host # Userhost
31
+ t.string :enduser_useragent # UserAgent
32
+ t.string :enduser_userlanguage # Webbrowser language
33
+ t.string :enduser_plateform # Exploitation system
34
+ # Transaction
35
+ t.string :ntu, null: false # Unique transaction number (NTU)
36
+ t.string :module_name # Name of the payment module
37
+ t.string :module_id # Module ID
38
+ t.string :site_name # Website name
39
+ t.string :solution_name # Payment solution name
40
+ t.string :payment_method # Payment used name
41
+ t.string :point_name # Point name
42
+ t.string :country_code # Country code name
43
+ t.string :country_name # Country name
44
+ t.integer :credits # Credits (only for virtual money)
45
+ t.decimal :amount # Commission
46
+ t.integer :status # Transaction status
47
+ # 1 = Valid, 2 = Rejected, 3 = Differed, 4 = Test
48
+ t.string :status_text # Transaction status in text
49
+ t.date :transaction_date # Transaction date
50
+ t.string :transaction_id # Transaction ID
51
+ t.string :custom # Custom parameters
52
+ ```
53
+
54
+ ### RAILS SECRETS
55
+
56
+ Add to your config/secrets.yml (don't forget to add it to .gitignore)
57
+
58
+ ```ruby
59
+ telikey: "your-telipass-key"
60
+ ```
61
+
62
+ ## USAGE
63
+
64
+ To check if the payment really comes from the Telipass website, set your params and just call call:
65
+
66
+ ```ruby
67
+ params = {
68
+ security_code: params[:security_code],
69
+ enduser_ip: params[:enduser_ip],
70
+ ntu: params[:ntu]
71
+ }
72
+
73
+ Telipass.new.security_check(params)
74
+ ```
75
+
76
+ It will return true if the payment really comes from Telipass, otherwise it will return false.
77
+
78
+ ## How to contribute?
79
+ * Fork this repository
80
+ * Create a branch to add some functionalities or solve some bugs
81
+ * Make a pull request - I will try to review and merge it asap
@@ -0,0 +1 @@
1
+ telikey: "123456"
data/lib/teligem.rb ADDED
@@ -0,0 +1,39 @@
1
+ #encoding: utf-8
2
+ require 'yaml'
3
+
4
+ class Teligem
5
+
6
+ def initialize
7
+ @configs = YAML.load_file("config/secrets.yml")
8
+ end
9
+
10
+ # === security_check(params)
11
+ # Hash that must at least contains:
12
+ # * security_code: the security code sent by telipass
13
+ # * enduser_ip: the enduser ip address
14
+ # * ntu: unique transaction number sent by telipass
15
+ def security_check(params)
16
+ security_code = params[:security_code]
17
+ enduser_ip = params[:enduser_ip]
18
+ ntu = params[:ntu]
19
+
20
+ unless security_code.nil? || enduser_ip.nil? || ntu.nil?
21
+ hash = get_security_code(enduser_ip, ntu)
22
+ end
23
+
24
+ if !hash.nil? && (security_code == hash)
25
+ response = true
26
+ else
27
+ response = false
28
+ end
29
+
30
+ return response
31
+ end
32
+
33
+ private
34
+ def get_security_code(enduser_ip, ntu)
35
+ code = enduser_ip + ntu + @configs['telikey']
36
+ Digest::MD5.hexdigest(code)
37
+ end
38
+
39
+ end
@@ -0,0 +1,44 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require "spec_helper"
3
+
4
+ RSpec.describe Teligem do
5
+
6
+ describe '#security_check' do
7
+ before(:each) do
8
+ @enduser_ip = "123456"
9
+ @ntu = "123456"
10
+
11
+ hash = YAML.load_file("config/secrets.yml")
12
+ code = @enduser_ip + @ntu + hash['telikey']
13
+ @security_code = Digest::MD5.hexdigest(code)
14
+ end
15
+ context 'when request comes from telipass' do
16
+ it 'should set response to true' do
17
+ @params = {
18
+ security_code: @security_code,
19
+ enduser_ip: @enduser_ip,
20
+ ntu: @ntu
21
+ }
22
+
23
+ response = Teligem.new.security_check(@params)
24
+
25
+ expect(response).to be true
26
+ end
27
+ end
28
+
29
+ context 'when not from telipass plateform' do
30
+ it 'should set response to false' do
31
+ @params = {
32
+ security_code: "not_matching_security_code",
33
+ enduser_ip: @enduser_ip,
34
+ ntu: @ntu
35
+ }
36
+
37
+ response = Teligem.new.security_check(@params)
38
+
39
+ expect(response).to be false
40
+ end
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,102 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ require 'bundler/setup'
20
+ Bundler.setup
21
+
22
+ require 'teligem'
23
+
24
+ RSpec.configure do |config|
25
+ # rspec-expectations config goes here. You can use an alternate
26
+ # assertion/expectation library such as wrong or the stdlib/minitest
27
+ # assertions if you prefer.
28
+
29
+ config.expect_with :rspec do |expectations|
30
+ # This option will default to `true` in RSpec 4. It makes the `description`
31
+ # and `failure_message` of custom matchers include text for helper methods
32
+ # defined using `chain`, e.g.:
33
+ # be_bigger_than(2).and_smaller_than(4).description
34
+ # # => "be bigger than 2 and smaller than 4"
35
+ # ...rather than:
36
+ # # => "be bigger than 2"
37
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
38
+ end
39
+
40
+ # rspec-mocks config goes here. You can use an alternate test double
41
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
42
+ config.mock_with :rspec do |mocks|
43
+ # Prevents you from mocking or stubbing a method that does not exist on
44
+ # a real object. This is generally recommended, and will default to
45
+ # `true` in RSpec 4.
46
+ mocks.verify_partial_doubles = true
47
+ end
48
+
49
+ # The settings below are suggested to provide a good initial experience
50
+ # with RSpec, but feel free to customize to your heart's content.
51
+ =begin
52
+ # These two settings work together to allow you to limit a spec run
53
+ # to individual examples or groups you care about by tagging them with
54
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
55
+ # get run.
56
+ config.filter_run :focus
57
+ config.run_all_when_everything_filtered = true
58
+
59
+ # Allows RSpec to persist some state between runs in order to support
60
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
61
+ # you configure your source control system to ignore this file.
62
+ config.example_status_persistence_file_path = "spec/examples.txt"
63
+
64
+ # Limits the available syntax to the non-monkey patched syntax that is
65
+ # recommended. For more details, see:
66
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
67
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
68
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
69
+ config.disable_monkey_patching!
70
+
71
+ # This setting enables warnings. It's recommended, but in some cases may
72
+ # be too noisy due to issues in dependencies.
73
+ config.warnings = true
74
+
75
+ # Many RSpec users commonly either run the entire suite or an individual
76
+ # file, and it's useful to allow more verbose output when running an
77
+ # individual spec file.
78
+ if config.files_to_run.one?
79
+ # Use the documentation formatter for detailed output,
80
+ # unless a formatter has already been configured
81
+ # (e.g. via a command-line flag).
82
+ config.default_formatter = 'doc'
83
+ end
84
+
85
+ # Print the 10 slowest examples and example groups at the
86
+ # end of the spec run, to help surface which specs are running
87
+ # particularly slow.
88
+ config.profile_examples = 10
89
+
90
+ # Run specs in random order to surface order dependencies. If you find an
91
+ # order dependency and want to debug it, you can fix the order by providing
92
+ # the seed, which is printed after each run.
93
+ # --seed 1234
94
+ config.order = :random
95
+
96
+ # Seed global randomization in this process using the `--seed` CLI option.
97
+ # Setting this allows you to use `--seed` to deterministically reproduce
98
+ # test failures related to randomization by passing the same `--seed` value
99
+ # as the one that triggered the failure.
100
+ Kernel.srand config.seed
101
+ =end
102
+ end
data/teligem.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'teligem'
3
+ s.version = '0.0.2'
4
+ s.date = '2015-07-22'
5
+ s.platform = Gem::Platform::RUBY
6
+ s.summary = "A gem to implement Telipass micropayment"
7
+ s.description = "A gem to implement Telipass micropayment notifications for basic payments"
8
+
9
+ s.authors = ["Arpsara, CT2C"]
10
+ s.email = 'contact@ct2c.fr'
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.require_paths = ["lib"]
14
+
15
+ s.add_development_dependency "rspec"
16
+
17
+ s.homepage = 'https://github.com/ct2c/teligem.git'
18
+ s.license = 'MIT'
19
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: teligem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Arpsara, CT2C
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A gem to implement Telipass micropayment notifications for basic payments
28
+ email: contact@ct2c.fr
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .rspec
34
+ - Gemfile
35
+ - Gemfile.lock
36
+ - LICENSE
37
+ - README.markdown
38
+ - config/secrets.yml
39
+ - lib/teligem.rb
40
+ - spec/lib/teligem_spec.rb
41
+ - spec/spec_helper.rb
42
+ - teligem.gemspec
43
+ homepage: https://github.com/ct2c/teligem.git
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.4.3
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: A gem to implement Telipass micropayment
67
+ test_files: []