lib/active_merchant/billing/gateways/redsys.rb in activemerchant-1.100.0 vs lib/active_merchant/billing/gateways/redsys.rb in activemerchant-1.101.0

- old
+ new

@@ -318,13 +318,11 @@ } end end def add_threeds(data, options) - if options[:execute_threed] == true - data[:threeds] = {threeDSInfo: 'CardData'} - end + data[:threeds] = {threeDSInfo: 'CardData'} if options[:execute_threed] == true end def determine_3ds_action(threeds_hash) return 'iniciaPeticion' if threeds_hash[:threeDSInfo] == 'CardData' return 'trataPeticion' if threeds_hash[:threeDSInfo] == 'AuthenticationData' || @@ -444,17 +442,13 @@ xml.DS_MERCHANT_DIRECTPAYMENT 'true' end # Set moto flag only if explicitly requested via moto field # Requires account configuration to be able to use - if options.dig(:moto) && options.dig(:metadata, :manual_entry) - xml.DS_MERCHANT_DIRECTPAYMENT 'moto' - end + xml.DS_MERCHANT_DIRECTPAYMENT 'moto' if options.dig(:moto) && options.dig(:metadata, :manual_entry) - if data[:threeds] - xml.DS_MERCHANT_EMV3DS data[:threeds].to_json - end + xml.DS_MERCHANT_EMV3DS data[:threeds].to_json if data[:threeds] end end def parse(data, action) params = {} @@ -462,22 +456,11 @@ message = '' options = @options.merge(:test => test?) xml = Nokogiri::XML(data) code = xml.xpath('//RETORNOXML/CODIGO').text - if ['iniciaPeticion', 'trataPeticion'].include?(action) - vxml = Nokogiri::XML(data).remove_namespaces!.xpath("//Envelope/Body/#{action}Response/#{action}Return").inner_text - xml = Nokogiri::XML(vxml) - node = (action == 'iniciaPeticion' ? 'INFOTARJETA' : 'OPERACION') - op = xml.xpath("//RETORNOXML/#{node}") - op.children.each do |element| - params[element.name.downcase.to_sym] = element.text - end - message = response_text_3ds(xml, params) - options[:authorization] = build_authorization(params) - success = params.size > 0 && is_success_response?(params[:ds_response]) - elsif code == '0' + if code == '0' && xml.xpath('//RETORNOXML/OPERACION').present? op = xml.xpath('//RETORNOXML/OPERACION') op.children.each do |element| params[element.name.downcase.to_sym] = element.text end if validate_signature(params) @@ -485,10 +468,21 @@ options[:authorization] = build_authorization(params) success = is_success_response?(params[:ds_response]) else message = 'Response failed validation check' end + elsif ['iniciaPeticion', 'trataPeticion'].include?(action) + vxml = Nokogiri::XML(data).remove_namespaces!.xpath("//Envelope/Body/#{action}Response/#{action}Return").inner_text + xml = Nokogiri::XML(vxml) + node = (action == 'iniciaPeticion' ? 'INFOTARJETA' : 'OPERACION') + op = xml.xpath("//RETORNOXML/#{node}") + op.children.each do |element| + params[element.name.downcase.to_sym] = element.text + end + message = response_text_3ds(xml, params) + options[:authorization] = build_authorization(params) + success = params.size > 0 && is_success_response?(params[:ds_response]) else # Some kind of programmer error with the request! message = "#{code} ERROR" end @@ -597,16 +591,12 @@ def xml_signed_fields(data) xml_signed_fields = data[:ds_amount] + data[:ds_order] + data[:ds_merchantcode] + data[:ds_currency] + data[:ds_response] - if data[:ds_cardnumber] - xml_signed_fields += data[:ds_cardnumber] - end + xml_signed_fields += data[:ds_cardnumber] if data[:ds_cardnumber] - if data[:ds_emv3ds] - xml_signed_fields += data[:ds_emv3ds] - end + xml_signed_fields += data[:ds_emv3ds] if data[:ds_emv3ds] xml_signed_fields + data[:ds_transactiontype] + data[:ds_securepayment] end def get_key(order_id)