sagepay_protocol3 0.1.0

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: f30c0dcebb7611d5a7409640ac070c1df0b75a68
4
+ data.tar.gz: c2dee42a6c0d0de1200bf9d3a22cc07048f32065
5
+ SHA512:
6
+ metadata.gz: eaf224c217d849fff84e62750c34cad9d6d3d4e64cb47704263d56c6cf4495c05d47f0c4ba1fc965dccd624cc39a3ff15d2b3439e94fef8580cd9c4afb9cd33b
7
+ data.tar.gz: 07123d3bfd3ebeda25c496f16323ef18d0f7375be2f4b9823cff825b6e5ec7fae80726b1d349edb55ee9df41c0c7ce72fe801b46629d754fc28d57db9f348e93
data/.gitignore ADDED
@@ -0,0 +1,33 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ # Vim
20
+ *.swp
21
+ *.swo
22
+
23
+ # Backup
24
+ *~
25
+
26
+ # Mac
27
+ .DS_Store
28
+
29
+ # RVM
30
+ .rvmrc
31
+
32
+ # CTAGS
33
+ tags
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ script: "bundle exec rspec"
3
+ before_install:
4
+ - gem install bundler -v '>= 1.3'
5
+ rvm:
6
+ - 1.9.3
7
+ - 1.9.3-p448
8
+ - 2.0.0
9
+ - 2.1.3
10
+ gemfile:
11
+ - Gemfile
12
+ notifications:
13
+ email: false
14
+
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --markup-provider=redcarpet
2
+ --markup=markdown
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sagepay_protocol3.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,23 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :cli => "--color --format documentation --fail-fast", :all_on_start => false, :all_after_pass => false do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Michael de Silva
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,39 @@
1
+ # SagepayProtocol3
2
+
3
+ [![Build Status](https://travis-ci.org/bsodmike/sagepay_protocol3.png?branch=master)](https://travis-ci.org/bsodmike/sagepay_protocol3)
4
+
5
+ Encryption in Ruby to interface with SagePay's payment gateway protocol v3.
6
+
7
+ ## Compatibility
8
+
9
+ * Supports multiple Ruby versions: Ruby 1.9.3, 2.0.0, 2.1.3 (see
10
+ Travis build status).
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'sagepay_protocol3'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install sagepay_protocol3
25
+
26
+ ## API Summary
27
+
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
36
+
37
+ ## License
38
+
39
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,40 @@
1
+ require 'openssl'
2
+
3
+ module SagepayProtocol3
4
+
5
+ module Encryption
6
+ extend self
7
+
8
+ def cipher(operation, cipher, cipher_key)
9
+ lambda do |data, padding|
10
+ c = OpenSSL::Cipher.new(cipher)
11
+ c.send(operation)
12
+ c.padding = padding
13
+ c.key = cipher_key
14
+ c.iv = cipher_key
15
+ c.update(data) + c.final
16
+ end
17
+ end
18
+
19
+ def decrypt(cipher_key, data, cipher = "AES-128-CBC")
20
+ hex = data.gsub(/\A(@)/, '')
21
+ input = [hex].pack('H*')
22
+ output = cipher(:decrypt, cipher, cipher_key)[input, 0]
23
+ sanitize_payload output
24
+ end
25
+
26
+ def encrypt(cipher_key, data, cipher = "AES-128-CBC")
27
+ _encrypted = cipher(:encrypt, cipher, cipher_key)[data, 1]
28
+ "@#{_encrypted.unpack('H*').first.upcase}"
29
+ end
30
+
31
+ def sanitize_payload(string)
32
+ string.gsub(/\005/, '').gsub("\r", '').gsub("\n", '')
33
+ end
34
+
35
+ def to_h(crypt_string)
36
+ Hash[*crypt_string.split(/[=&]/)]
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,3 @@
1
+ module SagepayProtocol3
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "sagepay_protocol3/version"
2
+
3
+ module SagepayProtocol3
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sagepay_protocol3/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sagepay_protocol3"
8
+ spec.version = SagepayProtocol3::VERSION
9
+ spec.authors = ["Michael de Silva"]
10
+ spec.email = ["michael@mwdesilva.com"]
11
+ spec.homepage = "http://mwdesilva.com"
12
+ spec.summary = "Encryption in Ruby to interface with SagePay's payment gateway protocol v3."
13
+ spec.description = spec.summary
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.required_ruby_version = '>= 1.8.7'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "mocha"
28
+ #spec.add_development_dependency "guard-rspec"
29
+ spec.add_development_dependency "yard"
30
+ spec.add_development_dependency "redcarpet"
31
+ end
@@ -0,0 +1,88 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'sagepay_protocol3/encryption'
4
+
5
+ module SagepayProtocol3
6
+
7
+ describe Encryption do
8
+ module TestRunner
9
+ extend self
10
+
11
+ def cipher_text
12
+ "@2DCD27338114D4C39A14A855702FBAB2EF40BCAC2D76A3ABC0F660A07E9C1C921C2C755BA9B59C39F882FBF6DFED114F23141D94E50A01A665B1E31A86C07CA1CD1BB8EF5B6CF2C23D495CD79F9C0F678D61773E7A1AA30AA5B23D56503FC0B52AC0694A8C341263D2C5FE1BAD93BDB94726761E155E900448F644AF1F67BE1AC77E852B9D90809A44F258EE9478B6D8C1C4ED58759263E7DBF8871C6592287C0358F36F4EEC326CEDDD440DA2FED8AB35F1B630A5C6FA671E4D78CC8CACECF9DFDC31D6C5EC8270FB21E297E2C2E14F99A04223EFFD4F00062D440E78A3D2C7140EC8F123D247B75E7482AE98858DA34D37EDE6D7C69AA74391F559305CF675ADB3615244A107ABBB6AF26E29A2FFA059B12688D90FE09E0DE069325BFF3587A695F5DA36E4B809B69CC9A37034F166B63B5A62B986F4DA34E9AC9516AFDE70642EC7DAD1AEBA93A1F347D6AC7046E967DCBFE7ACFCEE5DAFC0B29F1765032B3060EBE565CBD57D092075D15CF12725199C6881605B2E0F105698CE3ADD04361CA9D620C187B90E3F9849445B5C3C0FDF1768BFFD61F97E51316826F4F10E0E3E668F0A9F5ED9CCDA6F2C7CC957F12DB48F9041482E3D035E7A91852C404BFA325FED947E71F57B871DFAC6AF4FF29F4513A4A80B2D7ECC9D19D47ED04FA99CDFC881DFA771E1EA4F3F9B2C5AC673EF3DA2699A309CC8522993A63CB8D45D3CDF09B1DFDC573CD19679B250AD6721450B5042F201670B464505DCAEF59E2C67ABACC9AE2EEE793CE191FEBF66B8FAF4204EFFB359246B9C99FB52805C46375FF35140F74707FBC73C7731A28A2C883A"
13
+ end
14
+
15
+ def crypt_string
16
+ "VendorTxCode=TxCode-1310917599-223087284&Amount=36.95&Currency=GBP&Description=description&CustomerName=Fname Surname&CustomerEMail=customer@example.com&BillingSurname=Surname&BillingFirstnames=Fname&BillingAddress1=BillAddress Line 1&BillingCity=BillCity&BillingPostCode=W1A 1BL&BillingCountry=GB&BillingPhone=447933000000&DeliveryFirstnames=Fname&DeliverySurname=Surname&DeliveryAddress1=BillAddress Line 1&DeliveryCity=BillCity&DeliveryPostCode=W1A 1BL&DeliveryCountry=GB&DeliveryPhone=447933000000&SuccessURL=https://example.com/success&FailureURL=https://example.com/failure"
17
+
18
+ end
19
+ end
20
+
21
+ it "should be a Module" do
22
+ expect(described_class).to be_a(Module)
23
+ end
24
+
25
+ context "when provided a known cipher text and encryption key" do
26
+ describe "#decrypt" do
27
+ it "should decrypt the cipher text yielding the crypt string" do
28
+ cipher_text = TestRunner.cipher_text
29
+ encryption_key = "55a51621a6648525"
30
+
31
+ result = SagepayProtocol3::Encryption.decrypt(encryption_key, cipher_text)
32
+
33
+ expect(result).to eq(TestRunner.crypt_string)
34
+ end
35
+ end
36
+
37
+ describe "#encrypt" do
38
+ it "should encrypt the crypt string yielding the cipher text" do
39
+ crypt_string = TestRunner.crypt_string
40
+ encryption_key = "55a51621a6648525"
41
+
42
+ result = SagepayProtocol3::Encryption.encrypt(encryption_key, crypt_string)
43
+
44
+ expect(result).to eq(TestRunner.cipher_text)
45
+ end
46
+ end
47
+
48
+ describe "#to_h" do
49
+ it "should return the crypt_string data as a Hash" do
50
+ cipher_text = TestRunner.cipher_text
51
+ encryption_key = "55a51621a6648525"
52
+
53
+ result = SagepayProtocol3::Encryption.decrypt(encryption_key, cipher_text)
54
+
55
+ expect(result).to eq(TestRunner.crypt_string)
56
+ expect(SagepayProtocol3::Encryption.to_h(result)).to eq(
57
+ {
58
+ "Amount" => "36.95",
59
+ "BillingAddress1" => "BillAddress Line 1",
60
+ "BillingCity" => "BillCity",
61
+ "BillingCountry" => "GB",
62
+ "BillingFirstnames" => "Fname",
63
+ "BillingPhone" => "447933000000",
64
+ "BillingPostCode" => "W1A 1BL",
65
+ "BillingSurname" => "Surname",
66
+ "Currency" => "GBP",
67
+ "CustomerEMail" => "customer@example.com",
68
+ "CustomerName" => "Fname Surname",
69
+ "DeliveryAddress1" => "BillAddress Line 1",
70
+ "DeliveryCity" => "BillCity",
71
+ "DeliveryCountry" => "GB",
72
+ "DeliveryFirstnames" => "Fname",
73
+ "DeliveryPhone" => "447933000000",
74
+ "DeliveryPostCode" => "W1A 1BL",
75
+ "DeliverySurname" => "Surname",
76
+ "Description" => "description",
77
+ "FailureURL" => "https://example.com/failure",
78
+ "SuccessURL" => "https://example.com/success",
79
+ "VendorTxCode" => "TxCode-1310917599-223087284"
80
+ }
81
+ )
82
+ end
83
+ end
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe SagepayProtocol3 do
5
+
6
+ it "should be a Module" do
7
+ expect(described_class).to be_a(Module)
8
+ end
9
+
10
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ require 'sagepay_protocol3'
3
+ require 'mocha/api'
4
+ require 'pry'
5
+
6
+ # This file was generated by the `rspec --init` command. Conventionally, all
7
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
+ # Require this file using `require "spec_helper"` to ensure that it is only
9
+ # loaded once.
10
+ #
11
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
12
+ RSpec.configure do |config|
13
+ config.mock_with :mocha
14
+
15
+ config.treat_symbols_as_metadata_keys_with_true_values = true
16
+ config.run_all_when_everything_filtered = true
17
+ config.filter_run :focus
18
+
19
+ # Run specs in random order to surface order dependencies. If you find an
20
+ # order dependency and want to debug it, you can fix the order by providing
21
+ # the seed, which is printed after each run.
22
+ # --seed 1234
23
+ config.order = 'random'
24
+
25
+ # Disable should syntax
26
+ config.expect_with :rspec do |c|
27
+ c.syntax = :expect
28
+ end
29
+ end
30
+
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sagepay_protocol3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael de Silva
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-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
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: redcarpet
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Encryption in Ruby to interface with SagePay's payment gateway protocol
112
+ v3.
113
+ email:
114
+ - michael@mwdesilva.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - .rspec
121
+ - .travis.yml
122
+ - .yardopts
123
+ - Gemfile
124
+ - Guardfile
125
+ - MIT-LICENSE
126
+ - README.md
127
+ - Rakefile
128
+ - lib/sagepay_protocol3.rb
129
+ - lib/sagepay_protocol3/encryption.rb
130
+ - lib/sagepay_protocol3/version.rb
131
+ - sagepay_protocol3.gemspec
132
+ - spec/plugin/encryption_spec.rb
133
+ - spec/plugin/sagepay_protocol3_spec.rb
134
+ - spec/spec_helper.rb
135
+ homepage: http://mwdesilva.com
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: 1.8.7
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.1.11
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Encryption in Ruby to interface with SagePay's payment gateway protocol v3.
159
+ test_files:
160
+ - spec/plugin/encryption_spec.rb
161
+ - spec/plugin/sagepay_protocol3_spec.rb
162
+ - spec/spec_helper.rb
163
+ has_rdoc: