Class: Io::Flow::V0::Clients::Orders
- Inherits:
-
Object
- Object
- Io::Flow::V0::Clients::Orders
- Defined in:
- lib/flow_commerce/flow_api_v0_client.rb
Instance Method Summary collapse
-
#delete_by_number(organization, number) ⇒ Object
Delete an order.
-
#get(organization, incoming = {}) ⇒ Object
Search orders.
-
#get_allocations_by_number(organization, number) ⇒ Object
Order allocations provide a granular view of an order that is targeted for accounting / financial views of an order.
-
#get_by_number(organization, number, incoming = {}) ⇒ Object
Returns information about a specific order.
-
#get_identifier_by_identifier(organization, identifier, incoming = {}) ⇒ Object
Returns information about a specific order using an identifier number.
-
#get_status_and_fraud_by_number(organization, number) ⇒ Object
Returns the current fraud status for this order.
-
#get_versions(organization, incoming = {}) ⇒ Object
Provides visibility into recent changes of each order, including deletion.
-
#initialize(client) ⇒ Orders
constructor
A new instance of Orders.
-
#post(organization, order_form, incoming = {}) ⇒ Object
Create an order, using the localized information from the experience selected by the query parameters.
-
#post_authorizations_by_number(organization, number, authorization_form, incoming = {}) ⇒ Object
Creates an authorization, automatically associating to this order.
-
#post_installment_and_plan_and_authorizations_by_number(organization, number, installment_plan_payment_form) ⇒ Object
Creates an installment plan for this order, automatically associating to this order.
-
#post_labels_by_number(organization, number) ⇒ Object
Generate a shipping label given only an order number for the organziation.
-
#put_by_number(organization, number, order_put_form, incoming = {}) ⇒ Object
Upserts an order.
- #put_inventory_and_reservations_by_number(organization, number) ⇒ Object
-
#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.
-
#put_submissions_by_number(organization, number) ⇒ Object
Submits an order.
Constructor Details
#initialize(client) ⇒ Orders
Returns a new instance of Orders.
1184 1185 1186 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1184 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).
1288 1289 1290 1291 1292 1293 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1288 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.
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1189 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)), :status => (x = opts.delete(:status); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::OrderStatus) ? x : ::Io::Flow::V0::Models::OrderStatus.apply(x)).value), :submitted_at_on_or_after => (x = opts.delete(:submitted_at_on_or_after); x.nil? ? nil : HttpClient::Preconditions.assert_class('submitted_at_on_or_after', HttpClient::Helper.to_date_time_iso8601(x), DateTime)), :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_allocations_by_number(organization, number) ⇒ Object
Order allocations provide a granular view of an order that is targeted for accounting / financial views of an order
1297 1298 1299 1300 1301 1302 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1297 def get_allocations_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)}/allocations").get ::Io::Flow::V0::Models::AllocationV2.new(r) end |
#get_by_number(organization, number, incoming = {}) ⇒ Object
Returns information about a specific order.
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1255 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(organization, identifier, incoming = {}) ⇒ Object
Returns information about a specific order using an identifier number
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1227 def get_identifier_by_identifier(organization, identifier, incoming={}) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('identifier', identifier, 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)}").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
1361 1362 1363 1364 1365 1366 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1361 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
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1239 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) }), :journal_timestamp_on_or_after => (x = opts.delete(:journal_timestamp_on_or_after); x.nil? ? nil : HttpClient::Preconditions.assert_class('journal_timestamp_on_or_after', HttpClient::Helper.to_date_time_iso8601(x), DateTime)), :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
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1210 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 |
#post_authorizations_by_number(organization, number, authorization_form, incoming = {}) ⇒ Object
Creates an authorization, automatically associating to this order.
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1305 def (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? } (x = ; x.is_a?(::Io::Flow::V0::Models::AuthorizationForm) ? x : ::Io::Flow::V0::Models::AuthorizationForm.from_json(x)) r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}/authorizations").with_query(query).with_json(.to_json).post ::Io::Flow::V0::Models::Authorization.from_json(r) end |
#post_installment_and_plan_and_authorizations_by_number(organization, number, installment_plan_payment_form) ⇒ Object
Creates an installment plan for this order, automatically associating to this order.
1319 1320 1321 1322 1323 1324 1325 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1319 def (organization, number, installment_plan_payment_form) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('number', number, String) (x = installment_plan_payment_form; x.is_a?(::Io::Flow::V0::Models::InstallmentPlanPaymentForm) ? x : ::Io::Flow::V0::Models::InstallmentPlanPaymentForm.new(x)) r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}/installment/plan/authorizations").with_json(installment_plan_payment_form.to_json).post ::Io::Flow::V0::Models::Order.new(r) end |
#post_labels_by_number(organization, number) ⇒ Object
Generate a shipping label given only an order number for the organziation. This will assume all items in the order will be shipped and that there are no updates to the contact or destination address information.
1371 1372 1373 1374 1375 1376 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1371 def post_labels_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)}/labels").post ::Io::Flow::V0::Models::ShippingLabel.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
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1269 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_inventory_and_reservations_by_number(organization, number) ⇒ Object
1327 1328 1329 1330 1331 1332 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1327 def put_inventory_and_reservations_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)}/inventory/reservations").put ::Io::Flow::V0::Models::Reservation.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.
1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1336 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.
1353 1354 1355 1356 1357 1358 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1353 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 |