gmo_payment 0.0.1
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 +7 -0
- data/.coveralls.yml +1 -0
- data/.editorconfig +12 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +20 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +17 -0
- data/MIT-LICENSE +22 -0
- data/README.md +101 -0
- data/Rakefile +7 -0
- data/gmo_payment.gemspec +22 -0
- data/lib/generators/gmo_payment/install_generator.rb +15 -0
- data/lib/generators/gmo_payment/templates/ja.yml +246 -0
- data/lib/gmo_payment/client/options.rb +39 -0
- data/lib/gmo_payment/client/request.rb +294 -0
- data/lib/gmo_payment/client/response.rb +205 -0
- data/lib/gmo_payment/client.rb +538 -0
- data/lib/gmo_payment/configure.rb +30 -0
- data/lib/gmo_payment/errors.rb +95 -0
- data/lib/gmo_payment/glossary.rb +66 -0
- data/lib/gmo_payment/version.rb +3 -0
- data/lib/gmo_payment.rb +31 -0
- data/spec/cassettes/GmoPayment_Client/_auth_to_sales/return_6_items.yml +120 -0
- data/spec/cassettes/GmoPayment_Client/_call/with_ResponseHTTPError/raise_ResponseHTTPError.yml +46 -0
- data/spec/cassettes/GmoPayment_Client/_call/with_ResponseHasErrCodeError/raise_ResponseHTTPError.yml +48 -0
- data/spec/cassettes/GmoPayment_Client/_change_tran/return_6_items.yml +120 -0
- data/spec/cassettes/GmoPayment_Client/_delete_card/return_1_items.yml +114 -0
- data/spec/cassettes/GmoPayment_Client/_delete_member/return_1_items.yml +77 -0
- data/spec/cassettes/GmoPayment_Client/_delete_tran/return_6_items.yml +120 -0
- data/spec/cassettes/GmoPayment_Client/_entry_tran/return_2_items.yml +40 -0
- data/spec/cassettes/GmoPayment_Client/_entry_tran_btc/return_2_items.yml +42 -0
- data/spec/cassettes/GmoPayment_Client/_exec_tran/return_12_items.yml +83 -0
- data/spec/cassettes/GmoPayment_Client/_exec_tran_3d/return_4_items.yml +77 -0
- data/spec/cassettes/GmoPayment_Client/_exec_tran_btc/return_3_items.yml +81 -0
- data/spec/cassettes/GmoPayment_Client/_exec_tran_member/return_12_items.yml +157 -0
- data/spec/cassettes/GmoPayment_Client/_exec_tran_member_3d/return_4_items.yml +151 -0
- data/spec/cassettes/GmoPayment_Client/_get_rate_btc/return_1_item.yml +42 -0
- data/spec/cassettes/GmoPayment_Client/_re_exec_tran/return_6_items.yml +157 -0
- data/spec/cassettes/GmoPayment_Client/_save_card/return_3_items.yml +77 -0
- data/spec/cassettes/GmoPayment_Client/_save_member/return_1_items.yml +40 -0
- data/spec/cassettes/GmoPayment_Client/_save_traded_card/return_3_items.yml +157 -0
- data/spec/cassettes/GmoPayment_Client/_search_card/return_7_items.yml +114 -0
- data/spec/cassettes/GmoPayment_Client/_search_member/return_3_items.yml +77 -0
- data/spec/cassettes/GmoPayment_Client/_search_trade/return_21_items.yml +77 -0
- data/spec/cassettes/GmoPayment_Client/_search_trade_btc/return_11_items.yml +79 -0
- data/spec/cassettes/GmoPayment_Client/_secure_tran/return_11_items.yml +120 -0
- data/spec/cassettes/GmoPayment_Client/_update_card/return_3_items.yml +114 -0
- data/spec/cassettes/GmoPayment_Client/_update_member/return_1_items.yml +77 -0
- data/spec/cassettes/GmoPayment_Client_Response/GmoPayment_GLOSSARY_keys_to_method/return_body_values_if_body_match_Hash_keys_and_GLOSSARY_keys.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_body/with_prebody_match_Hash_keys_and_GLOSSARY_keys/return_Hash_keys_Symbol_and_values_as_it_is.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_body/without_prebody_match_Hash_keys_and_GLOSSARY_keys/return_Hash_keys_String_and_values_as_it_is.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_encoded_raw_body/return_String_of_encoded_Shift_JIS_to_UTF-8.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_error_/with_ErrCode/return_true.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_error_/without_ErrCode/return_false.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_http_code/return_Integer_of_HTTP_status_code.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_http_error_/with_2xx/return_false.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_http_error_/without_2xx/return_true.yml +44 -0
- data/spec/cassettes/GmoPayment_Client_Response/_http_header/return_Hash_of_HTTP_header.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_http_message/return_String_of_HTTP_message.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_prebody/with_ErrCode/behaves_like_getting_Hash_values_Array/return_Hash_keys_String_and_values_Array.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_prebody/with_called_return_array_true/behaves_like_getting_Hash_values_Array/return_Hash_keys_String_and_values_Array.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_prebody/with_no_ErroCode_and_called_return_array_false/return_Hash_keys_and_values_String.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_raw_body/return_String_of_HTTP_response_body_as_it_is.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_split_encoded_raw_body/behaves_like_URI_decode_www_form/with_response_body_have_invalid_parameters_to_split/return_empty_Array.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_split_encoded_raw_body/behaves_like_URI_decode_www_form/with_response_body_have_only_GLOSSARY_keys/return_predefined_Array_format.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_split_encoded_raw_body_/behaves_like_URI_decode_www_form/with_response_body_have_invalid_parameters_to_split/return_empty_Array.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_split_encoded_raw_body_/behaves_like_URI_decode_www_form/with_response_body_have_only_GLOSSARY_keys/return_predefined_Array_format.yml +46 -0
- data/spec/cassettes/GmoPayment_Client_Response/_split_encoded_raw_body_/with_response_body_have_not_only_GLOSSARY_keys/returns_predefined_Array_format_without_GLOSSARY_keys.yml +46 -0
- data/spec/gmo_payment/client/options_spec.rb +107 -0
- data/spec/gmo_payment/client/request_spec.rb +403 -0
- data/spec/gmo_payment/client/response_spec.rb +280 -0
- data/spec/gmo_payment/client_spec.rb +809 -0
- data/spec/gmo_payment/configure_spec.rb +90 -0
- data/spec/gmo_payment/errors_spec.rb +118 -0
- data/spec/gmo_payment/glossary_spec.rb +15 -0
- data/spec/gmo_payment_spec.rb +22 -0
- data/spec/spec_helper.rb +70 -0
- data/spec/support/request_validation.rb +71 -0
- metadata +179 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
require 'base64'
|
|
3
|
+
|
|
4
|
+
module GmoPayment
|
|
5
|
+
class Client
|
|
6
|
+
class Request
|
|
7
|
+
# @param [Symbol] called_method
|
|
8
|
+
# @param [Hash] args
|
|
9
|
+
def initialize(called_method, args)
|
|
10
|
+
@called_method = called_method
|
|
11
|
+
input =
|
|
12
|
+
args.each_with_object({}) do |(k, v), hash|
|
|
13
|
+
key = k.to_s.downcase.to_sym
|
|
14
|
+
value = case key
|
|
15
|
+
when :job_cd
|
|
16
|
+
v.to_s.upcase
|
|
17
|
+
when :amount, :card_seq, :default_flag, :method, :pay_times, :seq_mode, :tax, :td_flag, :timeout
|
|
18
|
+
v.to_i.to_s
|
|
19
|
+
else
|
|
20
|
+
v.to_s
|
|
21
|
+
end
|
|
22
|
+
hash[key] = value
|
|
23
|
+
end
|
|
24
|
+
[:site_id, :site_pass, :shop_id, :shop_pass].each do |key|
|
|
25
|
+
if all_items.include?(key)
|
|
26
|
+
input[key] ||= GmoPayment::Configure.__send__(key) || ENV[GmoPayment::GLOSSARY[key]]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
@input = input.reject { |_, v| v.nil? }
|
|
30
|
+
@missing_items = self.missing_items
|
|
31
|
+
@invalid_items = self.invalid_items
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @!attribute [r] called_method
|
|
35
|
+
attr_reader :called_method
|
|
36
|
+
|
|
37
|
+
# Check missing items.
|
|
38
|
+
#
|
|
39
|
+
# @return [Array]
|
|
40
|
+
def missing_items
|
|
41
|
+
return @missing_items if @missing_items
|
|
42
|
+
|
|
43
|
+
array = case @called_method
|
|
44
|
+
when :entry_tran
|
|
45
|
+
if @input[:job_cd] && ['CAPTURE', 'AUTH', 'SAUTH'].include?(@input[:job_cd])
|
|
46
|
+
required_items << :amount
|
|
47
|
+
else
|
|
48
|
+
required_items
|
|
49
|
+
end
|
|
50
|
+
when :exec_tran, :exec_tran_3d, :exec_tran_member, :exec_tran_member_3d, :re_exec_tran
|
|
51
|
+
if @input[:method] && ['2', '4'].include?(@input[:method])
|
|
52
|
+
required_items << :pay_times
|
|
53
|
+
else
|
|
54
|
+
required_items
|
|
55
|
+
end
|
|
56
|
+
else
|
|
57
|
+
required_items
|
|
58
|
+
end
|
|
59
|
+
@missing_items = array.select { |item| @input[item].nil? }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Whether to have missing items or not.
|
|
63
|
+
#
|
|
64
|
+
# @return [Boolean]
|
|
65
|
+
def missing?
|
|
66
|
+
!missing_items.empty?
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Validate to have invalid items.
|
|
70
|
+
#
|
|
71
|
+
# @return [Hash]
|
|
72
|
+
def invalid_items
|
|
73
|
+
return @invalid_items if @invalid_items
|
|
74
|
+
|
|
75
|
+
items = @input.select { |k, v| validate_invalid?(k, v) if all_items.include?(k) }
|
|
76
|
+
case @called_method
|
|
77
|
+
when :entry_tran, :re_exec_tran, :change_tran
|
|
78
|
+
unless (1..9_999_999).include?(@input[:amount].to_i + @input[:tax].to_i)
|
|
79
|
+
items[:amount] = @input[:amount] if @input[:amount]
|
|
80
|
+
items[:tax] = @input[:tax] if @input[:tax]
|
|
81
|
+
end
|
|
82
|
+
when :entry_tran_btc
|
|
83
|
+
unless (1..300_000).include?(@input[:amount].to_i + @input[:tax].to_i)
|
|
84
|
+
items[:amount] = @input[:amount] if @input[:amount]
|
|
85
|
+
items[:tax] = @input[:tax] if @input[:tax]
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
@invalid_items = items
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Whether to have invalid items or not.
|
|
92
|
+
#
|
|
93
|
+
# @return [Bloolean]
|
|
94
|
+
def invalid?
|
|
95
|
+
!invalid_items.empty?
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Request body.
|
|
99
|
+
#
|
|
100
|
+
# @return [String, nil]
|
|
101
|
+
def body
|
|
102
|
+
body_hash =
|
|
103
|
+
@input.each_with_object({}) do |(k, v), hash|
|
|
104
|
+
next unless (key = GmoPayment::GLOSSARY[k]) && all_items.include?(k)
|
|
105
|
+
hash[key] = k == :td_tenant_name ? encode_euc_base64(v) : encode_sjis(v)
|
|
106
|
+
end
|
|
107
|
+
body = ::URI.encode_www_form(body_hash)
|
|
108
|
+
body.empty? ? nil : body
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
private
|
|
112
|
+
|
|
113
|
+
# @param [String] str
|
|
114
|
+
# @return [String] String of encoding to Base64 encoded in EUC-JP.
|
|
115
|
+
def encode_euc_base64(str)
|
|
116
|
+
::Base64.strict_encode64(str.encode('EUC-JP', :invalid => :replace, :undef => :replace))
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# @param [String] str
|
|
120
|
+
# @return [String] String encoded in Shif_JIS.
|
|
121
|
+
def encode_sjis(str)
|
|
122
|
+
str.encode('Shift_JIS', :invalid => :replace, :undef => :replace)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# @return [Array]
|
|
126
|
+
def all_items
|
|
127
|
+
required_items + optional_items
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# @return [Array]
|
|
131
|
+
def required_items
|
|
132
|
+
case @called_method
|
|
133
|
+
when :entry_tran
|
|
134
|
+
[:shop_id, :shop_pass, :order_id, :job_cd]
|
|
135
|
+
when :exec_tran
|
|
136
|
+
[:access_id, :access_pass, :order_id, :card_no, :expire]
|
|
137
|
+
when :exec_tran_3d
|
|
138
|
+
[:access_id, :access_pass, :order_id, :card_no, :expire, :http_accept, :http_user_agent, :device_category]
|
|
139
|
+
when :secure_tran
|
|
140
|
+
[:pa_res, :md]
|
|
141
|
+
when :save_member, :update_member, :delete_member, :search_member
|
|
142
|
+
[:site_id, :site_pass, :member_id]
|
|
143
|
+
when :save_card
|
|
144
|
+
[:site_id, :site_pass, :member_id, :card_no, :expire]
|
|
145
|
+
when :update_card
|
|
146
|
+
[:site_id, :site_pass, :member_id, :card_seq, :card_no, :expire]
|
|
147
|
+
when :delete_card
|
|
148
|
+
[:site_id, :site_pass, :member_id, :card_seq]
|
|
149
|
+
when :search_card
|
|
150
|
+
[:site_id, :site_pass, :member_id, :seq_mode]
|
|
151
|
+
when :exec_tran_member
|
|
152
|
+
[:access_id, :access_pass, :order_id, :site_id, :site_pass, :member_id, :card_seq]
|
|
153
|
+
when :exec_tran_member_3d
|
|
154
|
+
[:access_id, :access_pass, :order_id, :site_id, :site_pass, :member_id, :card_seq, :http_accept, :http_user_agent, :device_category]
|
|
155
|
+
when :delete_tran
|
|
156
|
+
[:shop_id, :shop_pass, :access_id, :access_pass, :job_cd]
|
|
157
|
+
when :re_exec_tran
|
|
158
|
+
[:shop_id, :shop_pass, :access_id, :access_pass, :job_cd, :amount, :method]
|
|
159
|
+
when :auth_to_sales, :change_tran
|
|
160
|
+
[:shop_id, :shop_pass, :access_id, :access_pass, :job_cd, :amount]
|
|
161
|
+
when :search_trade
|
|
162
|
+
[:shop_id, :shop_pass, :order_id]
|
|
163
|
+
when :save_traded_card
|
|
164
|
+
[:shop_id, :shop_pass, :order_id, :site_id, :site_pass, :member_id]
|
|
165
|
+
when :entry_tran_btc
|
|
166
|
+
[:shop_id, :shop_pass, :order_id, :amount]
|
|
167
|
+
when :exec_tran_btc
|
|
168
|
+
[:shop_id, :access_id, :access_pass, :order_id, :ret_url, :item_name, :timeout, :item_memo]
|
|
169
|
+
when :get_rate_btc
|
|
170
|
+
[:shop_id, :shop_pass]
|
|
171
|
+
when :search_trade_btc
|
|
172
|
+
[:shop_id, :shop_pass, :order_id, :pay_type]
|
|
173
|
+
else
|
|
174
|
+
[]
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# @return [Array]
|
|
179
|
+
def optional_items
|
|
180
|
+
case @called_method
|
|
181
|
+
when :entry_tran
|
|
182
|
+
[:item_code, :amount, :tax, :td_flag, :td_tenant_name]
|
|
183
|
+
when :exec_tran
|
|
184
|
+
[:method, :pay_times, :security_code, :pin, :client_field_1, :client_field_2, :client_field_3, :client_field_flag]
|
|
185
|
+
when :exec_tran_3d
|
|
186
|
+
[:method, :pay_times, :security_code, :client_field_1, :client_field_2, :client_field_3, :client_field_flag]
|
|
187
|
+
when :save_member, :update_member
|
|
188
|
+
[:member_name]
|
|
189
|
+
when :save_card, :update_card
|
|
190
|
+
[:seq_mode, :default_flag, :card_name, :card_pass, :holder_name]
|
|
191
|
+
when :delete_card
|
|
192
|
+
[:seq_mode]
|
|
193
|
+
when :search_card
|
|
194
|
+
[:card_seq]
|
|
195
|
+
when :exec_tran_member, :exec_tran_member_3d
|
|
196
|
+
[:method, :pay_times, :seq_mode, :card_pass, :security_code, :client_field_1, :client_field_2, :client_field_3, :client_field_flag]
|
|
197
|
+
when :re_exec_tran
|
|
198
|
+
[:tax, :pay_times]
|
|
199
|
+
when :change_tran, :entry_tran_btc
|
|
200
|
+
[:tax]
|
|
201
|
+
when :save_traded_card
|
|
202
|
+
[:seq_mode, :default_flag, :holder_name]
|
|
203
|
+
when :exec_tran_btc
|
|
204
|
+
[:client_field_1, :client_field_2, :client_field_3]
|
|
205
|
+
else
|
|
206
|
+
[]
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
# @param [Symbol] key
|
|
211
|
+
# @param [String] value
|
|
212
|
+
# @return [Boolean]
|
|
213
|
+
def validate_invalid?(key, value)
|
|
214
|
+
!validate_valid?(key, value)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# @param [Symbol] key
|
|
218
|
+
# @param [String] value
|
|
219
|
+
# @return [Boolean]
|
|
220
|
+
def validate_valid?(key, value)
|
|
221
|
+
case key
|
|
222
|
+
when :access_id, :access_pass
|
|
223
|
+
value.length <= 32
|
|
224
|
+
when :amount, :tax
|
|
225
|
+
(value =~ /\D/).nil? && value.length <= 7
|
|
226
|
+
when :card_name
|
|
227
|
+
value.length <= 10
|
|
228
|
+
when :card_no
|
|
229
|
+
(value =~ /\D/).nil? && (10..16).include?(value.length)
|
|
230
|
+
when :card_pass
|
|
231
|
+
(value =~ /[^a-zA-Z0-9]/).nil? && value.length <= 20
|
|
232
|
+
when :card_seq
|
|
233
|
+
(value =~ /\D/).nil? && value.length <= 4
|
|
234
|
+
when :client_field_1, :client_field_2, :client_field_3
|
|
235
|
+
(value =~ /[\{\}\|^`~&<>"']/).nil? && value.length <= 100
|
|
236
|
+
when :client_field_flag, :default_flag, :device_category, :seq_mode, :td_flag
|
|
237
|
+
['0', '1'].include?(value)
|
|
238
|
+
when :expire
|
|
239
|
+
(value =~ /\D/).nil? && value.length == 4
|
|
240
|
+
when :holder_name
|
|
241
|
+
(value =~ /[^a-zA-Z0-9\s]/).nil? && value.length <= 50
|
|
242
|
+
when :item_code
|
|
243
|
+
(value =~ /\D/).nil? && value.length == 7
|
|
244
|
+
when :item_memo
|
|
245
|
+
value.length <= 128
|
|
246
|
+
when :item_name
|
|
247
|
+
value.length <= 64
|
|
248
|
+
when :job_cd
|
|
249
|
+
case @called_method
|
|
250
|
+
when :entry_tran
|
|
251
|
+
['CHECK', 'CAPTURE', 'AUTH', 'SAUTH'].include?(value)
|
|
252
|
+
when :delete_tran
|
|
253
|
+
['VOID', 'RETURN', 'RETURNX'].include?(value)
|
|
254
|
+
when :re_exec_tran
|
|
255
|
+
['CAPTURE', 'AUTH'].include?(value)
|
|
256
|
+
when :change_tran
|
|
257
|
+
['CAPTURE', 'AUTH', 'SAUTH'].include?(value)
|
|
258
|
+
else
|
|
259
|
+
true
|
|
260
|
+
end
|
|
261
|
+
when :member_id
|
|
262
|
+
(value =~ /[^\w\-\.@]/).nil? && value.length <= 60
|
|
263
|
+
when :member_name
|
|
264
|
+
(value =~ /[\{\}\|^`~&<>"']/).nil? && value.length <= 255
|
|
265
|
+
when :method
|
|
266
|
+
['1', '2', '3', '4', '5'].include?(value)
|
|
267
|
+
when :order_id
|
|
268
|
+
(value =~ /[^a-zA-Z0-9\-]/).nil? && value.length <= 27
|
|
269
|
+
when :pay_times
|
|
270
|
+
(value =~ /\D/).nil? && value.length <= 2
|
|
271
|
+
when :pin
|
|
272
|
+
value.length <= 4
|
|
273
|
+
when :ret_url
|
|
274
|
+
value.length <= 256
|
|
275
|
+
when :security_code
|
|
276
|
+
(value =~ /\D/).nil? && (3..4).include?(value.length)
|
|
277
|
+
when :shop_id, :site_id
|
|
278
|
+
value.length <= 13
|
|
279
|
+
when :shop_pass
|
|
280
|
+
value.length <= 10
|
|
281
|
+
when :site_pass
|
|
282
|
+
value.length <= 20
|
|
283
|
+
when :td_tenant_name
|
|
284
|
+
encode_euc_base64(value).bytesize <= 25
|
|
285
|
+
when :timeout
|
|
286
|
+
value.to_i <= 86400
|
|
287
|
+
else
|
|
288
|
+
true
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
end
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
module GmoPayment
|
|
4
|
+
class Client
|
|
5
|
+
class Response
|
|
6
|
+
# @param [Symbol] called_method
|
|
7
|
+
# @param [Net::HTTPResponse] response
|
|
8
|
+
def initialize(called_method, response)
|
|
9
|
+
@called_method = called_method
|
|
10
|
+
@response = response
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @!attribute [r] called_method
|
|
14
|
+
attr_reader :called_method
|
|
15
|
+
|
|
16
|
+
# Whether {#prebody} which of Hash values should return array or not.
|
|
17
|
+
# If called {GmoPayment::Api#search_card}, it will return true.
|
|
18
|
+
def called_return_array?
|
|
19
|
+
@called_method == :search_card
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# When generating {#prebody}, whether to use {#split_encoded_raw_body} or not.
|
|
23
|
+
# If called {GmoPayment::Api#search_trade_btc}, it will return true.
|
|
24
|
+
def called_split_normal?
|
|
25
|
+
@called_method != :search_trade_btc
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# HTTP response header.
|
|
29
|
+
#
|
|
30
|
+
# @return [Hash]
|
|
31
|
+
def http_header
|
|
32
|
+
hash = {}
|
|
33
|
+
@response.each do |key, value|
|
|
34
|
+
hash[key] = value
|
|
35
|
+
end
|
|
36
|
+
hash
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# HTTP status code.
|
|
40
|
+
#
|
|
41
|
+
# @return [Integer]
|
|
42
|
+
def http_code
|
|
43
|
+
@response.code.to_i
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# HTTP status message.
|
|
47
|
+
#
|
|
48
|
+
# @return [String]
|
|
49
|
+
def http_message
|
|
50
|
+
@response.message.to_s
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Reponse body as it is.
|
|
54
|
+
#
|
|
55
|
+
# @return [String]
|
|
56
|
+
def raw_body
|
|
57
|
+
@response.body.to_s
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Encode {#raw_body} Shift_JIS to UTF-8.
|
|
61
|
+
#
|
|
62
|
+
# @return [String]
|
|
63
|
+
def encoded_raw_body
|
|
64
|
+
self.raw_body.encode('UTF-8', 'Shift_JIS', :invalid => :replace, :undef => :replace)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Split {#encoded_raw_body} by {GmoPayment::GLOSSARY} keys.
|
|
68
|
+
# It works like URI.decode_www_form.
|
|
69
|
+
#
|
|
70
|
+
# @example
|
|
71
|
+
# "AccessID=xxx&AccessPass=zzz-1|zzz-2&PayTimes="
|
|
72
|
+
# # => [["AccessID", ["xxx"]], ["AccessPass", ["zzz-1", "zzz-2"]]] # PayTimes is unavailable.
|
|
73
|
+
#
|
|
74
|
+
# @return [Array]
|
|
75
|
+
def split_encoded_raw_body
|
|
76
|
+
return_array = []
|
|
77
|
+
array = self.encoded_raw_body.split(/(&?#{GmoPayment::GLOSSARY.values.join('=)|(&?')}=)/).values_at(1..-1)
|
|
78
|
+
array.each_slice(2) do |(key, value)|
|
|
79
|
+
next if value.nil? || value.empty?
|
|
80
|
+
return_array << [key.gsub(/[&=]/, ''), value.split('|')]
|
|
81
|
+
end
|
|
82
|
+
return_array
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Split {#encoded_raw_body} by "&" and "=".
|
|
86
|
+
# It works like URI.decode_www_form.
|
|
87
|
+
#
|
|
88
|
+
# @example
|
|
89
|
+
# "A=a&B=&C=c-1|c-2"
|
|
90
|
+
# # => [["A", ["a"]], ["C", ["c-1", "c-2"]]] # B is unavailable.
|
|
91
|
+
#
|
|
92
|
+
# @return [Array]
|
|
93
|
+
def split_encoded_raw_body!
|
|
94
|
+
self.encoded_raw_body.split('&').map do |elem|
|
|
95
|
+
key, value = elem.split('=', 2)
|
|
96
|
+
[key, value.split('|')] unless value.nil? || value.empty?
|
|
97
|
+
end.compact
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Convert response body to an easy-to-use format.
|
|
101
|
+
#
|
|
102
|
+
# @return [Hash]
|
|
103
|
+
# Hash<String, Array> if {#encoded_raw_body} has "ErrCode" or {#called_return_array?} is true.
|
|
104
|
+
# The other cases, it will return Hash<String, String>.
|
|
105
|
+
def prebody
|
|
106
|
+
array = called_split_normal? ? self.split_encoded_raw_body : self.split_encoded_raw_body!
|
|
107
|
+
array.each_with_object({}) do |(key, value), hash|
|
|
108
|
+
if called_return_array? || ['ErrCode', 'ErrInfo'].include?(key)
|
|
109
|
+
hash[key] = value
|
|
110
|
+
else
|
|
111
|
+
hash[key] = value.join('|')
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Convert {#prebody} keys to Symbol that is {GmoPayment::GLOSSARY} key.
|
|
117
|
+
#
|
|
118
|
+
# @return [Hash]
|
|
119
|
+
def body
|
|
120
|
+
self.prebody.each_with_object({}) do |(key, value), hash|
|
|
121
|
+
hash[GmoPayment::GLOSSARY.key(key) || key] = value
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Whether HTTP response is not 2xx.
|
|
126
|
+
def http_error?
|
|
127
|
+
!(200..299).include?(http_code)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Whether response body has "ErrCode" or not.
|
|
131
|
+
def error?
|
|
132
|
+
self.body.keys.include?(:err_code)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Define {GmoPayment::GLOSSARY} keys' name to methods.
|
|
136
|
+
#
|
|
137
|
+
# @!method access_id
|
|
138
|
+
# @!method access_pass
|
|
139
|
+
# @!method acs
|
|
140
|
+
# @!method acs_url
|
|
141
|
+
# @!method amount
|
|
142
|
+
# @!method approve
|
|
143
|
+
# @!method card_name
|
|
144
|
+
# @!method card_no
|
|
145
|
+
# @!method card_pass
|
|
146
|
+
# @!method card_seq
|
|
147
|
+
# @!method check_string
|
|
148
|
+
# @!method client_field_1
|
|
149
|
+
# @!method client_field_2
|
|
150
|
+
# @!method client_field_3
|
|
151
|
+
# @!method client_field_flag
|
|
152
|
+
# @!method currency
|
|
153
|
+
# @!method default_flag
|
|
154
|
+
# @!method delete_flag
|
|
155
|
+
# @!method device_category
|
|
156
|
+
# @!method err_code
|
|
157
|
+
# @!method err_info
|
|
158
|
+
# @!method expire
|
|
159
|
+
# @!method forward
|
|
160
|
+
# @!method holder_name
|
|
161
|
+
# @!method http_accept
|
|
162
|
+
# @!method http_user_agent
|
|
163
|
+
# @!method item_code
|
|
164
|
+
# @!method item_memo
|
|
165
|
+
# @!method item_name
|
|
166
|
+
# @!method job_cd
|
|
167
|
+
# @!method md
|
|
168
|
+
# @!method member_id
|
|
169
|
+
# @!method member_name
|
|
170
|
+
# @!method method
|
|
171
|
+
# @!method order_id
|
|
172
|
+
# @!method pa_req
|
|
173
|
+
# @!method pa_res
|
|
174
|
+
# @!method pay_times
|
|
175
|
+
# @!method pay_type
|
|
176
|
+
# @!method pin
|
|
177
|
+
# @!method process_date
|
|
178
|
+
# @!method recv_res
|
|
179
|
+
# @!method ret_url
|
|
180
|
+
# @!method security_code
|
|
181
|
+
# @!method seq_mode
|
|
182
|
+
# @!method shop_id
|
|
183
|
+
# @!method shop_pass
|
|
184
|
+
# @!method site_id
|
|
185
|
+
# @!method site_pass
|
|
186
|
+
# @!method start_url
|
|
187
|
+
# @!method status
|
|
188
|
+
# @!method tax
|
|
189
|
+
# @!method td_flag
|
|
190
|
+
# @!method td_tenant_name
|
|
191
|
+
# @!method term_url
|
|
192
|
+
# @!method token
|
|
193
|
+
# @!method tran_id
|
|
194
|
+
# @!method tran_date
|
|
195
|
+
GmoPayment::GLOSSARY.each_key do |key|
|
|
196
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
197
|
+
def #{key}
|
|
198
|
+
self.body[__method__]
|
|
199
|
+
end
|
|
200
|
+
RUBY
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|