pay_rb 0.2.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: 57139eedbae4d0f81dcd43b157ade3f34331aadabf39424fcf10513b7ca998f0
4
+ data.tar.gz: 2aab59ec6e54fc7f6c4035139fd93b08ec6c1f7e80597dc19e97faa94e27e018
5
+ SHA512:
6
+ metadata.gz: f57aaa4e3e786dafc3a184e2f160de5d5428de6a1f6cca12ab3db206af757a63a0782a4d54b8518a708bbb00454ccc0d6dc2b422d1334e5fdf4a05e02839b32a
7
+ data.tar.gz: f320ee6cecd277c47e36435a6e4fc90202049aa251ed448f7f28da7ea9325bf13a47ecbcd31002e37d8c38bf57534745be5de92e6435f1af5d87f31af83c57c0
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-01-06
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,76 @@
1
+ # PayRb
2
+
3
+ 🚧 UNDER DEVELOPMENT 🚧
4
+
5
+ Ruby client for bank APIs.
6
+
7
+ A Ruby wrapper for banks' REST API that provides a simple interface for managing banking operations. It support banks
8
+ that have [this kind of API](https://gateway.jcc.com.cy/developer/en/integration/api/rest/rest.html).
9
+
10
+ It currently supports [JCC](https://gateway.jcc.com.cy/developer/en/integration/api/rest/rest.html) and [DSK](https://uat.dskbank.bg/sandbox/en/integration/api/rest/rest.html) banks.
11
+
12
+ ## Installation
13
+
14
+ Install the gem and add to the application's Gemfile by executing:
15
+
16
+ ```bash
17
+ bundle add pay_rb
18
+ ```
19
+
20
+ If bundler is not being used to manage dependencies, install the gem by executing:
21
+
22
+ ```bash
23
+ gem install pay_rb
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ```ruby
29
+ require 'pay_rb'
30
+
31
+ # Initialize the client
32
+ # Requires the following parameters:
33
+ # - username: Provided by Bank
34
+ # - password: Provided by Bank
35
+ # - environment: The environment to use (uat or production)
36
+ # - bank: The bank to use (dsk, jcc)
37
+ client = PayRb::Client.new(username: 'username', password: 'password', environment: 'uat', bank: 'dsk')
38
+
39
+ # Register a new payment
40
+
41
+ # The register_payment method requires the following parameters:
42
+ # - amount: The amount of the payment
43
+ # - return_url: The URL to redirect the user to after the payment is completed
44
+ # - description: The description of the payment
45
+ # - order_number: The order number
46
+
47
+ response = client.register_payment(amount: 100, return_url: 'https://example.com', description: 'Test payment', orderNumber: '123')
48
+ redirect_url = response['formUrl']
49
+
50
+ # Get order status
51
+ # The get_order_status method requires the following parameters:
52
+ # - order_id: The order ID
53
+
54
+ response = client.get_order_status('123')
55
+
56
+ # Refund a payment
57
+ # The refund_payment method requires the following parameters:
58
+ # - amount: The amount of the refund in smaller unit
59
+ # - order_id: The order ID
60
+
61
+ response = client.refund_payment(amount: 100, order_id: '123')
62
+ ```
63
+
64
+ ## Development
65
+
66
+ 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.
67
+
68
+ 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).
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kiriakosv/pay_rb.
73
+
74
+ ## License
75
+
76
+ 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,109 @@
1
+ module PayRb
2
+ class Client
3
+ BASE_URLS = {
4
+ dsk: {
5
+ uat: 'https://uat.dskbank.bg',
6
+ production: 'https://epg.dskbank.bg'
7
+ },
8
+ jcc: {
9
+ uat: 'https://gateway-test.jcc.com.cy',
10
+ production: 'https://gateway.jcc.com.cy'
11
+ }
12
+ }.freeze
13
+
14
+ def initialize(username:, password:, environment:, bank:)
15
+ @username = username
16
+ @password = password
17
+ @environment = environment.to_sym
18
+ @bank = bank.to_sym
19
+
20
+ validate_environment
21
+ validate_bank
22
+
23
+ @base_url = BASE_URLS[@bank][@environment]
24
+ end
25
+
26
+ def payment_registration(params)
27
+ camelized_params = params.transform_keys { |key| key.to_s.camelize(:lower) }
28
+
29
+ response = connection.post('/payment/rest/register.do') do |req|
30
+ req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
31
+ req.body = URI.encode_www_form(default_params.merge(camelized_params))
32
+ end
33
+
34
+ JSON.parse(response.body)
35
+ end
36
+
37
+ def get_order_status(order_id)
38
+ params = { orderId: order_id }
39
+
40
+ response = connection.post('/payment/rest/getOrderStatus.do') do |req|
41
+ req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
42
+ req.body = URI.encode_www_form(default_params.merge(params))
43
+ end
44
+
45
+ JSON.parse(response.body)
46
+ end
47
+
48
+ def refund_payment(params)
49
+ camelized_params = params.transform_keys { |key| key.to_s.camelize(:lower) }
50
+
51
+ response = connection.post('/payment/rest/refund.do') do |req|
52
+ req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
53
+ req.body = URI.encode_www_form(default_params.merge(camelized_params))
54
+ end
55
+
56
+ JSON.parse(response.body)
57
+ end
58
+
59
+ private
60
+
61
+ attr_reader :username, :password, :environment, :bank, :base_url
62
+
63
+ ALLOWED_ENVIRONMENTS = %i[uat].freeze
64
+ private_constant :ALLOWED_ENVIRONMENTS
65
+
66
+ ALLOWED_BANKS = %i[dsk].freeze
67
+ private_constant :ALLOWED_BANKS
68
+
69
+ def validate_environment
70
+ return if ALLOWED_ENVIRONMENTS.include?(environment)
71
+
72
+ raise(
73
+ ArgumentError,
74
+ "Invalid environment: #{environment}. Allowed environments: #{ALLOWED_ENVIRONMENTS.join(", ")}"
75
+ )
76
+ end
77
+
78
+ def validate_bank
79
+ return if ALLOWED_BANKS.include?(bank)
80
+
81
+ raise(
82
+ ArgumentError,
83
+ "Invalid bank: #{bank}. Allowed banks: #{ALLOWED_BANKS.join(", ")}"
84
+ )
85
+ end
86
+
87
+ def connection
88
+ @connection ||= Faraday.new(url: base_url, headers: default_headers) do |conn|
89
+ conn.adapter Faraday.default_adapter
90
+ conn.response :json
91
+ conn.response :raise_error
92
+ conn.request :url_encoded
93
+ end
94
+ end
95
+
96
+ def default_headers
97
+ {
98
+ 'Content-Type' => 'application/x-www-form-urlencoded'
99
+ }
100
+ end
101
+
102
+ def default_params
103
+ {
104
+ 'userName' => username,
105
+ 'password' => password
106
+ }
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PayRb
4
+ VERSION = "0.2.0"
5
+ end
data/lib/pay_rb.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "pay_rb/version"
4
+ require_relative "pay_rb/client"
5
+
6
+ require 'faraday'
7
+ require 'active_support/core_ext/string/inflections'
8
+
9
+ module PayRb
10
+ class Error < StandardError; end
11
+ end
data/sig/pay_rb.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module PayRb
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: pay_rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Kiriakos Velissariou
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-01-06 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 banks' REST API that provides a simple interface for
56
+ 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/pay_rb.rb
70
+ - lib/pay_rb/client.rb
71
+ - lib/pay_rb/version.rb
72
+ - sig/pay_rb.rbs
73
+ homepage: https://github.com/kiriakosv/pay_rb
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ homepage_uri: https://github.com/kiriakosv/pay_rb
78
+ source_code_uri: https://github.com/kiriakosv/pay_rb
79
+ changelog_uri: https://github.com/kiriakosv/pay_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 banks
99
+ test_files: []