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.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.editorconfig +12 -0
  4. data/.gitignore +9 -0
  5. data/.rspec +2 -0
  6. data/.travis.yml +20 -0
  7. data/CHANGELOG.md +5 -0
  8. data/Gemfile +17 -0
  9. data/MIT-LICENSE +22 -0
  10. data/README.md +101 -0
  11. data/Rakefile +7 -0
  12. data/gmo_payment.gemspec +22 -0
  13. data/lib/generators/gmo_payment/install_generator.rb +15 -0
  14. data/lib/generators/gmo_payment/templates/ja.yml +246 -0
  15. data/lib/gmo_payment/client/options.rb +39 -0
  16. data/lib/gmo_payment/client/request.rb +294 -0
  17. data/lib/gmo_payment/client/response.rb +205 -0
  18. data/lib/gmo_payment/client.rb +538 -0
  19. data/lib/gmo_payment/configure.rb +30 -0
  20. data/lib/gmo_payment/errors.rb +95 -0
  21. data/lib/gmo_payment/glossary.rb +66 -0
  22. data/lib/gmo_payment/version.rb +3 -0
  23. data/lib/gmo_payment.rb +31 -0
  24. data/spec/cassettes/GmoPayment_Client/_auth_to_sales/return_6_items.yml +120 -0
  25. data/spec/cassettes/GmoPayment_Client/_call/with_ResponseHTTPError/raise_ResponseHTTPError.yml +46 -0
  26. data/spec/cassettes/GmoPayment_Client/_call/with_ResponseHasErrCodeError/raise_ResponseHTTPError.yml +48 -0
  27. data/spec/cassettes/GmoPayment_Client/_change_tran/return_6_items.yml +120 -0
  28. data/spec/cassettes/GmoPayment_Client/_delete_card/return_1_items.yml +114 -0
  29. data/spec/cassettes/GmoPayment_Client/_delete_member/return_1_items.yml +77 -0
  30. data/spec/cassettes/GmoPayment_Client/_delete_tran/return_6_items.yml +120 -0
  31. data/spec/cassettes/GmoPayment_Client/_entry_tran/return_2_items.yml +40 -0
  32. data/spec/cassettes/GmoPayment_Client/_entry_tran_btc/return_2_items.yml +42 -0
  33. data/spec/cassettes/GmoPayment_Client/_exec_tran/return_12_items.yml +83 -0
  34. data/spec/cassettes/GmoPayment_Client/_exec_tran_3d/return_4_items.yml +77 -0
  35. data/spec/cassettes/GmoPayment_Client/_exec_tran_btc/return_3_items.yml +81 -0
  36. data/spec/cassettes/GmoPayment_Client/_exec_tran_member/return_12_items.yml +157 -0
  37. data/spec/cassettes/GmoPayment_Client/_exec_tran_member_3d/return_4_items.yml +151 -0
  38. data/spec/cassettes/GmoPayment_Client/_get_rate_btc/return_1_item.yml +42 -0
  39. data/spec/cassettes/GmoPayment_Client/_re_exec_tran/return_6_items.yml +157 -0
  40. data/spec/cassettes/GmoPayment_Client/_save_card/return_3_items.yml +77 -0
  41. data/spec/cassettes/GmoPayment_Client/_save_member/return_1_items.yml +40 -0
  42. data/spec/cassettes/GmoPayment_Client/_save_traded_card/return_3_items.yml +157 -0
  43. data/spec/cassettes/GmoPayment_Client/_search_card/return_7_items.yml +114 -0
  44. data/spec/cassettes/GmoPayment_Client/_search_member/return_3_items.yml +77 -0
  45. data/spec/cassettes/GmoPayment_Client/_search_trade/return_21_items.yml +77 -0
  46. data/spec/cassettes/GmoPayment_Client/_search_trade_btc/return_11_items.yml +79 -0
  47. data/spec/cassettes/GmoPayment_Client/_secure_tran/return_11_items.yml +120 -0
  48. data/spec/cassettes/GmoPayment_Client/_update_card/return_3_items.yml +114 -0
  49. data/spec/cassettes/GmoPayment_Client/_update_member/return_1_items.yml +77 -0
  50. 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
  51. 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
  52. 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
  53. data/spec/cassettes/GmoPayment_Client_Response/_encoded_raw_body/return_String_of_encoded_Shift_JIS_to_UTF-8.yml +46 -0
  54. data/spec/cassettes/GmoPayment_Client_Response/_error_/with_ErrCode/return_true.yml +46 -0
  55. data/spec/cassettes/GmoPayment_Client_Response/_error_/without_ErrCode/return_false.yml +46 -0
  56. data/spec/cassettes/GmoPayment_Client_Response/_http_code/return_Integer_of_HTTP_status_code.yml +46 -0
  57. data/spec/cassettes/GmoPayment_Client_Response/_http_error_/with_2xx/return_false.yml +46 -0
  58. data/spec/cassettes/GmoPayment_Client_Response/_http_error_/without_2xx/return_true.yml +44 -0
  59. data/spec/cassettes/GmoPayment_Client_Response/_http_header/return_Hash_of_HTTP_header.yml +46 -0
  60. data/spec/cassettes/GmoPayment_Client_Response/_http_message/return_String_of_HTTP_message.yml +46 -0
  61. 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
  62. 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
  63. data/spec/cassettes/GmoPayment_Client_Response/_prebody/with_no_ErroCode_and_called_return_array_false/return_Hash_keys_and_values_String.yml +46 -0
  64. data/spec/cassettes/GmoPayment_Client_Response/_raw_body/return_String_of_HTTP_response_body_as_it_is.yml +46 -0
  65. 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
  66. 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
  67. 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
  68. 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
  69. 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
  70. data/spec/gmo_payment/client/options_spec.rb +107 -0
  71. data/spec/gmo_payment/client/request_spec.rb +403 -0
  72. data/spec/gmo_payment/client/response_spec.rb +280 -0
  73. data/spec/gmo_payment/client_spec.rb +809 -0
  74. data/spec/gmo_payment/configure_spec.rb +90 -0
  75. data/spec/gmo_payment/errors_spec.rb +118 -0
  76. data/spec/gmo_payment/glossary_spec.rb +15 -0
  77. data/spec/gmo_payment_spec.rb +22 -0
  78. data/spec/spec_helper.rb +70 -0
  79. data/spec/support/request_validation.rb +71 -0
  80. metadata +179 -0
@@ -0,0 +1,538 @@
1
+ # coding: utf-8
2
+ require 'net/https'
3
+ require 'gmo_payment/client/options'
4
+ require 'gmo_payment/client/request'
5
+ require 'gmo_payment/client/response'
6
+
7
+ module GmoPayment
8
+ class Client
9
+ # Network errors that may occur when sending a request.
10
+ #
11
+ # @see https://github.com/aws/aws-sdk-ruby/blob/master/aws-sdk-core/lib/seahorse/client/net_http/handler.rb#L9-L13 aws/aws-sdk-ruby
12
+ # @see https://github.com/edward/net_http_exception_fix/blob/master/lib/net_http_exception_fix.rb edward/net_http_exception_fix
13
+ #
14
+ # @return [Array]
15
+ NETWORK_ERRORS = [
16
+ ::SocketError, ::EOFError, ::Timeout::Error, ::OpenSSL::SSL::SSLError,
17
+ ::Errno::ECONNABORTED, ::Errno::ECONNRESET, ::Errno::ECONNREFUSED,
18
+ ::Errno::EINVAL, ::Errno::EPIPE, ::Errno::ETIMEDOUT,
19
+ ::Net::ProtocolError, ::Net::HTTPHeaderSyntaxError, ::Net::HTTPBadResponse,
20
+ ]
21
+
22
+ # @param [Hash] opts
23
+ # @see {Options#initialize}
24
+ def initialize(opts = {})
25
+ @options = Options.new(opts)
26
+ end
27
+
28
+ # Call the GMO-PG API.
29
+ #
30
+ # @param [Hash] args
31
+ # @param [Symbol] method
32
+ # @return [Response]
33
+ # @raise [NetworkError]
34
+ # @raise [RequestMissingItemError]
35
+ # @raise [RequestInvalidItemError]
36
+ # @raise [ResponseHTTPError]
37
+ # @raise [ResponseHasErrCodeError]
38
+ def call(method, args)
39
+ request = Request.new(method, args)
40
+ raise GmoPayment::Errors::RequestMissingItemError.new(method, request.missing_items) if request.missing?
41
+ raise GmoPayment::Errors::RequestInvalidItemError.new(method, request.invalid_items) if request.invalid?
42
+
43
+ http_request = ::Net::HTTP::Post.new(post_path(method), header)
44
+ if request_body = request.body
45
+ http_request.body = request_body
46
+ http_request.content_length = request_body.bytesize
47
+ http_request.content_type = 'application/x-www-form-urlencoded'
48
+ end
49
+
50
+ proxy = @options.proxy
51
+ http = ::Net::HTTP.new(@options.api_endpoint, 443,
52
+ proxy.host, proxy.port, proxy.user, proxy.password)
53
+ http.use_ssl = true
54
+ http.ssl_version = :TLSv1
55
+ http.verify_mode = @options.verify_mode
56
+ http.ssl_timeout = 120
57
+ http.open_timeout = 15
58
+ http.read_timeout = 90
59
+
60
+ res = http.request(http_request)
61
+ rescue *NETWORK_ERRORS => error
62
+ raise GmoPayment::Errors::NetworkError.new(method, request, error.message)
63
+ else
64
+ response = Response.new(method, res)
65
+ raise GmoPayment::Errors::ResponseHTTPError.new(method, request) if response.http_error?
66
+ raise GmoPayment::Errors::ResponseHasErrCodeError.new(method, response) if response.error?
67
+
68
+ response
69
+ end
70
+
71
+ # [2.1.2.1 取引登録]
72
+ # これ以降の決済取引で必要となる取引IDと取引パスワードの発行を行い、取引を開始します。
73
+ #
74
+ # @param [Hash] args
75
+ # @option args [String] :shop_id required
76
+ # @option args [String] :shop_pass required
77
+ # @option args [String] :order_id required
78
+ # @option args [String] :job_cd required
79
+ # @option args [Integer] :amount required if :job_cd is not CHECK
80
+ # @option args [String] :item_code
81
+ # @option args [Integer] :tax
82
+ # @option args [Integer] :td_flag (0)
83
+ # @option args [String] :td_tenant_name
84
+ # @return [Response]
85
+ def entry_tran(args = {})
86
+ if args[:job_cd] == 'CHECK'
87
+ args.delete(:amount)
88
+ args.delete(:tax)
89
+ end
90
+ call(__method__, args)
91
+ end
92
+
93
+ # [2.1.2.2 決済実行]
94
+ # お客様が入力したカード番号と有効期限の情報でカード会社と通信を行い決済を実施し、結果を返します。
95
+ #
96
+ # @param [Hash] args
97
+ # @option args [String] :access_id required
98
+ # @option args [String] :access_pass required
99
+ # @option args [String] :order_id required
100
+ # @option args [String] :card_no required
101
+ # @option args [String] :expire required
102
+ # @option args [Integer] :method required if :job_cd is not CHECK
103
+ # @option args [Integer] :pay_times required if :method is 2 or 4
104
+ # @option args [String] :pin required if you contracted to use this
105
+ # @option args [String] :security_code
106
+ # @option args [String] :client_field_1
107
+ # @option args [String] :client_field_2
108
+ # @option args [String] :client_field_3
109
+ # @return [Response]
110
+ def exec_tran(args = {})
111
+ args[:client_field_flag] = 1
112
+ call(__method__, args)
113
+ end
114
+
115
+ # [2.2.2.2 決済実行(本人認証サービス有)]
116
+ # お客様が入力したカード番号と有効期限の情報でカード会社と通信を行い決済を実施し、結果を返します。
117
+ # カード情報が本人認証サービスに対応していない場合は、カード会社との通信を行い決済を実行します。
118
+ # その際の出力パラメータは「2.1.2.2 決済実行」の出力パラメータと同じになります。
119
+ #
120
+ # @param [Hash] args
121
+ # @option args [String] :access_id required
122
+ # @option args [String] :access_pass required
123
+ # @option args [String] :order_id required
124
+ # @option args [String] :card_no required
125
+ # @option args [String] :expire required
126
+ # @option args [String] :http_accept required
127
+ # @option args [String] :http_user_agent required
128
+ # @option args [Integer] :method required if :job_cd is not CHECK
129
+ # @option args [Integer] :pay_times required if :method is 2 or 4
130
+ # @option args [String] :security_code
131
+ # @option args [String] :client_field_1
132
+ # @option args [String] :client_field_2
133
+ # @option args [String] :client_field_3
134
+ # @return [Response]
135
+ def exec_tran_3d(args = {})
136
+ args[:client_field_flag] = 1
137
+ args[:device_category] = 0
138
+ call(__method__, args)
139
+ end
140
+
141
+ # [2.2.2.4 認証後決済実行(本人認証サービス有)]
142
+ # 本人認証サービスの結果を解析し、その情報を使用してカード会社と通信を行い決済を実施して結果を返します。
143
+ #
144
+ # @param [Hash] args
145
+ # @option args [String] :pa_res required
146
+ # @option args [String] :md required
147
+ # @return [Response]
148
+ def secure_tran(args = {})
149
+ call(__method__, args)
150
+ end
151
+
152
+ # [2.3.2.1 会員登録]
153
+ # 指定されたサイトに会員を登録します。
154
+ #
155
+ # @param [Hash] args
156
+ # @option args [String] :site_id required
157
+ # @option args [String] :site_pass required
158
+ # @option args [String] :member_id required
159
+ # @option args [String] :member_name
160
+ # @return [Response]
161
+ def save_member(args = {})
162
+ call(__method__, args)
163
+ end
164
+
165
+ # [2.4.2.1 会員更新]
166
+ # 指定されたサイトに会員情報を更新します。
167
+ #
168
+ # @param [Hash] args
169
+ # @option args [String] :site_id required
170
+ # @option args [String] :site_pass required
171
+ # @option args [String] :member_id required
172
+ # @option args [String] :member_name
173
+ # @return [Response]
174
+ def update_member(args = {})
175
+ call(__method__, args)
176
+ end
177
+
178
+ # [2.5.2.1 会員削除]
179
+ # 指定したサイトから会員情報を削除します。
180
+ #
181
+ # @param [Hash] args
182
+ # @option args [String] :site_id required
183
+ # @option args [String] :site_pass required
184
+ # @option args [String] :member_id required
185
+ # @return [Response]
186
+ def delete_member(args = {})
187
+ call(__method__, args)
188
+ end
189
+
190
+ # [2.6.2.1 会員参照]
191
+ # 指定したサイトの会員情報を参照します。
192
+ #
193
+ # @param [Hash] args
194
+ # @option args [String] :site_id required
195
+ # @option args [String] :site_pass required
196
+ # @option args [String] :member_id required
197
+ # @return [Response]
198
+ def search_member(args = {})
199
+ call(__method__, args)
200
+ end
201
+
202
+ # [2.7.2.1 カード登録]
203
+ # 指定した会員にカード情報を登録します。
204
+ # 尚、サイトに設定されたショップIDを使用してカード会社と通信を行い、有効性の確認を行います。
205
+ #
206
+ # @param [Hash] args
207
+ # @option args [String] :site_id required
208
+ # @option args [String] :site_pass required
209
+ # @option args [String] :member_id required
210
+ # @option args [String] :card_no required
211
+ # @option args [String] :expire required
212
+ # @option args [Integer] :seq_mode (0)
213
+ # @option args [Integer] :default_flag (0)
214
+ # @option args [String] :card_name
215
+ # @option args [String] :card_pass
216
+ # @option args [String] :holder_name
217
+ # @return [Response]
218
+ def save_card(args = {})
219
+ call(__method__, args)
220
+ end
221
+
222
+ # [2.7.2.1 カード更新]
223
+ # 指定した会員のカード情報を更新します。
224
+ # 尚、サイトに設定されたショップIDを使用してカード会社と通信を行い、有効性の確認を行います。
225
+ #
226
+ # @param [Hash] args
227
+ # @option args [String] :site_id required
228
+ # @option args [String] :site_pass required
229
+ # @option args [String] :member_id required
230
+ # @option args [Integer] :card_seq required
231
+ # @option args [String] :card_no required
232
+ # @option args [String] :expire required
233
+ # @option args [Integer] :seq_mode (0)
234
+ # @option args [Integer] :default_flag (0)
235
+ # @option args [String] :card_name
236
+ # @option args [String] :card_pass
237
+ # @option args [String] :holder_name
238
+ # @return [Response]
239
+ def update_card(args = {})
240
+ call(__method__, args)
241
+ end
242
+
243
+ # [2.8.2.1 カード削除]
244
+ # 指定した会員のカード情報を削除します。
245
+ #
246
+ # @param [Hash] args
247
+ # @option args [String] :site_id required
248
+ # @option args [String] :site_pass required
249
+ # @option args [String] :member_id required
250
+ # @option args [Integer] :card_seq required
251
+ # @option args [Integer] :seq_mode (0)
252
+ # @return [Response]
253
+ def delete_card(args = {})
254
+ call(__method__, args)
255
+ end
256
+
257
+ # [2.9.2.1 カード参照]
258
+ # 指定した会員のカード情報を参照します。
259
+ #
260
+ # @param [Hash] args
261
+ # @option args [String] :site_id required
262
+ # @option args [String] :site_pass required
263
+ # @option args [String] :member_id required
264
+ # @option args [Integer] :seq_mode required
265
+ # @option args [Integer] :card_seq
266
+ # @return [Response]
267
+ def search_card(args = {})
268
+ call(__method__, args)
269
+ end
270
+
271
+ # [2.10.2.3 決済実行]
272
+ # お客様が選択したカード登録連番のカード情報を取得します。
273
+ # 取得したカード情報でカード会社と通信を行い決済を実施し、結果を返します。
274
+ #
275
+ # @param [Hash] args
276
+ # @option args [String] :access_id required
277
+ # @option args [String] :access_pass required
278
+ # @option args [String] :order_id required
279
+ # @option args [String] :site_id required
280
+ # @option args [String] :site_pass required
281
+ # @option args [String] :member_id required
282
+ # @option args [Integer] :card_seq required
283
+ # @option args [Integer] :method required if :job_cd is not CHECK
284
+ # @option args [Integer] :pay_times required if :method is 2 or 4
285
+ # @option args [String] :card_pass required if :card_pass is set
286
+ # @option args [Integer] :seq_mode (0)
287
+ # @option args [String] :security_code
288
+ # @option args [String] :client_field_1
289
+ # @option args [String] :client_field_2
290
+ # @option args [String] :client_field_3
291
+ # @return [Response]
292
+ def exec_tran_member(args = {})
293
+ args[:client_field_flag] = 1
294
+ call(__method__, args)
295
+ end
296
+
297
+ # [2.11.2.3 決済実行]
298
+ # お客様が選択したカード登録連番のカード情報を取得します。
299
+ # カード情報が本人認証サービスに対応していない場合は、カード会社との通信を行い決済を実行します。
300
+ # その際の出力パラメータは「2.10.2.3 決済実行」の出力パラメータと同じになります。
301
+ #
302
+ # @param [Hash] args
303
+ # @option args [String] :access_id required
304
+ # @option args [String] :access_pass required
305
+ # @option args [String] :order_id required
306
+ # @option args [String] :site_id required
307
+ # @option args [String] :site_pass required
308
+ # @option args [String] :member_id required
309
+ # @option args [Integer] :card_seq required
310
+ # @option args [String] :http_accept required
311
+ # @option args [String] :http_user_agent required
312
+ # @option args [Integer] :method required if :job_cd is not CHECK
313
+ # @option args [Integer] :pay_times required if :method is 2 or 4
314
+ # @option args [Integer] :seq_mode (0)
315
+ # @option args [String] :card_pass
316
+ # @option args [String] :security_code
317
+ # @option args [String] :client_field_1
318
+ # @option args [String] :client_field_2
319
+ # @option args [String] :client_field_3
320
+ # @return [Response]
321
+ def exec_tran_member_3d(args = {})
322
+ args[:client_field_flag] = 1
323
+ args[:device_category] = 0
324
+ call(__method__, args)
325
+ end
326
+
327
+ # [2.12.2.1 決済変更(取消)]
328
+ # 決済が完了した取引に対して決済内容の取り消しを行います。
329
+ # 指定された取引情報を使用してカード会社と通信を行い取り消しを実施します。
330
+ #
331
+ # @param [Hash] args
332
+ # @option args [String] :shop_id required
333
+ # @option args [String] :shop_pass required
334
+ # @option args [String] :access_id required
335
+ # @option args [String] :access_pass required
336
+ # @option args [String] :job_cd required
337
+ # @return [Response]
338
+ def delete_tran(args = {})
339
+ call(__method__, args)
340
+ end
341
+
342
+ # [2.13.2.1 決済変更(再オーソリ)]
343
+ # 取り消されている決済に対して再オーソリを行います。指定された決済情報を使用してカード会社と通信を行い実施します。
344
+ #
345
+ # @param [Hash] args
346
+ # @option args [String] :shop_id required
347
+ # @option args [String] :shop_pass required
348
+ # @option args [String] :access_id required
349
+ # @option args [String] :access_pass required
350
+ # @option args [String] :job_cd required
351
+ # @option args [Integer] :amount required
352
+ # @option args [Integer] :method required
353
+ # @option args [Integer] :pay_times required if :method is 2 or 4
354
+ # @option args [Integer] :tax
355
+ # @return [Response]
356
+ def re_exec_tran(args = {})
357
+ call(__method__, args)
358
+ end
359
+
360
+ # [2.14.2.1 決済変更(実売上)]
361
+ # 仮売上の決済に対して実売上を行います。尚、実行時に仮売上時との金額チェックを行います。
362
+ #
363
+ # @param [Hash] args
364
+ # @option args [String] :shop_id required
365
+ # @option args [String] :shop_pass required
366
+ # @option args [String] :access_id required
367
+ # @option args [String] :access_pass required
368
+ # @option args [Integer] :amount required
369
+ # @return [Response]
370
+ def auth_to_sales(args = {})
371
+ args[:job_cd] = 'SALES'
372
+ call(__method__, args)
373
+ end
374
+
375
+ # [2.15.2.1 金額変更]
376
+ # 決済が完了した取引に対して金額の変更を行います。
377
+ #
378
+ # @param [Hash] args
379
+ # @option args [String] :shop_id required
380
+ # @option args [String] :shop_pass required
381
+ # @option args [String] :access_id required
382
+ # @option args [String] :access_pass required
383
+ # @option args [String] :job_cd required
384
+ # @option args [Integer] :amount required
385
+ # @option args [Integer] :tax
386
+ # @return [Response]
387
+ def change_tran(args = {})
388
+ call(__method__, args)
389
+ end
390
+
391
+ # [2.16.2.1 取引状態参照]
392
+ # 指定したオーダーIDの取引情報を取得します。
393
+ #
394
+ # @param [Hash] args
395
+ # @option args [String] :shop_id required
396
+ # @option args [String] :shop_pass required
397
+ # @option args [String] :order_id required
398
+ # @return [Response]
399
+ def search_trade(args = {})
400
+ call(__method__, args)
401
+ end
402
+
403
+ # [2.17.2.1 決済後カード登録]
404
+ # 指定されたオーダーIDの取引に使用したカードを登録します。
405
+ #
406
+ # @param [Hash] args
407
+ # @option args [String] :shop_id required
408
+ # @option args [String] :shop_pass required
409
+ # @option args [String] :order_id required
410
+ # @option args [String] :site_id required
411
+ # @option args [String] :site_pass required
412
+ # @option args [String] :member_id required
413
+ # @option args [Integer] :seq_mode (0)
414
+ # @option args [Integer] :default_flag (0)
415
+ # @option args [String] :holder_name
416
+ # @return [Response]
417
+ def save_traded_card(args = {})
418
+ call(__method__, args)
419
+ end
420
+
421
+ # [18.1.2.1 取引登録 (BTC)]
422
+ # これ以降の決済取引で必要となる取引IDと取引パスワードの発行を行い、取引を開始します。
423
+ #
424
+ # @param [Hash] args
425
+ # @option args [String] :shop_id required
426
+ # @option args [String] :shop_pass required
427
+ # @option args [String] :order_id required
428
+ # @option args [Integer] :amount required
429
+ # @option args [Integer] :tax
430
+ # @return [Response]
431
+ def entry_tran_btc(args = {})
432
+ call(__method__, args)
433
+ end
434
+
435
+ # [18.1.2.2 決済実行 (BTC)]
436
+ # 契約情報を確認し、これ以降の処理に必要なトークンを返却します。
437
+ #
438
+ # @param [Hash] args
439
+ # @option args [String] :shop_id required
440
+ # @option args [String] :access_id required
441
+ # @option args [String] :access_pass required
442
+ # @option args [String] :order_id required
443
+ # @option args [String] :ret_url required
444
+ # @option args [String] :item_name required
445
+ # @option args [Integer] :timeout required
446
+ # @option args [String] :item_memo required
447
+ # @option args [String] :client_field_1
448
+ # @option args [String] :client_field_2
449
+ # @option args [String] :client_field_3
450
+ # @return [Response]
451
+ def exec_tran_btc(args = {})
452
+ call(__method__, args)
453
+ end
454
+
455
+ # [18.1.2.5 決済実行 (BTC)]
456
+ # ビットコインのレート(参考値)を返却します。
457
+ #
458
+ # @note
459
+ # 注意: このレートは、決済後の円換算レートを保証するものではございません。
460
+ # エンドユーザーに表示する場合等、参考値としてご利用下さい。
461
+ # また、レートはリクエストビットコインウォレット事業者から取得した値を返却しております。
462
+ # レートの更新頻度は、ウォレット事業者に依存いたします。
463
+ #
464
+ # @param [Hash] args
465
+ # @option args [String] :shop_id required
466
+ # @option args [String] :shop_pass required
467
+ def get_rate_btc(args = {})
468
+ call(__method__, args)
469
+ end
470
+
471
+ # [21.1.2.1 取引状態参照 (BTC)]
472
+ # 指定したオーダーIDの取引情報を取得します。
473
+ #
474
+ # @param [Hash] args
475
+ # @option args [String] :shop_id required
476
+ # @option args [String] :shop_pass required
477
+ # @option args [String] :order_id required
478
+ # @return [Response]
479
+ def search_trade_btc(args = {})
480
+ args[:pay_type] = 17
481
+ call(__method__, args)
482
+ end
483
+
484
+ private
485
+
486
+ # @param [Symbol] method
487
+ # @return [String]
488
+ def post_path(method)
489
+ case method
490
+ when :entry_tran
491
+ '/payment/EntryTran.idPass'
492
+ when :exec_tran, :exec_tran_3d, :exec_tran_member, :exec_tran_member_3d
493
+ '/payment/ExecTran.idPass'
494
+ when :secure_tran
495
+ '/payment/SecureTran.idPass'
496
+ when :save_member
497
+ '/payment/SaveMember.idPass'
498
+ when :update_member
499
+ '/payment/UpdateMember.idPass'
500
+ when :delete_member
501
+ '/payment/DeleteMember.idPass'
502
+ when :search_member
503
+ '/payment/SearchMember.idPass'
504
+ when :save_card, :update_card
505
+ '/payment/SaveCard.idPass'
506
+ when :delete_card
507
+ '/payment/DeleteCard.idPass'
508
+ when :search_card
509
+ '/payment/SearchCard.idPass'
510
+ when :delete_tran, :re_exec_tran, :auth_to_sales
511
+ '/payment/AlterTran.idPass'
512
+ when :change_tran
513
+ '/payment/ChangeTran.idPass'
514
+ when :search_trade
515
+ '/payment/SearchTrade.idPass'
516
+ when :save_traded_card
517
+ '/payment/TradedCard.idPass'
518
+ when :entry_tran_btc
519
+ '/payment/EntryTranBTC.idPass'
520
+ when :exec_tran_btc
521
+ '/payment/ExecTranBTC.idPass'
522
+ when :get_rate_btc
523
+ '/payment/GetBTCRate.idPass'
524
+ when :search_trade_btc
525
+ '/payment/SearchTradeMulti.idPass'
526
+ end
527
+ end
528
+
529
+ # @return [Hash]
530
+ def header
531
+ {
532
+ 'Accept' => 'application/x-www-form-urlencoded;q=1.0,*/*;q=0.5',
533
+ 'User-Agent' => "RubyGem/GmoPayment/#{GmoPayment::VERSION}",
534
+ }
535
+ end
536
+
537
+ end
538
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+
3
+ module GmoPayment
4
+ module Configure
5
+ class << self
6
+ # @!attribute [rw] api_endpoint
7
+ # @!attribute [rw] proxy
8
+ # @!attribute [rw] verify_mode
9
+ # @!attribute [rw] error_list
10
+ # @!attribute [rw] site_id
11
+ # @!attribute [rw] site_pass
12
+ # @!attribute [rw] shop_id
13
+ # @!attribute [rw] shop_pass
14
+ attr_accessor :api_endpoint, :proxy, :verify_mode, :error_list, :site_id, :site_pass, :shop_id, :shop_pass
15
+
16
+ # See {GmoPayment.setup}
17
+ def setup
18
+ yield(self)
19
+ end
20
+
21
+ # See {GmoPayment.reset!}
22
+ def reset!
23
+ instance_variables.each do |variable|
24
+ remove_instance_variable(variable)
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,95 @@
1
+ # coding: utf-8
2
+
3
+ module GmoPayment
4
+ # Basic error of GmoPayment
5
+ class Errors < StandardError
6
+ # Network Error
7
+ #
8
+ # @see GmoPayment::Client::NETWORK_ERRORS
9
+ class NetworkError < self
10
+ # @!attribute [rw] called_method
11
+ # @!attribute [rw] request
12
+ attr_accessor :called_method, :request
13
+
14
+ # @param [Symbol] called_method
15
+ # @param [String] message
16
+ # @param [Request] request
17
+ def initialize(called_method = nil, request = nil, message = nil)
18
+ self.called_method = called_method
19
+ self.request = request
20
+ super(message)
21
+ end
22
+ end
23
+
24
+ # Error of request body has missing items.
25
+ class RequestMissingItemError < self
26
+ # @!attribute [rw] called_method
27
+ # @!attribute [rw] items
28
+ attr_accessor :called_method, :items
29
+
30
+ # @param [Symbol] called_method
31
+ # @param [Array] items
32
+ def initialize(called_method = nil, items = [])
33
+ self.called_method = called_method
34
+ self.items = items
35
+ super(items.join(', '))
36
+ end
37
+ end
38
+
39
+ # Error of request body has invalid items.
40
+ class RequestInvalidItemError < self
41
+ # @!attribute [rw] called_method
42
+ # @!attribute [rw] items
43
+ attr_accessor :called_method, :items
44
+
45
+ # @param [Symbol] called_method
46
+ # @param [Hash] items
47
+ def initialize(called_method = nil, items = {})
48
+ self.called_method = called_method
49
+ self.items = items
50
+ super(items.map { |k, v| ":#{k} (#{v})" }.join(', '))
51
+ end
52
+ end
53
+
54
+ # Error of response HTTP is not 2xx.
55
+ class ResponseHTTPError < self
56
+ # @!attribute [rw] called_method
57
+ # @!attribute [rw] request
58
+ attr_accessor :called_method, :request
59
+
60
+ # @param [Symbol] called_method
61
+ # @param [Request] request
62
+ def initialize(called_method = nil, request = nil)
63
+ self.called_method = called_method
64
+ self.request = request
65
+ super("HTTP response called from `#{called_method}' is not 2xx")
66
+ end
67
+ end
68
+
69
+ # Error of response body has "ErrCode".
70
+ class ResponseHasErrCodeError < self
71
+ # @!attribute [rw] called_method
72
+ # @!attribute [rw] response
73
+ attr_accessor :called_method, :response
74
+
75
+ # @param [Symbol] called_method
76
+ # @param [Response] response
77
+ def initialize(called_method = nil, response = nil)
78
+ self.called_method = called_method
79
+ self.response = response
80
+ super("HTTP response called from `#{called_method}' has ErrCode")
81
+ end
82
+
83
+ # @param [String] file
84
+ # @return [Hash]
85
+ def error_messages(file = nil)
86
+ require 'yaml'
87
+ error_list = YAML.load_file(file || GmoPayment::Configure.error_list)
88
+ self.response.err_info.each_with_object({}) do |error, hash|
89
+ hash[error] = error_list[error]
90
+ end
91
+ end
92
+ end
93
+
94
+ end
95
+ end