Sha256: 9b5114015b70e41214a1dc1fcb2fd587a8dcf6dfc29bff4ee2962066f36a8747

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

module WirecardSepa
  module DirectDebit
    class Response
      attr_reader :xml, :request

      def self.for_request(request)
        new(request.body, request: request)
      end

      def initialize(xml, request: nil)
        @xml = xml
        @request = request
      end

      def params
        {
          success:               success?,
          transaction_id:        transaction_id,
          transaction_state:     transaction_state,
          status_code:           status_code,
          status_description:    status_description,
          due_date:              due_date,
          reference_id:          provider_transaction_reference_id,
          original_response_xml: xml,
        }
      end

      def success?
        status_code == '201.0000'
      end

      def transaction_id
        xml_doc.at_css('transaction-id').text
      end

      def transaction_state
        xml_doc.at_css('transaction-state').text
      end

      def status_code
        xml_doc.at_css('status')[:code]
      end

      def status_description
        xml_doc.at_css('status')[:description]
      end

      def due_date
        xml_doc.at_css('due-date').text
      end

      def provider_transaction_reference_id
        xml_doc.at_css('provider-transaction-reference-id').text
      end

      private

      def xml_doc
        @xml_doc ||= Nokogiri::XML xml
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wirecard_sepa-0.0.2 lib/wirecard_sepa/direct_debit/response.rb