gmo_services 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,14 @@
1
- payments:
2
- card:
3
- entry_transaction_api_url: '/payment/EntryTran.idPass'
4
- execute_transaction_api_url: '/payment/ExecTran.idPass'
5
- search_transaction_api_url: '/payment/SearchTrade.idPass'
6
- alter_transaction_api_url: '/payment/AlterTran.idPass'
7
- member:
8
- register_member_api_url: '/payment/SaveMember.idPass'
9
- search_member_api_url: '/payment/SearchMember.idPass'
10
- update_member_api_url: '/payment/UpdateMember.idPass'
11
- delete_member_api_url: '/payment/DeleteMember.idPass'
12
- add_card_to_member_api_url: '/payment/SaveCard.idPass'
13
- search_card_api_url: '/payment/SearchCard.idPass'
14
- delete_card_api_url: '/payment/DeleteCard.idPass'
1
+ payments:
2
+ card:
3
+ entry_transaction_api_url: '/payment/EntryTran.idPass'
4
+ execute_transaction_api_url: '/payment/ExecTran.idPass'
5
+ search_transaction_api_url: '/payment/SearchTrade.idPass'
6
+ alter_transaction_api_url: '/payment/AlterTran.idPass'
7
+ member:
8
+ register_member_api_url: '/payment/SaveMember.idPass'
9
+ search_member_api_url: '/payment/SearchMember.idPass'
10
+ update_member_api_url: '/payment/UpdateMember.idPass'
11
+ delete_member_api_url: '/payment/DeleteMember.idPass'
12
+ add_card_to_member_api_url: '/payment/SaveCard.idPass'
13
+ search_card_api_url: '/payment/SearchCard.idPass'
14
+ delete_card_api_url: '/payment/DeleteCard.idPass'
@@ -1,35 +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
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
@@ -1,100 +1,117 @@
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
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
+ def update_transaction_to_actual_sale(params)
37
+ api_url = settings.alter_transaction_api_url
38
+ params = initialize_params_of_update_transaction_to_actual_sale(params)
39
+ post_request(api_url, params)
40
+ end
41
+
42
+ private
43
+
44
+ def initialize_settings
45
+ Settings.payments.card
46
+ end
47
+
48
+ def initialize_params_of_entry_transaction(params)
49
+ {
50
+ ShopID: shop_id,
51
+ ShopPass: shop_pass,
52
+ OrderID: params[:order_id],
53
+ JobCd: params[:job_cd],
54
+ Amount: params[:amount]
55
+ }
56
+ end
57
+
58
+ def initialize_default_params_of_execute_transaction(params)
59
+ {
60
+ AccessID: params[:access_id],
61
+ AccessPass: params[:access_pass],
62
+ OrderID: params[:order_id],
63
+ Method: params[:method],
64
+ PayTimes: params[:pay_times],
65
+ PIN: params[:pin]
66
+ }
67
+ end
68
+
69
+ def initialize_params_of_execute_transaction_by_token(params)
70
+ default_params = initialize_default_params_of_execute_transaction(params)
71
+ default_params.merge(TokenType: params[:token_type], Token: params[:token])
72
+ end
73
+
74
+ def initialize_params_of_execute_transaction_by_member(params)
75
+ default_params = initialize_default_params_of_execute_transaction(params)
76
+ default_params.merge(
77
+ SiteID: params[:site_id],
78
+ SitePass: params[:site_pass],
79
+ MemberID: params[:member_id],
80
+ CardSeq: params[:card_seq],
81
+ SeqMode: params[:seq_mode],
82
+ CardPass: params[:card_pass],
83
+ SecurityCode: params[:security_code]
84
+ )
85
+ end
86
+
87
+ def initialize_params_of_search_transaction(params)
88
+ {
89
+ ShopID: shop_id,
90
+ ShopPass: shop_pass,
91
+ OrderID: params[:order_id]
92
+ }
93
+ end
94
+
95
+ def initialize_params_of_cancel_transaction(params)
96
+ {
97
+ ShopID: shop_id,
98
+ ShopPass: shop_pass,
99
+ AccessID: params[:access_id],
100
+ AccessPass: params[:access_pass],
101
+ JobCd: 'CANCEL'
102
+ }
103
+ end
104
+
105
+ def initialize_params_of_update_transaction_to_actual_sale(params)
106
+ {
107
+ ShopID: shop_id,
108
+ ShopPass: shop_pass,
109
+ AccessID: params[:access_id],
110
+ AccessPass: params[:access_pass],
111
+ Amount: params[:amount],
112
+ JobCd: 'SALES'
113
+ }
114
+ end
115
+ end
116
+ end
117
+ end
@@ -1,28 +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
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
@@ -1,121 +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
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,9 @@
1
+ module GmoServices
2
+ module Payments
3
+ class Settings
4
+ def self.entry_transaction_api_url
5
+ '/payment/EntryTran.idPass'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
- module GmoServices
2
- VERSION = '0.1.5'.freeze
3
- end
1
+ module GmoServices
2
+ VERSION = '0.1.6'.freeze
3
+ end
data/lib/gmo_services.rb CHANGED
@@ -1,17 +1,17 @@
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
- english_locale_file_path = File.join(File.dirname(__FILE__), 'config/locales/gmo_error_info/en.yml')
10
- I18n.load_path << english_locale_file_path
11
-
12
- require 'config'
13
- settings_file_path = File.join(File.dirname(__FILE__), 'config/settings.yml')
14
- Config.load_and_set_settings(settings_file_path)
15
-
16
- module GmoServices
17
- end
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
+ english_locale_file_path = File.join(File.dirname(__FILE__), 'config/locales/gmo_error_info/en.yml')
10
+ I18n.load_path << english_locale_file_path
11
+
12
+ require 'config'
13
+ settings_file_path = File.join(File.dirname(__FILE__), 'config/settings.yml')
14
+ Config.load_and_set_settings(settings_file_path)
15
+
16
+ module GmoServices
17
+ end