diff --git a/lib/shopify/resources/order.ex b/lib/shopify/resources/order.ex index 4130029..c2361d8 100644 --- a/lib/shopify/resources/order.ex +++ b/lib/shopify/resources/order.ex @@ -135,4 +135,83 @@ defmodule Shopify.Order do @doc false def count_url, do: @plural <> "/count.json" + + defp non_rest_url(id, sub_url), do: @plural <> "/#{id}/#{sub_url}.json" + + defp non_rest_post(session, id, sub_url, opts \\ %{}) do + session + |> Request.new(non_rest_url(id, sub_url), opts, empty_resource()) + |> Client.post() + end + + @doc """ + Requests to close an order, see https://help.shopify.com/en/api/reference/orders/order#close. + + Returns `{:ok, %Shopify.Response{}}` or `{:error, %Shopify.Response{}}` + + ## Parameters + - session: A `%Shopify.Session{}` struct. + - id: The id of the resource. + + ## Examples + iex> Shopify.session |> Shopify.Order.close(1) + {:ok, %Shopify.Response{}} + """ + @spec close(%Shopify.Session{}, integer) :: {:ok, %__MODULE__{}} | {:error, map} + def close(session, id) do + session |> non_rest_post(id, "close") + end + + @doc """ + Requests to open an order, see https://help.shopify.com/en/api/reference/orders/order#open. + + Returns `{:ok, %Shopify.Response{}}` or `{:error, %Shopify.Response{}}` + + ## Parameters + - session: A `%Shopify.Session{}` struct. + - id: The id of the resource. + + ## Examples + iex> Shopify.session |> Shopify.Order.open(1) + {:ok, %Shopify.Response{}} + """ + @spec open(%Shopify.Session{}, integer) :: {:ok, %__MODULE__{}} | {:error, map} + def open(session, id) do + session |> non_rest_post(id, "open") + end + + @doc """ + Requests to open an order, see https://help.shopify.com/en/api/reference/orders/order#cancel. + amount + + Returns `{:ok, %Shopify.Response{}}` or `{:error, %Shopify.Response{}}` + + ### Options + * *amount* The amount to refund. If set, Shopify attempts to void or refund the payment, depending on its status. + + * *currency* The currency of the refund that's issued when the order is canceled. Required for multi-currency orders whenever the amount property is provided. + + * *restock* (_deprecated_) Whether to restock refunded items back to your store's inventory. + + * *reason* The reason for the order cancellation. Valid values: customer, inventory, fraud, declined, and other.) + + * *email* Whether to send an email to the customer notifying them of the cancellation. + + * *refund* The refund transactions to perform. Required for some more complex refund situations. For more information, see the Refund API. + + ## Parameters + - session: A `%Shopify.Session{}` struct. + - id: The id of the resource. + + ## Examples + iex> Shopify.session() |> Shopify.Order.cancel(1) + {:ok, %Shopify.Response{}} + + iex> Shopify.session() |> Shopify.Order.cancel(1, %{restock: true, amount: 120, currency: "USD"}) + {:ok, %Shopify.Response{}} + """ + @spec cancel(%Shopify.Session{}, integer) :: {:ok, %__MODULE__{}} | {:error, map} + def cancel(session, id, opts \\ %{}) do + session |> non_rest_post(id, "cancel", opts) + end end diff --git a/test/fixtures/orders/1/cancel.json b/test/fixtures/orders/1/cancel.json new file mode 100644 index 0000000..b9f6297 --- /dev/null +++ b/test/fixtures/orders/1/cancel.json @@ -0,0 +1,487 @@ +{ + "order": { + "id": 450789469, + "email": "bob.norman@hostmail.com", + "closed_at": null, + "created_at": "2008-01-10T11:00:00-05:00", + "updated_at": "2008-01-10T11:00:00-05:00", + "number": 1, + "note": null, + "token": "b1946ac92492d2347c6235b4d2611184", + "gateway": "authorize_net", + "test": false, + "total_price": "409.94", + "subtotal_price": "398.00", + "total_weight": 0, + "total_tax": "11.94", + "taxes_included": false, + "currency": "USD", + "financial_status": "authorized", + "confirmed": false, + "total_discounts": "0.00", + "total_line_items_price": "398.00", + "cart_token": "68778783ad298f1c80c3bafcddeea02f", + "buyer_accepts_marketing": false, + "name": "#1001", + "referring_site": "http:\/\/www.otherexample.com", + "landing_site": "http:\/\/www.example.com?source=abc", + "cancelled_at": null, + "cancel_reason": null, + "total_price_usd": "409.94", + "checkout_token": null, + "reference": "fhwdgads", + "user_id": null, + "location_id": null, + "source_identifier": "fhwdgads", + "source_url": null, + "processed_at": "2008-01-10T11:00:00-05:00", + "device_id": null, + "browser_ip": null, + "landing_site_ref": "abc", + "order_number": 1001, + "discount_codes": [ + { + "code": "TENOFF", + "amount": "10.00", + "type": "percentage" + } + ], + "note_attributes": [ + { + "name": "custom engraving", + "value": "Happy Birthday" + }, + { + "name": "colour", + "value": "green" + } + ], + "payment_gateway_names": [ + "bogus" + ], + "processing_method": "direct", + "checkout_id": 450789469, + "source_name": "web", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "11.94", + "rate": 0.06 + } + ], + "tags": "", + "contact_email": "bob.norman@hostmail.com", + "order_status_url": null, + "line_items": [ + { + "id": 466157049, + "variant_id": 39072856, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008GREEN", + "variant_title": "green", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - green", + "variant_inventory_management": "shopify", + "properties": [ + { + "name": "Custom Engraving Front", + "value": "Happy Birthday" + }, + { + "name": "Custom Engraving Back", + "value": "Merry Christmas" + } + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + }, + { + "id": 518995019, + "variant_id": 49148385, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008RED", + "variant_title": "red", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - red", + "variant_inventory_management": "shopify", + "properties": [ + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + }, + { + "id": 703073504, + "variant_id": 457924702, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008BLACK", + "variant_title": "black", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - black", + "variant_inventory_management": "shopify", + "properties": [ + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + } + ], + "shipping_lines": [ + { + "id": 369256396, + "title": "Free Shipping", + "price": "0.00", + "code": "Free Shipping", + "source": "shopify", + "phone": null, + "requested_fulfillment_service_id": null, + "delivery_category": null, + "carrier_identifier": null, + "tax_lines": [ + ] + } + ], + "billing_address": { + "first_name": "Bob", + "address1": "Chestnut Street 92", + "phone": "555-625-1199", + "city": "Louisville", + "zip": "40202", + "province": "Kentucky", + "country": "United States", + "last_name": "Norman", + "address2": "", + "company": null, + "latitude": 45.41634, + "longitude": -75.6868, + "name": "Bob Norman", + "country_code": "US", + "province_code": "KY" + }, + "shipping_address": { + "first_name": "Bob", + "address1": "Chestnut Street 92", + "phone": "555-625-1199", + "city": "Louisville", + "zip": "40202", + "province": "Kentucky", + "country": "United States", + "last_name": "Norman", + "address2": "", + "company": null, + "latitude": 45.41634, + "longitude": -75.6868, + "name": "Bob Norman", + "country_code": "US", + "province_code": "KY" + }, + "fulfillments": [ + { + "id": 255858046, + "order_id": 450789469, + "status": "failure", + "created_at": "2017-01-09T15:09:12-05:00", + "service": "manual", + "updated_at": "2017-01-09T15:09:12-05:00", + "tracking_company": null, + "shipment_status": null, + "tracking_number": "1Z2345", + "tracking_numbers": [ + "1Z2345" + ], + "tracking_url": "http:\/\/wwwapps.ups.com\/etracking\/tracking.cgi?InquiryNumber1=1Z2345&TypeOfInquiryNumber=T&AcceptUPSLicenseAgreement=yes&submit=Track", + "tracking_urls": [ + "http:\/\/wwwapps.ups.com\/etracking\/tracking.cgi?InquiryNumber1=1Z2345&TypeOfInquiryNumber=T&AcceptUPSLicenseAgreement=yes&submit=Track" + ], + "receipt": { + "testcase": true, + "authorization": "123456" + }, + "line_items": [ + { + "id": 466157049, + "variant_id": 39072856, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008GREEN", + "variant_title": "green", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - green", + "variant_inventory_management": "shopify", + "properties": [ + { + "name": "Custom Engraving Front", + "value": "Happy Birthday" + }, + { + "name": "Custom Engraving Back", + "value": "Merry Christmas" + } + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + } + ] + } + ], + "client_details": { + "browser_ip": "0.0.0.0", + "accept_language": null, + "user_agent": null, + "session_hash": null, + "browser_width": null, + "browser_height": null + }, + "refunds": [ + { + "id": 509562969, + "order_id": 450789469, + "created_at": "2017-01-09T15:09:12-05:00", + "note": "it broke during shipping", + "restock": true, + "user_id": 799407056, + "processed_at": "2017-01-09T15:09:12-05:00", + "refund_line_items": [ + { + "id": 104689539, + "quantity": 1, + "line_item_id": 703073504, + "subtotal": 195.67, + "total_tax": 3.98, + "line_item": { + "id": 703073504, + "variant_id": 457924702, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008BLACK", + "variant_title": "black", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - black", + "variant_inventory_management": "shopify", + "properties": [ + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + } + }, + { + "id": 709875399, + "quantity": 1, + "line_item_id": 466157049, + "subtotal": 195.66, + "total_tax": 3.98, + "line_item": { + "id": 466157049, + "variant_id": 39072856, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008GREEN", + "variant_title": "green", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - green", + "variant_inventory_management": "shopify", + "properties": [ + { + "name": "Custom Engraving Front", + "value": "Happy Birthday" + }, + { + "name": "Custom Engraving Back", + "value": "Merry Christmas" + } + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + } + } + ], + "transactions": [ + { + "id": 179259969, + "order_id": 450789469, + "amount": "209.00", + "kind": "refund", + "gateway": "bogus", + "status": "success", + "message": null, + "created_at": "2005-08-05T12:59:12-04:00", + "test": false, + "authorization": "authorization-key", + "currency": "USD", + "location_id": null, + "user_id": null, + "parent_id": null, + "device_id": null, + "receipt": {}, + "error_code": null, + "source_name": "web" + } + ], + "order_adjustments": [ + ] + } + ], + "payment_details": { + "credit_card_bin": null, + "avs_result_code": null, + "cvv_result_code": null, + "credit_card_number": "•••• •••• •••• 4242", + "credit_card_company": "Visa" + }, + "customer": { + "id": 207119551, + "email": "bob.norman@hostmail.com", + "accepts_marketing": false, + "created_at": "2017-01-09T15:09:12-05:00", + "updated_at": "2017-01-09T15:09:12-05:00", + "first_name": "Bob", + "last_name": "Norman", + "orders_count": 1, + "state": "disabled", + "total_spent": "41.94", + "last_order_id": 450789469, + "note": null, + "verified_email": true, + "multipass_identifier": null, + "tax_exempt": false, + "tags": "", + "last_order_name": "#1001", + "default_address": { + "id": 207119551, + "first_name": null, + "last_name": null, + "company": null, + "address1": "Chestnut Street 92", + "address2": "", + "city": "Louisville", + "province": "Kentucky", + "country": "United States", + "zip": "40202", + "phone": "555-625-1199", + "name": "", + "province_code": "KY", + "country_code": "US", + "country_name": "United States", + "default": true + }, + "addresses": [ + { + "id": 1053317305, + "first_name": "Mother", + "last_name": "Lastnameson", + "company": null, + "address1": "123 Oak St", + "address2": null, + "city": "Ottawa", + "province": "Ontario", + "country": "Canada", + "zip": "123 ABC", + "phone": "555-1212", + "name": "Mother Lastnameson", + "province_code": "ON", + "country_code": "CA", + "country_name": "Canada", + "default": true + } + ] + } + } +} diff --git a/test/fixtures/orders/1/close.json b/test/fixtures/orders/1/close.json new file mode 100644 index 0000000..b9f6297 --- /dev/null +++ b/test/fixtures/orders/1/close.json @@ -0,0 +1,487 @@ +{ + "order": { + "id": 450789469, + "email": "bob.norman@hostmail.com", + "closed_at": null, + "created_at": "2008-01-10T11:00:00-05:00", + "updated_at": "2008-01-10T11:00:00-05:00", + "number": 1, + "note": null, + "token": "b1946ac92492d2347c6235b4d2611184", + "gateway": "authorize_net", + "test": false, + "total_price": "409.94", + "subtotal_price": "398.00", + "total_weight": 0, + "total_tax": "11.94", + "taxes_included": false, + "currency": "USD", + "financial_status": "authorized", + "confirmed": false, + "total_discounts": "0.00", + "total_line_items_price": "398.00", + "cart_token": "68778783ad298f1c80c3bafcddeea02f", + "buyer_accepts_marketing": false, + "name": "#1001", + "referring_site": "http:\/\/www.otherexample.com", + "landing_site": "http:\/\/www.example.com?source=abc", + "cancelled_at": null, + "cancel_reason": null, + "total_price_usd": "409.94", + "checkout_token": null, + "reference": "fhwdgads", + "user_id": null, + "location_id": null, + "source_identifier": "fhwdgads", + "source_url": null, + "processed_at": "2008-01-10T11:00:00-05:00", + "device_id": null, + "browser_ip": null, + "landing_site_ref": "abc", + "order_number": 1001, + "discount_codes": [ + { + "code": "TENOFF", + "amount": "10.00", + "type": "percentage" + } + ], + "note_attributes": [ + { + "name": "custom engraving", + "value": "Happy Birthday" + }, + { + "name": "colour", + "value": "green" + } + ], + "payment_gateway_names": [ + "bogus" + ], + "processing_method": "direct", + "checkout_id": 450789469, + "source_name": "web", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "11.94", + "rate": 0.06 + } + ], + "tags": "", + "contact_email": "bob.norman@hostmail.com", + "order_status_url": null, + "line_items": [ + { + "id": 466157049, + "variant_id": 39072856, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008GREEN", + "variant_title": "green", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - green", + "variant_inventory_management": "shopify", + "properties": [ + { + "name": "Custom Engraving Front", + "value": "Happy Birthday" + }, + { + "name": "Custom Engraving Back", + "value": "Merry Christmas" + } + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + }, + { + "id": 518995019, + "variant_id": 49148385, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008RED", + "variant_title": "red", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - red", + "variant_inventory_management": "shopify", + "properties": [ + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + }, + { + "id": 703073504, + "variant_id": 457924702, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008BLACK", + "variant_title": "black", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - black", + "variant_inventory_management": "shopify", + "properties": [ + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + } + ], + "shipping_lines": [ + { + "id": 369256396, + "title": "Free Shipping", + "price": "0.00", + "code": "Free Shipping", + "source": "shopify", + "phone": null, + "requested_fulfillment_service_id": null, + "delivery_category": null, + "carrier_identifier": null, + "tax_lines": [ + ] + } + ], + "billing_address": { + "first_name": "Bob", + "address1": "Chestnut Street 92", + "phone": "555-625-1199", + "city": "Louisville", + "zip": "40202", + "province": "Kentucky", + "country": "United States", + "last_name": "Norman", + "address2": "", + "company": null, + "latitude": 45.41634, + "longitude": -75.6868, + "name": "Bob Norman", + "country_code": "US", + "province_code": "KY" + }, + "shipping_address": { + "first_name": "Bob", + "address1": "Chestnut Street 92", + "phone": "555-625-1199", + "city": "Louisville", + "zip": "40202", + "province": "Kentucky", + "country": "United States", + "last_name": "Norman", + "address2": "", + "company": null, + "latitude": 45.41634, + "longitude": -75.6868, + "name": "Bob Norman", + "country_code": "US", + "province_code": "KY" + }, + "fulfillments": [ + { + "id": 255858046, + "order_id": 450789469, + "status": "failure", + "created_at": "2017-01-09T15:09:12-05:00", + "service": "manual", + "updated_at": "2017-01-09T15:09:12-05:00", + "tracking_company": null, + "shipment_status": null, + "tracking_number": "1Z2345", + "tracking_numbers": [ + "1Z2345" + ], + "tracking_url": "http:\/\/wwwapps.ups.com\/etracking\/tracking.cgi?InquiryNumber1=1Z2345&TypeOfInquiryNumber=T&AcceptUPSLicenseAgreement=yes&submit=Track", + "tracking_urls": [ + "http:\/\/wwwapps.ups.com\/etracking\/tracking.cgi?InquiryNumber1=1Z2345&TypeOfInquiryNumber=T&AcceptUPSLicenseAgreement=yes&submit=Track" + ], + "receipt": { + "testcase": true, + "authorization": "123456" + }, + "line_items": [ + { + "id": 466157049, + "variant_id": 39072856, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008GREEN", + "variant_title": "green", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - green", + "variant_inventory_management": "shopify", + "properties": [ + { + "name": "Custom Engraving Front", + "value": "Happy Birthday" + }, + { + "name": "Custom Engraving Back", + "value": "Merry Christmas" + } + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + } + ] + } + ], + "client_details": { + "browser_ip": "0.0.0.0", + "accept_language": null, + "user_agent": null, + "session_hash": null, + "browser_width": null, + "browser_height": null + }, + "refunds": [ + { + "id": 509562969, + "order_id": 450789469, + "created_at": "2017-01-09T15:09:12-05:00", + "note": "it broke during shipping", + "restock": true, + "user_id": 799407056, + "processed_at": "2017-01-09T15:09:12-05:00", + "refund_line_items": [ + { + "id": 104689539, + "quantity": 1, + "line_item_id": 703073504, + "subtotal": 195.67, + "total_tax": 3.98, + "line_item": { + "id": 703073504, + "variant_id": 457924702, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008BLACK", + "variant_title": "black", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - black", + "variant_inventory_management": "shopify", + "properties": [ + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + } + }, + { + "id": 709875399, + "quantity": 1, + "line_item_id": 466157049, + "subtotal": 195.66, + "total_tax": 3.98, + "line_item": { + "id": 466157049, + "variant_id": 39072856, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008GREEN", + "variant_title": "green", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - green", + "variant_inventory_management": "shopify", + "properties": [ + { + "name": "Custom Engraving Front", + "value": "Happy Birthday" + }, + { + "name": "Custom Engraving Back", + "value": "Merry Christmas" + } + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + } + } + ], + "transactions": [ + { + "id": 179259969, + "order_id": 450789469, + "amount": "209.00", + "kind": "refund", + "gateway": "bogus", + "status": "success", + "message": null, + "created_at": "2005-08-05T12:59:12-04:00", + "test": false, + "authorization": "authorization-key", + "currency": "USD", + "location_id": null, + "user_id": null, + "parent_id": null, + "device_id": null, + "receipt": {}, + "error_code": null, + "source_name": "web" + } + ], + "order_adjustments": [ + ] + } + ], + "payment_details": { + "credit_card_bin": null, + "avs_result_code": null, + "cvv_result_code": null, + "credit_card_number": "•••• •••• •••• 4242", + "credit_card_company": "Visa" + }, + "customer": { + "id": 207119551, + "email": "bob.norman@hostmail.com", + "accepts_marketing": false, + "created_at": "2017-01-09T15:09:12-05:00", + "updated_at": "2017-01-09T15:09:12-05:00", + "first_name": "Bob", + "last_name": "Norman", + "orders_count": 1, + "state": "disabled", + "total_spent": "41.94", + "last_order_id": 450789469, + "note": null, + "verified_email": true, + "multipass_identifier": null, + "tax_exempt": false, + "tags": "", + "last_order_name": "#1001", + "default_address": { + "id": 207119551, + "first_name": null, + "last_name": null, + "company": null, + "address1": "Chestnut Street 92", + "address2": "", + "city": "Louisville", + "province": "Kentucky", + "country": "United States", + "zip": "40202", + "phone": "555-625-1199", + "name": "", + "province_code": "KY", + "country_code": "US", + "country_name": "United States", + "default": true + }, + "addresses": [ + { + "id": 1053317305, + "first_name": "Mother", + "last_name": "Lastnameson", + "company": null, + "address1": "123 Oak St", + "address2": null, + "city": "Ottawa", + "province": "Ontario", + "country": "Canada", + "zip": "123 ABC", + "phone": "555-1212", + "name": "Mother Lastnameson", + "province_code": "ON", + "country_code": "CA", + "country_name": "Canada", + "default": true + } + ] + } + } +} diff --git a/test/fixtures/orders/1/open.json b/test/fixtures/orders/1/open.json new file mode 100644 index 0000000..b9f6297 --- /dev/null +++ b/test/fixtures/orders/1/open.json @@ -0,0 +1,487 @@ +{ + "order": { + "id": 450789469, + "email": "bob.norman@hostmail.com", + "closed_at": null, + "created_at": "2008-01-10T11:00:00-05:00", + "updated_at": "2008-01-10T11:00:00-05:00", + "number": 1, + "note": null, + "token": "b1946ac92492d2347c6235b4d2611184", + "gateway": "authorize_net", + "test": false, + "total_price": "409.94", + "subtotal_price": "398.00", + "total_weight": 0, + "total_tax": "11.94", + "taxes_included": false, + "currency": "USD", + "financial_status": "authorized", + "confirmed": false, + "total_discounts": "0.00", + "total_line_items_price": "398.00", + "cart_token": "68778783ad298f1c80c3bafcddeea02f", + "buyer_accepts_marketing": false, + "name": "#1001", + "referring_site": "http:\/\/www.otherexample.com", + "landing_site": "http:\/\/www.example.com?source=abc", + "cancelled_at": null, + "cancel_reason": null, + "total_price_usd": "409.94", + "checkout_token": null, + "reference": "fhwdgads", + "user_id": null, + "location_id": null, + "source_identifier": "fhwdgads", + "source_url": null, + "processed_at": "2008-01-10T11:00:00-05:00", + "device_id": null, + "browser_ip": null, + "landing_site_ref": "abc", + "order_number": 1001, + "discount_codes": [ + { + "code": "TENOFF", + "amount": "10.00", + "type": "percentage" + } + ], + "note_attributes": [ + { + "name": "custom engraving", + "value": "Happy Birthday" + }, + { + "name": "colour", + "value": "green" + } + ], + "payment_gateway_names": [ + "bogus" + ], + "processing_method": "direct", + "checkout_id": 450789469, + "source_name": "web", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "11.94", + "rate": 0.06 + } + ], + "tags": "", + "contact_email": "bob.norman@hostmail.com", + "order_status_url": null, + "line_items": [ + { + "id": 466157049, + "variant_id": 39072856, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008GREEN", + "variant_title": "green", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - green", + "variant_inventory_management": "shopify", + "properties": [ + { + "name": "Custom Engraving Front", + "value": "Happy Birthday" + }, + { + "name": "Custom Engraving Back", + "value": "Merry Christmas" + } + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + }, + { + "id": 518995019, + "variant_id": 49148385, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008RED", + "variant_title": "red", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - red", + "variant_inventory_management": "shopify", + "properties": [ + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + }, + { + "id": 703073504, + "variant_id": 457924702, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008BLACK", + "variant_title": "black", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - black", + "variant_inventory_management": "shopify", + "properties": [ + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + } + ], + "shipping_lines": [ + { + "id": 369256396, + "title": "Free Shipping", + "price": "0.00", + "code": "Free Shipping", + "source": "shopify", + "phone": null, + "requested_fulfillment_service_id": null, + "delivery_category": null, + "carrier_identifier": null, + "tax_lines": [ + ] + } + ], + "billing_address": { + "first_name": "Bob", + "address1": "Chestnut Street 92", + "phone": "555-625-1199", + "city": "Louisville", + "zip": "40202", + "province": "Kentucky", + "country": "United States", + "last_name": "Norman", + "address2": "", + "company": null, + "latitude": 45.41634, + "longitude": -75.6868, + "name": "Bob Norman", + "country_code": "US", + "province_code": "KY" + }, + "shipping_address": { + "first_name": "Bob", + "address1": "Chestnut Street 92", + "phone": "555-625-1199", + "city": "Louisville", + "zip": "40202", + "province": "Kentucky", + "country": "United States", + "last_name": "Norman", + "address2": "", + "company": null, + "latitude": 45.41634, + "longitude": -75.6868, + "name": "Bob Norman", + "country_code": "US", + "province_code": "KY" + }, + "fulfillments": [ + { + "id": 255858046, + "order_id": 450789469, + "status": "failure", + "created_at": "2017-01-09T15:09:12-05:00", + "service": "manual", + "updated_at": "2017-01-09T15:09:12-05:00", + "tracking_company": null, + "shipment_status": null, + "tracking_number": "1Z2345", + "tracking_numbers": [ + "1Z2345" + ], + "tracking_url": "http:\/\/wwwapps.ups.com\/etracking\/tracking.cgi?InquiryNumber1=1Z2345&TypeOfInquiryNumber=T&AcceptUPSLicenseAgreement=yes&submit=Track", + "tracking_urls": [ + "http:\/\/wwwapps.ups.com\/etracking\/tracking.cgi?InquiryNumber1=1Z2345&TypeOfInquiryNumber=T&AcceptUPSLicenseAgreement=yes&submit=Track" + ], + "receipt": { + "testcase": true, + "authorization": "123456" + }, + "line_items": [ + { + "id": 466157049, + "variant_id": 39072856, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008GREEN", + "variant_title": "green", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - green", + "variant_inventory_management": "shopify", + "properties": [ + { + "name": "Custom Engraving Front", + "value": "Happy Birthday" + }, + { + "name": "Custom Engraving Back", + "value": "Merry Christmas" + } + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + } + ] + } + ], + "client_details": { + "browser_ip": "0.0.0.0", + "accept_language": null, + "user_agent": null, + "session_hash": null, + "browser_width": null, + "browser_height": null + }, + "refunds": [ + { + "id": 509562969, + "order_id": 450789469, + "created_at": "2017-01-09T15:09:12-05:00", + "note": "it broke during shipping", + "restock": true, + "user_id": 799407056, + "processed_at": "2017-01-09T15:09:12-05:00", + "refund_line_items": [ + { + "id": 104689539, + "quantity": 1, + "line_item_id": 703073504, + "subtotal": 195.67, + "total_tax": 3.98, + "line_item": { + "id": 703073504, + "variant_id": 457924702, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008BLACK", + "variant_title": "black", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - black", + "variant_inventory_management": "shopify", + "properties": [ + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + } + }, + { + "id": 709875399, + "quantity": 1, + "line_item_id": 466157049, + "subtotal": 195.66, + "total_tax": 3.98, + "line_item": { + "id": 466157049, + "variant_id": 39072856, + "title": "IPod Nano - 8gb", + "quantity": 1, + "price": "199.00", + "grams": 200, + "sku": "IPOD2008GREEN", + "variant_title": "green", + "vendor": null, + "fulfillment_service": "manual", + "product_id": 632910392, + "requires_shipping": true, + "taxable": true, + "gift_card": false, + "name": "IPod Nano - 8gb - green", + "variant_inventory_management": "shopify", + "properties": [ + { + "name": "Custom Engraving Front", + "value": "Happy Birthday" + }, + { + "name": "Custom Engraving Back", + "value": "Merry Christmas" + } + ], + "product_exists": true, + "fulfillable_quantity": 1, + "total_discount": "0.00", + "fulfillment_status": null, + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06 + } + ] + } + } + ], + "transactions": [ + { + "id": 179259969, + "order_id": 450789469, + "amount": "209.00", + "kind": "refund", + "gateway": "bogus", + "status": "success", + "message": null, + "created_at": "2005-08-05T12:59:12-04:00", + "test": false, + "authorization": "authorization-key", + "currency": "USD", + "location_id": null, + "user_id": null, + "parent_id": null, + "device_id": null, + "receipt": {}, + "error_code": null, + "source_name": "web" + } + ], + "order_adjustments": [ + ] + } + ], + "payment_details": { + "credit_card_bin": null, + "avs_result_code": null, + "cvv_result_code": null, + "credit_card_number": "•••• •••• •••• 4242", + "credit_card_company": "Visa" + }, + "customer": { + "id": 207119551, + "email": "bob.norman@hostmail.com", + "accepts_marketing": false, + "created_at": "2017-01-09T15:09:12-05:00", + "updated_at": "2017-01-09T15:09:12-05:00", + "first_name": "Bob", + "last_name": "Norman", + "orders_count": 1, + "state": "disabled", + "total_spent": "41.94", + "last_order_id": 450789469, + "note": null, + "verified_email": true, + "multipass_identifier": null, + "tax_exempt": false, + "tags": "", + "last_order_name": "#1001", + "default_address": { + "id": 207119551, + "first_name": null, + "last_name": null, + "company": null, + "address1": "Chestnut Street 92", + "address2": "", + "city": "Louisville", + "province": "Kentucky", + "country": "United States", + "zip": "40202", + "phone": "555-625-1199", + "name": "", + "province_code": "KY", + "country_code": "US", + "country_name": "United States", + "default": true + }, + "addresses": [ + { + "id": 1053317305, + "first_name": "Mother", + "last_name": "Lastnameson", + "company": null, + "address1": "123 Oak St", + "address2": null, + "city": "Ottawa", + "province": "Ontario", + "country": "Canada", + "zip": "123 ABC", + "phone": "555-1212", + "name": "Mother Lastnameson", + "province_code": "ON", + "country_code": "CA", + "country_name": "Canada", + "default": true + } + ] + } + } +} diff --git a/test/order_test.exs b/test/order_test.exs index 0083258..763a80d 100644 --- a/test/order_test.exs +++ b/test/order_test.exs @@ -50,4 +50,22 @@ defmodule Shopify.OrderTest do assert 200 == response.code assert nil == response.data end + + test "client can request to close an order" do + assert {:ok, response} = Shopify.session() |> Order.close(1) + assert %Shopify.Response{} = response + assert 200 == response.code + end + + test "client can request to open an order" do + assert {:ok, response} = Shopify.session() |> Order.open(1) + assert %Shopify.Response{} = response + assert 200 == response.code + end + + test "client can request to cancel an order" do + assert {:ok, response} = Shopify.session() |> Order.open(1) + assert %Shopify.Response{} = response + assert 200 == response.code + end end