gmo_services 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1872085610a13edebabc320c995d176a9ad27050bfc911acbb5b017dbfb5c351
4
+ data.tar.gz: 4414780cd8b6d9a78d80feb10858a31230a086300e3189a3f862d560827bc294
5
+ SHA512:
6
+ metadata.gz: 5910b0c06f4fdae4f248136160fc0a00d8ea8234b90a2c70efcfa51468e3c664b911885ad27160953236b610660a3f9b32f0cbb55bd223116bed8680da93c6e4
7
+ data.tar.gz: 94c2ae8fe0196e101f30c23aa21496c6a7cb3383f9001fc3d32b005e09911d4f03d576d841ec1b0bcb10f97048e9575dba13cc688ffb6c9b3e7c2a0d157fcdb8
@@ -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 nguyenthanhviet31031998@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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 NGUYEN THANH VIET
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,44 @@
1
+ # GmoServices
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gmo_services`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gmo_services'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gmo_services
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gmo_services. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/gmo_services/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the GmoServices project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/gmo_services/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,35 @@
1
+ module GmoServices
2
+ module Payments
3
+ class Base
4
+ attr_reader :site_id, :site_pass, :shop_id, :shop_pass, :base_api_url, :settings
5
+
6
+ def initialize(params = {})
7
+ @site_id = params[:site_id]
8
+ @site_pass = params[:site_pass]
9
+ @shop_id = params[:shop_id]
10
+ @shop_pass = params[:shop_pass]
11
+ @base_api_url = params[:base_api_url]
12
+ @settings = initialize_settings
13
+ end
14
+
15
+ private
16
+
17
+ def post_request(api_url, params = {})
18
+ url = URI(base_api_url + api_url)
19
+ response = Net::HTTP.post_form(url, params)
20
+ response_body = Rack::Utils.parse_query(response.body)
21
+ return response_body unless response_body['ErrInfo']
22
+
23
+ raise_error(response_body)
24
+ end
25
+
26
+ def raise_error(response_body)
27
+ Error.new(response_body).call
28
+ end
29
+
30
+ def initialize_settings
31
+ raise NotImplementedError
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,100 @@
1
+ require 'gmo_services/payments/base'
2
+
3
+ module GmoServices
4
+ module Payments
5
+ class Card < Base
6
+ def entry_transaction(params)
7
+ api_url = settings.entry_transaction_api_url
8
+ params = initialize_params_of_entry_transaction(params)
9
+ post_request(api_url, params)
10
+ end
11
+
12
+ def execute_transaction_by_token(params)
13
+ api_url = settings.execute_transaction_api_url
14
+ params = initialize_params_of_execute_transaction_by_token(params)
15
+ post_request(api_url, params)
16
+ end
17
+
18
+ def execute_transaction_by_member(params)
19
+ api_url = settings.execute_transaction_api_url
20
+ params = initialize_params_of_execute_transaction_by_member(params)
21
+ post_request(api_url, params)
22
+ end
23
+
24
+ def search_transaction(params)
25
+ api_url = settings.search_transaction_api_url
26
+ params = initialize_params_of_search_transaction(params)
27
+ post_request(api_url, params)
28
+ end
29
+
30
+ def cancel_transaction(params)
31
+ api_url = settings.alter_transaction_api_url
32
+ params = initialize_params_of_cancel_transaction(params)
33
+ post_request(api_url, params)
34
+ end
35
+
36
+ private
37
+
38
+ def initialize_settings
39
+ Settings.payments.card
40
+ end
41
+
42
+ def initialize_params_of_entry_transaction(params)
43
+ {
44
+ ShopID: shop_id,
45
+ ShopPass: shop_pass,
46
+ OrderID: params[:order_id],
47
+ JobCd: params[:job_cd],
48
+ Amount: params[:amount]
49
+ }
50
+ end
51
+
52
+ def initialize_default_params_of_execute_transaction(params)
53
+ {
54
+ AccessID: params[:access_id],
55
+ AccessPass: params[:access_pass],
56
+ OrderID: params[:order_id],
57
+ Method: params[:method],
58
+ PayTimes: params[:pay_times],
59
+ PIN: params[:pin]
60
+ }
61
+ end
62
+
63
+ def initialize_params_of_execute_transaction_by_token(params)
64
+ default_params = initialize_default_params_of_execute_transaction(params)
65
+ default_params.merge(TokenType: params[:token_type], Token: params[:token])
66
+ end
67
+
68
+ def initialize_params_of_execute_transaction_by_member(params)
69
+ default_params = initialize_default_params_of_execute_transaction(params)
70
+ default_params.merge(
71
+ SiteID: params[:site_id],
72
+ SitePass: params[:site_pass],
73
+ MemberID: params[:member_id],
74
+ CardSeq: params[:card_seq],
75
+ SeqMode: params[:seq_mode],
76
+ CardPass: params[:card_pass],
77
+ SecurityCode: params[:security_code]
78
+ )
79
+ end
80
+
81
+ def initialize_params_of_search_transaction(params)
82
+ {
83
+ ShopID: shop_id,
84
+ ShopPass: shop_pass,
85
+ OrderID: params[:order_id]
86
+ }
87
+ end
88
+
89
+ def initialize_params_of_cancel_transaction(params)
90
+ {
91
+ ShopID: shop_id,
92
+ ShopPass: shop_pass,
93
+ AccessID: params[:access_id],
94
+ AccessPass: params[:access_pass],
95
+ JobCd: 'CANCEL'
96
+ }
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,28 @@
1
+ module GmoServices
2
+ module Payments
3
+ class Error
4
+ attr_accessor :response_body, :locale
5
+
6
+ ERROR_INFO_SEPARATOR = '|'.freeze
7
+
8
+ def initialize(response_body, locale = :en)
9
+ @response_body = response_body
10
+ @locale = locale
11
+ end
12
+
13
+ def call
14
+ error_info_array = response_body['ErrInfo'].split(ERROR_INFO_SEPARATOR)
15
+ error_message_array = error_info_array.map { |error_info| translate(error_info) }
16
+ error_message = error_message_array.join(ERROR_INFO_SEPARATOR)
17
+ response_body['ErrMessage'] = error_message
18
+ response_body
19
+ end
20
+
21
+ private
22
+
23
+ def translate(error_info)
24
+ I18n.t(error_info, locale: locale)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,121 @@
1
+ require 'gmo_services/payments/base'
2
+
3
+ module GmoServices
4
+ module Payments
5
+ class Member < Base
6
+ def register_member(params)
7
+ api_url = settings.register_member_api_url
8
+ params = initialize_params_of_register_member(params)
9
+ post_request(api_url, params)
10
+ end
11
+
12
+ def search_member(params)
13
+ api_url = settings.search_member_api_url
14
+ params = initialize_params_of_search_member(params)
15
+ post_request(api_url, params)
16
+ end
17
+
18
+ def update_member(params)
19
+ api_url = settings.update_member_api_url
20
+ params = initialize_params_of_update_member(params)
21
+ post_request(api_url, params)
22
+ end
23
+
24
+ def delete_member(params)
25
+ api_url = settings.delete_member_api_url
26
+ params = initialize_params_of_delete_member(params)
27
+ post_request(api_url, params)
28
+ end
29
+
30
+ def add_card_by_token(params)
31
+ api_url = settings.add_card_to_member_api_url
32
+ params = initialize_params_of_add_card_by_token(params)
33
+ post_request(api_url, params)
34
+ end
35
+
36
+ def search_card(params)
37
+ api_url = settings.search_card_api_url
38
+ params = initialize_params_of_search_card(params)
39
+ post_request(api_url, params)
40
+ end
41
+
42
+ def delete_card(params)
43
+ api_url = settings.delete_card_api_url
44
+ params = initialize_params_of_delete_card(params)
45
+ post_request(api_url, params)
46
+ end
47
+
48
+ private
49
+
50
+ def initialize_settings
51
+ Settings.payments.member
52
+ end
53
+
54
+ def initialize_params_of_register_member(params)
55
+ {
56
+ SiteID: site_id,
57
+ SitePass: site_pass,
58
+ MemberID: params[:member_id],
59
+ MemberName: params[:member_name]
60
+ }
61
+ end
62
+
63
+ def initialize_params_of_search_member(params)
64
+ {
65
+ SiteID: site_id,
66
+ SitePass: site_pass,
67
+ MemberID: params[:member_id]
68
+ }
69
+ end
70
+
71
+ def initialize_params_of_update_member(params)
72
+ {
73
+ SiteID: site_id,
74
+ SitePass: site_pass,
75
+ MemberID: params[:member_id],
76
+ MemberName: params[:member_name]
77
+ }
78
+ end
79
+
80
+ def initialize_params_of_delete_member(params)
81
+ {
82
+ SiteID: site_id,
83
+ SitePass: site_pass,
84
+ MemberID: params[:member_id]
85
+ }
86
+ end
87
+
88
+ def initialize_params_of_add_card_by_token(params)
89
+ {
90
+ SiteID: site_id,
91
+ SitePass: site_pass,
92
+ MemberID: params[:member_id],
93
+ SeqMode: params[:seq_mode],
94
+ Token: params[:token]
95
+ }
96
+ end
97
+
98
+ def initialize_params_of_search_card(params)
99
+ {
100
+ SiteID: site_id,
101
+ SitePass: site_pass,
102
+ MemberID: params[:member_id],
103
+ SeqMode: params[:seq_mode],
104
+ ValidFlag: params[:valid_flag],
105
+ CardSeq: params[:card_seq],
106
+ UseFloatingMask: params[:use_floating_mask]
107
+ }
108
+ end
109
+
110
+ def initialize_params_of_delete_card(params)
111
+ {
112
+ SiteID: site_id,
113
+ SitePass: site_pass,
114
+ MemberID: params[:member_id],
115
+ SeqMode: params[:seq_mode],
116
+ CardSeq: params[:card_seq]
117
+ }
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,3 @@
1
+ module GmoServices
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'gmo_services/version'
2
+ require 'gmo_services/payments/card'
3
+ require 'gmo_services/payments/member'
4
+ require 'gmo_services/payments/error'
5
+ require 'net/http'
6
+ require 'rack/utils'
7
+
8
+ require 'i18n'
9
+ I18n.load_path << Dir["#{File.expand_path('config/locales')}/**/*.yml"]
10
+ I18n.default_locale = :en
11
+
12
+ require 'config'
13
+ Config.load_and_set_settings('config/settings.yml')
14
+
15
+ module GmoServices
16
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gmo_services
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - NGUYEN THANH VIET
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-10-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Payment solutions with GMO services
14
+ email:
15
+ - nguyenthanhviet31031998@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CODE_OF_CONDUCT.md
21
+ - LICENSE.txt
22
+ - README.md
23
+ - lib/gmo_services.rb
24
+ - lib/gmo_services/payments/base.rb
25
+ - lib/gmo_services/payments/card.rb
26
+ - lib/gmo_services/payments/error.rb
27
+ - lib/gmo_services/payments/member.rb
28
+ - lib/gmo_services/version.rb
29
+ homepage: https://github.com/VIETDEPTRAII/gmo_services_gem
30
+ licenses:
31
+ - MIT
32
+ metadata:
33
+ rubygems_mfa_required: 'true'
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '2.7'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubygems_version: 3.1.6
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Payment solutions with GMO services
53
+ test_files: []