gmo 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/LICENSE +22 -0
  2. data/README.ja.md +1 -3
  3. data/README.md +1 -3
  4. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_alter_tran_change_order_auth_to_sale.yml +15 -15
  5. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_alter_tran_gets_data_about_order.yml +15 -15
  6. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_alter_tran_got_error_if_missing_options.yml +3 -3
  7. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_change_tran_gets_data_about_order.yml +15 -15
  8. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_change_tran_got_error_if_missing_options.yml +3 -3
  9. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_entry_tran_gets_data_about_a_transaction.yml +6 -6
  10. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_entry_tran_got_error_if_missing_options.yml +5 -5
  11. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_exec_tran_gets_data_about_a_transaction.yml +35 -6
  12. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_exec_tran_got_error_if_missing_options.yml +5 -5
  13. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_search_trade_gets_data_about_order.yml +5 -5
  14. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_search_trade_got_error_if_missing_options.yml +3 -3
  15. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_search_trade_multi_gets_data_about_order.yml +7 -9
  16. data/fixtures/vcr_cassettes/GMO_Payment_ShopAPI/_search_trade_multi_got_error_if_missing_options.yml +5 -7
  17. data/fixtures/vcr_cassettes/GMO_Payment_ShopAndSiteAPI/_trade_card_got_error_if_missing_options.yml +3 -3
  18. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_delete_card_gets_data_about_a_card.yml +6 -8
  19. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_delete_member_gets_data_about_a_member.yml +35 -8
  20. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_save_card_gets_data_about_a_card.yml +6 -8
  21. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_save_member_gets_data_about_a_transaction.yml +6 -6
  22. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_search_card_gets_data_about_a_card.yml +12 -16
  23. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_search_member_gets_data_about_a_member.yml +14 -18
  24. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_update_member_gets_data_about_a_transaction.yml +5 -5
  25. data/gmo.gemspec +1 -1
  26. data/lib/gmo.rb +3 -7
  27. data/lib/gmo/http_services.rb +1 -1
  28. data/lib/gmo/shop_and_site_api.rb +8 -8
  29. data/lib/gmo/shop_api.rb +7 -7
  30. data/lib/gmo/site_api.rb +7 -7
  31. data/lib/gmo/version.rb +1 -1
  32. data/spec/gmo/http_service_spec.rb +2 -7
  33. data/spec/gmo/shop_and_site_api_spec.rb +6 -1
  34. data/spec/gmo/shop_api_spec.rb +28 -10
  35. data/spec/gmo/site_api_spec.rb +24 -13
  36. data/spec/support/config.example.yml +2 -1
  37. data/spec/support/config.yml +2 -1
  38. data/spec/support/factory.rb +4 -0
  39. data/spec/support/vcr.rb +1 -0
  40. data/travis.yml +1 -0
  41. metadata +6 -6
  42. data/fixtures/vcr_cassettes/GMO_Payment_SiteAPI/_save_member_got_error_if_missing_options.yml +0 -32
@@ -2,10 +2,10 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: post
5
- uri: https://pt01.mul-pay.jp/payment/UpdateMember.idPass
5
+ uri: https://<HOST>/payment/UpdateMember.idPass
6
6
  body:
7
7
  encoding: UTF-8
8
- string: MemberID=100&MemberName=John+Smith2&SiteID=<SITE_ID>&SitePass=<SITE_PASS>
8
+ string: MemberID=1362106780&MemberName=John+Smith2&SiteID=<SITE_ID>&SitePass=<SITE_PASS>
9
9
  headers:
10
10
  Accept:
11
11
  - ! '*/*'
@@ -17,7 +17,7 @@ http_interactions:
17
17
  message: OK
18
18
  headers:
19
19
  Date:
20
- - Sat, 16 Feb 2013 05:29:21 GMT
20
+ - Fri, 01 Mar 2013 02:59:41 GMT
21
21
  Connection:
22
22
  - close
23
23
  Content-Type:
@@ -26,7 +26,7 @@ http_interactions:
26
26
  - chunked
27
27
  body:
28
28
  encoding: US-ASCII
29
- string: MemberID=100
29
+ string: MemberID=1362106780
30
30
  http_version:
31
- recorded_at: Sat, 16 Feb 2013 05:29:21 GMT
31
+ recorded_at: Fri, 01 Mar 2013 02:59:41 GMT
32
32
  recorded_with: VCR 2.4.0
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
7
7
  gem.name = "gmo"
8
8
  gem.description = %q{Ruby client library for the GMO Payment Platform.}
9
9
  gem.summary = %q{GMO Payment API client: Ruby client library for the GMO Payment Platform.}
10
- gem.homepage = ""
10
+ gem.homepage = "https://github.com/t-k/gmo-payment-ruby"
11
11
  gem.version = GMO::VERSION
12
12
 
13
13
  gem.authors = ["Tatsuo Kaniwa"]
data/lib/gmo.rb CHANGED
@@ -17,21 +17,17 @@ module GMO
17
17
 
18
18
  module Payment
19
19
 
20
- DEV_SERVER = "pt01.mul-pay.jp"
21
- # TODO: Set production server
22
- PRO_SERVER = "pt01.mul-pay.jp"
23
-
24
20
  class API
25
21
 
26
22
  def initialize(options = {})
27
- @development = options[:development] || true
23
+ @host = options[:host]
28
24
  end
29
- attr_reader :development
25
+ attr_reader :host
30
26
 
31
27
  def api(path, args = {}, verb = "post", options = {}, &error_checking_block)
32
28
  # Setup args for make_request
33
29
  path = "/payment/#{path}" unless path =~ /^\//
34
- options.merge!({ "development" => @development })
30
+ options.merge!({ :host => @host })
35
31
  # Make request via the provided service
36
32
  result = GMO.make_request path, args, verb, options
37
33
  # Check for any 500 server errors before parsing the body
@@ -15,7 +15,7 @@ module GMO
15
15
  def self.included(base)
16
16
  base.class_eval do
17
17
  def self.server(options = {})
18
- options[:development] ? Payment::DEV_SERVER : Payment::PRO_SERVER
18
+ options[:host]
19
19
  end
20
20
  end# end class_eval
21
21
  end
@@ -4,16 +4,16 @@ module GMO
4
4
 
5
5
  module ShopAndSiteAPIMethods
6
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})"
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
+ @host = options[:host]
12
+ unless @site_id && @site_pass && @shop_id && @shop_pass && @host
13
+ raise ArgumentError, "Initialize must receive a hash with :site_id, :site_pass, :shop_id, :shop_pass and either :host! (received #{options.inspect})"
14
14
  end
15
15
  end
16
- attr_reader :shop_id, :shop_pass, :site_id, :site_pass, :development
16
+ attr_reader :shop_id, :shop_pass, :site_id, :site_pass, :host
17
17
 
18
18
  # 2.17.2.1.決済後カード登録
19
19
  # 指定されたオーダーID の取引に使用したカードを登録します。
@@ -6,7 +6,7 @@
6
6
  # gmo = GMO::Payment::ShopAPI.new({
7
7
  # shop_id: "foo",
8
8
  # shop_pass: "bar",
9
- # development: true
9
+ # host: "mul-pay.com"
10
10
  # })
11
11
  # result = gmo.post_request("EntryTran.idPass", options)
12
12
  module GMO
@@ -15,14 +15,14 @@ module GMO
15
15
  module ShopAPIMethods
16
16
 
17
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})"
18
+ @shop_id = options[:shop_id]
19
+ @shop_pass = options[:shop_pass]
20
+ @host = options[:host]
21
+ unless @shop_id && @shop_pass && @host
22
+ raise ArgumentError, "Initialize must receive a hash with :shop_id, :shop_pass and either :host! (received #{options.inspect})"
23
23
  end
24
24
  end
25
- attr_reader :shop_id, :shop_pass, :development
25
+ attr_reader :shop_id, :shop_pass, :host
26
26
 
27
27
  ## 2.1.2.1.取引登録
28
28
  # これ以降の決済取引で必要となる取引 ID と取引パスワードの発行を行い、取引を開始します。
@@ -6,7 +6,7 @@
6
6
  # gmo = GMO::Payment::SiteAPI.new({
7
7
  # site_id: "foo",
8
8
  # site_pass: "bar",
9
- # development: true
9
+ # host: "mul-pay.com"
10
10
  # })
11
11
  # result = gmo.post_request("EntryTran.idPass", options)
12
12
  module GMO
@@ -15,14 +15,14 @@ module GMO
15
15
  module SiteAPIMethods
16
16
 
17
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})"
18
+ @site_id = options[:site_id]
19
+ @site_pass = options[:site_pass]
20
+ @host = options[:host]
21
+ unless @site_id && @site_pass && @host
22
+ raise ArgumentError, "Initialize must receive a hash with :site_id, :site_pass and either :host! (received #{options.inspect})"
23
23
  end
24
24
  end
25
- attr_reader :site_id, :site_pass, :development
25
+ attr_reader :site_id, :site_pass, :host
26
26
 
27
27
  ## 2.3.2.1.会員登録
28
28
  # 指定されたサイトに会員を登録します。
@@ -1,3 +1,3 @@
1
1
  module GMO
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -8,14 +8,9 @@ describe "GMO::HTTPService" do
8
8
 
9
9
  describe "common methods" do
10
10
  describe "server" do
11
- it "should return the dev server if options[:development]" do
12
- FakeHTTPService.server(:development => true).should == GMO::Payment::DEV_SERVER
11
+ it "should return the host" do
12
+ FakeHTTPService.server(:host => SPEC_CONF["host"]).should == SPEC_CONF["host"]
13
13
  end
14
-
15
- it "should return the pro server if !options[:development]" do
16
- FakeHTTPService.server(:development => false).should == GMO::Payment::PRO_SERVER
17
- end
18
-
19
14
  end
20
15
 
21
16
  end
@@ -7,7 +7,8 @@ describe "GMO::Payment::ShopAndSiteAPI" do
7
7
  :shop_id => SPEC_CONF["shop_id"],
8
8
  :shop_pass => SPEC_CONF["shop_pass"],
9
9
  :site_id => SPEC_CONF["site_id"],
10
- :site_pass => SPEC_CONF["site_pass"]
10
+ :site_pass => SPEC_CONF["site_pass"],
11
+ :host => SPEC_CONF["host"]
11
12
  })
12
13
  end
13
14
 
@@ -33,6 +34,10 @@ describe "GMO::Payment::ShopAndSiteAPI" do
33
34
  @service.site_pass.should == SPEC_CONF["site_pass"]
34
35
  end
35
36
 
37
+ it "has an attr_reader for host" do
38
+ @service.host.should == SPEC_CONF["host"]
39
+ end
40
+
36
41
  describe "#trade_card" do
37
42
 
38
43
  it "got error if missing options", :vcr do
@@ -2,10 +2,15 @@ require "spec_helper"
2
2
 
3
3
  describe "GMO::Payment::ShopAPI" do
4
4
 
5
+ before(:all) do
6
+ @order_id = generate_id
7
+ end
8
+
5
9
  before(:each) do
6
10
  @service ||= GMO::Payment::ShopAPI.new({
7
11
  :shop_id => SPEC_CONF["shop_id"],
8
- :shop_pass => SPEC_CONF["shop_pass"]
12
+ :shop_pass => SPEC_CONF["shop_pass"],
13
+ :host => SPEC_CONF["host"]
9
14
  })
10
15
  end
11
16
 
@@ -23,10 +28,15 @@ describe "GMO::Payment::ShopAPI" do
23
28
  @service.shop_pass.should == SPEC_CONF["shop_pass"]
24
29
  end
25
30
 
31
+ it "has an attr_reader for host" do
32
+ @service.host.should == SPEC_CONF["host"]
33
+ end
34
+
26
35
  describe "#entry_tran" do
27
36
  it "gets data about a transaction", :vcr do
37
+ order_id = @order_id
28
38
  result = @service.entry_tran({
29
- :order_id => 100,
39
+ :order_id => order_id,
30
40
  :job_cd => "AUTH",
31
41
  :amount => 100
32
42
  })
@@ -43,11 +53,19 @@ describe "GMO::Payment::ShopAPI" do
43
53
 
44
54
  describe "#exec_tran" do
45
55
  it "gets data about a transaction", :vcr do
56
+ order_id = generate_id
46
57
  client_field1 = "client_field1"
58
+ result = @service.entry_tran({
59
+ :order_id => order_id,
60
+ :job_cd => "AUTH",
61
+ :amount => 100
62
+ })
63
+ access_id = result["AccessID"]
64
+ access_pass = result["AccessPass"]
47
65
  result = @service.exec_tran({
48
- :order_id => 100,
49
- :access_id => ACCESS_ID,
50
- :access_pass => ACCESS_PASS,
66
+ :order_id => order_id,
67
+ :access_id => access_id,
68
+ :access_pass => access_pass,
51
69
  :method => 1,
52
70
  :pay_times => 1,
53
71
  :card_no => "4111111111111111",
@@ -77,7 +95,7 @@ describe "GMO::Payment::ShopAPI" do
77
95
 
78
96
  describe "#alter_tran" do
79
97
  it "gets data about order", :vcr do
80
- order_id = 1001
98
+ order_id = generate_id
81
99
  result = @service.entry_tran({
82
100
  :order_id => order_id,
83
101
  :job_cd => "AUTH",
@@ -110,7 +128,7 @@ describe "GMO::Payment::ShopAPI" do
110
128
  end
111
129
 
112
130
  it "change order auth to sale", :vcr do
113
- order_id = 1002
131
+ order_id = generate_id
114
132
  result = @service.entry_tran({
115
133
  :order_id => order_id,
116
134
  :job_cd => "AUTH",
@@ -151,7 +169,7 @@ describe "GMO::Payment::ShopAPI" do
151
169
 
152
170
  describe "#change_tran" do
153
171
  it "gets data about order", :vcr do
154
- order_id = 1003
172
+ order_id = generate_id
155
173
  result = @service.entry_tran({
156
174
  :order_id => order_id,
157
175
  :job_cd => "AUTH",
@@ -192,7 +210,7 @@ describe "GMO::Payment::ShopAPI" do
192
210
 
193
211
  describe "#search_trade" do
194
212
  it "gets data about order", :vcr do
195
- order_id = 1003
213
+ order_id = @order_id
196
214
  result = @service.search_trade({
197
215
  :order_id => order_id
198
216
  })
@@ -227,7 +245,7 @@ describe "GMO::Payment::ShopAPI" do
227
245
  it "gets data about order", :vcr do
228
246
  client_field1 = "client_field1"
229
247
  result = @service.search_trade_multi({
230
- :order_id => 100,
248
+ :order_id => @order_id,
231
249
  :pay_type => "0"
232
250
  })
233
251
  result["Status"].nil?.should_not be_true
@@ -2,10 +2,15 @@ require "spec_helper"
2
2
 
3
3
  describe "GMO::Payment::SiteAPI" do
4
4
 
5
+ before(:all) do
6
+ @member_id = generate_id
7
+ end
8
+
5
9
  before(:each) do
6
10
  @service ||= GMO::Payment::SiteAPI.new({
7
11
  :site_id => SPEC_CONF["site_id"],
8
- :site_pass => SPEC_CONF["site_pass"]
12
+ :site_pass => SPEC_CONF["site_pass"],
13
+ :host => SPEC_CONF["host"]
9
14
  })
10
15
  end
11
16
 
@@ -23,11 +28,15 @@ describe "GMO::Payment::SiteAPI" do
23
28
  @service.site_pass.should == SPEC_CONF["site_pass"]
24
29
  end
25
30
 
31
+ it "has an attr_reader for host" do
32
+ @service.host.should == SPEC_CONF["host"]
33
+ end
34
+
26
35
  describe "#save_member" do
27
36
  it "gets data about a transaction", :vcr do
28
37
  member_name = "John Smith"
29
38
  result = @service.save_member({
30
- :member_id => 100,
39
+ :member_id => @member_id,
31
40
  :member_name => member_name
32
41
  })
33
42
  result["MemberID"].nil?.should_not be_true
@@ -36,34 +45,37 @@ describe "GMO::Payment::SiteAPI" do
36
45
 
37
46
  describe "#update_member" do
38
47
  it "gets data about a transaction", :vcr do
39
- member_id = 100
48
+ member_id = @member_id
40
49
  member_name = "John Smith2"
41
50
  result = @service.update_member({
42
51
  :member_id => member_id,
43
52
  :member_name => member_name
44
53
  })
45
54
  result["MemberID"].nil?.should_not be_true
46
- (result["MemberID"].to_i == member_id).should be_true
47
55
  end
48
56
  end
49
57
 
50
58
  describe "#delete_member" do
51
59
  it "gets data about a member", :vcr do
52
- member_id = 100
60
+ member_id = generate_id
61
+ member_name = "John Smith"
62
+ result = @service.save_member({
63
+ :member_id => member_id,
64
+ :member_name => member_name
65
+ })
53
66
  result = @service.delete_member({
54
67
  :member_id => member_id
55
68
  })
56
69
  result["MemberID"].nil?.should_not be_true
57
- (result["MemberID"].to_i == member_id).should be_true
58
70
  end
59
71
  end
60
72
 
61
73
  describe "#search_member" do
62
74
  it "gets data about a member", :vcr do
63
75
  member_name = "John Smith"
64
- member_id = 101
76
+ member_id = generate_id
65
77
  result = @service.save_member({
66
- :member_id => 101,
78
+ :member_id => member_id,
67
79
  :member_name => member_name
68
80
  })
69
81
  result["MemberID"].nil?.should_not be_true
@@ -72,7 +84,6 @@ describe "GMO::Payment::SiteAPI" do
72
84
  :member_id => member_id
73
85
  })
74
86
  result["MemberID"].nil?.should_not be_true
75
- (result["MemberID"].to_i == member_id).should be_true
76
87
  result["MemberName"].nil?.should_not be_true
77
88
  (result["MemberName"].to_s == member_name).should be_true
78
89
  result["DeleteFlag"].nil?.should_not be_true
@@ -82,7 +93,7 @@ describe "GMO::Payment::SiteAPI" do
82
93
 
83
94
  describe "#save_card" do
84
95
  it "gets data about a card", :vcr do
85
- member_id = 101
96
+ member_id = @member_id
86
97
  card_no = "4111111111111111"
87
98
  expire = "1405"
88
99
  result = @service.save_card({
@@ -96,7 +107,7 @@ describe "GMO::Payment::SiteAPI" do
96
107
 
97
108
  describe "#delete_card" do
98
109
  it "gets data about a card", :vcr do
99
- member_id = 101
110
+ member_id = @member_id
100
111
  card_seq = 0
101
112
  result = @service.delete_card({
102
113
  :member_id => member_id,
@@ -109,8 +120,8 @@ describe "GMO::Payment::SiteAPI" do
109
120
 
110
121
  describe "#search_card" do
111
122
  it "gets data about a card", :vcr do
112
- member_id = 101
113
- card_no = "4111111111111111"
123
+ member_id = generate_id
124
+ card_no = "4111111111111112"
114
125
  expire = "1405"
115
126
  result = @service.save_card({
116
127
  :member_id => member_id,
@@ -1,4 +1,5 @@
1
1
  shop_id: tshophoge
2
2
  shop_pass: hoge
3
3
  site_id: tsitehoge
4
- site_pass: hoge
4
+ site_pass: hoge
5
+ host: pt01.mul-pay.jp
@@ -1,4 +1,5 @@
1
1
  shop_id: tshop0001
2
2
  shop_pass: 1
3
3
  site_id: tsite0001
4
- site_pass: 1
4
+ site_pass: 1
5
+ host: pt01.mul-pay.jp
@@ -4,5 +4,9 @@ def generate_token
4
4
  Digest::MD5.new.update(rand(10).to_s).to_s
5
5
  end
6
6
 
7
+ def generate_id
8
+ Time.now.to_i
9
+ end
10
+
7
11
  ACCESS_ID = generate_token
8
12
  ACCESS_PASS = generate_token
@@ -8,6 +8,7 @@ VCR.configure do |c|
8
8
  c.filter_sensitive_data('<SITE_ID>') { SPEC_CONF["site_id"] }
9
9
  c.filter_sensitive_data('<SITE_PASS>') { SPEC_CONF["site_pass"] }
10
10
  c.filter_sensitive_data('<SITE_PASS>') { SPEC_CONF["site_pass"] }
11
+ c.filter_sensitive_data('<HOST>') { SPEC_CONF["host"] }
11
12
  c.filter_sensitive_data('<ACCESS_ID>') { ACCESS_ID }
12
13
  c.filter_sensitive_data('<ACCESS_PASS>') { ACCESS_PASS }
13
14
  end