From 91a8fd8f69d446ebcfdd4a1cefd80e3f5c2979e8 Mon Sep 17 00:00:00 2001 From: Paulina Khew Date: Tue, 23 Feb 2021 17:07:40 -0500 Subject: [PATCH 1/4] Add method for getting order using customer_id with tests --- shopify/resources/order.py | 9 + test/fixtures/orders.json | 935 +++++++++++++++++++++++++++++++++++++ test/order_test.py | 7 + 3 files changed, 951 insertions(+) create mode 100644 test/fixtures/orders.json diff --git a/shopify/resources/order.py b/shopify/resources/order.py index 4e780b0a..2e31a8c3 100644 --- a/shopify/resources/order.py +++ b/shopify/resources/order.py @@ -4,6 +4,15 @@ class Order(ShopifyResource, mixins.Metafields, mixins.Events): + _prefix_source = "/customers/$customer_id/" + + @classmethod + def _prefix(cls, options={}): + customer_id = options.get("customer_id") + if customer_id: + return "%s/customers/%s" % (cls.site, customer_id) + else: + return cls.site def close(self): self._load_attributes_from_response(self.post("close")) diff --git a/test/fixtures/orders.json b/test/fixtures/orders.json new file mode 100644 index 00000000..58ebd2d1 --- /dev/null +++ b/test/fixtures/orders.json @@ -0,0 +1,935 @@ +{ + "orders": [ + { + "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": "598.94", + "subtotal_price": "597.00", + "total_weight": 0, + "total_tax": "11.94", + "taxes_included": false, + "currency": "USD", + "financial_status": "partially_refunded", + "confirmed": true, + "total_discounts": "10.00", + "total_line_items_price": "597.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": "598.94", + "checkout_token": "bd5a8aa1ecd019dd3520ff791ee3a24c", + "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, + "phone": "+557734881234", + "customer_locale": null, + "app_id": null, + "browser_ip": "0.0.0.0", + "client_details": { + "accept_language": null, + "browser_height": null, + "browser_ip": "0.0.0.0", + "browser_width": null, + "session_hash": null, + "user_agent": null + }, + "landing_site_ref": "abc", + "order_number": 1001, + "discount_applications": [ + { + "type": "discount_code", + "value": "10.0", + "value_type": "fixed_amount", + "allocation_method": "across", + "target_selection": "all", + "target_type": "line_item", + "code": "TENOFF" + } + ], + "discount_codes": [ + { + "code": "TENOFF", + "amount": "10.00", + "type": "fixed_amount" + } + ], + "note_attributes": [ + { + "name": "custom engraving", + "value": "Happy Birthday" + }, + { + "name": "colour", + "value": "green" + } + ], + "payment_details": { + "credit_card_bin": null, + "avs_result_code": null, + "cvv_result_code": null, + "credit_card_number": "•••• •••• •••• 4242", + "credit_card_company": "Visa", + "credit_card_name": null, + "credit_card_wallet": null, + "credit_card_expiration_month": null, + "credit_card_expiration_year": null + }, + "payment_gateway_names": [ + "bogus" + ], + "processing_method": "direct", + "checkout_id": 901414060, + "source_name": "web", + "fulfillment_status": null, + "tax_lines": [ + { + "price": "11.94", + "rate": 0.06, + "title": "State Tax", + "price_set": { + "shop_money": { + "amount": "11.94", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "11.94", + "currency_code": "USD" + } + } + } + ], + "tags": "", + "contact_email": "bob.norman@hostmail.com", + "order_status_url": "https://apple.myshopify.com/690933842/orders/b1946ac92492d2347c6235b4d2611184/authenticate?key=ccde591a93123786bd8d257abd970200", + "presentment_currency": "USD", + "total_line_items_price_set": { + "shop_money": { + "amount": "597.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "597.00", + "currency_code": "USD" + } + }, + "total_discounts_set": { + "shop_money": { + "amount": "10.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "10.00", + "currency_code": "USD" + } + }, + "total_shipping_price_set": { + "shop_money": { + "amount": "0.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "0.00", + "currency_code": "USD" + } + }, + "subtotal_price_set": { + "shop_money": { + "amount": "597.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "597.00", + "currency_code": "USD" + } + }, + "total_price_set": { + "shop_money": { + "amount": "598.94", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "598.94", + "currency_code": "USD" + } + }, + "total_tax_set": { + "shop_money": { + "amount": "11.94", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "11.94", + "currency_code": "USD" + } + }, + "line_items": [ + { + "id": 466157049, + "variant_id": 39072856, + "title": "IPod Nano - 8gb", + "quantity": 1, + "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, + "grams": 200, + "price": "199.00", + "total_discount": "0.00", + "fulfillment_status": null, + "price_set": { + "shop_money": { + "amount": "199.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "199.00", + "currency_code": "USD" + } + }, + "total_discount_set": { + "shop_money": { + "amount": "0.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "0.00", + "currency_code": "USD" + } + }, + "discount_allocations": [ + { + "amount": "3.34", + "discount_application_index": 0, + "amount_set": { + "shop_money": { + "amount": "3.34", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "3.34", + "currency_code": "USD" + } + } + } + ], + "duties": [], + "admin_graphql_api_id": "gid://shopify/LineItem/466157049", + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06, + "price_set": { + "shop_money": { + "amount": "3.98", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "3.98", + "currency_code": "USD" + } + } + } + ] + }, + { + "id": 518995019, + "variant_id": 49148385, + "title": "IPod Nano - 8gb", + "quantity": 1, + "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, + "grams": 200, + "price": "199.00", + "total_discount": "0.00", + "fulfillment_status": null, + "price_set": { + "shop_money": { + "amount": "199.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "199.00", + "currency_code": "USD" + } + }, + "total_discount_set": { + "shop_money": { + "amount": "0.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "0.00", + "currency_code": "USD" + } + }, + "discount_allocations": [ + { + "amount": "3.33", + "discount_application_index": 0, + "amount_set": { + "shop_money": { + "amount": "3.33", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "3.33", + "currency_code": "USD" + } + } + } + ], + "duties": [], + "admin_graphql_api_id": "gid://shopify/LineItem/518995019", + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06, + "price_set": { + "shop_money": { + "amount": "3.98", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "3.98", + "currency_code": "USD" + } + } + } + ] + }, + { + "id": 703073504, + "variant_id": 457924702, + "title": "IPod Nano - 8gb", + "quantity": 1, + "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, + "grams": 200, + "price": "199.00", + "total_discount": "0.00", + "fulfillment_status": null, + "price_set": { + "shop_money": { + "amount": "199.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "199.00", + "currency_code": "USD" + } + }, + "total_discount_set": { + "shop_money": { + "amount": "0.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "0.00", + "currency_code": "USD" + } + }, + "discount_allocations": [ + { + "amount": "3.33", + "discount_application_index": 0, + "amount_set": { + "shop_money": { + "amount": "3.33", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "3.33", + "currency_code": "USD" + } + } + } + ], + "duties": [], + "admin_graphql_api_id": "gid://shopify/LineItem/703073504", + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06, + "price_set": { + "shop_money": { + "amount": "3.98", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "3.98", + "currency_code": "USD" + } + } + } + ] + } + ], + "fulfillments": [ + { + "id": 255858046, + "order_id": 450789469, + "status": "failure", + "created_at": "2021-02-12T13:51:00-05:00", + "service": "manual", + "updated_at": "2021-02-12T13:51:00-05:00", + "tracking_company": "USPS", + "shipment_status": null, + "location_id": 905684977, + "line_items": [ + { + "id": 466157049, + "variant_id": 39072856, + "title": "IPod Nano - 8gb", + "quantity": 1, + "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, + "grams": 200, + "price": "199.00", + "total_discount": "0.00", + "fulfillment_status": null, + "price_set": { + "shop_money": { + "amount": "199.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "199.00", + "currency_code": "USD" + } + }, + "total_discount_set": { + "shop_money": { + "amount": "0.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "0.00", + "currency_code": "USD" + } + }, + "discount_allocations": [ + { + "amount": "3.34", + "discount_application_index": 0, + "amount_set": { + "shop_money": { + "amount": "3.34", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "3.34", + "currency_code": "USD" + } + } + } + ], + "duties": [], + "admin_graphql_api_id": "gid://shopify/LineItem/466157049", + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06, + "price_set": { + "shop_money": { + "amount": "3.98", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "3.98", + "currency_code": "USD" + } + } + } + ] + } + ], + "tracking_number": "1Z2345", + "tracking_numbers": [ + "1Z2345" + ], + "tracking_url": "https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=1Z2345", + "tracking_urls": [ + "https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=1Z2345" + ], + "receipt": { + "testcase": true, + "authorization": "123456" + }, + "name": "#1001.0", + "admin_graphql_api_id": "gid://shopify/Fulfillment/255858046" + } + ], + "refunds": [ + { + "id": 509562969, + "order_id": 450789469, + "created_at": "2021-02-12T13:51:00-05:00", + "note": "it broke during shipping", + "user_id": 799407056, + "processed_at": "2021-02-12T13:51:00-05:00", + "restock": true, + "duties": [], + "total_duties_set": { + "shop_money": { + "amount": "0.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "0.00", + "currency_code": "USD" + } + }, + "admin_graphql_api_id": "gid://shopify/Refund/509562969", + "refund_line_items": [ + { + "id": 104689539, + "quantity": 1, + "line_item_id": 703073504, + "location_id": 487838322, + "restock_type": "legacy_restock", + "subtotal": 195.67, + "total_tax": 3.98, + "subtotal_set": { + "shop_money": { + "amount": "195.67", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "195.67", + "currency_code": "USD" + } + }, + "total_tax_set": { + "shop_money": { + "amount": "3.98", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "3.98", + "currency_code": "USD" + } + }, + "line_item": { + "id": 703073504, + "variant_id": 457924702, + "title": "IPod Nano - 8gb", + "quantity": 1, + "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, + "grams": 200, + "price": "199.00", + "total_discount": "0.00", + "fulfillment_status": null, + "price_set": { + "shop_money": { + "amount": "199.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "199.00", + "currency_code": "USD" + } + }, + "total_discount_set": { + "shop_money": { + "amount": "0.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "0.00", + "currency_code": "USD" + } + }, + "discount_allocations": [ + { + "amount": "3.33", + "discount_application_index": 0, + "amount_set": { + "shop_money": { + "amount": "3.33", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "3.33", + "currency_code": "USD" + } + } + } + ], + "duties": [], + "admin_graphql_api_id": "gid://shopify/LineItem/703073504", + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06, + "price_set": { + "shop_money": { + "amount": "3.98", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "3.98", + "currency_code": "USD" + } + } + } + ] + } + }, + { + "id": 709875399, + "quantity": 1, + "line_item_id": 466157049, + "location_id": 487838322, + "restock_type": "legacy_restock", + "subtotal": 195.66, + "total_tax": 3.98, + "subtotal_set": { + "shop_money": { + "amount": "195.66", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "195.66", + "currency_code": "USD" + } + }, + "total_tax_set": { + "shop_money": { + "amount": "3.98", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "3.98", + "currency_code": "USD" + } + }, + "line_item": { + "id": 466157049, + "variant_id": 39072856, + "title": "IPod Nano - 8gb", + "quantity": 1, + "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, + "grams": 200, + "price": "199.00", + "total_discount": "0.00", + "fulfillment_status": null, + "price_set": { + "shop_money": { + "amount": "199.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "199.00", + "currency_code": "USD" + } + }, + "total_discount_set": { + "shop_money": { + "amount": "0.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "0.00", + "currency_code": "USD" + } + }, + "discount_allocations": [ + { + "amount": "3.34", + "discount_application_index": 0, + "amount_set": { + "shop_money": { + "amount": "3.34", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "3.34", + "currency_code": "USD" + } + } + } + ], + "duties": [], + "admin_graphql_api_id": "gid://shopify/LineItem/466157049", + "tax_lines": [ + { + "title": "State Tax", + "price": "3.98", + "rate": 0.06, + "price_set": { + "shop_money": { + "amount": "3.98", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "3.98", + "currency_code": "USD" + } + } + } + ] + } + } + ], + "transactions": [ + { + "id": 179259969, + "order_id": 450789469, + "kind": "refund", + "gateway": "bogus", + "status": "success", + "message": null, + "created_at": "2005-08-05T12:59:12-04:00", + "test": false, + "authorization": "authorization-key", + "location_id": null, + "user_id": null, + "parent_id": 801038806, + "processed_at": "2005-08-05T12:59:12-04:00", + "device_id": null, + "error_code": null, + "source_name": "web", + "receipt": {}, + "amount": "209.00", + "currency": "USD", + "admin_graphql_api_id": "gid://shopify/OrderTransaction/179259969" + } + ], + "order_adjustments": [] + } + ], + "total_tip_received": "0.0", + "original_total_duties_set": null, + "current_total_duties_set": null, + "admin_graphql_api_id": "gid://shopify/Order/450789469", + "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, + "discounted_price": "0.00", + "price_set": { + "shop_money": { + "amount": "0.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "0.00", + "currency_code": "USD" + } + }, + "discounted_price_set": { + "shop_money": { + "amount": "0.00", + "currency_code": "USD" + }, + "presentment_money": { + "amount": "0.00", + "currency_code": "USD" + } + }, + "discount_allocations": [], + "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" + }, + "customer": { + "id": 207119551, + "email": "bob.norman@hostmail.com", + "accepts_marketing": false, + "created_at": "2021-02-12T13:51:00-05:00", + "updated_at": "2021-02-12T13:51:00-05:00", + "first_name": "Bob", + "last_name": "Norman", + "orders_count": 1, + "state": "disabled", + "total_spent": "199.65", + "last_order_id": 450789469, + "note": null, + "verified_email": true, + "multipass_identifier": null, + "tax_exempt": false, + "phone": "+16136120707", + "tags": "", + "last_order_name": "#1001", + "currency": "USD", + "accepts_marketing_updated_at": "2005-06-12T11:57:11-04:00", + "marketing_opt_in_level": null, + "tax_exemptions": [], + "admin_graphql_api_id": "gid://shopify/Customer/207119551", + "default_address": { + "id": 207119551, + "customer_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 + } + } + } + ] +} diff --git a/test/order_test.py b/test/order_test.py index 46278a72..a915a1ab 100644 --- a/test/order_test.py +++ b/test/order_test.py @@ -48,3 +48,10 @@ def test_get_order_transaction(self): self.fake('orders/450789469/transactions', method='GET', body=self.load_fixture('transactions')) transactions = order.transactions() self.assertEqual("409.94", transactions[0].amount) + + def test_get_customer_orders(self): + self.fake("customers/207119551/orders", method='GET', body=self.load_fixture('orders'), code=200) + orders = shopify.Order.find(customer_id=207119551) + self.assertIsInstance(orders[0], shopify.Order) + self.assertEqual(450789469, orders[0].id) + self.assertEqual(207119551, orders[0].customer.id) From 5b67f82402b53d272b3617b3ee67a17974afbe24 Mon Sep 17 00:00:00 2001 From: Paulina Khew Date: Tue, 23 Feb 2021 17:14:16 -0500 Subject: [PATCH 2/4] Update CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 5a7a80ab..6d863d7d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ - Add FulfillmentEvent resource ([#454](https://github.com/Shopify/shopify_python_api/pull/454)) - Fix for being unable to get the len() of a filter ([#456](https://github.com/Shopify/shopify_python_api/pull/456)) - Add ApplicationCredit resource ([#457](https://github.com/Shopify/shopify_python_api/pull/457)) +- Add support for retrieving all orders using customer_id ([#466](https://github.com/Shopify/shopify_python_api/pull/466)) == Version 8.2.0 - [Feature] Add support for Dynamic API Versioning. When the library is initialized, it will now make a request to From 31dfa868760eca88439cf8fe9f068431fe907221 Mon Sep 17 00:00:00 2001 From: Paulina Khew Date: Wed, 24 Feb 2021 15:55:28 -0500 Subject: [PATCH 3/4] Remove unused data from orders.json --- test/fixtures/orders.json | 731 +------------------------------------- 1 file changed, 1 insertion(+), 730 deletions(-) diff --git a/test/fixtures/orders.json b/test/fixtures/orders.json index 58ebd2d1..925a4a5d 100644 --- a/test/fixtures/orders.json +++ b/test/fixtures/orders.json @@ -51,69 +51,13 @@ }, "landing_site_ref": "abc", "order_number": 1001, - "discount_applications": [ - { - "type": "discount_code", - "value": "10.0", - "value_type": "fixed_amount", - "allocation_method": "across", - "target_selection": "all", - "target_type": "line_item", - "code": "TENOFF" - } - ], - "discount_codes": [ - { - "code": "TENOFF", - "amount": "10.00", - "type": "fixed_amount" - } - ], - "note_attributes": [ - { - "name": "custom engraving", - "value": "Happy Birthday" - }, - { - "name": "colour", - "value": "green" - } - ], "payment_details": { - "credit_card_bin": null, - "avs_result_code": null, - "cvv_result_code": null, "credit_card_number": "•••• •••• •••• 4242", - "credit_card_company": "Visa", - "credit_card_name": null, - "credit_card_wallet": null, - "credit_card_expiration_month": null, - "credit_card_expiration_year": null + "credit_card_company": "Visa" }, "payment_gateway_names": [ "bogus" ], - "processing_method": "direct", - "checkout_id": 901414060, - "source_name": "web", - "fulfillment_status": null, - "tax_lines": [ - { - "price": "11.94", - "rate": 0.06, - "title": "State Tax", - "price_set": { - "shop_money": { - "amount": "11.94", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "11.94", - "currency_code": "USD" - } - } - } - ], "tags": "", "contact_email": "bob.norman@hostmail.com", "order_status_url": "https://apple.myshopify.com/690933842/orders/b1946ac92492d2347c6235b4d2611184/authenticate?key=ccde591a93123786bd8d257abd970200", @@ -178,680 +122,7 @@ "currency_code": "USD" } }, - "line_items": [ - { - "id": 466157049, - "variant_id": 39072856, - "title": "IPod Nano - 8gb", - "quantity": 1, - "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, - "grams": 200, - "price": "199.00", - "total_discount": "0.00", - "fulfillment_status": null, - "price_set": { - "shop_money": { - "amount": "199.00", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "199.00", - "currency_code": "USD" - } - }, - "total_discount_set": { - "shop_money": { - "amount": "0.00", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "0.00", - "currency_code": "USD" - } - }, - "discount_allocations": [ - { - "amount": "3.34", - "discount_application_index": 0, - "amount_set": { - "shop_money": { - "amount": "3.34", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "3.34", - "currency_code": "USD" - } - } - } - ], - "duties": [], - "admin_graphql_api_id": "gid://shopify/LineItem/466157049", - "tax_lines": [ - { - "title": "State Tax", - "price": "3.98", - "rate": 0.06, - "price_set": { - "shop_money": { - "amount": "3.98", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "3.98", - "currency_code": "USD" - } - } - } - ] - }, - { - "id": 518995019, - "variant_id": 49148385, - "title": "IPod Nano - 8gb", - "quantity": 1, - "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, - "grams": 200, - "price": "199.00", - "total_discount": "0.00", - "fulfillment_status": null, - "price_set": { - "shop_money": { - "amount": "199.00", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "199.00", - "currency_code": "USD" - } - }, - "total_discount_set": { - "shop_money": { - "amount": "0.00", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "0.00", - "currency_code": "USD" - } - }, - "discount_allocations": [ - { - "amount": "3.33", - "discount_application_index": 0, - "amount_set": { - "shop_money": { - "amount": "3.33", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "3.33", - "currency_code": "USD" - } - } - } - ], - "duties": [], - "admin_graphql_api_id": "gid://shopify/LineItem/518995019", - "tax_lines": [ - { - "title": "State Tax", - "price": "3.98", - "rate": 0.06, - "price_set": { - "shop_money": { - "amount": "3.98", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "3.98", - "currency_code": "USD" - } - } - } - ] - }, - { - "id": 703073504, - "variant_id": 457924702, - "title": "IPod Nano - 8gb", - "quantity": 1, - "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, - "grams": 200, - "price": "199.00", - "total_discount": "0.00", - "fulfillment_status": null, - "price_set": { - "shop_money": { - "amount": "199.00", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "199.00", - "currency_code": "USD" - } - }, - "total_discount_set": { - "shop_money": { - "amount": "0.00", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "0.00", - "currency_code": "USD" - } - }, - "discount_allocations": [ - { - "amount": "3.33", - "discount_application_index": 0, - "amount_set": { - "shop_money": { - "amount": "3.33", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "3.33", - "currency_code": "USD" - } - } - } - ], - "duties": [], - "admin_graphql_api_id": "gid://shopify/LineItem/703073504", - "tax_lines": [ - { - "title": "State Tax", - "price": "3.98", - "rate": 0.06, - "price_set": { - "shop_money": { - "amount": "3.98", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "3.98", - "currency_code": "USD" - } - } - } - ] - } - ], - "fulfillments": [ - { - "id": 255858046, - "order_id": 450789469, - "status": "failure", - "created_at": "2021-02-12T13:51:00-05:00", - "service": "manual", - "updated_at": "2021-02-12T13:51:00-05:00", - "tracking_company": "USPS", - "shipment_status": null, - "location_id": 905684977, - "line_items": [ - { - "id": 466157049, - "variant_id": 39072856, - "title": "IPod Nano - 8gb", - "quantity": 1, - "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, - "grams": 200, - "price": "199.00", - "total_discount": "0.00", - "fulfillment_status": null, - "price_set": { - "shop_money": { - "amount": "199.00", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "199.00", - "currency_code": "USD" - } - }, - "total_discount_set": { - "shop_money": { - "amount": "0.00", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "0.00", - "currency_code": "USD" - } - }, - "discount_allocations": [ - { - "amount": "3.34", - "discount_application_index": 0, - "amount_set": { - "shop_money": { - "amount": "3.34", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "3.34", - "currency_code": "USD" - } - } - } - ], - "duties": [], - "admin_graphql_api_id": "gid://shopify/LineItem/466157049", - "tax_lines": [ - { - "title": "State Tax", - "price": "3.98", - "rate": 0.06, - "price_set": { - "shop_money": { - "amount": "3.98", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "3.98", - "currency_code": "USD" - } - } - } - ] - } - ], - "tracking_number": "1Z2345", - "tracking_numbers": [ - "1Z2345" - ], - "tracking_url": "https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=1Z2345", - "tracking_urls": [ - "https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1=1Z2345" - ], - "receipt": { - "testcase": true, - "authorization": "123456" - }, - "name": "#1001.0", - "admin_graphql_api_id": "gid://shopify/Fulfillment/255858046" - } - ], - "refunds": [ - { - "id": 509562969, - "order_id": 450789469, - "created_at": "2021-02-12T13:51:00-05:00", - "note": "it broke during shipping", - "user_id": 799407056, - "processed_at": "2021-02-12T13:51:00-05:00", - "restock": true, - "duties": [], - "total_duties_set": { - "shop_money": { - "amount": "0.00", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "0.00", - "currency_code": "USD" - } - }, - "admin_graphql_api_id": "gid://shopify/Refund/509562969", - "refund_line_items": [ - { - "id": 104689539, - "quantity": 1, - "line_item_id": 703073504, - "location_id": 487838322, - "restock_type": "legacy_restock", - "subtotal": 195.67, - "total_tax": 3.98, - "subtotal_set": { - "shop_money": { - "amount": "195.67", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "195.67", - "currency_code": "USD" - } - }, - "total_tax_set": { - "shop_money": { - "amount": "3.98", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "3.98", - "currency_code": "USD" - } - }, - "line_item": { - "id": 703073504, - "variant_id": 457924702, - "title": "IPod Nano - 8gb", - "quantity": 1, - "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, - "grams": 200, - "price": "199.00", - "total_discount": "0.00", - "fulfillment_status": null, - "price_set": { - "shop_money": { - "amount": "199.00", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "199.00", - "currency_code": "USD" - } - }, - "total_discount_set": { - "shop_money": { - "amount": "0.00", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "0.00", - "currency_code": "USD" - } - }, - "discount_allocations": [ - { - "amount": "3.33", - "discount_application_index": 0, - "amount_set": { - "shop_money": { - "amount": "3.33", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "3.33", - "currency_code": "USD" - } - } - } - ], - "duties": [], - "admin_graphql_api_id": "gid://shopify/LineItem/703073504", - "tax_lines": [ - { - "title": "State Tax", - "price": "3.98", - "rate": 0.06, - "price_set": { - "shop_money": { - "amount": "3.98", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "3.98", - "currency_code": "USD" - } - } - } - ] - } - }, - { - "id": 709875399, - "quantity": 1, - "line_item_id": 466157049, - "location_id": 487838322, - "restock_type": "legacy_restock", - "subtotal": 195.66, - "total_tax": 3.98, - "subtotal_set": { - "shop_money": { - "amount": "195.66", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "195.66", - "currency_code": "USD" - } - }, - "total_tax_set": { - "shop_money": { - "amount": "3.98", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "3.98", - "currency_code": "USD" - } - }, - "line_item": { - "id": 466157049, - "variant_id": 39072856, - "title": "IPod Nano - 8gb", - "quantity": 1, - "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, - "grams": 200, - "price": "199.00", - "total_discount": "0.00", - "fulfillment_status": null, - "price_set": { - "shop_money": { - "amount": "199.00", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "199.00", - "currency_code": "USD" - } - }, - "total_discount_set": { - "shop_money": { - "amount": "0.00", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "0.00", - "currency_code": "USD" - } - }, - "discount_allocations": [ - { - "amount": "3.34", - "discount_application_index": 0, - "amount_set": { - "shop_money": { - "amount": "3.34", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "3.34", - "currency_code": "USD" - } - } - } - ], - "duties": [], - "admin_graphql_api_id": "gid://shopify/LineItem/466157049", - "tax_lines": [ - { - "title": "State Tax", - "price": "3.98", - "rate": 0.06, - "price_set": { - "shop_money": { - "amount": "3.98", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "3.98", - "currency_code": "USD" - } - } - } - ] - } - } - ], - "transactions": [ - { - "id": 179259969, - "order_id": 450789469, - "kind": "refund", - "gateway": "bogus", - "status": "success", - "message": null, - "created_at": "2005-08-05T12:59:12-04:00", - "test": false, - "authorization": "authorization-key", - "location_id": null, - "user_id": null, - "parent_id": 801038806, - "processed_at": "2005-08-05T12:59:12-04:00", - "device_id": null, - "error_code": null, - "source_name": "web", - "receipt": {}, - "amount": "209.00", - "currency": "USD", - "admin_graphql_api_id": "gid://shopify/OrderTransaction/179259969" - } - ], - "order_adjustments": [] - } - ], - "total_tip_received": "0.0", - "original_total_duties_set": null, - "current_total_duties_set": null, "admin_graphql_api_id": "gid://shopify/Order/450789469", - "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, - "discounted_price": "0.00", - "price_set": { - "shop_money": { - "amount": "0.00", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "0.00", - "currency_code": "USD" - } - }, - "discounted_price_set": { - "shop_money": { - "amount": "0.00", - "currency_code": "USD" - }, - "presentment_money": { - "amount": "0.00", - "currency_code": "USD" - } - }, - "discount_allocations": [], - "tax_lines": [] - } - ], "billing_address": { "first_name": "Bob", "address1": "Chestnut Street 92", From 006e3e645f5d58ddf75e140ef2d4c42e65934a7d Mon Sep 17 00:00:00 2001 From: Paulina Khew Date: Fri, 26 Feb 2021 10:49:45 -0500 Subject: [PATCH 4/4] Add optional customer.orders() support with tests --- shopify/resources/customer.py | 4 ++++ test/customer_test.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/shopify/resources/customer.py b/shopify/resources/customer.py index 80be7fc5..e52c8d80 100644 --- a/shopify/resources/customer.py +++ b/shopify/resources/customer.py @@ -1,6 +1,7 @@ from ..base import ShopifyResource from shopify import mixins from .customer_invite import CustomerInvite +from .order import Order class Customer(ShopifyResource, mixins.Metafields): @@ -24,3 +25,6 @@ def search(cls, **kwargs): def send_invite(self, customer_invite=CustomerInvite()): resource = self.post("send_invite", customer_invite.encode()) return CustomerInvite(Customer.format.decode(resource.body)) + + def orders(self): + return Order.find(customer_id=self.id) diff --git a/test/customer_test.py b/test/customer_test.py index 5819f292..9547b835 100644 --- a/test/customer_test.py +++ b/test/customer_test.py @@ -53,3 +53,12 @@ def test_send_invite_with_params(self): self.assertEqual(customer_invite, json.loads(self.http.request.data.decode("utf-8"))) self.assertIsInstance(customer_invite_response, shopify.CustomerInvite) self.assertEqual(customer_invite['customer_invite']['to'], customer_invite_response.to) + + def test_get_customer_orders(self): + self.fake('customers/207119551', method='GET', body=self.load_fixture('customer')) + customer = shopify.Customer.find(207119551) + self.fake('customers/207119551/orders', method='GET', body=self.load_fixture('orders')) + orders = customer.orders() + self.assertIsInstance(orders[0], shopify.Order) + self.assertEqual(450789469, orders[0].id) + self.assertEqual(207119551, orders[0].customer.id)