Class: Io::Flow::V0::Clients::Orders

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Orders

Returns a new instance of Orders.



828
829
830
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 828

def initialize(client)
  @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client)
end

Instance Method Details

#delete_by_number(organization, number) ⇒ Object

Delete an order. Note that production orders that have already been submitted cannot be deleted (you will see a 422 response in these cases).



895
896
897
898
899
900
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 895

def delete_by_number(organization, number)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}").delete
  nil
end

#get(organization, incoming = {}) ⇒ Object

Search orders. Always paginated.



833
834
835
836
837
838
839
840
841
842
843
844
845
846
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 833

def get(organization, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
    :identifier => (x = opts.delete(:identifier); x.nil? ? nil : HttpClient::Preconditions.assert_class('identifier', x, Array).map { |v| HttpClient::Preconditions.assert_class('identifier', v, String) }),
    :number => (x = opts.delete(:number); x.nil? ? nil : HttpClient::Preconditions.assert_class('number', x, Array).map { |v| HttpClient::Preconditions.assert_class('number', v, String) }),
    :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
    :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
    :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "-created_at" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/orders").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Order.new(x) }
end

#get_by_number(organization, number) ⇒ Object

Returns information about a specific order.



867
868
869
870
871
872
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 867

def get_by_number(organization, number)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}").get
  ::Io::Flow::V0::Models::Order.new(r)
end

#get_identifier_by_identifier_number(organization, identifier_number) ⇒ Object

Returns information about a specific order using an identifier number



915
916
917
918
919
920
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 915

def get_identifier_by_identifier_number(organization, identifier_number)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('identifier_number', identifier_number, String)
  r = @client.request("/#{CGI.escape(organization)}/orders/identifier/#{CGI.escape(identifier_number)}").get
  ::Io::Flow::V0::Models::Order.new(r)
end

#get_versions(organization, incoming = {}) ⇒ Object

Provides visibility into recent changes of each order, including deletion



923
924
925
926
927
928
929
930
931
932
933
934
935
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 923

def get_versions(organization, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
    :number => (x = opts.delete(:number); x.nil? ? nil : HttpClient::Preconditions.assert_class('number', x, Array).map { |v| HttpClient::Preconditions.assert_class('number', v, String) }),
    :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
    :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
    :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "journal_timestamp" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/orders/versions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::OrderVersion.new(x) }
end

#post(organization, order_form, incoming = {}) ⇒ Object

Create an order, using the localized information from the experience selected by the query parameters. Note the order must be submitted before its expiration



851
852
853
854
855
856
857
858
859
860
861
862
863
864
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 851

def post(organization, order_form, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :experience => (x = opts.delete(:experience); x.nil? ? nil : HttpClient::Preconditions.assert_class('experience', x, String)),
    :country => (x = opts.delete(:country); x.nil? ? nil : HttpClient::Preconditions.assert_class('country', x, String)),
    :ip => (x = opts.delete(:ip); x.nil? ? nil : HttpClient::Preconditions.assert_class('ip', x, String)),
    :currency => (x = opts.delete(:currency); x.nil? ? nil : HttpClient::Preconditions.assert_class('currency', x, String)),
    :language => (x = opts.delete(:language); x.nil? ? nil : HttpClient::Preconditions.assert_class('language', x, String))
  }.delete_if { |k, v| v.nil? }
  HttpClient::Preconditions.assert_class('order_form', order_form, ::Io::Flow::V0::Models::OrderForm)
  r = @client.request("/#{CGI.escape(organization)}/orders").with_query(query).with_json(order_form.to_json).post
  ::Io::Flow::V0::Models::Order.new(r)
end

#put_by_number(organization, number, order_put_form, incoming = {}) ⇒ Object

Upserts an order. using the localized information from the experience selected by the query parameters. Note the order must be submitted before its expiration



877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 877

def put_by_number(organization, number, order_put_form, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :experience => (x = opts.delete(:experience); x.nil? ? nil : HttpClient::Preconditions.assert_class('experience', x, String)),
    :country => (x = opts.delete(:country); x.nil? ? nil : HttpClient::Preconditions.assert_class('country', x, String)),
    :ip => (x = opts.delete(:ip); x.nil? ? nil : HttpClient::Preconditions.assert_class('ip', x, String)),
    :currency => (x = opts.delete(:currency); x.nil? ? nil : HttpClient::Preconditions.assert_class('currency', x, String)),
    :language => (x = opts.delete(:language); x.nil? ? nil : HttpClient::Preconditions.assert_class('language', x, String))
  }.delete_if { |k, v| v.nil? }
  HttpClient::Preconditions.assert_class('order_put_form', order_put_form, ::Io::Flow::V0::Models::OrderPutForm)
  r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}").with_query(query).with_json(order_put_form.to_json).put
  ::Io::Flow::V0::Models::Order.new(r)
end

#put_submissions_by_number(organization, number, hash) ⇒ Object

Submits an order. You will get a validation error if the order has already expired (and a new quote could not be automatically recreated for a lower or same price). This method is idempotent - submitting an order a second time has no effect.



906
907
908
909
910
911
912
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 906

def put_submissions_by_number(organization, number, hash)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  HttpClient::Preconditions.assert_class('hash', hash, Hash)
  r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}/submissions").with_json(hash.to_json).put
  ::Io::Flow::V0::Models::Order.new(r)
end