|
| 1 | +require 'nokogiri' |
| 2 | + |
1 | 3 | module ActiveMerchant # :nodoc: |
2 | 4 | module Billing # :nodoc: |
3 | 5 | # Initial setup instructions can be found in |
@@ -202,8 +204,8 @@ def purchase(money, payment_method, options = {}) |
202 | 204 | end |
203 | 205 | end |
204 | 206 |
|
205 | | - def void(identification, options = {}) |
206 | | - commit(build_void_request(identification, options), :void, nil, options) |
| 207 | + def void(money, identification, options = {}) |
| 208 | + commit(build_void_request(money, identification, options), :void, nil, options) |
207 | 209 | end |
208 | 210 |
|
209 | 211 | def refund(money, identification, options = {}) |
@@ -466,11 +468,14 @@ def reference_is_a_check?(payment_method_or_reference) |
466 | 468 | payment_method_or_reference.is_a?(String) && payment_method_or_reference.split(';')[7] == 'check' |
467 | 469 | end |
468 | 470 |
|
469 | | - def build_void_request(identification, options) |
470 | | - order_id, request_id, request_token, action, money, currency = identification.split(';') |
471 | | - options[:order_id] = order_id |
472 | | - |
| 471 | + def build_void_request(money, identification, options) |
473 | 472 | xml = Builder::XmlMarkup.new indent: 2 |
| 473 | + if identification.nil? |
| 474 | + request_id = nil |
| 475 | + else |
| 476 | + order_id, request_id, request_token, action, money, currency = identification.split(';') |
| 477 | + options[:order_id] = order_id |
| 478 | + end |
474 | 479 | case action |
475 | 480 | when 'capture', 'purchase' |
476 | 481 | add_mdd_fields(xml, options) |
@@ -1016,7 +1021,7 @@ def add_void_service(xml, request_id, request_token) |
1016 | 1021 |
|
1017 | 1022 | def add_auth_reversal_service(xml, request_id, request_token) |
1018 | 1023 | xml.tag! 'ccAuthReversalService', { 'run' => 'true' } do |
1019 | | - xml.tag! 'authRequestID', request_id |
| 1024 | + xml.tag! 'authRequestID', request_id unless request_id.nil? |
1020 | 1025 | xml.tag! 'authRequestToken', request_token |
1021 | 1026 | end |
1022 | 1027 | end |
@@ -1053,6 +1058,7 @@ def add_subscription_retrieve_service(xml, options) |
1053 | 1058 | end |
1054 | 1059 |
|
1055 | 1060 | def add_merchant_category_code(xml, options) |
| 1061 | + xml.tag! 'merchantTransactionIdentifier', options[:merchant_identifier] if options[:merchant_identifier] |
1056 | 1062 | xml.tag! 'merchantCategoryCode', options[:merchant_category_code] if options[:merchant_category_code] |
1057 | 1063 | end |
1058 | 1064 |
|
@@ -1196,6 +1202,7 @@ def add_partner_solution_id(xml) |
1196 | 1202 | # Where we actually build the full SOAP request using builder |
1197 | 1203 | def build_request(body, options) |
1198 | 1204 | xsd_version = test? ? TEST_XSD_VERSION : PRODUCTION_XSD_VERSION |
| 1205 | + validate_with_xsd(body, options) |
1199 | 1206 |
|
1200 | 1207 | xml = Builder::XmlMarkup.new indent: 2 |
1201 | 1208 | xml.instruct! |
@@ -1332,6 +1339,23 @@ def eligible_for_zero_auth?(payment_method, options = {}) |
1332 | 1339 | def format_routing_number(routing_number, options) |
1333 | 1340 | options[:currency] == 'CAD' && routing_number.length > 8 ? routing_number[-8..-1] : routing_number |
1334 | 1341 | end |
| 1342 | + |
| 1343 | + def validate_with_xsd(xml_body, options, xsd_path: '/Users/gsanmartin/Documents/Spreedly/active_merchant/test/schema/cyber_source/CyberSourceTransaction_1.201.xsd') |
| 1344 | + xsd = Nokogiri::XML::Schema(File.read(xsd_path)) |
| 1345 | + xml = Builder::XmlMarkup.new indent: 2 |
| 1346 | + |
| 1347 | + xsd_version = test? ? TEST_XSD_VERSION : PRODUCTION_XSD_VERSION |
| 1348 | + |
| 1349 | + xml.tag! 'requestMessage', { 'xmlns' => "urn:schemas-cybersource-com:transaction-data-#{xsd_version}" } do |
| 1350 | + add_merchant_data(xml, options) |
| 1351 | + xml << xml_body |
| 1352 | + end |
| 1353 | + xml_t = xml.target! |
| 1354 | + puts xml_t |
| 1355 | + doc = Nokogiri::XML(xml_t) |
| 1356 | + errors = xsd.validate(doc) |
| 1357 | + errors.empty? ? true : puts(errors.map(&:message)) |
| 1358 | + end |
1335 | 1359 | end |
1336 | 1360 | end |
1337 | 1361 | end |
0 commit comments