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.



1011
1012
1013
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1011

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).



1085
1086
1087
1088
1089
1090
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1085

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.



1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1016

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) }),
    :number => (x = opts.delete(:number); x.nil? ? nil : HttpClient::Preconditions.assert_class('number', x, Array).map { |v| HttpClient::Preconditions.assert_class('number', v, String) }),
    :identifier => (x = opts.delete(:identifier); x.nil? ? nil : HttpClient::Preconditions.assert_class('identifier', x, 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),
    :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, 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, incoming = {}) ⇒ Object

Returns information about a specific order.



1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1052

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

#get_identifier_by_identifier_number(organization, identifier_number, incoming = {}) ⇒ Object

Returns information about a specific order using an identifier number



1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1135

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

#get_status_and_fraud_by_number(organization, number) ⇒ Object

Returns the current fraud status for this order



1162
1163
1164
1165
1166
1167
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1162

def get_status_and_fraud_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)}/status/fraud").get
  ::Io::Flow::V0::Models::OrderFraudStatus.new(r)
end

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

Provides visibility into recent changes of each order, including deletion



1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1147

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



1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1035

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)),
    :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) })
  }.delete_if { |k, v| v.nil? }
  (x = order_form; x.is_a?(::Io::Flow::V0::Models::OrderForm) ? x : ::Io::Flow::V0::Models::OrderForm.new(x))
  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



1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1066

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)),
    :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) })
  }.delete_if { |k, v| v.nil? }
  (x = order_put_form; x.is_a?(::Io::Flow::V0::Models::OrderPutForm) ? x : ::Io::Flow::V0::Models::OrderPutForm.new(x))
  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_cancellations_by_number(organization, number, order_cancellation_form) ⇒ Object



1092
1093
1094
1095
1096
1097
1098
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1092

def put_cancellations_by_number(organization, number, order_cancellation_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  (x = order_cancellation_form; x.is_a?(::Io::Flow::V0::Models::OrderCancellationForm) ? x : ::Io::Flow::V0::Models::OrderCancellationForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}/cancellations").with_json(order_cancellation_form.to_json).put
  ::Io::Flow::V0::Models::Order.new(r)
end

#put_promotions_and_free_shipping_by_number_and_key(organization, number, key, free_shipping_order_promotion_form, incoming = {}) ⇒ Object

Creates a free shipping promotion for this order, automatically applying it to the order if the order meets the defined promotion trigger.



1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1102

def put_promotions_and_free_shipping_by_number_and_key(organization, number, key, free_shipping_order_promotion_form, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) })
  }.delete_if { |k, v| v.nil? }
  (x = free_shipping_order_promotion_form; x.is_a?(::Io::Flow::V0::Models::FreeShippingOrderPromotionForm) ? x : ::Io::Flow::V0::Models::FreeShippingOrderPromotionForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}/promotions/#{CGI.escape(key)}/free_shipping").with_query(query).with_json(free_shipping_order_promotion_form.to_json).put
  ::Io::Flow::V0::Models::FreeShippingOrderPromotion.new(r)
end

#put_submissions_by_number(organization, number) ⇒ 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.



1119
1120
1121
1122
1123
1124
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1119

def put_submissions_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)}/submissions").put
  ::Io::Flow::V0::Models::Order.new(r)
end

#put_updates_by_number(organization, number, order_update_form) ⇒ Object



1126
1127
1128
1129
1130
1131
1132
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1126

def put_updates_by_number(organization, number, order_update_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  (x = order_update_form; x.is_a?(::Io::Flow::V0::Models::OrderUpdateForm) ? x : ::Io::Flow::V0::Models::OrderUpdateForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}/updates").with_json(order_update_form.to_json).put
  ::Io::Flow::V0::Models::Order.new(r)
end