killbill-cybersource 4.0.9 → 4.0.10

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f29b96955182c07ea9f8c6c0b2664828c9b385d
4
- data.tar.gz: 43392e1684880a50f286cdaaae67b8c8666e2d91
3
+ metadata.gz: 58cb83423a65c33db773647d189febf28e53c799
4
+ data.tar.gz: 047b2949668e415baa08694d5adda58f28c78abe
5
5
  SHA512:
6
- metadata.gz: 6ccc1ae57b5fef06cf6e45f2518704aaebaaf3f0b195a8356f4a9eae084cdb748e245e6e04d1f67d42580c5c8d981eec90276df47826c6bbdd50e2dfd190d292
7
- data.tar.gz: 2da7bfe0ff896e517ea1ec8be1450cf850633274b629afad4cac5997947a2ac1fd16b62aa1560f3cec2c4f98f2aeef58bb879050432432835334f6a622ee1ba9
6
+ metadata.gz: 228be79b3eb1f98e22367db93ec779e54fe67c529e9b1cb827f1e94cd818a0933f3fa2c36c4a8d45ce89a14db9700005547863540fb986414d9daea9e7ef343d
7
+ data.tar.gz: 7febfe2b9798496d89af92ea4b5da908cedf79d516f72b740f06dd4890aa8ac92af21c386cc775c2bbd4be507c473b7b9e80eff997300af3aa98b4f50d2ad416
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- killbill-cybersource (4.0.9)
4
+ killbill-cybersource (4.0.10)
5
5
  actionpack (~> 4.1.0)
6
6
  actionview (~> 4.1.0)
7
7
  activemerchant (~> 1.48.0)
data/NEWS CHANGED
@@ -1,3 +1,8 @@
1
+ 4.0.10
2
+ Fix parsing of AVS and CVV responses
3
+ Specify User-Agent, X-Request-Id and Content-Type headers to CyberSource
4
+ Better handling of 5xx errors
5
+
1
6
  4.0.9
2
7
  Android Pay bugfix
3
8
  Cancel UNDEFINED payments after 24 hours by default
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.9
1
+ 4.0.10
@@ -26,8 +26,10 @@ module Killbill #:nodoc:
26
26
 
27
27
  headers = {
28
28
  # Don't use symbols or it will confuse Net/HTTP
29
- 'Authorization' => 'Basic ' + Base64.encode64("#{@config[:username]}:#{@config[:password]}").chomp
29
+ 'Authorization' => 'Basic ' + Base64.encode64("#{@config[:username]}:#{@config[:password]}").chomp,
30
+ 'User-Agent' => ActiveMerchant::Billing::CyberSourceGateway.ua
30
31
  }
32
+ headers['X-Request-Id'] = ActiveMerchant::Billing::CyberSourceGateway.x_request_id unless ActiveMerchant::Billing::CyberSourceGateway.x_request_id.blank?
31
33
 
32
34
  data = URI.encode_www_form(params)
33
35
 
@@ -5,6 +5,13 @@ module ActiveMerchant
5
5
 
6
6
  class CyberSourceGateway
7
7
 
8
+ cattr_reader :ua
9
+
10
+ def self.x_request_id
11
+ # See KillbillMDCInsertingServletFilter
12
+ org::slf4j::MDC::get('req.requestId') rescue nil
13
+ end
14
+
8
15
  def initialize(options = {})
9
16
  super
10
17
 
@@ -104,13 +111,18 @@ module ActiveMerchant
104
111
  end
105
112
  end
106
113
 
107
- # See https://github.com/killbill/killbill-cybersource-plugin/issues/4
108
114
  def commit(request, options)
109
115
  request = build_request(request, options)
110
116
  begin
111
- raw_response = ssl_post(test? ? self.test_url : self.live_url, request)
117
+ raw_response = ssl_post(test? ? self.test_url : self.live_url, request, build_headers(options))
112
118
  rescue ResponseError => e
113
- raw_response = e.response.body
119
+ if !e.response.nil? && e.response.code.to_i == 500 && !e.response.body.blank?
120
+ # See https://github.com/killbill/killbill-cybersource-plugin/issues/4
121
+ raw_response = e.response.body
122
+ else
123
+ # Don't swallow other 5xx errors like proxy timeouts - these should most likely be UNKNOWN
124
+ raise e
125
+ end
114
126
  end
115
127
  response = parse(raw_response)
116
128
 
@@ -135,9 +147,29 @@ module ActiveMerchant
135
147
  Response.new(success, message, response,
136
148
  :test => test?,
137
149
  :authorization => authorization,
138
- :avs_result => {:code => response[:avsCode]},
139
- :cvv_result => response[:cvCode]
140
- )
150
+ :avs_result => {:code => response['avsCode']},
151
+ :cvv_result => response['cvCode'])
152
+ end
153
+
154
+ def user_agent
155
+ @@ua ||= JSON.dump({
156
+ :bindings_version => KB_PLUGIN_VERSION,
157
+ :lang => 'ruby',
158
+ :lang_version => "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
159
+ :platform => RUBY_PLATFORM,
160
+ :publisher => 'killbill'
161
+ })
162
+ end
163
+
164
+ def build_headers(options)
165
+ options[:x_request_id] ||= self.class.x_request_id
166
+ options[:content_type] ||= 'text/xml'
167
+
168
+ headers = {}
169
+ headers['Content-Type'] = options[:content_type]
170
+ headers['User-Agent'] = user_agent
171
+ headers['X-Request-Id'] = options[:x_request_id] unless options[:x_request_id].blank?
172
+ headers
141
173
  end
142
174
 
143
175
  def add_merchant_data(xml, options)
data/pom.xml CHANGED
@@ -25,7 +25,7 @@
25
25
  <groupId>org.kill-bill.billing.plugin.ruby</groupId>
26
26
  <artifactId>cybersource-plugin</artifactId>
27
27
  <packaging>pom</packaging>
28
- <version>4.0.9</version>
28
+ <version>4.0.10</version>
29
29
  <name>cybersource-plugin</name>
30
30
  <url>http://github.com/killbill/killbill-cybersource-plugin</url>
31
31
  <description>Plugin for accessing Cybersource as a payment gateway</description>
@@ -147,6 +147,27 @@ describe Killbill::Cybersource::PaymentPlugin do
147
147
 
148
148
  context 'Errors handling' do
149
149
 
150
+ it 'handles proxy errors as UNDEFINED transactions' do
151
+ ::ActiveMerchant::Billing::CyberSourceGateway.any_instance.stub(:ssl_post) do |_, _|
152
+ raise ::ActiveMerchant::ResponseError.new(OpenStruct.new(:body => 'Oops', :code => 502))
153
+ end
154
+ purchase_with_token(:UNDEFINED).gateway_error.should == 'Failed with 502 '
155
+ end
156
+
157
+ it 'handles generic 500 errors as UNDEFINED transactions' do
158
+ ::ActiveMerchant::Billing::CyberSourceGateway.any_instance.stub(:ssl_post) do |_, _|
159
+ raise ::ActiveMerchant::ResponseError.new(OpenStruct.new(:body => nil, :code => 500))
160
+ end
161
+ purchase_with_token(:UNDEFINED).gateway_error.should == 'Failed with 500 '
162
+ end
163
+
164
+ it 'handles CyberSource errors as CANCELED transactions' do
165
+ ::ActiveMerchant::Billing::CyberSourceGateway.any_instance.stub(:ssl_post) do |_, _|
166
+ raise ::ActiveMerchant::ResponseError.new(OpenStruct.new(:body => one_or_more_fields_contains_invalid_data, :code => 500))
167
+ end
168
+ purchase_with_token(:CANCELED).gateway_error.should == 'One or more fields contains invalid data'
169
+ end
170
+
150
171
  it 'handles expired passwords as CANCELED transactions' do
151
172
  ::ActiveMerchant::Billing::CyberSourceGateway.any_instance.stub(:ssl_post).and_return(password_expired_response)
152
173
  purchase_with_token(:CANCELED).gateway_error.should == 'wsse:FailedCheck: Security Data : Merchant password has expired.'
@@ -425,4 +446,12 @@ describe Killbill::Cybersource::PaymentPlugin do
425
446
  <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-28121162"><wsu:Created>2008-01-15T21:50:41.580Z</wsu:Created></wsu:Timestamp></wsse:Security></soap:Header><soap:Body><c:replyMessage xmlns:c="urn:schemas-cybersource-com:transaction-data-1.26"><c:merchantReferenceCode>a1efca956703a2a5037178a8a28f7357</c:merchantReferenceCode><c:requestID>2004338415330008402434</c:requestID><c:decision>REJECT</c:decision><c:reasonCode>102</c:reasonCode><c:requestToken>Afvvj7KfIgU12gooCFE2/DanQIApt+G1OgTSA+R9PTnyhFTb0KRjgFY+ynyIFNdoKKAghwgx</c:requestToken><c:ccAuthReversalReply><c:reasonCode>102</c:reasonCode></c:ccAuthReversalReply><c:originalTransaction><c:amount>0.00</c:amount><c:reasonCode>100</c:reasonCode></c:originalTransaction></c:replyMessage></soap:Body></soap:Envelope>
426
447
  XML
427
448
  end
449
+
450
+ def one_or_more_fields_contains_invalid_data
451
+ <<-XML
452
+ <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
453
+ <soap:Header>
454
+ <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-28121162"><wsu:Created>2008-01-15T21:50:41.580Z</wsu:Created></wsu:Timestamp></wsse:Security></soap:Header><soap:Body><c:replyMessage xmlns:c="urn:schemas-cybersource-com:transaction-data-1.26"><c:requestID>12345</c:requestID><c:decision>REJECT</c:decision><c:reasonCode>102</c:reasonCode><c:invalidField>c:billTo/c:state</c:invalidField><c:requestToken>Afvvj7KfIgU12gooCFE2/DanQIApt+G1OgTSA+R9PTnyhFTb0KRjgFY+ynyIFNdoKKAghwgx</c:requestToken></c:replyMessage></soap:Body></soap:Envelope>
455
+ XML
456
+ end
428
457
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: killbill-cybersource
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.9
4
+ version: 4.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kill Bill core team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-10 00:00:00.000000000 Z
11
+ date: 2016-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: killbill