dsk_rb 0.3.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ac3dfeb251e816134336bb98e517ee8b3ebea0676d009344eac8b17de2123561
4
+ data.tar.gz: 5c3d9ef83a2f1fd7cf0eb735bbdbfe18ccda5227fd3bb5118ce1f54e7baa01cd
5
+ SHA512:
6
+ metadata.gz: b8694c14eafb447fc72c6792f5703dd781dc348b1c64c5bcdf9ea6245188485324647ff771af64e4c1ad96f0412bb5c43a2b60789ac23cca7c3a077d5004c212
7
+ data.tar.gz: 2c8c5aca51ccdda24151a70cd1bfed811cabe304f0ceb722def5426a2562b04117d170576cc42394203fd8e5d386333193a2cf3df30f04d670e0cff8dc157421
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiteralsInInterpolation:
5
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-12-21
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Kiriakos Velissariou
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,60 @@
1
+ # DskRb
2
+
3
+ 🚧 UNDER DEVELOPMENT 🚧
4
+
5
+ Ruby client for the DSK Bank API.
6
+
7
+ A Ruby wrapper for DSK Bank's REST API that provides a simple interface for managing banking operations.
8
+
9
+ ## Installation
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add dsk_rb
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install dsk_rb
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'dsk_rb'
27
+
28
+ # Initialize the client
29
+ # Requires the following parameters:
30
+ # - username: Provided by DSK Bank
31
+ # - password: Provided by DSK Bank
32
+ # - environment: The environment to use. For now, it can only be uat.
33
+
34
+ client = DskRb::Client.new(username: 'username', password: 'password', environment: 'uat')
35
+
36
+ # Register a new payment
37
+
38
+ # The register_payment method requires the following parameters:
39
+ # - amount: The amount of the payment
40
+ # - return_url: The URL to redirect the user to after the payment is completed
41
+ # - description: The description of the payment
42
+ # - order_number: The order number
43
+
44
+ response = client.register_payment(amount: 100, return_url: 'https://example.com', description: 'Test payment', orderNumber: '123')
45
+ redirect_url = response['formUrl']
46
+ ```
47
+
48
+ ## Development
49
+
50
+ 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.
51
+
52
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kiriakosv/dsk_rb.
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,66 @@
1
+ module DskRb
2
+ class Client
3
+ BASE_URLS = {
4
+ uat: 'https://uat.dskbank.bg'
5
+ }.freeze
6
+
7
+ def initialize(username:, password:, environment:)
8
+ @username = username
9
+ @password = password
10
+ @environment = environment.to_sym
11
+
12
+ validate_environment
13
+
14
+ @base_url = BASE_URLS[@environment]
15
+ end
16
+
17
+ def payment_registration(params)
18
+ camelized_params = params.transform_keys { |key| key.to_s.camelize(:lower) }
19
+
20
+ response = connection.post('/payment/rest/register.do') do |req|
21
+ req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
22
+ req.body = URI.encode_www_form(default_params.merge(camelized_params))
23
+ end
24
+
25
+ JSON.parse(response.body)
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :username, :password, :environment, :base_url
31
+
32
+ ALLOWED_ENVIRONMENTS = %i[uat].freeze
33
+ private_constant :ALLOWED_ENVIRONMENTS
34
+
35
+ def validate_environment
36
+ return if ALLOWED_ENVIRONMENTS.include?(environment)
37
+
38
+ raise(
39
+ ArgumentError,
40
+ "Invalid environment: #{environment}. Allowed environments: #{ALLOWED_ENVIRONMENTS.join(", ")}"
41
+ )
42
+ end
43
+
44
+ def connection
45
+ @connection ||= Faraday.new(url: base_url, headers: default_headers) do |conn|
46
+ conn.adapter Faraday.default_adapter
47
+ conn.response :json
48
+ conn.response :raise_error
49
+ conn.request :url_encoded
50
+ end
51
+ end
52
+
53
+ def default_headers
54
+ {
55
+ 'Content-Type' => 'application/x-www-form-urlencoded'
56
+ }
57
+ end
58
+
59
+ def default_params
60
+ {
61
+ 'userName' => username,
62
+ 'password' => password
63
+ }
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DskRb
4
+ VERSION = "0.3.0"
5
+ end
data/lib/dsk_rb.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "dsk_rb/version"
4
+ require_relative "dsk_rb/client"
5
+
6
+ require 'faraday'
7
+ require 'active_support/core_ext/string/inflections'
8
+
9
+ module DskRb
10
+ class Error < StandardError; end
11
+ end
data/sig/dsk_rb.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module DskRb
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dsk_rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Kiriakos Velissariou
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.12'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '7.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '7.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.24'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.24'
55
+ description: A Ruby wrapper for DSK Bank's REST API that provides a simple interface
56
+ for managing banking operations.
57
+ email:
58
+ - kiriakos@hey.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - CHANGELOG.md
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/dsk_rb.rb
70
+ - lib/dsk_rb/client.rb
71
+ - lib/dsk_rb/version.rb
72
+ - sig/dsk_rb.rbs
73
+ homepage: https://github.com/kiriakosv/dsk_rb
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ homepage_uri: https://github.com/kiriakosv/dsk_rb
78
+ source_code_uri: https://github.com/kiriakosv/dsk_rb
79
+ changelog_uri: https://github.com/kiriakosv/dsk_rb/blob/main/CHANGELOG.md
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 3.0.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubygems_version: 3.3.7
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Ruby client for the DSK Bank API
99
+ test_files: []