scanpay 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6093d5e45c3d89d5d0a00932332b77480fc9302f
4
+ data.tar.gz: 3816e82d5806ccf80cda78133eafb099e741a380
5
+ SHA512:
6
+ metadata.gz: 8c6efd2da4e67b56d8b9cbbe412d1517d1a2c6faf2b5c93143a58b914158c616a91a0c3c6304b1d3827cbedb6a790303cf420590b6ea89937787d3bbfc022223
7
+ data.tar.gz: 87d7e4fd38b66776004915cb3b7aa0cf77eb4a3399123b4cc332ade055c501c838daeb00808d34ef84b8377a9d679042224bb830320e4aaf7fabcfff866ddfcf
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 scanpay
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.
@@ -0,0 +1,72 @@
1
+ require 'net/http'
2
+ require 'base64'
3
+ require 'json'
4
+ require 'openssl'
5
+ require 'httpclient'
6
+
7
+ module Scanpay
8
+
9
+ class Error < Exception
10
+ end
11
+
12
+ class Client
13
+ @httpclient
14
+ @apikey
15
+
16
+ def initialize(apikey)
17
+ @httpclient = HTTPClient.new
18
+ @httpclient.ssl_config.set_default_paths
19
+ @apikey = apikey
20
+ end
21
+
22
+ def consttime_streq(a, b)
23
+ return false if a.bytesize != b.bytesize
24
+ neq = 0
25
+ a.bytes.each_index { |i|
26
+ neq |= a.bytes[i] ^ b.bytes[i];
27
+ }
28
+ neq == 0
29
+ end
30
+
31
+ def request(uri, data, opts)
32
+ header = {
33
+ 'Authorization' => 'Basic ' + Base64.strict_encode64(@apikey),
34
+ 'X-Scanpay-SDK' => 'Ruby-1.0.0',
35
+ 'Content-Type' => 'application/json',
36
+ }
37
+ res = nil
38
+ if data == nil
39
+ res = @httpclient.get('https://api.scanpay.dk/v1' + uri, nil, header)
40
+ else
41
+ res = @httpclient.post('https://api.scanpay.dk/v1' + uri, data.to_json, header)
42
+ end
43
+ raise Error, 'Invalid API-key' if res.code == 403
44
+ raise Error, 'Unexpected http response code: ' + res.code.to_s unless res.code == 200
45
+ resobj = JSON.parse(res.body)
46
+ raise Error, 'Received error from Scanpay: ' + resobj['error'] if resobj['error'] != nil
47
+ resobj
48
+ end
49
+
50
+ def newURL(data)
51
+ resobj = request('/new', data, nil)
52
+ if !resobj.has_key? 'url'
53
+ raise Error, 'Missing url field'
54
+ end
55
+ resobj['url']
56
+ end
57
+
58
+ def seq(seqnum)
59
+ request('/seq/' + seqnum.to_s, nil, nil)
60
+ end
61
+
62
+ def handlePing(body, signature)
63
+ myrawsig = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), @apikey, body || '')
64
+ mysig = Base64.strict_encode64(myrawsig)
65
+ raise Error, 'invalid signature' unless consttime_streq(mysig, signature || '')
66
+ resobj = JSON.parse(body)
67
+ raise Error, 'missing fields' unless [resobj['shopid'], resobj['seq']].all? { |i| i.is_a?(Integer) }
68
+ resobj
69
+ end
70
+ private :request, :consttime_streq
71
+ end
72
+ end
@@ -0,0 +1,46 @@
1
+ require '../lib/scanpay'
2
+
3
+ client = Scanpay::Client.new(' API KEY ')
4
+ data = {
5
+ 'orderid' => 'a766409',
6
+ 'language' => 'da',
7
+ 'successurl' => 'https://insertyoursuccesspage.dk',
8
+ 'items' => [
9
+ {
10
+ 'name' => 'Pink Floyd: The Dark Side Of The Moon',
11
+ 'quantity' => 2,
12
+ 'price' => '99.99 DKK',
13
+ 'sku' => 'fadf23',
14
+ }, {
15
+ 'name' => '巨人宏偉的帽子',
16
+ 'quantity' => 2,
17
+ 'price' => '420 DKK',
18
+ 'sku' => '124',
19
+ },
20
+ ],
21
+ 'billing' => {
22
+ 'name' => 'John Doe',
23
+ 'company' => 'The Shop A/S',
24
+ 'email' => 'john@doe.com',
25
+ 'phone' => '+4512345678',
26
+ 'address' => ['Langgade 23, 2. th'],
27
+ 'city' => 'Havneby',
28
+ 'zip' => '1234',
29
+ 'state' => '',
30
+ 'country' => 'DK',
31
+ 'vatin' => '35413308',
32
+ 'gln' => '7495563456235',
33
+ },
34
+ 'shipping' => {
35
+ 'name' => 'Jan Dåh',
36
+ 'company' => 'The Choppa A/S',
37
+ 'email' => 'jan@doh.com',
38
+ 'phone' => '+4587654321',
39
+ 'address' => ['Langgade 23, 1. th', 'C/O The Choppa'],
40
+ 'city' => 'Haveby',
41
+ 'zip' => '1235',
42
+ 'state' => '',
43
+ 'country' => 'DK',
44
+ },
45
+ }
46
+ puts "Generated payment url: #{client.newURL(data)}"
@@ -0,0 +1,13 @@
1
+ require 'webrick'
2
+ require '../lib/scanpay'
3
+
4
+ client = Scanpay::Client.new(' API KEY ')
5
+
6
+ server = WEBrick::HTTPServer.new :Port => 8080
7
+ server.mount_proc '/' do |req, res|
8
+ ping = client.handlePing(req.body(), req.header['x-signature'][0])
9
+ puts 'Succesfully received ping: shopid=' + ping['shopid'].to_s + ', seq=' + ping['seq'].to_s
10
+ end
11
+
12
+ trap 'INT' do server.shutdown end
13
+ server.start
@@ -0,0 +1,18 @@
1
+ require '../lib/scanpay'
2
+
3
+ client = Scanpay::Client.new(' API KEY ')
4
+ seqobj = client.seq(3)
5
+
6
+ puts "After applying the changes your system will be at seq=#{seqobj['seq'].to_s}"
7
+ puts "Listing transaction changes(#{seqobj['changes'].length}) since old seq:"
8
+ seqobj['changes'].each do |trn|
9
+ puts " Tranaction id: #{trn['id'].to_s}"
10
+ if trn['error']
11
+ puts " Encountered error: #{trn['error']}"
12
+ next
13
+ end
14
+ puts " Order id: #{trn['orderid']}"
15
+ puts " Authorized: #{trn['totals']['authorized'].to_s}"
16
+ puts " Captured: #{trn['totals']['captured'].to_s}"
17
+ puts " Refunded: #{trn['totals']['refunded']}\n\n"
18
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scanpay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Scanpay
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httpclient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.8'
27
+ description: Accept payments with the Scanpay payment gateway. See https://scanpay.dk
28
+ for more details.
29
+ email: contact@scanpay.dk
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - LICENSE
36
+ - lib/scanpay.rb
37
+ - tests/newURL.rb
38
+ - tests/ping.rb
39
+ - tests/seq.rb
40
+ homepage: https://github.com/scanpaydk/ruby-scanpay
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.6.10
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Ruby bindings for the Scanpay API
64
+ test_files:
65
+ - tests/newURL.rb
66
+ - tests/ping.rb
67
+ - tests/seq.rb