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.
- #delete_tax_and_registration_by_number_and_key(organization, number, key) ⇒ Object
-
#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
Retrieve the current fraud status for an 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_and_documents_and_invoice_by_number(organization, number) ⇒ Object
Generate a commercial invoice for the order without providing a label.
- #post_service_and_changes_by_number(organization, number, order_service_change_form) ⇒ Object
-
#put_by_number(organization, number, order_put_form, incoming = {}) ⇒ Object
Upserts an order.
-
#put_destination_by_number(organization, number, order_destination_put_form) ⇒ Object
Updates an order's destination address.
- #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, order_submission_form, incoming = {}) ⇒ Object
Submits an order.
-
#put_tax_and_registration_by_number(organization, number, tax_registration_form) ⇒ Object
Validates a tax registration number, proxying to underlying services and recording the result on the order.
Constructor Details
#initialize(client) ⇒ Orders
Returns a new instance of Orders.
1562 1563 1564 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1562 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).
1672 1673 1674 1675 1676 1677 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1672 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 |
#delete_tax_and_registration_by_number_and_key(organization, number, key) ⇒ Object
1776 1777 1778 1779 1780 1781 1782 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1776 def delete_tax_and_registration_by_number_and_key(organization, number, key) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('number', number, String) HttpClient::Preconditions.assert_class('key', key, String) r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}/tax/registration/#{CGI.escape(key)}").delete nil end |
#get(organization, incoming = {}) ⇒ Object
Search orders. Always paginated.
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1567 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), :customer_number => (x = opts.delete(:customer_number); x.nil? ? nil : HttpClient::Preconditions.assert_class('customer_number', x, String)), :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)), :romanize => (x = opts.delete(:romanize); x.nil? ? nil : HttpClient::Preconditions.assert_class('romanize', x, Array).map { |v| HttpClient::Preconditions.assert_class('romanize', 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), :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
1681 1682 1683 1684 1685 1686 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1681 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.
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1637 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) }), :romanize => (x = opts.delete(:romanize); x.nil? ? nil : HttpClient::Preconditions.assert_class('romanize', x, Array).map { |v| HttpClient::Preconditions.assert_class('romanize', 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
1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1608 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) }), :romanize => (x = opts.delete(:romanize); x.nil? ? nil : HttpClient::Preconditions.assert_class('romanize', x, Array).map { |v| HttpClient::Preconditions.assert_class('romanize', 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
Retrieve the current fraud status for an order.
1785 1786 1787 1788 1789 1790 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1785 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
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1621 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
1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1590 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) }), :romanize => (x = opts.delete(:romanize); x.nil? ? nil : HttpClient::Preconditions.assert_class('romanize', x, Array).map { |v| HttpClient::Preconditions.assert_class('romanize', 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.
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1689 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.
1712 1713 1714 1715 1716 1717 1718 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1712 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_and_documents_and_invoice_by_number(organization, number) ⇒ Object
Generate a commercial invoice for the order without providing a label.
1793 1794 1795 1796 1797 1798 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1793 def post_labels_and_documents_and_invoice_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/documents/invoice").post ::Io::Flow::V0::Models::ShippingLabelDocument.new(r) end |
#post_service_and_changes_by_number(organization, number, order_service_change_form) ⇒ Object
1742 1743 1744 1745 1746 1747 1748 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1742 def post_service_and_changes_by_number(organization, number, order_service_change_form) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('number', number, String) (x = order_service_change_form; x.is_a?(::Io::Flow::V0::Models::OrderServiceChangeForm) ? x : ::Io::Flow::V0::Models::OrderServiceChangeForm.new(x)) r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}/service/changes").with_json(order_service_change_form.to_json).post ::Io::Flow::V0::Models::OrderServiceChange.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
1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1652 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) }), :romanize => (x = opts.delete(:romanize); x.nil? ? nil : HttpClient::Preconditions.assert_class('romanize', x, Array).map { |v| HttpClient::Preconditions.assert_class('romanize', 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_destination_by_number(organization, number, order_destination_put_form) ⇒ Object
Updates an order's destination address
1702 1703 1704 1705 1706 1707 1708 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1702 def put_destination_by_number(organization, number, order_destination_put_form) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('number', number, String) (x = order_destination_put_form; x.is_a?(::Io::Flow::V0::Models::OrderDestinationPutForm) ? x : ::Io::Flow::V0::Models::OrderDestinationPutForm.new(x)) r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}/destination").with_json(order_destination_put_form.to_json).put ::Io::Flow::V0::Models::Order.new(r) end |
#put_inventory_and_reservations_by_number(organization, number) ⇒ Object
1720 1721 1722 1723 1724 1725 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1720 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.
1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1729 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, order_submission_form, incoming = {}) ⇒ 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.
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1754 def put_submissions_by_number(organization, number, order_submission_form, 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 = order_submission_form; x.is_a?(::Io::Flow::V0::Models::OrderSubmissionForm) ? x : ::Io::Flow::V0::Models::OrderSubmissionForm.new(x)) r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}/submissions").with_query(query).with_json(order_submission_form.to_json).put ::Io::Flow::V0::Models::Order.new(r) end |
#put_tax_and_registration_by_number(organization, number, tax_registration_form) ⇒ Object
Validates a tax registration number, proxying to underlying services and recording the result on the order.
1768 1769 1770 1771 1772 1773 1774 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1768 def put_tax_and_registration_by_number(organization, number, tax_registration_form) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('number', number, String) (x = tax_registration_form; x.is_a?(::Io::Flow::V0::Models::TaxRegistrationForm) ? x : ::Io::Flow::V0::Models::TaxRegistrationForm.new(x)) r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}/tax/registration").with_json(tax_registration_form.to_json).put ::Io::Flow::V0::Models::TaxRegistration.new(r) end |