pci_proxy 1.0.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
+ SHA256:
3
+ metadata.gz: 0d2e838d63aadc950a829e6d3b50e7c6fddcfffdb216ae9f7646d4dc06fbb930
4
+ data.tar.gz: 42b52b3106e60c53a75de4424f445edca6ddc9251c899f12f07dfeadee30b722
5
+ SHA512:
6
+ metadata.gz: e9c4197a8b75b8070f5174d0a64ffd3fdb374ce4e279bc45b0f2386be6ccfdda3172baac6b00c8ac795526ac45e92bd4e19f41a23f959c5df803643d0b46562a
7
+ data.tar.gz: 11735efca4a2ce834ea0c6a05906b38649796b999eda37e9f6b697d39bce4b494cc1e92ba376d41a67e5ba270376a91388da925173541c2a46a8b09ec76f3b0f
@@ -0,0 +1,10 @@
1
+ .DS_Store
2
+ /.idea/
3
+ /.bundle/
4
+ /.yardoc
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
@@ -0,0 +1 @@
1
+ ruby-2.6.5
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.8
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,7 @@
1
+ # PciProxy
2
+
3
+ A simple client library for [PCI Proxy](https://pci-proxy.com)'s API
4
+
5
+ #CHANGE LOG
6
+
7
+ v1.0.0 - 14th January 2020 - Initial release - covers the [Token API](https://docs.pci-proxy.com/collect-and-store-cards/capture-iframes/token-api)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in pci_proxy.gemspec
4
+ gemspec
@@ -0,0 +1,29 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pci_proxy (1.0.0)
5
+ faraday (~> 0.17.3)
6
+ multi_json (~> 1.14.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ faraday (0.17.3)
12
+ multipart-post (>= 1.2, < 3)
13
+ minitest (5.13.0)
14
+ multi_json (1.14.1)
15
+ multipart-post (2.1.1)
16
+ rake (10.5.0)
17
+
18
+ PLATFORMS
19
+ java
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 2.0)
24
+ minitest (~> 5.0)
25
+ pci_proxy!
26
+ rake (~> 10.0)
27
+
28
+ BUNDLED WITH
29
+ 2.1.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Rory Sinclair
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,67 @@
1
+ # PciProxy
2
+
3
+ A simple client library for [PCI Proxy](https://pci-proxy.com)'s API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pci_proxy', '~> 1.0.0'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pci_proxy
20
+
21
+ ## Usage
22
+
23
+ Initially, this gem only covers the [Token API](https://docs.pci-proxy.com/collect-and-store-cards/capture-iframes/token-api), which converts a transactionId from the [secure fields](https://docs.pci-proxy.com/collect-and-store-cards/capture-iframes) mechanism into tokenised card PAN and CVV.
24
+
25
+ Pull requests are most welcome for coverage of other PCI Proxy APIs :)
26
+ ### Token API - Usage
27
+
28
+ Create an instance of ```PciProxy::Token``` and call ```execute``` as follows:
29
+ ```ruby
30
+ client = PciProxy::Token.new(api_username: 'username', api_password: 'password')
31
+ ```
32
+
33
+ And execute a token exchange like so:
34
+ ```ruby
35
+ client.execute(transaction_id: '1234567890')
36
+ ```
37
+
38
+ In the event of a 200 OK response, the JSON response body is returned as a hash, for example:
39
+
40
+ ```ruby
41
+ {"aliasCC"=>"411111GGCMUJ1111", "aliasCVV"=>"vCslSwP0SQ9JXJy-nDzLKHaS"}
42
+ ```
43
+
44
+ In the event of an error, a subclass of ```PciProxyAPIError``` will be raised.
45
+
46
+ The most likely error is that the transactionId temporary token has expired, resulting in:
47
+
48
+ ```ruby
49
+ PciProxy::BadRequestError (HTTP status: 400, Response: Tokenization not found)
50
+ ```
51
+
52
+ ## Changes
53
+ See [Changelog](CHANGELOG.md)
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ 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).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/asmallworldsite/pci_proxy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pci_proxy"
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,22 @@
1
+ require 'bundler'
2
+ require "pci_proxy/version"
3
+
4
+ require 'pci_proxy/base'
5
+ require 'pci_proxy/token'
6
+
7
+ module PciProxy
8
+ PciProxyAPIError = Class.new(StandardError)
9
+ BadRequestError = Class.new(PciProxyAPIError)
10
+ UnauthorizedError = Class.new(PciProxyAPIError)
11
+ ForbiddenError = Class.new(PciProxyAPIError)
12
+ NotFoundError = Class.new(PciProxyAPIError)
13
+ UnprocessableEntityError = Class.new(PciProxyAPIError)
14
+
15
+ HTTP_OK_CODE = 200
16
+
17
+ HTTP_BAD_REQUEST_CODE = 400
18
+ HTTP_UNAUTHORIZED_CODE = 401
19
+ HTTP_FORBIDDEN_CODE = 403
20
+ HTTP_NOT_FOUND_CODE = 404
21
+ HTTP_UNPROCESSABLE_ENTITY_CODE = 429
22
+ end
@@ -0,0 +1,62 @@
1
+ require 'faraday'
2
+ require 'multi_json'
3
+
4
+ module PciProxy
5
+ class Base
6
+
7
+ attr_reader :api_endpoint, :api_username, :api_password
8
+
9
+ ##
10
+ # Create and memoise a Faraday client for this API client
11
+ def client
12
+ @client ||= Faraday.new(@api_endpoint) do |client|
13
+ client.request :url_encoded
14
+ client.adapter Faraday.default_adapter
15
+ client.basic_auth(@api_username, @api_password)
16
+ end
17
+ end
18
+
19
+ ##
20
+ # Perform the API request
21
+ #
22
+ # @param +endpoint+ [String] (Optional) - the API endpoint to hit - defaults to the value of the api_endpoint reader
23
+ # @param +http_method+ [Symbol] (Optional) - the HTTP method to use - defaults to GET
24
+ # @param +params+ [Hash] (Optional) - any parameters to supply to the API call
25
+ #
26
+ # @raise [PciProxyAPIError] in cases where the API responds with a non-200 response code
27
+ # @return [Hash] parsed JSON response
28
+ #
29
+ def request(endpoint: @api_endpoint, http_method: :get, params: {})
30
+ response = client.public_send(http_method, endpoint, params)
31
+
32
+ if response.status == HTTP_OK_CODE
33
+ return MultiJson.load(response.body)
34
+ end
35
+
36
+ raise error_class(response), "HTTP status: #{response.status}, Response: #{response.body}"
37
+ end
38
+
39
+ ##
40
+ # Fetch the error klass appropriate for the given Faraday +response+
41
+ #
42
+ # @param +response+ (Response) - the Faraday response object
43
+ # @return [StandardError] - the StandardError subclass appropriate to the +response+
44
+ def error_class(response)
45
+ case response.status
46
+ when HTTP_BAD_REQUEST_CODE
47
+ BadRequestError
48
+ when HTTP_UNAUTHORIZED_CODE
49
+ UnauthorizedError
50
+ when HTTP_FORBIDDEN_CODE
51
+ ForbiddenError
52
+ when HTTP_NOT_FOUND_CODE
53
+ NotFoundError
54
+ when HTTP_UNPROCESSABLE_ENTITY_CODE
55
+ UnprocessableEntityError
56
+ else
57
+ PciProxyAPIError
58
+ end
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,25 @@
1
+ module PciProxy
2
+ class Token < Base
3
+
4
+ ##
5
+ # Initialise with the specified +api_username+ and +api_password+ from PCI Proxy.
6
+ def initialize(api_username:, api_password:)
7
+ @api_endpoint = 'https://api.sandbox.datatrans.com/upp/services/v1/inline/token'.freeze
8
+ @api_username = api_username
9
+ @api_password = api_password
10
+ end
11
+
12
+ ##
13
+ # Perform a token request to turn the specified +transaction_id+ into card and CVV tokens
14
+ #
15
+ # @param +return_payment_method+ (true/false) - whether or not to return the identified payment method (default: true)
16
+ # @param +cvv_mandatory+ (true/false) - whether or not to consider the CVV alias should be mandatory (default: false)
17
+ #
18
+ # @raise [PciProxyAPIError] in cases where the API responds with a non-200 response code
19
+ # @return [Hash] result from PCI Proxy, decoded from JSON
20
+ def execute(transaction_id:, return_payment_method: true, cvv_mandatory: false)
21
+ request(params: { transactionId: transaction_id, returnPaymentMethod: return_payment_method, mandatoryAliasCVV: cvv_mandatory })
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module PciProxy
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "pci_proxy/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "pci_proxy"
7
+ spec.version = PciProxy::VERSION
8
+ spec.authors = ["Rory Sinclair"]
9
+ spec.email = ["rory@mungler.com"]
10
+
11
+ spec.summary = 'A client library for the PCI-Proxy service'
12
+ spec.description = 'A ruby library covering the server-server aspects of the PCI-Proxy API'
13
+ spec.homepage = "https://github.com/asmallworldsite/pci_proxy"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "https://github.com/asmallworldsite/pci_proxy/blob/master/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 2.0"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "minitest", "~> 5.0"
32
+
33
+ spec.add_dependency "faraday", "~> 0.17.3"
34
+ spec.add_dependency "multi_json", "~> 1.14.1"
35
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pci_proxy
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rory Sinclair
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-14 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.17.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.17.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: multi_json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.14.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.14.1
83
+ description: A ruby library covering the server-server aspects of the PCI-Proxy API
84
+ email:
85
+ - rory@mungler.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".ruby-version"
92
+ - ".travis.yml"
93
+ - CHANGELOG.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - lib/pci_proxy.rb
102
+ - lib/pci_proxy/base.rb
103
+ - lib/pci_proxy/token.rb
104
+ - lib/pci_proxy/version.rb
105
+ - pci_proxy.gemspec
106
+ homepage: https://github.com/asmallworldsite/pci_proxy
107
+ licenses:
108
+ - MIT
109
+ metadata:
110
+ homepage_uri: https://github.com/asmallworldsite/pci_proxy
111
+ source_code_uri: https://github.com/asmallworldsite/pci_proxy
112
+ changelog_uri: https://github.com/asmallworldsite/pci_proxy/blob/master/CHANGELOG.md
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
+ rubygems_version: 3.0.3
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: A client library for the PCI-Proxy service
132
+ test_files: []