opayo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gem-release.yml +5 -0
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/changelog.yml +37 -0
- data/.github/workflows/standardrb.yml +33 -0
- data/.github/workflows/test.yml +33 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +86 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/opayo.rb +12 -0
- data/lib/opayo/client.rb +81 -0
- data/lib/opayo/configuration.rb +35 -0
- data/lib/opayo/error.rb +10 -0
- data/lib/opayo/response.rb +28 -0
- data/lib/opayo/struct/base.rb +14 -0
- data/lib/opayo/struct/merchant_session_key.rb +8 -0
- data/lib/opayo/version.rb +3 -0
- data/opayo.gemspec +27 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a5d4cd10581167bbe065fbb03034f70a9dfbba1b424d1463773aee64c0e417e7
|
4
|
+
data.tar.gz: 983c4d16226c97e12082c09688153e40b7919d50499fc4ce1d0af21d488e23bc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8dc7811ca0e707590624f4a9bf4b4e8168396f72942309946938d465b8cbfcfff9bf54219d06497f2a6358a9a75cb0ad975000676004fdbf2f72e0181fb42598
|
7
|
+
data.tar.gz: 5e7fd373a67dbe2ad4fe12163c6b4a7f48ec0dedcc16a153ecf0730f616ae2a7eb8815ce7517330a3065f8d22b756f232e5c04a07ca1628e99289e8b0359981d
|
data/.gem-release.yml
ADDED
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
github: peterberkenbosch
|
@@ -0,0 +1,37 @@
|
|
1
|
+
name: Changelog
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
build:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
timeout-minutes: 4
|
12
|
+
if: "!contains(github.event.head_commit.message, '[nodoc]')"
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@master
|
15
|
+
- name: Set up Ruby 2.6
|
16
|
+
uses: actions/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: 2.6.x
|
19
|
+
- uses: actions/cache@v1.1.2
|
20
|
+
with:
|
21
|
+
path: vendor/bundle
|
22
|
+
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
|
23
|
+
restore-keys: |
|
24
|
+
${{ runner.os }}-gem-
|
25
|
+
- name: Create local changes
|
26
|
+
run: |
|
27
|
+
gem install github_changelog_generator
|
28
|
+
github_changelog_generator -u peterberkenbosch -p opayo --token ${{ secrets.CHANGELOG_GITHUB_TOKEN }} --exclude-labels duplicate,question,invalid,wontfix,nodoc
|
29
|
+
- name: Commit files
|
30
|
+
run: |
|
31
|
+
git config --local user.email "github-actions@example.com"
|
32
|
+
git config --local user.name "GitHub Actions"
|
33
|
+
git commit -m "[nodoc] update changelog" -a
|
34
|
+
- name: Push changes
|
35
|
+
uses: ad-m/github-push-action@master
|
36
|
+
with:
|
37
|
+
github_token: ${{ secrets.CHANGELOG_GITHUB_TOKEN }}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: StandardRB
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- '*'
|
7
|
+
push:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
standard:
|
13
|
+
name: StandardRB Check Action
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@master
|
17
|
+
- name: Set up Ruby 2.6
|
18
|
+
uses: actions/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: 2.6.x
|
21
|
+
- uses: actions/cache@v1
|
22
|
+
with:
|
23
|
+
path: vendor/bundle
|
24
|
+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
25
|
+
restore-keys: |
|
26
|
+
${{ runner.os }}-gems-
|
27
|
+
- name: Bundle install
|
28
|
+
run: |
|
29
|
+
gem install bundler
|
30
|
+
bundle config path vendor/bundle
|
31
|
+
bundle install --jobs 4 --retry 3
|
32
|
+
- name: Run StandardRB
|
33
|
+
run: bundle exec standardrb --format progress
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- '*'
|
7
|
+
push:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
ruby_test:
|
13
|
+
name: Ruby Test Action
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@master
|
17
|
+
- name: Set up Ruby 2.6
|
18
|
+
uses: actions/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: 2.6.x
|
21
|
+
- uses: actions/cache@v1
|
22
|
+
with:
|
23
|
+
path: vendor/bundle
|
24
|
+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
25
|
+
restore-keys: |
|
26
|
+
${{ runner.os }}-gems-
|
27
|
+
- name: Bundle install
|
28
|
+
run: |
|
29
|
+
gem install bundler
|
30
|
+
bundle config path vendor/bundle
|
31
|
+
bundle install --jobs 4 --retry 3
|
32
|
+
- name: Run ruby tests
|
33
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at info@peterberkenbosch.nl. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in opayo.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem "rake", "~> 13.0"
|
7
|
+
gem "rspec", "~> 3.0"
|
8
|
+
gem "webmock", "~> 3.8"
|
9
|
+
gem "pry"
|
10
|
+
gem "standard"
|
11
|
+
gem "simplecov", require: false, group: :test
|
12
|
+
|
13
|
+
gem "gem-release"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
opayo (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.7.0)
|
10
|
+
public_suffix (>= 2.0.2, < 5.0)
|
11
|
+
ast (2.4.1)
|
12
|
+
coderay (1.1.3)
|
13
|
+
crack (0.4.3)
|
14
|
+
safe_yaml (~> 1.0.0)
|
15
|
+
diff-lcs (1.4.4)
|
16
|
+
docile (1.3.2)
|
17
|
+
gem-release (2.1.1)
|
18
|
+
hashdiff (1.0.1)
|
19
|
+
method_source (1.0.0)
|
20
|
+
parallel (1.19.2)
|
21
|
+
parser (2.7.1.4)
|
22
|
+
ast (~> 2.4.1)
|
23
|
+
pry (0.13.1)
|
24
|
+
coderay (~> 1.1)
|
25
|
+
method_source (~> 1.0)
|
26
|
+
public_suffix (4.0.5)
|
27
|
+
rainbow (3.0.0)
|
28
|
+
rake (13.0.1)
|
29
|
+
regexp_parser (1.7.1)
|
30
|
+
rexml (3.2.4)
|
31
|
+
rspec (3.9.0)
|
32
|
+
rspec-core (~> 3.9.0)
|
33
|
+
rspec-expectations (~> 3.9.0)
|
34
|
+
rspec-mocks (~> 3.9.0)
|
35
|
+
rspec-core (3.9.2)
|
36
|
+
rspec-support (~> 3.9.3)
|
37
|
+
rspec-expectations (3.9.2)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.9.0)
|
40
|
+
rspec-mocks (3.9.1)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.9.0)
|
43
|
+
rspec-support (3.9.3)
|
44
|
+
rubocop (0.89.1)
|
45
|
+
parallel (~> 1.10)
|
46
|
+
parser (>= 2.7.1.1)
|
47
|
+
rainbow (>= 2.2.2, < 4.0)
|
48
|
+
regexp_parser (>= 1.7)
|
49
|
+
rexml
|
50
|
+
rubocop-ast (>= 0.3.0, < 1.0)
|
51
|
+
ruby-progressbar (~> 1.7)
|
52
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
53
|
+
rubocop-ast (0.3.0)
|
54
|
+
parser (>= 2.7.1.4)
|
55
|
+
rubocop-performance (1.7.1)
|
56
|
+
rubocop (>= 0.82.0)
|
57
|
+
ruby-progressbar (1.10.1)
|
58
|
+
safe_yaml (1.0.5)
|
59
|
+
simplecov (0.19.0)
|
60
|
+
docile (~> 1.1)
|
61
|
+
simplecov-html (~> 0.11)
|
62
|
+
simplecov-html (0.12.2)
|
63
|
+
standard (0.5.2)
|
64
|
+
rubocop (~> 0.89.1)
|
65
|
+
rubocop-performance (~> 1.7.1)
|
66
|
+
unicode-display_width (1.7.0)
|
67
|
+
webmock (3.8.3)
|
68
|
+
addressable (>= 2.3.6)
|
69
|
+
crack (>= 0.3.2)
|
70
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
71
|
+
|
72
|
+
PLATFORMS
|
73
|
+
ruby
|
74
|
+
|
75
|
+
DEPENDENCIES
|
76
|
+
gem-release
|
77
|
+
opayo!
|
78
|
+
pry
|
79
|
+
rake (~> 13.0)
|
80
|
+
rspec (~> 3.0)
|
81
|
+
simplecov
|
82
|
+
standard
|
83
|
+
webmock (~> 3.8)
|
84
|
+
|
85
|
+
BUNDLED WITH
|
86
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Peter Berkenbosch
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Opayo
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/opayo`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'opayo'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install opayo
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/peterberkenbosch/opayo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/peterberkenbosch/opayo/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
Everyone interacting in the Opayo project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/peterberkenbosch/opayo/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "opayo"
|
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__)
|
data/bin/setup
ADDED
data/lib/opayo.rb
ADDED
data/lib/opayo/client.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
module Opayo
|
2
|
+
class Client
|
3
|
+
def initialize
|
4
|
+
@version_strings = []
|
5
|
+
add_version_string "Opayo/" << VERSION
|
6
|
+
add_version_string "Ruby/" << RUBY_VERSION
|
7
|
+
add_version_string OpenSSL::OPENSSL_VERSION.split(" ").slice(0, 2).join "/"
|
8
|
+
end
|
9
|
+
|
10
|
+
def user_agent_string
|
11
|
+
@version_strings.join(" ")
|
12
|
+
end
|
13
|
+
|
14
|
+
# The MSK (merchant session key)
|
15
|
+
#
|
16
|
+
# The Merchant Session Key expires after 400 seconds and can only be used to create
|
17
|
+
# one successful Card Identifier (tokenised card details).
|
18
|
+
# It will also expire and be removed after 3 failed attempts to create a Card Identifier.
|
19
|
+
#
|
20
|
+
# @return <Response> the payload on a succesfull response will <Struct::MerchantSessionKey>
|
21
|
+
def merchant_session_key
|
22
|
+
http_call(:post, "merchant-session-keys", Opayo::Struct::MerchantSessionKey, nil, { "vendorName" => Opayo.config.vendor_name })
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
# Executes a request, validates and returns the response.
|
27
|
+
#
|
28
|
+
# @param [String] http_method The HTTP method (:get, :post)
|
29
|
+
# @param [String] api_method The api method to call
|
30
|
+
# @param [Class] payload_struct_class The payload struct class for successfull request
|
31
|
+
# @param [String] id the optional id to be pasted in
|
32
|
+
# @param [Hash] body an optional body to post to the endpoint
|
33
|
+
# @return [Hash]
|
34
|
+
# @raise [RequestError]
|
35
|
+
# @raise [NotFoundError]
|
36
|
+
# @raise [AuthenticationFailed]
|
37
|
+
def http_call(http_method, api_method, payload_struct_class, id = nil, body = {})
|
38
|
+
version = "v1"
|
39
|
+
|
40
|
+
path = "/api/#{version}/#{api_method}/#{id}".chomp("/")
|
41
|
+
api_endpoint = Opayo.config.endpoint
|
42
|
+
uri = URI.parse(api_endpoint)
|
43
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
44
|
+
http.use_ssl = true
|
45
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
46
|
+
http.set_debug_output($stdout) if ENV["DEBUG"]
|
47
|
+
|
48
|
+
case http_method
|
49
|
+
when :get
|
50
|
+
request = Net::HTTP::Get.new(path)
|
51
|
+
when :post
|
52
|
+
body.delete_if { |_k, v| v.nil? }
|
53
|
+
request = Net::HTTP::Post.new(path)
|
54
|
+
request.body = body.to_json
|
55
|
+
else
|
56
|
+
raise RequestError, "Invalid HTTP Method: #{http_method.to_s.upcase}"
|
57
|
+
end
|
58
|
+
|
59
|
+
request.basic_auth Opayo.config.integration_key, Opayo.config.integration_password
|
60
|
+
|
61
|
+
request["Accept"] = "application/json"
|
62
|
+
request["Content-Type"] = "application/json"
|
63
|
+
request["User-Agent"] = user_agent_string
|
64
|
+
|
65
|
+
begin
|
66
|
+
response = http.request(request)
|
67
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
68
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
69
|
+
raise RequestError, e.message
|
70
|
+
end
|
71
|
+
|
72
|
+
Response.new(response, payload_struct_class)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def add_version_string(version_string)
|
78
|
+
@version_strings << version_string.gsub(/\s+/, "-")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "base64"
|
2
|
+
|
3
|
+
module Opayo
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :integration_key
|
6
|
+
attr_accessor :integration_password
|
7
|
+
attr_accessor :vendor_name
|
8
|
+
attr_accessor :environment
|
9
|
+
|
10
|
+
ENDPOINTS = {
|
11
|
+
test: "pi-test.sagepay.com",
|
12
|
+
live: "pi-live.sagepay.com"
|
13
|
+
}
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@environment = :test
|
17
|
+
end
|
18
|
+
|
19
|
+
def endpoint
|
20
|
+
"https://#{ENDPOINTS[environment]}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
def config
|
26
|
+
@configuration ||= Configuration.new
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_writer :configuration
|
30
|
+
|
31
|
+
def configure
|
32
|
+
yield config
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/opayo/error.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Opayo
|
2
|
+
class Response
|
3
|
+
attr_reader :success, :payload, :error, :http_code
|
4
|
+
|
5
|
+
def initialize(http_response, payload_struct_class)
|
6
|
+
http_code = http_response.code.to_i
|
7
|
+
@http_code = http_code
|
8
|
+
case http_code
|
9
|
+
when 200, 201
|
10
|
+
@success = true
|
11
|
+
@payload = build_payload(JSON.parse(http_response.body), payload_struct_class)
|
12
|
+
else
|
13
|
+
@success = false
|
14
|
+
@error = http_response
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def success?
|
19
|
+
@success
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def build_payload(json_body, payload_struct_class)
|
25
|
+
payload_struct_class.new(json_body)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/opayo.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative "lib/opayo/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "opayo"
|
5
|
+
spec.version = Opayo::VERSION
|
6
|
+
spec.authors = ["Peter Berkenbosch"]
|
7
|
+
spec.email = ["info@peterberkenbosch.nl"]
|
8
|
+
|
9
|
+
spec.summary = "ruby api client for Opayo"
|
10
|
+
spec.description = spec.summary
|
11
|
+
spec.homepage = "https://github.com/peterberkenbosch/opayo"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/peterberkenbosch/opayo"
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/peterberkenbosch/opayo/CHANGELOG.md"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opayo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Berkenbosch
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ruby api client for Opayo
|
14
|
+
email:
|
15
|
+
- info@peterberkenbosch.nl
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gem-release.yml"
|
21
|
+
- ".github/FUNDING.yml"
|
22
|
+
- ".github/workflows/changelog.yml"
|
23
|
+
- ".github/workflows/standardrb.yml"
|
24
|
+
- ".github/workflows/test.yml"
|
25
|
+
- ".gitignore"
|
26
|
+
- ".rspec"
|
27
|
+
- CHANGELOG.md
|
28
|
+
- CODE_OF_CONDUCT.md
|
29
|
+
- Gemfile
|
30
|
+
- Gemfile.lock
|
31
|
+
- LICENSE.txt
|
32
|
+
- README.md
|
33
|
+
- Rakefile
|
34
|
+
- bin/console
|
35
|
+
- bin/setup
|
36
|
+
- lib/opayo.rb
|
37
|
+
- lib/opayo/client.rb
|
38
|
+
- lib/opayo/configuration.rb
|
39
|
+
- lib/opayo/error.rb
|
40
|
+
- lib/opayo/response.rb
|
41
|
+
- lib/opayo/struct/base.rb
|
42
|
+
- lib/opayo/struct/merchant_session_key.rb
|
43
|
+
- lib/opayo/version.rb
|
44
|
+
- opayo.gemspec
|
45
|
+
homepage: https://github.com/peterberkenbosch/opayo
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata:
|
49
|
+
homepage_uri: https://github.com/peterberkenbosch/opayo
|
50
|
+
source_code_uri: https://github.com/peterberkenbosch/opayo
|
51
|
+
changelog_uri: https://github.com/peterberkenbosch/opayo/CHANGELOG.md
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.5.0
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubygems_version: 3.1.4
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: ruby api client for Opayo
|
71
|
+
test_files: []
|