Sha256: 60a2d1bf6915b2e15e21c7b9c33e61cc43922ed07d95f4ab441c41c342a7a65c

Contents?: true

Size: 1.03 KB

Versions: 11

Compression:

Stored size: 1.03 KB

Contents

module Spreedly

  class Transaction < Model

    field :state, :message
    field :succeeded, type: :boolean

    def self.new_from(xml_doc)
      case xml_doc.at_xpath('.//transaction_type').inner_text
      when 'AddPaymentMethod'
        return AddPaymentMethod.new(xml_doc)
      when 'Purchase'
        return Purchase.new(xml_doc)
      when 'Authorization'
        return Authorization.new(xml_doc)
      when 'Capture'
        return Capture.new(xml_doc)
      when 'Credit'
        return Refund.new(xml_doc)
      when 'Void'
        return Void.new(xml_doc)
      when 'RetainPaymentMethod'
        return RetainPaymentMethod.new(xml_doc)
      when 'RedactPaymentMethod'
        return RedactPaymentMethod.new(xml_doc)
      when 'RedactGateway'
        return RedactGateway.new(xml_doc)
      else
        Transaction.new(xml_doc)
      end
    end

    def self.new_list_from(xml_doc)
      transactions = xml_doc.xpath('.//transactions/transaction')
      transactions.map do |each|
        self.new_from(each)
      end
    end

  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spreedly-2.0.11 lib/spreedly/transactions/transaction.rb
spreedly-2.0.10 lib/spreedly/transactions/transaction.rb
spreedly-2.0.9 lib/spreedly/transactions/transaction.rb
spreedly-2.0.8 lib/spreedly/transactions/transaction.rb
spreedly-2.0.7 lib/spreedly/transactions/transaction.rb
spreedly-2.0.6 lib/spreedly/transactions/transaction.rb
spreedly-2.0.5 lib/spreedly/transactions/transaction.rb
spreedly-2.0.4 lib/spreedly/transactions/transaction.rb
spreedly-2.0.3 lib/spreedly/transactions/transaction.rb
spreedly-2.0.2 lib/spreedly/transactions/transaction.rb
spreedly-2.0.1 lib/spreedly/transactions/transaction.rb