gmo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.gitignore +8 -0
  2. data/Gemfile +22 -0
  3. data/README.ja.md +54 -0
  4. data/README.md +54 -0
  5. data/Rakefile +15 -0
  6. data/autotest/discover.rb +1 -0
  7. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_alter_tran_change_order_auth_to_sale.yml +90 -0
  8. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_alter_tran_gets_data_about_order.yml +90 -0
  9. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_alter_tran_got_error_if_missing_options.yml +32 -0
  10. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_change_tran_gets_data_about_order.yml +90 -0
  11. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_change_tran_got_error_if_missing_options.yml +32 -0
  12. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_entry_tran_gets_data_about_a_transaction.yml +32 -0
  13. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_entry_tran_got_error_if_missing_options.yml +32 -0
  14. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_exec_tran_gets_data_about_a_transaction.yml +32 -0
  15. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_exec_tran_got_error_if_missing_options.yml +32 -0
  16. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_search_trade_gets_data_about_order.yml +32 -0
  17. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_search_trade_got_error_if_missing_options.yml +32 -0
  18. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_search_trade_multi_gets_data_about_order.yml +34 -0
  19. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_search_trade_multi_got_error_if_missing_options.yml +34 -0
  20. data/fixtures/vcr_cassettes/GMO_Payment_ShopAndSiteAPI/_trade_card_got_error_if_missing_options.yml +32 -0
  21. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_delete_card_gets_data_about_a_card.yml +34 -0
  22. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_delete_member_gets_data_about_a_member.yml +34 -0
  23. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_save_card_gets_data_about_a_card.yml +34 -0
  24. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_save_member_gets_data_about_a_transaction.yml +32 -0
  25. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_save_member_got_error_if_missing_options.yml +32 -0
  26. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_search_card_gets_data_about_a_card.yml +65 -0
  27. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_search_member_gets_data_about_a_member.yml +65 -0
  28. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_update_member_gets_data_about_a_transaction.yml +32 -0
  29. data/gmo.gemspec +30 -0
  30. data/lib/gmo.rb +99 -0
  31. data/lib/gmo/errors.rb +51 -0
  32. data/lib/gmo/http_services.rb +77 -0
  33. data/lib/gmo/shop_and_site_api.rb +56 -0
  34. data/lib/gmo/shop_api.rb +218 -0
  35. data/lib/gmo/site_api.rb +146 -0
  36. data/lib/gmo/version.rb +3 -0
  37. data/spec/gmo/api_spec.rb +32 -0
  38. data/spec/gmo/error_spec.rb +25 -0
  39. data/spec/gmo/http_service_spec.rb +23 -0
  40. data/spec/gmo/shop_and_site_api_spec.rb +45 -0
  41. data/spec/gmo/shop_api_spec.rb +261 -0
  42. data/spec/gmo/site_api_spec.rb +140 -0
  43. data/spec/spec_helper.rb +21 -0
  44. data/spec/support/config.example.yml +4 -0
  45. data/spec/support/config.yml +4 -0
  46. data/spec/support/config_loader.rb +2 -0
  47. data/spec/support/factory.rb +8 -0
  48. data/spec/support/vcr.rb +21 -0
  49. data/travis.yml +11 -0
  50. metadata +202 -0
@@ -0,0 +1,56 @@
1
+ # coding: utf-8
2
+ module GMO
3
+ module Payment
4
+
5
+ module ShopAndSiteAPIMethods
6
+ def initialize(options = {})
7
+ @shop_id = options[:shop_id]
8
+ @shop_pass = options[:shop_pass]
9
+ @site_id = options[:site_id]
10
+ @site_pass = options[:site_pass]
11
+ @development = options[:development] || true
12
+ unless @site_id && @site_pass && @shop_id && @shop_pass
13
+ raise ArgumentError, "Initialize must receive a hash with :site_id, :site_pass, :shop_id and either :shop_pass! (received #{options.inspect})"
14
+ end
15
+ end
16
+ attr_reader :shop_id, :shop_pass, :site_id, :site_pass, :development
17
+
18
+ # 2.17.2.1.決済後カード登録
19
+ # 指定されたオーダーID の取引に使用したカードを登録します。
20
+ ### @return ###
21
+ # CardSeq
22
+ # CardNo
23
+ # Forward
24
+ def trade_card(options = {})
25
+ name = "TradedCard.idPass"
26
+ args = {
27
+ "OrderID" => options[:order_id],
28
+ "MemberID" => options[:member_id],
29
+ "SeqMode" => options[:seq_mode] || "0",
30
+ "DefaultFlag" => options[:default_flag] || "0",
31
+ "HolderName" => options[:holder_name]
32
+ }
33
+ args.delete("HolderName") if options[:holder_name].nil?
34
+ post_request name, args
35
+ end
36
+
37
+ private
38
+
39
+ def api_call(name, args = {}, verb = "post", options = {})
40
+ args.merge!({
41
+ "ShopID" => @shop_id,
42
+ "ShopPass" => @shop_pass,
43
+ "SiteID" => @site_id,
44
+ "SitePass" => @site_pass
45
+ })
46
+ response = api(name, args, verb, options) do |response|
47
+ if response.is_a?(Hash) && !response["ErrInfo"].nil?
48
+ raise APIError.new(response)
49
+ end
50
+ end
51
+ response
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,218 @@
1
+ # coding: utf-8
2
+
3
+ # A client for the GMO Payment API.
4
+ #
5
+ # example
6
+ # gmo = GMO::Payment::ShopAPI.new({
7
+ # shop_id: "foo",
8
+ # shop_pass: "bar",
9
+ # development: true
10
+ # })
11
+ # result = gmo.post_request("EntryTran.idPass", options)
12
+ module GMO
13
+ module Payment
14
+
15
+ module ShopAPIMethods
16
+
17
+ def initialize(options = {})
18
+ @shop_id = options[:shop_id]
19
+ @shop_pass = options[:shop_pass]
20
+ @development = options[:development] || true
21
+ unless @shop_id && @shop_pass
22
+ raise ArgumentError, "Initialize must receive a hash with :shop_id and either :shop_pass! (received #{options.inspect})"
23
+ end
24
+ end
25
+ attr_reader :shop_id, :shop_pass, :development
26
+
27
+ ## 2.1.2.1.取引登録
28
+ # これ以降の決済取引で必要となる取引 ID と取引パスワードの発行を行い、取引を開始します。
29
+ # ItemCode
30
+ # Tax
31
+ # TdFlag
32
+ # TdTenantName
33
+ ### @return ###
34
+ # AccessID
35
+ # AccessPass
36
+ # ErrCode
37
+ # ErrInfo
38
+ ### example ###
39
+ # gmo.entry_tran({
40
+ # order_id: 100,
41
+ # job_cd: "AUTH",
42
+ # amount: 100
43
+ # })
44
+ # {"AccessID"=>"a41d83f1f4c908baeda04e6dc03e300c", "AccessPass"=>"d72eca02e28c88f98b9341a33ba46d5d"}
45
+ def entry_tran(options = {})
46
+ name = "EntryTran.idPass"
47
+ args = {
48
+ "OrderID" => options[:order_id],
49
+ "JobCd" => options[:job_cd],
50
+ "Amount" => options[:amount]
51
+ }
52
+ post_request name, args
53
+ end
54
+
55
+ ## 2.2.2.2.決済実行
56
+ # 指定されたサイトに会員を登録します。
57
+ # return
58
+ # ACS
59
+ # OrderID
60
+ # Forward
61
+ # Method
62
+ # PayTimes
63
+ # Approve
64
+ # TranID
65
+ # TranDate
66
+ # CheckString
67
+ # ClientField1
68
+ # ClientField2
69
+ # ClientField3
70
+ ### @return ###
71
+ # ACS
72
+ # OrderID
73
+ # Forward
74
+ # Method
75
+ # PayTimes
76
+ # Approve
77
+ # TranID
78
+ # CheckString
79
+ # ClientField1
80
+ # ClientField2
81
+ # ClientField3
82
+ ### example ###
83
+ # gmo.exec_tran({
84
+ # order_id: 100,
85
+ # access_id: "a41d83f1f4c908baeda04e6dc03e300c",
86
+ # access_pass: "d72eca02e28c88f98b9341a33ba46d5d",
87
+ # method: 1,
88
+ # pay_times: 1,
89
+ # card_no: "4111111111111111",
90
+ # expire: "1405", #format YYMM
91
+ # client_field1: "client_field1"
92
+ # })
93
+ # {"ACS"=>"0", "OrderID"=>"100", "Forward"=>"2a99662", "Method"=>"1", "PayTimes"=>"", "Approve"=>"6294780", "TranID"=>"1302160543111111111111192829", "TranDate"=>"20130216054346", "CheckString"=>"3e455a2168fefc90dbb7db7ef7b0fe82", "ClientField1"=>"client_field1", "ClientField2"=>"", "ClientField3"=>""}
94
+ def exec_tran(options = {})
95
+ name = "ExecTran.idPass"
96
+ if options[:client_field1] || options[:client_field2] || options[:client_field3]
97
+ client_field_flg = "1"
98
+ else
99
+ client_field_flg = "0"
100
+ end
101
+ args = {
102
+ "AccessID" => options[:access_id],
103
+ "AccessPass" => options[:access_pass],
104
+ "OrderID" => options[:order_id],
105
+ "Method" => options[:method],
106
+ "PayTimes" => options[:pay_times],
107
+ "CardNo" => options[:card_no],
108
+ "Expire" => options[:expire],
109
+ "HttpAccept" => options[:http_accept],
110
+ "HttpUserAgent" => options[:http_ua],
111
+ "DeviceCategory" => "0",
112
+ "ClientField1" => options[:client_field1],
113
+ "ClientField2" => options[:client_field2],
114
+ "ClientField3" => options[:client_field3],
115
+ "ClientFieldFlag" => client_field_flg
116
+ }
117
+ post_request name, args
118
+ end
119
+
120
+ ## 2.14.2.1.決済変更
121
+ # 仮売上の決済に対して実売上を行います。尚、実行時に仮売上時との金額チェックを行います。
122
+ # /payment/AlterTran.idPass
123
+ # ShopID
124
+ # ShopPass
125
+ # AccessID 取引ID
126
+ # AccessPass 取引パスワード
127
+ # JobCd 処理区分 "SALES"
128
+ # Amount 利用金額
129
+ ### @return ###
130
+ # AccessID
131
+ # AccessPass
132
+ # Forward
133
+ # Approve
134
+ # TranID
135
+ # TranDate
136
+ ### example ###
137
+ # gmo.alter_tran({
138
+ # access_id: "a41d83f1f4c908baeda04e6dc03e300c",
139
+ # access_pass: "d72eca02e28c88f98b9341a33ba46d5d",
140
+ # job_cd: "SALES",
141
+ # amount: 100
142
+ # })
143
+ # {"AccessID"=>"381d84ae4e6fc37597482573a9569f10", "AccessPass"=>"cc0093ca8758c6616fa0ab9bf6a43e8d", "Forward"=>"2a99662", "Approve"=>"6284199", "TranID"=>"1302140555111111111111193536", "TranDate"=>"20130215110651"}
144
+ def alter_tran(options = {})
145
+ name = "AlterTran.idPass"
146
+ args = {
147
+ "AccessID" => options[:access_id],
148
+ "AccessPass" => options[:access_pass],
149
+ "JobCd" => options[:job_cd] || "SALES",
150
+ "Amount" => options[:amount]
151
+ }
152
+ post_request name, args
153
+ end
154
+
155
+ ## 2.15.2.1.金額変更
156
+ # 決済が完了した取引に対して金額の変更を行います。
157
+ ### @return ###
158
+ # AccessID
159
+ # AccessPass
160
+ # Forward
161
+ # Approve
162
+ # TranID
163
+ # TranDate
164
+ ### example ###
165
+ # gmo.change_tran({
166
+ # access_id: "a41d83f1f4c908baeda04e6dc03e300c",
167
+ # access_pass: "d72eca02e28c88f98b9341a33ba46d5d",
168
+ # JobCd: 100,
169
+ # Amount: 100
170
+ # })
171
+ def change_tran(options = {})
172
+ name = "ChangeTran.idPass"
173
+ args = {
174
+ "AccessID" => options[:access_id],
175
+ "AccessPass" => options[:access_pass],
176
+ "JobCd" => options[:job_cd],
177
+ "Amount" => options[:amount]
178
+ }
179
+ post_request name, args
180
+ end
181
+
182
+ ## 2.16.2.1.取引状態参照
183
+ # 指定したオーダーID の取引情報を取得します。
184
+ def search_trade(options = {})
185
+ name = "SearchTrade.idPass"
186
+ args = {
187
+ "OrderID" => options[:order_id]
188
+ }
189
+ post_request name, args
190
+ end
191
+
192
+ # 13.1.2.1.取引状態参照
193
+ # 指定したオーダーIDの取引情報を取得します。
194
+ def search_trade_multi(options = {})
195
+ name = "SearchTradeMulti.idPass"
196
+ args = {
197
+ "OrderID" => options[:order_id],
198
+ "PayType" => options[:pay_type]
199
+ }
200
+ post_request name, args
201
+ end
202
+
203
+ private
204
+
205
+ def api_call(name, args = {}, verb = "post", options = {})
206
+ args.merge!({ "ShopID" => @shop_id, "ShopPass" => @shop_pass })
207
+ response = api(name, args, verb, options) do |response|
208
+ if response.is_a?(Hash) && !response["ErrInfo"].nil?
209
+ raise APIError.new(response)
210
+ end
211
+ end
212
+ response
213
+ end
214
+
215
+ end
216
+
217
+ end
218
+ end
@@ -0,0 +1,146 @@
1
+ # coding: utf-8
2
+
3
+ # A client for the GMO Payment API.
4
+ #
5
+ # example
6
+ # gmo = GMO::Payment::SiteAPI.new({
7
+ # site_id: "foo",
8
+ # site_pass: "bar",
9
+ # development: true
10
+ # })
11
+ # result = gmo.post_request("EntryTran.idPass", options)
12
+ module GMO
13
+ module Payment
14
+
15
+ module SiteAPIMethods
16
+
17
+ def initialize(options = {})
18
+ @site_id = options[:site_id]
19
+ @site_pass = options[:site_pass]
20
+ @development = options[:development] || true
21
+ unless @site_id && @site_pass
22
+ raise ArgumentError, "Initialize must receive a hash with :site_id and either :site_pass! (received #{options.inspect})"
23
+ end
24
+ end
25
+ attr_reader :site_id, :site_pass, :development
26
+
27
+ ## 2.3.2.1.会員登録
28
+ # 指定されたサイトに会員を登録します。
29
+ def save_member(options = {})
30
+ name = "SaveMember.idPass"
31
+ args = {
32
+ "MemberID" => options[:member_id],
33
+ "MemberName" => options[:member_name]
34
+ }
35
+ post_request name, args
36
+ end
37
+
38
+ ## 2.4.2.1.会員更新
39
+ # 指定されたサイトに会員情報を更新します。
40
+ def update_member(options = {})
41
+ name = "UpdateMember.idPass"
42
+ args = {
43
+ "MemberID" => options[:member_id],
44
+ "MemberName" => options[:member_name]
45
+ }
46
+ post_request name, args
47
+ end
48
+
49
+ ## 2.5.2.1.会員削除
50
+ # 指定したサイトから会員情報を削除します。
51
+ def delete_member(options = {})
52
+ name = "DeleteMember.idPass"
53
+ args = {
54
+ "MemberID" => options[:member_id]
55
+ }
56
+ post_request name, args
57
+ end
58
+
59
+ ## 2.6.2.1.会員参照
60
+ # 指定したサイトの会員情報を参照します。
61
+ def search_member(options = {})
62
+ name = "SearchMember.idPass"
63
+ args = {
64
+ "MemberID" => options[:member_id]
65
+ }
66
+ post_request name, args
67
+ end
68
+
69
+ ## 2.7.2.1.カード登録/更新
70
+ # 指定した会員にカード情報を登録します。尚、サイトに設定されたショップ ID を使用してカード会社と通信を行い有効性の確認を行います。
71
+ def save_card(options = {})
72
+ name = "SaveCard.idPass"
73
+ args = {
74
+ "MemberID" => options[:member_id],
75
+ "CardSeq" => options[:card_seq],
76
+ "CardNo" => options[:card_no],
77
+ "Expire" => options[:expire]
78
+ }
79
+ args.delete("CardSeq") if options[:card_seq].nil?
80
+ post_request name, args
81
+ end
82
+
83
+ ## 2.8.2.1.カード削除
84
+ # 指定した会員のカード情報を削除します。
85
+ def delete_card(options = {})
86
+ name = "DeleteCard.idPass"
87
+ args = {
88
+ "MemberID" => options[:member_id],
89
+ "CardSeq" => options[:card_seq]
90
+ }
91
+ post_request name, args
92
+ end
93
+
94
+ ## 2.9.2.1.カード参照
95
+ # お客様が選択したカード登録連番のカード情報を取得します。
96
+ # カード情報が本人認証サービスに対応していない場合は、カード会社との通信を行い決済を実行します。その際の出力パラメータは「2.10.2.3決済実行」の出力パラメータと同じになります。
97
+ # /payment/ExecTran.idPass
98
+ def search_card(options = {})
99
+ name = "SearchCard.idPass"
100
+ args = {
101
+ "MemberID" => options[:member_id],
102
+ "CardSeq" => options[:card_seq],
103
+ "SeqMode" => options[:seq_mode]
104
+ }
105
+ post_request name, args
106
+ end
107
+
108
+ ## 2.11.2.3. 決済実行
109
+ # お客様が選択したカード登録連番のカード情報を取得します。
110
+ # カード情報が本人認証サービスに対応していない場合は、カード会社との通信を行い決済を実行します。その際の出力パラメータは「2.10.2.3決済実行」の出力パラメータと同じになります。
111
+ # /payment/ExecTran.idPass
112
+ def exec_tran(options = {})
113
+ name = "ExecTran.idPass"
114
+ args = {
115
+ "AccessID" => options[:access_id],
116
+ "AccessPass" => options[:access_pass],
117
+ "OrderID" => options[:order_id],
118
+ "JobCd" => "SALES",
119
+ "Method" => options[:method],
120
+ "PayTimes" => options[:pay_times],
121
+ "MemberID" => options[:member_id],
122
+ "CardSeq" => options[:card_seq],
123
+ "Amount" => options[:amount],
124
+ "HttpAccept" => options[:http_accept],
125
+ "HttpUserAgent" => options[:http_ua],
126
+ "DeviceCategory" => "0"
127
+ }
128
+ post_request name, args
129
+ end
130
+
131
+ private
132
+
133
+ def api_call(name, args = {}, verb = "post", options = {})
134
+ args.merge!({ "SiteID" => @site_id, "SitePass" => @site_pass })
135
+ response = api(name, args, verb, options) do |response|
136
+ if response.is_a?(Hash) && !response["ErrInfo"].nil?
137
+ raise APIError.new(response)
138
+ end
139
+ end
140
+ response
141
+ end
142
+
143
+ end
144
+
145
+ end
146
+ end
@@ -0,0 +1,3 @@
1
+ module GMO
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ describe "GMO::Payment::API" do
4
+
5
+ describe "#get_request" do
6
+ it "raises" do
7
+ lambda {
8
+ service = GMO::Payment::API.new()
9
+ service.get_request("foo")
10
+ }.should raise_error(RuntimeError)
11
+ end
12
+ end
13
+
14
+ describe "#post_request" do
15
+ it "raises" do
16
+ lambda {
17
+ service = GMO::Payment::API.new()
18
+ service.post_request("foo")
19
+ }.should raise_error(RuntimeError)
20
+ end
21
+ end
22
+
23
+ describe "#api_call" do
24
+ it "raises" do
25
+ lambda {
26
+ service = GMO::Payment::API.new()
27
+ service.api_call
28
+ }.should raise_error(NoMethodError)
29
+ end
30
+ end
31
+
32
+ end