o
    ˷eU                     @   sD   d Z ddlmZ ddlZddlmZ ddlmZ G dd deZdS )z
The E-commerce Store Orders endpoint API endpoint

Documentation: http://developer.mailchimp.com/documentation/mailchimp/reference/ecommerce/stores/orders/
Schema: https://api.mailchimp.com/schema/3.0/Ecommerce/Stores/Customers/Instance.json
    )unicode_literalsN)BaseApi)StoreOrderLinesc                       sJ   e Zd ZdZ fddZdd ZdddZd	d
 Zdd Zdd Z	  Z
S )StoreOrdersas  
    Orders represent successful e-commerce transactions, and this data can be
    used to provide more detailed campaign reports, track sales, and
    personalize emails to your targeted consumers, and view other e-commerce
    data in your MailChimp account.

    .. note::
        If a financial_status or fulfillment_status value is provided when
        creating or updating an order, it will trigger a notification email if
        they have been designed and enabled in your account. The following sets
        of statuses trigger the following notification types:

        financial_status = 'paid' -> Order Invoice
        financial_status = 'pending' -> Order Confirmation
        financial_status = 'refunded' -> Refund Confirmation
        financial_status = 'cancelled' -> Cancellation Confirmation
        fulfillment_status = 'shipped' -> Shipping Confirmation

        The current list of notification types and triggers can be found at
        http://developer.mailchimp.com/documentation/mailchimp/guides/getting-started-with-ecommerce/#order-notifications
        and should be consulted in the event of any changes
    c                    s6   t t| j|i | d| _d| _d| _t| | _dS )z)
        Initialize the endpoint
        zecommerce/storesN)superr   __init__endpointstore_idorder_idr   lines)selfargskwargs	__class__ V/var/www/ideatree/venv/lib/python3.10/site-packages/mailchimp3/entities/storeorders.pyr   '   s
   zStoreOrders.__init__c                 C   s  || _ d|vrtdd|vrtdd|d vrtdd|vr%tdtd|d s1td	d
|vr9tdd|vrAtd|d D ]*}d|vrOtdd|vrWtdd|vr_tdd|vrgtdd|vrotdqE| jj| |d|d}|dur|d | _|S d| _|S )a  
        Add a new order to a store.

        :param store_id: The store id.
        :type store_id: :py:class:`str`
        :param data: The request body parameters
        :type data: :py:class:`dict`
        data = {
            "id": string*,
            "customer": object*
            {
                "'id": string*
            },
            "curency_code": string*,
            "order_total": number*,
            "lines": array*
            [
                {
                    "id": string*,
                    "product_id": string*,
                    "product_variant_id": string*,
                    "quantity": integer*,
                    "price": number*
                }
            ]
        }
        idzThe order must have an idcustomerzThe order must have a customerz"The order customer must have an idcurrency_codez#The order must have a currency_codez
^[A-Z]{3}$zAThe currency_code must be a valid 3-letter ISO 4217 currency codeorder_totalz"The order must have an order_totalr   z+The order must have at least one order linezEach order line must have an id
product_idz&Each order line must have a product_idproduct_variant_idz.Each order line must have a product_variant_idquantityz$Each order line must have a quantitypricez!Each order line must have a priceordersurldataN)	r	   KeyErrorrematch
ValueError
_mc_client_post_build_pathr
   )r   r	   r   lineresponser   r   r   create2   sB   
zStoreOrders.createFc                 K   sJ   || _ d| _|r| jdd| |di|S | jjdd| |di|S )u  
        Get information about a store’s orders.

        :param store_id: The store id.
        :type store_id: :py:class:`str`
        :param get_all: Should the query get all results
        :type get_all: :py:class:`bool`
        :param queryparams: The query string parameters
        queryparams['fields'] = []
        queryparams['exclude_fields'] = []
        queryparams['count'] = integer
        queryparams['offset'] = integer
        queryparams['customer_id'] = string
        Nr   r   r   )r	   r
   _iterater%   r#   _get)r   r	   get_allqueryparamsr   r   r   allp   s
   zStoreOrders.allc                 K   s,   || _ || _| jjdd| |d|i|S )aq  
        Get information about a specific order.

        :param store_id: The store id.
        :type store_id: :py:class:`str`
        :param order_id: The id for the order in a store.
        :type order_id: :py:class:`str`
        :param queryparams: The query string parameters
        queryparams['fields'] = []
        queryparams['exclude_fields'] = []
        r   r   Nr   )r	   r
   r#   r*   r%   )r   r	   r
   r,   r   r   r   get   s    zStoreOrders.getc                 C   s&   || _ || _| jj| |d||dS )a2  
        Update a specific order.

        :param store_id: The store id.
        :type store_id: :py:class:`str`
        :param order_id: The id for the order in a store.
        :type order_id: :py:class:`str`
        :param data: The request body parameters
        :type data: :py:class:`dict`
        r   r   )r	   r
   r#   _patchr%   )r   r	   r
   r   r   r   r   update   s   zStoreOrders.updatec                 C   s$   || _ || _| jj| |d|dS )z
        Delete an order.

        :param store_id: The store id.
        :type store_id: :py:class:`str`
        :param order_id: The id for the order in a store.
        :type order_id: :py:class:`str`
        r   )r   )r	   r
   r#   _deleter%   )r   r	   r
   r   r   r   delete   s   	zStoreOrders.delete)F)__name__
__module____qualname____doc__r   r(   r-   r.   r0   r2   __classcell__r   r   r   r   r      s    
>r   )	r6   
__future__r   r    mailchimp3.baseapir   #mailchimp3.entities.storeorderlinesr   r   r   r   r   r   <module>   s   