def rewrite_request_block(auth_type="ST3DAUTH")

      # set the required AUTH type
      REXML::XPath.first(@request_xml, "//Request").attributes["Type"] = auth_type

      # delete term url and merchant name
      ops = REXML::XPath.first(@request_xml, "//Operation")
      ["TermUrl", "MerchantName"].each { |e| ops.delete_element e }

      # delete accept and user agent in customer info
      customer_info = REXML::XPath.first(@request_xml, "//CustomerInfo")
      ["Accept", "UserAgent"].each { |e| customer_info.delete_element e }

      # delete credit card details and add TransactionVerifier and TransactionReference from response xml
      # CC details are not needed anymore as verifier and reference are sufficient
      cc_details = REXML::XPath.first(@request_xml, "//CreditCard")
      ["Number", "Type", "SecurityCode", "StartDate", "ExpiryDate", "Issue"].each { |e| cc_details.delete_element e }
      cc_details.add_element("TransactionVerifier").text = REXML::XPath.first(@response_xml, "//TransactionVerifier").text
      cc_details.add_element("ParentTransactionReference").text = REXML::XPath.first(@response_xml, "//TransactionReference").text

      # unless it is an AUTH request, add additional required info for a 3DAUTH request
      unless auth_type == "AUTH"
        pm_method = REXML::XPath.first(@request_xml, "//PaymentMethod")
        threedsecure = pm_method.add_element("ThreeDSecure")
        threedsecure.add_element("Enrolled").text = REXML::XPath.first(@response_xml, "//Enrolled").text
        threedsecure.add_element("MD").text = REXML::XPath.first(@response_xml, "//MD").text rescue ""
      end
      true
    end
def rewrite_request_block(auth_type="ST3DAUTH")

      # set the required AUTH type
      REXML::XPath.first(@request_xml, "//Request").attributes["Type"] = auth_type

      # delete term url and merchant name
      ops = REXML::XPath.first(@request_xml, "//Operation")
      ["TermUrl", "MerchantName"].each { |e| ops.delete_element e }

      # delete accept and user agent in customer info
      customer_info = REXML::XPath.first(@request_xml, "//CustomerInfo")
      ["Accept", "UserAgent"].each { |e| customer_info.delete_element e }

      # delete credit card details and add TransactionVerifier and TransactionReference from response xml
      # CC details are not needed anymore as verifier and reference are sufficient
      cc_details = REXML::XPath.first(@request_xml, "//CreditCard")
      ["Number", "Type", "SecurityCode", "StartDate", "ExpiryDate", "Issue"].each { |e| cc_details.delete_element e }
      cc_details.add_element("TransactionVerifier").text = REXML::XPath.first(@response_xml, "//TransactionVerifier").text
      cc_details.add_element("ParentTransactionReference").text = REXML::XPath.first(@response_xml, "//TransactionReference").text

      # unless it is an AUTH request, add additional required info for a 3DAUTH request
      unless auth_type == "AUTH"
        pm_method = REXML::XPath.first(@request_xml, "//PaymentMethod")
        threedsecure = pm_method.add_element("ThreeDSecure")
        threedsecure.add_element("Enrolled").text = REXML::XPath.first(@response_xml, "//Enrolled").text
        threedsecure.add_element("MD").text = REXML::XPath.first(@response_xml, "//MD").text rescue ""
      end
      true
    end
Rewrites the request according to the response coming from SecureTrading according to the required auth_type
 This only applies if the inital request was a ST3DCARDQUERY
 It deletes elements which are not needed for the subsequent request and
 adds the required additional information if an ST3DAUTH is needed