bank_of_baku 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f7c9afcd0aae59cdc6af02070e536f647a1da1e489f9acc5d659066525aeeb2f
4
+ data.tar.gz: 4a47ce1ba3f7b048c926c35bfb87db0f8dce030e82ade87aa9d650c95f0b0029
5
+ SHA512:
6
+ metadata.gz: c5757cfc6f773bbd0c530ba9e024764c85fc2254ca7420bd9f49d5258970cb178bb89dc49d211b1cbe1d6486cba49df4fc881fe3c77ee92dde4281e50a069191
7
+ data.tar.gz: ffbfcad6c44477d1ba4db89463f40a17322ddb5cc891b38b211b0ad4b37d45a6d516765122b8441a06cdb907f5d8d7dda0714fe3b859a62b521ceb771487f36d
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2019, Nihad Abbasov <nihad@42na.in>
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24
+ POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,60 @@
1
+ # Bank of Baku
2
+
3
+ Ruby interface to Bank of Baku online payment gateway.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bank_of_baku'
11
+ # gem 'bank_of_baku', github: 'NARKOZ/bank_of_baku'
12
+ ```
13
+
14
+ And then execute: `bundle`
15
+
16
+ ## Configuration
17
+
18
+ ```ruby
19
+ BankOfBaku.configure do |config|
20
+ config.endpoint = 'https://api.example.com/rest'
21
+ config.username = 'test-user'
22
+ config.password = 'secret'
23
+ config.success_url = 'https://merchant.example.net/success'
24
+ config.failure_url = 'https://merchant.example.net/fail'
25
+ end
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```ruby
31
+ # Order registration
32
+ request_options = {
33
+ orderNumber: rand(1000..2000),
34
+ amount: 5 * 100,
35
+ currency: 944,
36
+ description: 'Lorem ipsum dolor sit amet',
37
+ pageView: %w[DESKTOP MOBILE].sample
38
+ }
39
+
40
+ begin
41
+ BankOfBaku::Request.register request_options
42
+ rescue BankOfBaku::Error => e
43
+ e.message
44
+ end
45
+ ```
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
50
+ `rake test` to run the tests. You can also run `bin/console` for an interactive
51
+ prompt that will allow you to experiment.
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at
56
+ https://github.com/NARKOZ/bank_of_baku
57
+
58
+ ## Copyright
59
+
60
+ Copyright (c) 2019 Nihad Abbasov
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bank_of_baku/version'
4
+ require 'bank_of_baku/configuration'
5
+ require 'bank_of_baku/error'
6
+ require 'bank_of_baku/request'
7
+
8
+ module BankOfBaku
9
+ extend Configuration
10
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BankOfBaku
4
+ module Configuration
5
+ VALID_OPTIONS_KEYS = %i[endpoint username password user_agent success_url failure_url].freeze
6
+ DEFAULT_USER_AGENT = "BankOfBaku Ruby Gem #{BankOfBaku::VERSION}"
7
+
8
+ attr_accessor(*VALID_OPTIONS_KEYS)
9
+
10
+ def self.extended(base)
11
+ base.reset
12
+ end
13
+
14
+ def configure
15
+ yield self
16
+ end
17
+
18
+ def reset
19
+ VALID_OPTIONS_KEYS.each do |key|
20
+ send("#{key}=", nil)
21
+ end
22
+ self.user_agent = DEFAULT_USER_AGENT
23
+ end
24
+
25
+ def default_options
26
+ {
27
+ userName: username,
28
+ password: password,
29
+ returnUrl: success_url,
30
+ failUrl: failure_url,
31
+ language: 'en'
32
+ }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BankOfBaku
4
+ class Error < StandardError; end
5
+ class HTTPResponseError < Error; end
6
+ class RegisteredOrder < Error; end
7
+ class InvalidCurrency < Error; end
8
+ class MissingParameter < Error; end
9
+ class InvalidParameterValue < Error; end
10
+ class GatewayError < Error; end
11
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'typhoeus'
4
+ require 'json'
5
+
6
+ module BankOfBaku
7
+ module Request
8
+ # @param [Hash] request_options
9
+ # @return [Hash]
10
+ # @raise [BankOfBaku::HTTPResponseError]
11
+ # @raise [BankOfBaku::RegisteredOrder]
12
+ # @raise [BankOfBaku::InvalidCurrency]
13
+ # @raise [BankOfBaku::MissingParameter]
14
+ # @raise [BankOfBaku::InvalidParameterValue]
15
+ # @raise [BankOfBaku::GatewayError]
16
+ def self.register(request_options)
17
+ request = Typhoeus::Request.new(
18
+ "#{BankOfBaku.endpoint}/register.do",
19
+ method: :post,
20
+ followlocation: true,
21
+ headers: { 'User-Agent' => BankOfBaku.user_agent },
22
+ body: BankOfBaku.default_options.merge(request_options)
23
+ )
24
+ handle_response(request.run)
25
+ end
26
+
27
+ # @private
28
+ def self.handle_response(response)
29
+ raise HTTPResponseError, "Gateway request failed: #{response.code}" unless response.success?
30
+
31
+ response = JSON.parse response.body
32
+ error_klass = case response['errorCode']
33
+ when '1' then RegisteredOrder
34
+ when '3' then InvalidCurrency
35
+ when '4' then MissingParameter
36
+ when '5' then InvalidParameterValue
37
+ when '7' then GatewayError
38
+ end
39
+
40
+ raise error_klass, response['errorMessage'] if error_klass
41
+
42
+ response
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BankOfBaku
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bank_of_baku
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nihad Abbasov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: Provides Ruby APIs to create, process and manage Bank of Baku payments
84
+ email:
85
+ - nihad@42na.in
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE.txt
91
+ - README.md
92
+ - lib/bank_of_baku.rb
93
+ - lib/bank_of_baku/configuration.rb
94
+ - lib/bank_of_baku/error.rb
95
+ - lib/bank_of_baku/request.rb
96
+ - lib/bank_of_baku/version.rb
97
+ homepage: https://github.com/narkoz/bank_of_baku
98
+ licenses:
99
+ - BSD-2-Clause
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.0.2
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Ruby interface to Bank of Baku online payment gateway
120
+ test_files: []