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.
1180 1181 1182 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1180 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).
1254 1255 1256 1257 1258 1259 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1254 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.
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1185 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_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
1263 1264 1265 1266 1267 1268 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1263 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.
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1221 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
1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1327 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
1354 1355 1356 1357 1358 1359 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1354 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
1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1339 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
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1204 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.
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1271 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.
1285 1286 1287 1288 1289 1290 1291 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1285 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.
1364 1365 1366 1367 1368 1369 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1364 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
1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1235 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
1293 1294 1295 1296 1297 1298 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1293 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.
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1302 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.
1319 1320 1321 1322 1323 1324 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1319 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 |