nedbank_api 0.2.2 → 0.2.5
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/nedbank_api.rb +0 -2
- data/lib/nedbank_api/api_wrapper.rb +6 -6
- data/lib/nedbank_api/authentications_api.rb +8 -3
- data/lib/nedbank_api/payments_api.rb +12 -6
- data/lib/nedbank_api/services/http.rb +15 -18
- data/lib/nedbank_api/version.rb +1 -1
- data/nedbank_api.gemspec +1 -1
- data/spec/payments_api_spec.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fb9117ddc2c8216ec72760a551d41982c267fd1
|
4
|
+
data.tar.gz: 242312db170605559aec9b75e24755d8485e4dd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46ce862d9507e3f3f261557295d0f4586145145b87a004c196eb5efb220dee39cef4b486ac1ba8288a1e34bff5f5f6768dc16fe2f0807367cbbee3a1c6a27ffc
|
7
|
+
data.tar.gz: 0ddb5f94ddfe19a3d2287821781cecb05acc25cdd3fa17ccf17afa7e1b43a637c879e3e6c5308c0ccd76c1a32729ca645801d6bcf398752f4db1695590be4235
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Nedbank API
|
2
2
|
|
3
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
4
|
|
@@ -9,7 +9,7 @@ This gem currently only uses the Authoristaions API and Payments API. If you are
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem 'nedbank_api'
|
12
|
+
gem 'nedbank_api'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
data/lib/nedbank_api.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
module NedbankApi
|
2
2
|
class ApiWrapper
|
3
3
|
class << self
|
4
|
-
def idempotency_key
|
5
|
-
rand.to_s[2..24]
|
6
|
-
end
|
7
|
-
|
8
4
|
def auth_headers(overrides={})
|
9
5
|
{
|
10
6
|
"Content-Type" => "application/json",
|
@@ -17,8 +13,12 @@ module NedbankApi
|
|
17
13
|
}.merge(overrides)
|
18
14
|
end
|
19
15
|
|
20
|
-
def
|
21
|
-
|
16
|
+
def idempotency_key
|
17
|
+
rand.to_s[2..24]
|
18
|
+
end
|
19
|
+
|
20
|
+
def endpoint(path, suffix: nil)
|
21
|
+
[NedbankApi.configuration.api_endpoint, path, suffix].compact.join('/')
|
22
22
|
end
|
23
23
|
|
24
24
|
def json_to_object(json)
|
@@ -1,8 +1,13 @@
|
|
1
1
|
module NedbankApi
|
2
2
|
class AuthenticationsApi < ApiWrapper
|
3
3
|
class << self
|
4
|
+
API_PATHS = {
|
5
|
+
request_token: 'nboauth/oauth20/token',
|
6
|
+
authorise: 'nboauth/oauth20/authorize'
|
7
|
+
}
|
8
|
+
|
4
9
|
def request_token_light
|
5
|
-
http = Http.new(url: endpoint(
|
10
|
+
http = Http.new(url: endpoint(API_PATHS[:request_token]))
|
6
11
|
|
7
12
|
response = http.post(
|
8
13
|
body: URI.encode_www_form({
|
@@ -21,7 +26,7 @@ module NedbankApi
|
|
21
26
|
end
|
22
27
|
|
23
28
|
def request_token_heavy(request_body: {})
|
24
|
-
http = Http.new(url: endpoint(
|
29
|
+
http = Http.new(url: endpoint(API_PATHS[:request_token]))
|
25
30
|
|
26
31
|
response = http.post(
|
27
32
|
body: URI.encode_www_form({
|
@@ -40,7 +45,7 @@ module NedbankApi
|
|
40
45
|
end
|
41
46
|
|
42
47
|
def authorisation_url(request_body: {})
|
43
|
-
url = endpoint(
|
48
|
+
url = endpoint(API_PATHS[:authorise])
|
44
49
|
|
45
50
|
body = URI.encode_www_form({
|
46
51
|
client_id: NedbankApi.configuration.client_id,
|
@@ -1,8 +1,14 @@
|
|
1
1
|
module NedbankApi
|
2
2
|
class PaymentsApi < ApiWrapper
|
3
3
|
class << self
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
API_PATHS = {
|
6
|
+
payments: 'open-banking/payments',
|
7
|
+
payment_submissions: 'open-banking/payment-submissions'
|
8
|
+
}
|
9
|
+
|
10
|
+
def create_intent(request_body: {}, headers: {})
|
11
|
+
http = Http.new(url: endpoint(API_PATHS[:payments]))
|
6
12
|
|
7
13
|
response = http.post(
|
8
14
|
headers: auth_headers,
|
@@ -12,8 +18,8 @@ module NedbankApi
|
|
12
18
|
return Models::Payment.new(json_to_object(response.body))
|
13
19
|
end
|
14
20
|
|
15
|
-
def submit_payment(request_body: {})
|
16
|
-
http = Http.new(url: endpoint(
|
21
|
+
def submit_payment(request_body: {}, headers: {})
|
22
|
+
http = Http.new(url: endpoint(API_PATHS[:payment_submissions]))
|
17
23
|
|
18
24
|
response = http.post(
|
19
25
|
headers: auth_headers,
|
@@ -23,8 +29,8 @@ module NedbankApi
|
|
23
29
|
return Models::PaymentSubmission.new(json_to_object(response.body))
|
24
30
|
end
|
25
31
|
|
26
|
-
def get_payment_submission(payment_submission_id:)
|
27
|
-
http = Http.new(url: endpoint(
|
32
|
+
def get_payment_submission(payment_submission_id:, headers: {})
|
33
|
+
http = Http.new(url: endpoint(API_PATHS[:payment_submissions], suffix: payment_submission_id))
|
28
34
|
|
29
35
|
response = http.get(
|
30
36
|
headers: auth_headers
|
@@ -4,36 +4,33 @@ module NedbankApi
|
|
4
4
|
@url = URI(url)
|
5
5
|
end
|
6
6
|
|
7
|
-
def net_http
|
8
|
-
@net_http ||= Net::HTTP.new(@url.host, @url.port).tap do |http|
|
9
|
-
http.use_ssl = true
|
10
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
7
|
def get(body: {}, headers: {})
|
15
8
|
request = Net::HTTP::Get.new(@url)
|
16
|
-
|
17
|
-
headers.each do |key,value|
|
18
|
-
request[key] = value
|
19
|
-
end
|
20
|
-
|
21
|
-
request.body = body
|
22
|
-
response = net_http.request(request)
|
23
|
-
|
24
|
-
return response
|
9
|
+
make_request(request: request, body: body, headers: headers)
|
25
10
|
end
|
11
|
+
|
26
12
|
def post(body: {}, headers: {})
|
27
13
|
request = Net::HTTP::Post.new(@url)
|
14
|
+
make_request(request: request, body: body, headers: headers)
|
15
|
+
end
|
28
16
|
|
17
|
+
def make_request(request:, body: {}, headers: {})
|
29
18
|
headers.each do |key,value|
|
30
19
|
request[key] = value
|
31
20
|
end
|
32
21
|
|
33
22
|
request.body = body
|
34
|
-
|
23
|
+
net_http.request(request)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
35
27
|
|
36
|
-
|
28
|
+
def net_http
|
29
|
+
@net_http ||= Net::HTTP.new(@url.host, @url.port).tap do |http|
|
30
|
+
http.use_ssl = true
|
31
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
32
|
+
end
|
37
33
|
end
|
34
|
+
|
38
35
|
end
|
39
36
|
end
|
data/lib/nedbank_api/version.rb
CHANGED
data/nedbank_api.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.email = 'jonobth@gmail.com'
|
14
14
|
s.metadata = { 'source_code_uri' => 'https://github.com/jono-booth/nedbank_api' }
|
15
15
|
|
16
|
-
s.files = `git ls-files -z`.split("\x0")
|
16
|
+
s.files = `git ls-files -z`.split("\x0").reject{ |f| f.end_with? '.gem' }
|
17
17
|
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
s.test_files = s.files.grep(%r{^spec/})
|
19
19
|
s.require_paths = ['lib']
|
data/spec/payments_api_spec.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
RSpec.describe NedbankApi::PaymentsApi do
|
2
|
+
before :each do
|
3
|
+
NedbankApi.intent_token = build(:fake_client)
|
4
|
+
end
|
5
|
+
|
2
6
|
describe '.create_intent' do
|
3
7
|
let(:request_body) { File.read('spec/support/payment/post_intent_request.json') }
|
4
8
|
let(:response_body) { File.read('spec/support/payment/post_intent_response.json') }
|