nedbank_api 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +3 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +7 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +6 -0
  8. data/Gemfile.lock +120 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +46 -0
  11. data/Rakefile +10 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/lib/nedbank_api.rb +39 -0
  15. data/lib/nedbank_api/api_wrapper.rb +29 -0
  16. data/lib/nedbank_api/authentications_api.rb +57 -0
  17. data/lib/nedbank_api/exceptions.rb +5 -0
  18. data/lib/nedbank_api/models/base_model.rb +21 -0
  19. data/lib/nedbank_api/models/intent_token.rb +36 -0
  20. data/lib/nedbank_api/models/payment.rb +10 -0
  21. data/lib/nedbank_api/models/payment_submission.rb +6 -0
  22. data/lib/nedbank_api/payments_api.rb +37 -0
  23. data/lib/nedbank_api/services/client.rb +18 -0
  24. data/lib/nedbank_api/services/configuration.rb +18 -0
  25. data/lib/nedbank_api/services/http.rb +39 -0
  26. data/lib/nedbank_api/version.rb +3 -0
  27. data/nedbank_api.gemspec +34 -0
  28. data/spec/authorisations_api_spec.rb +51 -0
  29. data/spec/client_spec.rb +16 -0
  30. data/spec/factories/client.rb +17 -0
  31. data/spec/factories/payment.rb +0 -0
  32. data/spec/nedbank_api_spec.rb +12 -0
  33. data/spec/payments_api_spec.rb +51 -0
  34. data/spec/spec_helper.rb +31 -0
  35. data/spec/support/authentication/post_auth_token.json +0 -0
  36. data/spec/support/payment/post_intent_request.json +41 -0
  37. data/spec/support/payment/post_intent_response.json +47 -0
  38. data/spec/support/payment/post_payment_submission_request.json +55 -0
  39. data/spec/support/payment/post_payment_submission_response.json +16 -0
  40. metadata +264 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 232191d832adf52be4ec8b3819395c3624a33d57
4
+ data.tar.gz: 1963075ba078b1d5327ad81991767daac2a472cd
5
+ SHA512:
6
+ metadata.gz: 0d1264a544ff92c7d3557428b15084a43f6b5441ebcbaf7452ee1afa66786c615cfa7975ff5ca8aea62e63c78a21b0c83f2b3af2e2bdd214f928c1cb4f0648fa
7
+ data.tar.gz: 678d7a4f9d708e93cc57300c86b06675e7e3a12f5f723d9c77798467b148c139e8653d9fcead30a6f8ba0d76e05943e78b1d606e43db0360e90bf53a4daeb4e9
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/factories/real_client.rb
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.4
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.7
7
+ before_install: gem install bundler -v 1.17.1
@@ -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 jonobth@gmail.com. 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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in nedbank_api.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,120 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nedbank_api (0.2.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (5.2.3)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 0.7, < 2)
12
+ minitest (~> 5.1)
13
+ tzinfo (~> 1.1)
14
+ addressable (2.7.0)
15
+ public_suffix (>= 2.0.2, < 5.0)
16
+ coderay (1.1.2)
17
+ concurrent-ruby (1.1.5)
18
+ crack (0.4.3)
19
+ safe_yaml (~> 1.0.0)
20
+ diff-lcs (1.3)
21
+ factory_bot (5.0.2)
22
+ activesupport (>= 4.2.0)
23
+ ffi (1.11.1)
24
+ formatador (0.2.5)
25
+ guard (2.15.1)
26
+ formatador (>= 0.2.4)
27
+ listen (>= 2.7, < 4.0)
28
+ lumberjack (>= 1.0.12, < 2.0)
29
+ nenv (~> 0.1)
30
+ notiffany (~> 0.0)
31
+ pry (>= 0.9.12)
32
+ shellany (~> 0.0)
33
+ thor (>= 0.18.1)
34
+ guard-compat (1.2.1)
35
+ guard-rspec (4.7.3)
36
+ guard (~> 2.1)
37
+ guard-compat (~> 1.1)
38
+ rspec (>= 2.99.0, < 4.0)
39
+ hashdiff (1.0.0)
40
+ httplog (1.3.2)
41
+ rack (>= 1.0)
42
+ rainbow (>= 2.0.0)
43
+ i18n (1.6.0)
44
+ concurrent-ruby (~> 1.0)
45
+ listen (3.1.5)
46
+ rb-fsevent (~> 0.9, >= 0.9.4)
47
+ rb-inotify (~> 0.9, >= 0.9.7)
48
+ ruby_dep (~> 1.2)
49
+ lumberjack (1.0.13)
50
+ method_source (0.9.2)
51
+ minitest (5.11.3)
52
+ nenv (0.3.0)
53
+ notiffany (0.1.3)
54
+ nenv (~> 0.1)
55
+ shellany (~> 0.0)
56
+ pry (0.12.2)
57
+ coderay (~> 1.1.0)
58
+ method_source (~> 0.9.0)
59
+ pry-nav (0.3.0)
60
+ pry (>= 0.9.10, < 0.13.0)
61
+ pry-remote (0.1.8)
62
+ pry (~> 0.9)
63
+ slop (~> 3.0)
64
+ public_suffix (4.0.1)
65
+ rack (2.0.7)
66
+ rainbow (3.0.0)
67
+ rake (12.3.3)
68
+ rb-fsevent (0.10.3)
69
+ rb-inotify (0.10.0)
70
+ ffi (~> 1.0)
71
+ rspec (3.8.0)
72
+ rspec-core (~> 3.8.0)
73
+ rspec-expectations (~> 3.8.0)
74
+ rspec-mocks (~> 3.8.0)
75
+ rspec-core (3.8.2)
76
+ rspec-support (~> 3.8.0)
77
+ rspec-expectations (3.8.4)
78
+ diff-lcs (>= 1.2.0, < 2.0)
79
+ rspec-support (~> 3.8.0)
80
+ rspec-mocks (3.8.1)
81
+ diff-lcs (>= 1.2.0, < 2.0)
82
+ rspec-support (~> 3.8.0)
83
+ rspec-nc (0.3.0)
84
+ rspec (>= 3)
85
+ terminal-notifier (>= 1.4)
86
+ rspec-support (3.8.2)
87
+ ruby_dep (1.5.0)
88
+ safe_yaml (1.0.5)
89
+ shellany (0.0.1)
90
+ slop (3.6.0)
91
+ terminal-notifier (2.0.0)
92
+ thor (0.20.3)
93
+ thread_safe (0.3.6)
94
+ tzinfo (1.2.5)
95
+ thread_safe (~> 0.1)
96
+ webmock (3.7.2)
97
+ addressable (>= 2.3.6)
98
+ crack (>= 0.3.2)
99
+ hashdiff (>= 0.4.0, < 2.0.0)
100
+
101
+ PLATFORMS
102
+ ruby
103
+
104
+ DEPENDENCIES
105
+ bundler (~> 1.5)
106
+ factory_bot (~> 5.0)
107
+ guard (~> 2.15)
108
+ guard-rspec (~> 4.7)
109
+ httplog (~> 1.3)
110
+ nedbank_api!
111
+ pry (~> 0.12)
112
+ pry-nav (~> 0.3)
113
+ pry-remote (~> 0.1)
114
+ rake (~> 12.3)
115
+ rspec (~> 3.8)
116
+ rspec-nc (~> 0.3)
117
+ webmock (~> 3.7)
118
+
119
+ BUNDLED WITH
120
+ 1.17.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Jono Booth
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,46 @@
1
+ # NedbankApi
2
+
3
+ The purpose of this gem is to streamline development of a Ruby application when using the [Nedbank Marketplace API](https://apim.nedbank.co.za/static/docs).
4
+
5
+ This gem currently only uses the Authoristaions API and Payments API. If you are in need of other parts of the API then please feel free to contribute or submit a feature request.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'nedbank_api', github: 'jono-booth/nedbank_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ ## Documentation
20
+
21
+ **[1. Quickstart Guide](https://github.com/jono-booth/nedbank_api/wiki)**
22
+
23
+ **[2. Getting Started Properly](https://github.com/jono-booth/nedbank_api/wiki/Getting-Started)**
24
+
25
+ **[3. Authorisations API](https://github.com/jono-booth/nedbank_api/wiki/Authorisations-API)**
26
+
27
+ **[4. Payments API](https://github.com/jono-booth/nedbank_api/wiki/Payments-API)**
28
+
29
+
30
+ ## Development
31
+
32
+ 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.
33
+
34
+ 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).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jono-booth/nedbank_api. 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.
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
43
+
44
+ ## Code of Conduct
45
+
46
+ Everyone interacting in the NedbankApi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jono-booth/nedbank_api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ # Default directory to look in is `/specs`
5
+ # Run with `rake spec`
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
+ task.rspec_opts = ['--color', '--format', 'nested']
8
+ end
9
+
10
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nedbank_api"
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
@@ -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,39 @@
1
+ require 'nedbank_api/api_wrapper'
2
+ require 'nedbank_api/authentications_api'
3
+ require 'nedbank_api/exceptions'
4
+ require 'nedbank_api/payments_api'
5
+ require 'nedbank_api/version'
6
+ require 'nedbank_api/models/base_model'
7
+ require 'nedbank_api/models/intent_token'
8
+ require 'nedbank_api/models/payment'
9
+ require 'nedbank_api/models/payment_submission'
10
+ require 'nedbank_api/services/client'
11
+ require 'nedbank_api/services/configuration'
12
+ require 'nedbank_api/services/http'
13
+
14
+ require 'uri'
15
+ require 'openssl'
16
+ require 'net/http'
17
+ require 'uri'
18
+ require 'securerandom'
19
+
20
+ module NedbankApi
21
+ @intent_token = Models::IntentToken.new(Object.new)
22
+
23
+ class << self
24
+ attr_accessor :intent_token,
25
+ :configuration
26
+
27
+ def configuration
28
+ @configuration ||= Configuration.new
29
+ end
30
+
31
+ def reset
32
+ @configuration = Configuration.new
33
+ end
34
+
35
+ def configure
36
+ yield(configuration)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,29 @@
1
+ module NedbankApi
2
+ class ApiWrapper
3
+ class << self
4
+ def idempotency_key
5
+ rand.to_s[2..24]
6
+ end
7
+
8
+ def auth_headers(overrides={})
9
+ {
10
+ "Content-Type" => "application/json",
11
+ "accept" => 'application/json',
12
+ "x-fapi-financial-id" => "OB/2017/001",
13
+ "x-idempotency-key" => idempotency_key,
14
+ "Authorization" => "Bearer #{NedbankApi.intent_token.access_token}",
15
+ "x-ibm-client-id" => NedbankApi.configuration.client_id,
16
+ "x-ibm-client-secret" => NedbankApi.configuration.client_secret
17
+ }.merge(overrides)
18
+ end
19
+
20
+ def endpoint(path)
21
+ NedbankApi.configuration.api_endpoint + path
22
+ end
23
+
24
+ def json_to_object(json)
25
+ JSON.parse(json, object_class: OpenStruct)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,57 @@
1
+ module NedbankApi
2
+ class AuthenticationsApi < ApiWrapper
3
+ class << self
4
+ def request_token_light
5
+ http = Http.new(url: endpoint('/nboauth/oauth20/token'))
6
+
7
+ response = http.post(
8
+ body: URI.encode_www_form({
9
+ client_id: NedbankApi.configuration.client_id,
10
+ client_secret: NedbankApi.configuration.client_secret,
11
+ grant_type: 'client_credentials',
12
+ scope: 'tpp_client_credential'
13
+ })
14
+ )
15
+
16
+ intent_token = Models::IntentToken.new(JSON.parse(response.body, object_class: OpenStruct))
17
+
18
+ NedbankApi.intent_token = intent_token
19
+
20
+ return intent_token
21
+ end
22
+
23
+ def request_token_heavy(request_body: {})
24
+ http = Http.new(url: endpoint('/nboauth/oauth20/token'))
25
+
26
+ response = http.post(
27
+ body: URI.encode_www_form({
28
+ client_id: NedbankApi.configuration.client_id,
29
+ client_secret: NedbankApi.configuration.client_secret,
30
+ redirect_uri: NedbankApi.configuration.oauth_redirect_url,
31
+ grant_type: 'authorization_code',
32
+ }.merge(request_body))
33
+ )
34
+
35
+ intent_token = Models::IntentToken.new(JSON.parse(response.body, object_class: OpenStruct))
36
+
37
+ NedbankApi.intent_token = intent_token
38
+
39
+ return intent_token
40
+ end
41
+
42
+ def authorisation_url(request_body: {})
43
+ url = endpoint('/nboauth/oauth20/authorize')
44
+
45
+ body = URI.encode_www_form({
46
+ client_id: NedbankApi.configuration.client_id,
47
+ redirect_uri: NedbankApi.configuration.oauth_redirect_url,
48
+ response_type: 'code',
49
+ scope: 'payments',
50
+ itype: 'payments'
51
+ }.merge(request_body))
52
+
53
+ return "#{url}?#{body}"
54
+ end
55
+ end
56
+ end
57
+ end