gmo 0.3.0 → 0.4.0

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 (44) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +20 -1
  3. data/fixtures/vcr_cassettes/GMO_Payment_RemittanceAPI/_cancel_deposit_gets_data_about_a_deposit.yml +38 -0
  4. data/fixtures/vcr_cassettes/GMO_Payment_RemittanceAPI/_cancel_mail_deposit_gets_data_about_a_mail_deposit.yml +38 -0
  5. data/fixtures/vcr_cassettes/GMO_Payment_RemittanceAPI/_create_account_gets_data_about_an_account.yml +38 -0
  6. data/fixtures/vcr_cassettes/GMO_Payment_RemittanceAPI/_create_deposit_gets_data_about_a_deposit.yml +38 -0
  7. data/fixtures/vcr_cassettes/GMO_Payment_RemittanceAPI/_create_mail_deposit_gets_data_about_a_mail_deposit.yml +38 -0
  8. data/fixtures/vcr_cassettes/GMO_Payment_RemittanceAPI/_delete_account_gets_data_about_an_account.yml +38 -0
  9. data/fixtures/vcr_cassettes/GMO_Payment_RemittanceAPI/_search_account_gets_data_about_an_account.yml +38 -0
  10. data/fixtures/vcr_cassettes/GMO_Payment_RemittanceAPI/_search_balance_gets_data_about_balance.yml +38 -0
  11. data/fixtures/vcr_cassettes/GMO_Payment_RemittanceAPI/_search_deposit_gets_data_about_a_deposit.yml +38 -0
  12. data/fixtures/vcr_cassettes/GMO_Payment_RemittanceAPI/_search_mail_deposit_gets_data_about_a_mail_deposit.yml +38 -0
  13. data/fixtures/vcr_cassettes/GMO_Payment_RemittanceAPI/_update_account_gets_data_about_an_account.yml +38 -0
  14. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_change_tran_brandtoken_gets_data_about_order.yml +108 -0
  15. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_entry_tran_brandtoken_gets_data_about_a_transaction.yml +38 -0
  16. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_exec_tran_brandtoken_gets_data_about_a_transaction.yml +73 -0
  17. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_exec_tran_brandtoken_parameter_contains_Japanese_characters_should_correctly_handle_Japanese.yml +73 -0
  18. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_exec_tran_doesn_t_require_card_info_if_token_is_present.yml +69 -0
  19. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_refund_tran_brandtoken_gets_data_about_a_transaction.yml +108 -0
  20. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_sales_tran_brandtoken_gets_data_about_a_transaction.yml +143 -0
  21. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_void_tran_brandtoken_gets_data_about_order.yml +108 -0
  22. data/fixtures/vcr_cassettes/GMO_Payment_ShopAndSiteAPI/_exec_tran_brandtoken_got_data.yml +73 -0
  23. data/fixtures/vcr_cassettes/GMO_Payment_ShopAndSiteAPI/_trade_brandtoken_got_data.yml +108 -0
  24. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_delete_brandtoken_gets_data_about_a_brandtoken.yml +73 -0
  25. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_search_brandtoken_gets_data_about_a_brandtoken.yml +74 -0
  26. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_search_card_detail_by_member_id_gets_data_about_card_detail.yml +36 -0
  27. data/lib/gmo.rb +6 -1
  28. data/lib/gmo/const.rb +1159 -1
  29. data/lib/gmo/errors.rb +20 -2
  30. data/lib/gmo/remittance_api.rb +329 -0
  31. data/lib/gmo/shop_and_site_api.rb +73 -0
  32. data/lib/gmo/shop_api.rb +223 -2
  33. data/lib/gmo/site_api.rb +64 -0
  34. data/lib/gmo/version.rb +1 -1
  35. data/spec/gmo/{error_spec.rb → errors_spec.rb} +11 -2
  36. data/spec/gmo/remittance_api_spec.rb +504 -0
  37. data/spec/gmo/shop_and_site_api_spec.rb +74 -0
  38. data/spec/gmo/shop_api_spec.rb +278 -0
  39. data/spec/gmo/site_api_spec.rb +84 -1
  40. data/spec/support/config.example.yml +5 -0
  41. data/spec/support/config.yml +5 -0
  42. data/spec/support/config_loader.rb +1 -1
  43. data/spec/support/vcr.rb +9 -2
  44. metadata +30 -4
@@ -9,7 +9,15 @@
9
9
 
10
10
  module GMO
11
11
 
12
- class GMOError < StandardError; end
12
+ class GMOError < StandardError
13
+ ERROR_INFO_SEPARATOR = '|'.freeze
14
+
15
+ private
16
+
17
+ def error_message(info)
18
+ ::GMO::Const::API_ERROR_MESSAGES[:en][info] || info
19
+ end
20
+ end
13
21
 
14
22
  module Payment
15
23
  class Error < ::GMO::GMOError
@@ -41,11 +49,21 @@ module GMO
41
49
  def initialize(error_info = {})
42
50
  self.error_info = error_info
43
51
  self.response_body = "ErrCode=#{error_info["ErrCode"]}&ErrInfo=#{error_info["ErrInfo"]}"
52
+ set_error_messages
44
53
  message = self.response_body
45
54
  super(message)
46
55
  end
56
+
57
+ private
58
+
59
+ def set_error_messages
60
+ error_messages = self.error_info['ErrInfo'].to_s.split(ERROR_INFO_SEPARATOR)
61
+ .map { |e| error_message(e) || e }
62
+ .join(ERROR_INFO_SEPARATOR)
63
+ self.response_body += "&ErrMessage=#{error_messages}"
64
+ end
47
65
  end
48
66
 
49
67
  end
50
68
 
51
- end
69
+ end
@@ -0,0 +1,329 @@
1
+ # coding: utf-8
2
+
3
+ # A client for the GMO Remittance API.
4
+ #
5
+ # example
6
+ # gmo = GMO::Payment::RemittanceAPI.new({
7
+ # shop_id: "foo",
8
+ # shop_pass: "bar",
9
+ # host: "test-remittance.gmopg.jp"
10
+ # })
11
+ module GMO
12
+ module Payment
13
+
14
+ module RemittanceAPIMethods
15
+
16
+ def initialize(options = {})
17
+ @shop_id = options[:shop_id]
18
+ @shop_pass = options[:shop_pass]
19
+ @host = options[:host]
20
+ unless @shop_id && @shop_pass && @host
21
+ raise ArgumentError, "Initialize must receive a hash with :shop_id, :shop_pass and either :host! (received #{options.inspect})"
22
+ end
23
+ end
24
+ attr_reader :shop_id, :shop_pass, :host
25
+
26
+ #########
27
+ # Method
28
+ # Bank_ID
29
+ # Bank_Code
30
+ # Branch_Code
31
+ # Account_Type
32
+ # Account_Name
33
+ # Account_Number
34
+ # Branch_Code_Jpbank
35
+ # Account_Number_Jpbank
36
+ # Free
37
+ ### @return ###
38
+ # Bank_ID
39
+ # Method
40
+ # ErrCode
41
+ # ErrInfo
42
+ ### example ###
43
+ # gmo.create_account({
44
+ # bank_id: 'bank00000',
45
+ # bank_code: '0001',
46
+ # branch_code: '813',
47
+ # account_type: :normal,
48
+ # account_name: 'An Yutzy',
49
+ # account_number: '0012345',
50
+ # branch_code_jp: '00567',
51
+ # account_number_jp: '01234567',
52
+ # free: 'foobar' # Metadata
53
+ # })
54
+ # {"Bank_ID"=>"bank00000", "Method"=>"1"}
55
+ def create_account(options = {})
56
+ name = "/api/AccountRegistration.idPass"
57
+ options[:method] = 1
58
+ options[:account_type] = GMO::Const::ACCOUNT_TYPES_MAP[options[:account_type]]
59
+ required = %i(bank_id bank_code branch_code account_type account_name account_number)
60
+ assert_required_options(required, options)
61
+ post_request name, options
62
+ end
63
+
64
+ #########
65
+ # Method
66
+ # Bank_ID
67
+ # Bank_Code
68
+ # Branch_Code
69
+ # Account_Type
70
+ # Account_Name
71
+ # Account_Number
72
+ # Branch_Code_Jpbank
73
+ # Account_Number_Jpbank
74
+ # Free
75
+ ### @return ###
76
+ # Bank_ID
77
+ # Method
78
+ # ErrCode
79
+ # ErrInfo
80
+ ### example ###
81
+ # gmo.update_account({
82
+ # bank_id: 'bank00000',
83
+ # bank_code: '0001',
84
+ # branch_code: '813',
85
+ # account_type: :normal,
86
+ # account_name: 'An Yutzy',
87
+ # account_number: '0012345',
88
+ # branch_code_jp: '00567',
89
+ # account_number_jp: '01234567',
90
+ # free: 'foobar' # Metadata
91
+ # })
92
+ # {"Bank_ID"=>"bank00000", "Method"=>"2"}
93
+ def update_account(options = {})
94
+ name = "/api/AccountRegistration.idPass"
95
+ options[:method] = 2
96
+ options[:account_type] = GMO::Const::ACCOUNT_TYPES_MAP[options[:account_type]]
97
+ required = %i(bank_id bank_code branch_code account_type account_name account_number)
98
+ assert_required_options(required, options)
99
+ post_request name, options
100
+ end
101
+
102
+ #########
103
+ # Method
104
+ # Bank_ID
105
+ ### @return ###
106
+ # Bank_ID
107
+ # Method
108
+ # ErrCode
109
+ # ErrInfo
110
+ ### example ###
111
+ # gmo.delete_account({
112
+ # bank_id: 'bank00000',
113
+ # })
114
+ # {"Bank_ID"=>"bank00000", "Method"=>"3"}
115
+ def delete_account(options = {})
116
+ name = "/api/AccountRegistration.idPass"
117
+ options[:method] = 3
118
+ required = %i(bank_id)
119
+ assert_required_options(required, options)
120
+ post_request name, options
121
+ end
122
+
123
+ #########
124
+ # Bank_ID
125
+ ### @return ###
126
+ # Bank_ID
127
+ # Delete_Flag
128
+ # Bank_Name
129
+ # Bank_Code
130
+ # Branch_Name
131
+ # Branch_Code
132
+ # Account_Type
133
+ # Account_Number
134
+ # Account_Name
135
+ # Free
136
+ # Branch_Code_Jpbank
137
+ # Account_Number_Jpbank
138
+ ### example ###
139
+ # gmo.search_account({
140
+ # bank_id: 'bank12345'
141
+ # })
142
+ # {"Bank_ID"=>"bank12345", "Delete_Flag"=>"0", "Bank_Name"=>"みずほ銀行", "Bank_Code"=>"0001", "Branch_Name"=>"札幌支店", "Branch_Code"=>"813", "Account_Type"=>"1", "Account_Number"=>"0012345", "Account_Name"=>"An Yutzy", "Free"=>"", "Branch_Code_Jpbank"=>"", "Account_Number_Jpbank"=>""}
143
+ def search_account(options = {})
144
+ name = "/api/AccountSearch.idPass"
145
+ required = %i(bank_id)
146
+ assert_required_options(required, options)
147
+ post_request name, options
148
+ end
149
+
150
+ #########
151
+ # Method
152
+ # Deposit_ID
153
+ # Bank_ID
154
+ # Amount
155
+ ### @return ###
156
+ # Deposit_ID
157
+ # Bank_ID
158
+ # Method
159
+ # Amount
160
+ # Bank_Fee
161
+ ### example ###
162
+ # gmo.create_deposit({
163
+ # deposit_id: 'dep00000',
164
+ # bank_id: 'bank00000',
165
+ # amount: '1000'
166
+ # })
167
+ # {"Deposit_ID"=>"dep00000", "Bank_ID"=>"bank00000", "Method"=>"1", "Amount"=>"1000", "Bank_Fee"=>"27"}
168
+ def create_deposit(options = {})
169
+ name = "/api/DepositRegistration.idPass"
170
+ options[:method] = 1
171
+ required = %i(bank_id deposit_id amount)
172
+ assert_required_options(required, options)
173
+ post_request name, options
174
+ end
175
+
176
+ #########
177
+ # Method
178
+ # Deposit_ID
179
+ # Bank_ID
180
+ ### @return ###
181
+ # Deposit_ID
182
+ # Bank_ID
183
+ # Method
184
+ ### example ###
185
+ # gmo.cancel_deposit({
186
+ # deposit_id: 'dep00000',
187
+ # bank_id: 'bank00000',
188
+ # })
189
+ # {"Deposit_ID"=>"dep00000", "Bank_ID"=>"bank00000", "Method"=>"2"}
190
+ def cancel_deposit(options = {})
191
+ name = "/api/DepositRegistration.idPass"
192
+ options[:method] = 2
193
+ required = %i(bank_id deposit_id)
194
+ assert_required_options(required, options)
195
+ post_request name, options
196
+ end
197
+
198
+ #############
199
+ # Deposit_ID
200
+ ### @return ###
201
+ # Deposit_ID
202
+ # Bank_ID
203
+ # Bank_Name
204
+ # Bank_Code
205
+ # Branch_Name
206
+ # Branch_Code
207
+ # Account_Type
208
+ # Account_Number
209
+ # Account_Name
210
+ # Free
211
+ # Amount
212
+ # Bank_Fee
213
+ # Result
214
+ # Branch_Code_Jpbank
215
+ # Account_Number_Jpbank
216
+ # Deposit_Date
217
+ # Result_Detail
218
+ ### example ###
219
+ # gmo.search_deposit({
220
+ # deposit_id: 'dep00000'
221
+ # })
222
+ # {"Deposit_ID"=>"dep00000", "Bank_ID"=>"bank163144", "Bank_Name"=>"みずほ銀行", "Bank_Code"=>"0001", "Branch_Name"=>"札幌支店", "Branch_Code"=>"813", "Account_Type"=>"1", "Account_Number"=>"0012345", "Account_Name"=>"An Yutzy", "Free"=>"", "Amount"=>"181035", "Bank_Fee"=>"270", "Result"=>"0", "Branch_Code_Jpbank"=>"", "Account_Number_Jpbank"=>"", "Deposit_Date"=>"", "Result_Detail"=>""}
223
+ def search_deposit(options = {})
224
+ name = "/api/DepositSearch.idPass"
225
+ required = %i(deposit_id)
226
+ assert_required_options(required, options)
227
+ post_request name, options
228
+ end
229
+
230
+ #########
231
+ ### @return ###
232
+ # Shop_ID
233
+ # Balance
234
+ # Balance_Forecast
235
+ ### example ###
236
+ # gmo.search_balance
237
+ # {"Shop_ID"=>"rshop00000071", "Balance"=>"9818965", "Balance_Forecast"=>"9818965"}
238
+ def search_balance(options = {})
239
+ name = "/api/BalanceSearch.idPass"
240
+ post_request name, options
241
+ end
242
+
243
+ ###########
244
+ # Method
245
+ # Deposit_ID
246
+ # Mail_Address
247
+ # Amount
248
+ # Mail_Deposit_Account_Name
249
+ # Expire
250
+ # Shop_Mail_Address
251
+ ### @return ###
252
+ # Method
253
+ # Amount
254
+ # Deposit_ID
255
+ # Expire
256
+ ### example ###
257
+ # gmo.create_mail_deposit({
258
+ # deposit_id: 'dep00001',
259
+ # deposit_email: 'anyutzy@demo.com',
260
+ # amount: 1000,
261
+ # deposit_account_name: 'An Yutzy',
262
+ # expire: 5,
263
+ # deposit_shop_email: 'anyutzy@demo.com'
264
+ # })
265
+ # {"Deposit_ID"=>"dep00009", "Method"=>"1", "Amount"=>"1200", "Expire"=>"20170503"}
266
+ def create_mail_deposit(options = {})
267
+ name = "/api/MailDepositRegistration.idPass"
268
+ options[:method] = 1
269
+ required = %i(deposit_id deposit_email amount deposit_account_name expire deposit_shop_email)
270
+ assert_required_options(required, options)
271
+ post_request name, options
272
+ end
273
+
274
+ ###########
275
+ # Method
276
+ # Deposit_ID
277
+ ### @return ###
278
+ # Deposit_ID
279
+ # Method
280
+ ### example ###
281
+ # gmo.cancel_mail_deposit({
282
+ # deposit_id: 'dep00001',
283
+ # })
284
+ # {"Deposit_ID"=>"dep00001", "Method"=>"2"}
285
+ def cancel_mail_deposit(options = {})
286
+ name = "/api/MailDepositRegistration.idPass"
287
+ options[:method] = 2
288
+ required = %i(deposit_id)
289
+ assert_required_options(required, options)
290
+ post_request name, options
291
+ end
292
+
293
+ #########
294
+ # Deposit_ID
295
+ ### @return ###
296
+ # Deposit_ID
297
+ # Mail_Address
298
+ # Shop_Mail_Address
299
+ # Account_Name
300
+ # Amount
301
+ # Expire
302
+ # Status
303
+ ### example ###
304
+ # gmo.search_mail_deposit({
305
+ # deposit_id: 'dep00001'
306
+ # })
307
+ # {"Deposit_ID"=>"dep0001516", "Mail_Address"=>"anyutzy@demo.com", "Shop_Mail_Address"=>"anyutzy@demo.com", "Account_Name"=>"An Yutzy", "Amount"=>"1000", "Expire"=>"20170503", "Status"=>"0"}
308
+ def search_mail_deposit(options = {})
309
+ name = "/api/MailDepositSearch.idPass"
310
+ required = %i(deposit_id)
311
+ assert_required_options(required, options)
312
+ post_request name, options
313
+ end
314
+
315
+ private
316
+
317
+ def api_call(name, args = {}, verb = "post", options = {})
318
+ args.merge!({ "Shop_ID" => @shop_id, "Shop_Pass" => @shop_pass })
319
+ api(name, args, verb, options) do |response|
320
+ if response.is_a?(Hash) && !response["ErrInfo"].nil?
321
+ raise APIError.new(response)
322
+ end
323
+ end
324
+ end
325
+
326
+ end
327
+
328
+ end
329
+ end
@@ -1,4 +1,15 @@
1
1
  # coding: utf-8
2
+
3
+ # A client for the GMO Payment API.
4
+ #
5
+ # example
6
+ # gmo = GMO::Payment::ShopAndSiteAPI.new({
7
+ # site_id: "foo",
8
+ # site_pass: "bar",
9
+ # shop_id: "baz",
10
+ # shop_pass: "bax",
11
+ # host: "p01.mul-pay.jp"
12
+ # })
2
13
  module GMO
3
14
  module Payment
4
15
 
@@ -28,6 +39,68 @@ module GMO
28
39
  post_request name, options
29
40
  end
30
41
 
42
+ ### @params ###
43
+ # MemberID
44
+ # OrderID
45
+ # DefaultFlag
46
+ # SeqMode
47
+ ### @return ###
48
+ # TokenSeq
49
+ # CardNoToken
50
+ # Forward
51
+ ### example ###
52
+ # gmo.trade_brandtoken({
53
+ # member_id: 'mem10001',
54
+ # order_id: 'ord10001'
55
+ # })
56
+ # => {"TokenSeq"=>"0", "CardNoToken"=>"*************111", "Forward"=>"2a99663"}
57
+ def trade_brandtoken(options = {})
58
+ name = "TradedBrandtoken.idPass"
59
+ required = [:order_id, :member_id]
60
+ assert_required_options(required, options)
61
+ post_request name, options
62
+ end
63
+
64
+ ### @params ###
65
+ # AccessID
66
+ # AccessPass
67
+ # OrderID
68
+ # TokenType
69
+ # Token
70
+ # MemberID
71
+ # SeqMode
72
+ # TokenSeq
73
+ # ClientField1
74
+ # ClientField2
75
+ # ClientField3
76
+ ### @return ###
77
+ # Status
78
+ # OrderID
79
+ # Forward
80
+ # Approve
81
+ # TranID
82
+ # TranDate
83
+ # ClientField1
84
+ # ClientField2
85
+ # ClientField3
86
+ ### example ###
87
+ # gmo.exec_tran_brandtoken({
88
+ # order_id: "597ae8c36120b23a3c00014e",
89
+ # access_id: "139f8ec33a07c55f406937c52ce4473d",
90
+ # access_pass: "2689b204d2c17192fa35f9269fa7e744",
91
+ # token_type: :apple_pay,
92
+ # token: <Base64 encoded payment data>,
93
+ # member_id: "mem10001"
94
+ # })
95
+ # => {"Status"=>"CAPTURE", "OrderID"=>"597ae8c36120b23a3c00014e", "Forward"=>"2a99663", "Approve"=>"5487394", "TranID"=>"1707281634111111111111771216", "TranDate"=>"20170728163453", "ClientField1"=>"Custom field value 1", "ClientField2"=>"Custom field value 2", "ClientField3"=>"Custom field value 3"}
96
+ def exec_tran_brandtoken(options = {})
97
+ name = "ExecTranBrandtoken.idPass"
98
+ options[:token_type] = GMO::Const::TOKEN_TYPES_MAP[options[:token_type]]
99
+ required = [:access_id, :access_pass, :member_id, :order_id]
100
+ assert_required_options(required, options)
101
+ post_request name, options
102
+ end
103
+
31
104
  private
32
105
 
33
106
  def api_call(name, args = {}, verb = "post", options = {})