Sha256: 26a983f42f5aa70a1bacf2077896e9ba8fbffa1261aeda15a2719a0267dc867b

Contents?: true

Size: 1.06 KB

Versions: 5

Compression:

Stored size: 1.06 KB

Contents

require 'nori'

module Gateway

# Class who handles Gateway post notification XML
  class PostNotification

    # This method parse the Xml sent by Gateway when notify a change in a transaction.
    #
    # @param request [String] XML received in the Gateway POST request.
    # @return [Hash<Symbol, String>] A hash collection containing the XML data parsed.
    def self.ParseNotification(xml)

      nori = Nori.new(:convert_tags_to => lambda { |tag| PostNotification.to_underscore(tag).to_sym })
      xml_hash = nori.parse(CGI::unescapeHTML(xml))

      return xml_hash
    end

    # Converts a string in Camel Case format to lower case with underscore.
    #
    # @param Example: 'StatusNotification' outputs 'status_notification'
    # @returns [String] lower case string separated with underscore
    def self.to_underscore(camel_case_string)
      return camel_case_string.gsub(/::/, '/').
          gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
          gsub(/([a-z\d])([A-Z])/, '\1_\2').
          tr("-", "_").
          downcase
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
mundipagg_sdk-1.3.0 lib/gateway/post_notification.rb
stone_ecommerce-1.2.4 lib/gateway/post_notification.rb
mundipagg_sdk-1.2.4 lib/gateway/post_notification.rb
mundipagg_sdk-1.2.3 lib/gateway/post_notification.rb
mundipagg_sdk-1.2.3rc lib/gateway/post_notification.rb