Sha256: bdfb8f5abeb2a2d013b6ab7e09f397931d393aad1f9715ca6c483c053f4d91b1

Contents?: true

Size: 1.52 KB

Versions: 16

Compression:

Stored size: 1.52 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 application = attributes[:application]
        @application = Application.new(app.delete(:id), app)
      end
      if from = attributes[:from]
        @from = User.new(from.delete(:id), from)
      end
      if to = attributes[:to]
        @to = User.new(to.delete(: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, :refund_funding_source => true)
    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_.to_json
      }
      post params
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
fb_graph-1.8.0 lib/fb_graph/order.rb
fb_graph-1.8.0.alpha2 lib/fb_graph/order.rb
fb_graph-1.7.5 lib/fb_graph/order.rb
fb_graph-1.8.0.alpha lib/fb_graph/order.rb
fb_graph-1.7.4 lib/fb_graph/order.rb
fb_graph-1.7.3 lib/fb_graph/order.rb
fb_graph-1.7.2 lib/fb_graph/order.rb
fb_graph-1.7.1 lib/fb_graph/order.rb
fb_graph-1.7.0 lib/fb_graph/order.rb
fb_graph-1.7.0.alpha2 lib/fb_graph/order.rb
fb_graph-1.6.9 lib/fb_graph/order.rb
fb_graph-1.7.0.alpha lib/fb_graph/order.rb
fb_graph-1.6.8 lib/fb_graph/order.rb
fb_graph-1.6.7 lib/fb_graph/order.rb
fb_graph-1.6.5 lib/fb_graph/order.rb
fb_graph-1.6.4 lib/fb_graph/order.rb