Sha256: d7e44a3fda13b82a346fb3cb80fc9515c8865c3ac326a9cabb10008b4156aa56

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 KB

Contents

module FbGraph
  class Order < Node
    attr_accessor :application, :from, :to, :amount, :status, :country, :created_time, :updated_time

    def initialize(identifier, attributes = {})
      super
      if app = attributes[:application]
        @application = Application.new(app[:id], app)
      end
      if from = attributes[:from]
        @from = User.new(from[:id], from)
      end
      if to = attributes[:to]
        @to = User.new(to[:id], to)
      end
      @status = attributes[:status]
      @country = attributes[:country]
      if attributes[:created_time]
        @created_time = Time.parse(attributes[:created_time]).utc
      end
      if attributes[:updated_time]
        @updated_time = Time.parse(attributes[:updated_time]).utc
      end
    end

    def settled!(options = {})
      update options.merge(:status => :settled)
    end

    def refunded!(options = {})
      update options.merge(:status => :refunded)
    end

    def canceled!(options = {})
      update options.merge(:status => :canceled)
    end

    def update(attributes = {})
      _attributes_ = attributes.dup
      params = {
        :access_token => self.access_token,
        :status => _attributes_.delete(:status),
        :message => _attributes_.delete(:message),
        :refund_funding_source => _attributes_.delete(:refund_funding_source),
        :refund_reason => _attributes_.delete(:refund_reason),
        :params => _attributes_
      }
      super params
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fb_graph-2.0.1 lib/fb_graph/order.rb
fb_graph-2.0.0 lib/fb_graph/order.rb
fb_graph-2.0.0.beta lib/fb_graph/order.rb
fb_graph-2.0.0.alpha lib/fb_graph/order.rb
fb_graph-1.9.5 lib/fb_graph/order.rb
fb_graph-1.9.4 lib/fb_graph/order.rb