active_merchant-epsilon 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21731c597893be5cdf7c104d2b8401b23a50c94c
4
- data.tar.gz: 59c99f9120cdb5d08805d36847f4c4e71f1d7c49
3
+ metadata.gz: 60b0318fc5b7ae333a3fb3a50e7566c9b30bdd50
4
+ data.tar.gz: a3a6fa696e3c912e1b2f5791ef45f04ad466fd4d
5
5
  SHA512:
6
- metadata.gz: ead8517eff83884440b66bf11d21dd3d6e79ad1149223207f2fbbb4888235597a62e8310aca937c5cb9dadacaf5fffbe96eb319e56ad1203e29f076f39ff86f0
7
- data.tar.gz: cd7c1c310052e5fed03e431cdba28565e6f1e689b91f6d49306c8367d77a380fd5adc6ee5e8e1bc554b7b4fda662f521cea42f663b8b4cfc52e78e49d8809aa9
6
+ metadata.gz: 486586c8622f27eacab5d2f052203510dc17dd1c6c561e6c4c7223f23d292db860f6fe3736e84d34867a5fa051afd5ba38f819d23b7cce7c0991589d9987aafd
7
+ data.tar.gz: 678d4a7a4625d46eb84ccd6aaac32275da62ef2a140d12e2427c2ff870974acfdd0ac9004aebd83a0c7f61db78b6ab1db5b067afd5e73b9a8b938b7a7a3ec397
@@ -1,6 +1,13 @@
1
1
  language: ruby
2
-
3
2
  rvm:
4
- - 2.1.6
5
- - 2.2.2
3
+ - 2.1.7
4
+ - 2.2.3
5
+ - 2.3.0
6
+
6
7
  script: bundle exec rake test:remote
8
+ script: bundle exec rake test:unit
9
+
10
+ notifications:
11
+ slack:
12
+ rooms:
13
+ secure: rYtA4FBXqKHYv+v7xA6FfkcsDXRexWyMj9WMG2YK7bgZoNG2N7q461Dr/lCU0JTuRGsxDIs5jHK+QFFZNW/h+SbhQfiew++W8FgoIbP/z7HuEW50SXLcigGb02YmQm+ybbh5Dw1QGmcTOVItXJfuFmrDm1fq0qO0HC0543Yn4BzrSdWnEWQSaK7JMBRc9aYVPc0VlWG8pGRLtW0PDb6D32MvEI4jPrnh2NPDomPT9YutmMC+jNBPKr72m68g3v2GogbX4irZ6Kp5UUUZtaDbt9yLRfNL/3bsVGVrS1S2qCO4If5xTtE7lvV807a8QuQIj4Y9YqRO7K+/wUrz4Yb2ycF7agAkjN+w2WNEjgsKeFk50R4BWKpSy6y2N2RIl7rdHVEnU1T9I6LH0do5hMGqhgDYgppb2F7YFL9buUqag6gKAX3BHIV16ADJOFBT2Hh2m6x9f5TRb5ZR4LDJBQaflMhj0pwmIcC5Bhr3yi45r/4xiJ1IQaspXCzvfUMXARgWqqSxxveVQ07obiFeFCZ2YJEyv9fYLxT39+9koP48iKHTzbtFi4ay37PfMaztiXM0dqTwdjbJ95krc8AoNuTDphgwLLW2Zxxz2+tFQiLcj1tebUZa1hBsil1EVI7P/8PjAjGowckCnEAnFBZS5oFrgE2qzuwIGbLRYeeoRev0tks=
@@ -29,27 +29,6 @@ module ActiveMerchant #:nodoc:
29
29
 
30
30
  self.abstract_class = true
31
31
 
32
- module ResponseXpath
33
- RESULT = '//Epsilon_result/result[@result]/@result'
34
- TRANSACTION_CODE = '//Epsilon_result/result[@trans_code]/@trans_code'
35
- ERROR_CODE = '//Epsilon_result/result[@err_code]/@err_code'
36
- ERROR_DETAIL = '//Epsilon_result/result[@err_detail]/@err_detail'
37
- CARD_NUMBER_MASK = '//Epsilon_result/result[@card_number_mask]/@card_number_mask'
38
- CARD_BRAND = '//Epsilon_result/result[@card_brand]/@card_brand'
39
- ACS_URL = '//Epsilon_result/result[@acsurl]/@acsurl' # ACS (Access Control Server)
40
- PA_REQ = '//Epsilon_result/result[@pareq]/@pareq' # PAReq (payer authentication request)
41
- RECEIPT_NUMBER = '//Epsilon_result/result[@receipt_no][1]/@receipt_no'
42
- RECEIPT_DATE = '//Epsilon_result/result[@receipt_date][1]/@receipt_date'
43
- CONVENIENCE_STORE_LIMIT_DATE = '//Epsilon_result/result[@conveni_limit][1]/@conveni_limit'
44
- end
45
-
46
- module ResultCode
47
- FAILURE = '0'
48
- SUCCESS = '1'
49
- THREE_D_SECURE = '5'
50
- SYSTEM_ERROR = '9'
51
- end
52
-
53
32
  cattr_accessor :contract_code, :proxy_address, :proxy_port
54
33
 
55
34
  self.test_url = 'https://beta.epsilon.jp/cgi-bin/order/'
@@ -59,16 +38,26 @@ module ActiveMerchant #:nodoc:
59
38
  self.homepage_url = 'http://www.example.net/'
60
39
  self.display_name = 'New Gateway'
61
40
 
41
+ DEFAULT_RESPONSE_KEYS = [
42
+ :transaction_code,
43
+ :error_code,
44
+ :error_detail,
45
+ :card_number_mask,
46
+ :card_brand,
47
+ :three_d_secure,
48
+ :acs_url,
49
+ :pa_req,
50
+ :receipt_number,
51
+ :receipt_date
52
+ ].freeze
53
+
62
54
  private
63
55
 
64
- def authorization_from(response)
65
- {}
66
- end
56
+ def commit(path, request_params, response_keys = DEFAULT_RESPONSE_KEYS)
57
+ parser = ResponseParser.new
67
58
 
68
- def commit(path, params)
69
- url = (test? ? test_url : live_url)
70
- raw_response = ssl_post(File.join(url, path), post_data(params))
71
- response = parse(raw_response)
59
+ url = (test? ? test_url : live_url)
60
+ response = parser.parse(ssl_post(File.join(url, path), post_data(request_params)), response_keys)
72
61
 
73
62
  options = {
74
63
  authorization: authorization_from(response),
@@ -78,54 +67,20 @@ module ActiveMerchant #:nodoc:
78
67
  Response.new(success_from(response), message_from(response), response, options)
79
68
  end
80
69
 
81
- def message_from(response)
82
- response[:message]
83
- end
84
-
85
- def parse(body)
86
- # because of following error
87
- # Nokogiri::XML::SyntaxError: Unsupported encoding x-sjis-cp932
88
- xml = Nokogiri::XML(body.sub('x-sjis-cp932', 'UTF-8'))
89
-
90
- result = xml.xpath(ResponseXpath::RESULT).to_s
91
- transaction_code = xml.xpath(ResponseXpath::TRANSACTION_CODE).to_s
92
- error_code = xml.xpath(ResponseXpath::ERROR_CODE).to_s
93
- error_detail = uri_decode(xml.xpath(ResponseXpath::ERROR_DETAIL).to_s)
94
- card_number_mask = uri_decode(xml.xpath(ResponseXpath::CARD_NUMBER_MASK).to_s)
95
- card_brand = uri_decode(xml.xpath(ResponseXpath::CARD_BRAND).to_s)
96
- acs_url = uri_decode(xml.xpath(ResponseXpath::ACS_URL).to_s)
97
- pa_req = uri_decode(xml.xpath(ResponseXpath::PA_REQ).to_s)
98
- receipt_number = xml.xpath(ResponseXpath::RECEIPT_NUMBER).to_s
99
- receipt_date = uri_decode(xml.xpath(ResponseXpath::RECEIPT_DATE).to_s)
100
- convenience_store_limit_date = uri_decode(xml.xpath(ResponseXpath::CONVENIENCE_STORE_LIMIT_DATE).to_s)
101
-
102
- {
103
- success: [ResultCode::SUCCESS, ResultCode::THREE_D_SECURE].include?(result),
104
- message: "#{error_code}: #{error_detail}",
105
- transaction_code: transaction_code,
106
- error_code: error_code,
107
- error_detail: error_detail,
108
- card_number_mask: card_number_mask,
109
- card_brand: card_brand,
110
- three_d_secure: result == ResultCode::THREE_D_SECURE,
111
- acs_url: acs_url,
112
- pa_req: pa_req,
113
- receipt_number: receipt_number,
114
- receipt_date: receipt_date,
115
- convenience_store_limit_date: convenience_store_limit_date,
116
- }
117
- end
118
-
119
70
  def post_data(parameters = {})
120
71
  parameters.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
121
72
  end
122
73
 
74
+ def message_from(response)
75
+ response[:message]
76
+ end
77
+
123
78
  def success_from(response)
124
79
  response[:success]
125
80
  end
126
81
 
127
- def uri_decode(string)
128
- URI.decode(string).encode(Encoding::UTF_8, Encoding::CP932)
82
+ def authorization_from(response)
83
+ {}
129
84
  end
130
85
  end
131
86
  end
@@ -1,6 +1,12 @@
1
1
  module ActiveMerchant #:nodoc:
2
2
  module Billing #:nodoc:
3
3
  class EpsilonConvenienceStoreGateway < EpsilonBaseGateway
4
+
5
+ RESPONSE_KEYS = DEFAULT_RESPONSE_KEYS + [
6
+ :convenience_store_limit_date,
7
+ :convenience_store_payment_slip_url
8
+ ]
9
+
4
10
  def purchase(amount, payment_method, detail = {})
5
11
  params = {
6
12
  contract_code: self.contract_code,
@@ -20,7 +26,7 @@ module ActiveMerchant #:nodoc:
20
26
  user_name_kana: payment_method.name,
21
27
  }
22
28
 
23
- commit('receive_order3.cgi', params)
29
+ commit('receive_order3.cgi', params, RESPONSE_KEYS)
24
30
  end
25
31
  end
26
32
  end
@@ -0,0 +1,99 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class ResponseParser
4
+ def parse(body, required_items)
5
+ # because of following error
6
+ # Nokogiri::XML::SyntaxError: Unsupported encoding x-sjis-cp932
7
+ @xml = Nokogiri::XML(body.sub('x-sjis-cp932', 'UTF-8'))
8
+ @result = @xml.xpath(ResponseXpath::RESULT).to_s
9
+
10
+ response = {
11
+ success: [ResultCode::SUCCESS, ResultCode::THREE_D_SECURE].include?(@result),
12
+ message: "#{error_code}: #{error_detail}"
13
+ }
14
+
15
+ required_items.each do |item_name|
16
+ response[item_name] = self.send(item_name)
17
+ end
18
+
19
+ response
20
+ end
21
+
22
+ private
23
+
24
+ def transaction_code
25
+ @xml.xpath(ResponseXpath::TRANSACTION_CODE).to_s
26
+ end
27
+
28
+ def error_code
29
+ @xml.xpath(ResponseXpath::ERROR_CODE).to_s
30
+ end
31
+
32
+ def error_detail
33
+ uri_decode(@xml.xpath(ResponseXpath::ERROR_DETAIL).to_s)
34
+ end
35
+
36
+ def card_number_mask
37
+ uri_decode(@xml.xpath(ResponseXpath::CARD_NUMBER_MASK).to_s)
38
+ end
39
+
40
+ def card_brand
41
+ uri_decode(@xml.xpath(ResponseXpath::CARD_BRAND).to_s)
42
+ end
43
+
44
+ def three_d_secure
45
+ @result == ResultCode::THREE_D_SECURE
46
+ end
47
+
48
+ def acs_url
49
+ uri_decode(@xml.xpath(ResponseXpath::ACS_URL).to_s)
50
+ end
51
+
52
+ def pa_req
53
+ uri_decode(@xml.xpath(ResponseXpath::PA_REQ).to_s)
54
+ end
55
+
56
+ def receipt_number
57
+ @xml.xpath(ResponseXpath::RECEIPT_NUMBER).to_s
58
+ end
59
+
60
+ def receipt_date
61
+ uri_decode(@xml.xpath(ResponseXpath::RECEIPT_DATE).to_s)
62
+ end
63
+
64
+ def convenience_store_limit_date
65
+ uri_decode(@xml.xpath(ResponseXpath::CONVENIENCE_STORE_LIMIT_DATE).to_s)
66
+ end
67
+
68
+ def convenience_store_payment_slip_url
69
+ uri_decode(@xml.xpath(ResponseXpath::CONVENIENCE_STORE_PAYMENT_SLIP_URL).to_s)
70
+ end
71
+
72
+ def uri_decode(string)
73
+ URI.decode(string).encode(Encoding::UTF_8, Encoding::CP932)
74
+ end
75
+
76
+ module ResponseXpath
77
+ RESULT = '//Epsilon_result/result[@result]/@result'
78
+ TRANSACTION_CODE = '//Epsilon_result/result[@trans_code]/@trans_code'
79
+ ERROR_CODE = '//Epsilon_result/result[@err_code]/@err_code'
80
+ ERROR_DETAIL = '//Epsilon_result/result[@err_detail]/@err_detail'
81
+ CARD_NUMBER_MASK = '//Epsilon_result/result[@card_number_mask]/@card_number_mask'
82
+ CARD_BRAND = '//Epsilon_result/result[@card_brand]/@card_brand'
83
+ ACS_URL = '//Epsilon_result/result[@acsurl]/@acsurl' # ACS (Access Control Server)
84
+ PA_REQ = '//Epsilon_result/result[@pareq]/@pareq' # PAReq (payer authentication request)
85
+ RECEIPT_NUMBER = '//Epsilon_result/result[@receipt_no][1]/@receipt_no'
86
+ RECEIPT_DATE = '//Epsilon_result/result[@receipt_date][1]/@receipt_date'
87
+ CONVENIENCE_STORE_LIMIT_DATE = '//Epsilon_result/result[@conveni_limit][1]/@conveni_limit'
88
+ CONVENIENCE_STORE_PAYMENT_SLIP_URL = '//Epsilon_result/result[@haraikomi_url][1]/@haraikomi_url'
89
+ end
90
+
91
+ module ResultCode
92
+ FAILURE = '0'
93
+ SUCCESS = '1'
94
+ THREE_D_SECURE = '5'
95
+ SYSTEM_ERROR = '9'
96
+ end
97
+ end
98
+ end
99
+ end
@@ -7,3 +7,4 @@ require_relative 'billing/gateways/epsilon/epsilon_mission_code'
7
7
  require_relative 'billing/gateways/epsilon/epsilon_base'
8
8
  require_relative 'billing/gateways/epsilon'
9
9
  require_relative 'billing/gateways/epslion_convenience_store'
10
+ require_relative 'billing/gateways/response_parser'
@@ -1,5 +1,5 @@
1
1
  module ActiveMerchant
2
2
  module Epsilon
3
- VERSION = "0.5.4"
3
+ VERSION = "0.5.5"
4
4
  end
5
5
  end
@@ -15,6 +15,7 @@ class RemoteEpsilonConvenienceStoreGatewayTest < MiniTest::Test
15
15
  assert_match /\d{7}/, response.params['receipt_number']
16
16
  assert_match /\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}/, response.params['receipt_date']
17
17
  assert_match /\d{4}\-\d{2}\-\d{2}/, response.params['convenience_store_limit_date']
18
+ assert_match %r!\Ahttp://.+!, response.params['convenience_store_payment_slip_url']
18
19
  end
19
20
  end
20
21
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_merchant-epsilon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenichi TAKAHASHI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-04 00:00:00.000000000 Z
11
+ date: 2016-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant
@@ -157,6 +157,7 @@ files:
157
157
  - lib/active_merchant/billing/gateways/epsilon/epsilon_base.rb
158
158
  - lib/active_merchant/billing/gateways/epsilon/epsilon_mission_code.rb
159
159
  - lib/active_merchant/billing/gateways/epslion_convenience_store.rb
160
+ - lib/active_merchant/billing/gateways/response_parser.rb
160
161
  - lib/active_merchant/epsilon.rb
161
162
  - lib/active_merchant/epsilon/version.rb
162
163
  - test/fixtures/vcr_cassettes/autheticate_three_d_secure_card_successful.yml
@@ -191,7 +192,6 @@ files:
191
192
  - test/test_helper.rb
192
193
  - test/unit/billing/convenience_store_test.rb
193
194
  - test/unit/gateways/epsilon_test.rb
194
- - wercker.yml
195
195
  homepage: http://github.com/pepabo/active_merchant-epsilon
196
196
  licenses:
197
197
  - MIT
@@ -212,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
212
  version: '0'
213
213
  requirements: []
214
214
  rubyforge_project:
215
- rubygems_version: 2.4.8
215
+ rubygems_version: 2.5.1
216
216
  signing_key:
217
217
  specification_version: 4
218
218
  summary: Epsilon integration for ActiveMerchant.
@@ -1,11 +0,0 @@
1
- box: wercker/rvm
2
- build:
3
- steps:
4
- - rvm-use:
5
- version: 2.1.6
6
-
7
- - bundle-install
8
-
9
- - script:
10
- name: rake test:unit
11
- code: bundle exec rake test:remote