Exemplo n.º 1
0
 def __send_order_post_request(self):
     self.__logger.debug(self.__po_params)
     try:
         post_order_doc = get_document_from_url(
             url='https://atomy.kr/center/payreq.asp',
             encoding='euc-kr',
             headers=[{
                 'Cookie': c
             } for c in self.__session_cookies] +
             [{
                 'Referer': 'https://atomy.kr/center/c_sale_ins.asp'
             }],
             raw_data=urlencode(self.__po_params, encoding='euc-kr'))
         script = post_order_doc.cssselect('head script')[0].text
         message_match = re.search(r"alert\(['\"](.*)['\"]\);", script)
         if message_match is not None:
             message = message_match.groups()[0]
             raise PurchaseOrderError(self.__purchase_order, self, message)
         return \
             post_order_doc.cssselect('#LGD_OID')[0].attrib['value'], \
             self.__get_bank_account_number(script)
     except HTTPError:
         self.__logger.warning(self.__po_params)
         raise PurchaseOrderError(self.__purchase_order, self,
                                  "Unexpected error has occurred")
Exemplo n.º 2
0
 def __get_order_details(self, order_id):
     order_details_doc = get_document_from_url(
         url='https://www.atomy.kr/v2/Home/MyAtomyMall/GetMyOrderView',
         encoding='utf-8',
         headers=[{'Cookie': c} for c in self.__session_cookies ] + [
             {'Content-Type': 'application/json'}
         ],
         raw_data='{"SaleNum":"%s","CustNo":"%s"}' % \
             (order_id, self.__purchase_order.customer.username)
     )
     return json.loads(order_details_doc.text)
Exemplo n.º 3
0
 def __get_product(self, product_id):
     result = get_document_from_url(
         url=f"https://atomy.kr/center/pop_mcode.asp?id={product_id}",
         encoding='euc-kr',
         headers=[{
             'Cookie': c
         } for c in self.__session_cookies])
     script = result.cssselect('script')[0].text
     return {
         'vat_price': int(re.search(r'vat_price\.value = "(\d+)"', script).groups()[0])
     } \
         if re.search(r'alert\(.+\);', result.text) is None \
         else None
Exemplo n.º 4
0
 def __get_product(self, product_id):
     if self.__is_valid_product(product_id):
         result = get_document_from_url(
             url="https://www.atomy.kr/v2/Home/Payment/GetMCode",
             encoding='utf-8',
             headers=[{'Cookie': c} for c in self.__session_cookies ] + [
                 {'Content-Type': 'application/json'}
             ],
             raw_data='{"MaterialCode":"%s"}' % product_id
         )
         result = json.loads(result.text)
         return result['jsonData'] if result['jsonData'] is not None else None
     else:
         return None
Exemplo n.º 5
0
    def __get_purchase_orders(self):
        logger = self.__logger.getChild('__get_purchase_orders')
        logger.debug('Getting purchase orders')
        search_params = {
            "CurrentPage": 1,
            "PageSize": 100,
            "SDate": (datetime.now() - timedelta(days=7)).strftime('%Y-%m-%d'),
            "EDate": (datetime.now() + timedelta(days=3)).strftime('%Y-%m-%d'),
            "OrderStatus":""
        }
        try:
            response = get_document_from_url(
                url='https://www.atomy.kr/v2/Home/MyAtomyMall/GetMyOrderList',
                encoding='utf-8',
                headers=[{'Cookie': c} for c in self.__session_cookies ] + [
                    {'Content-Type': 'application/json'}
                ],
                raw_data=json.dumps(search_params)
            )
            from app.purchase.models import PurchaseOrderStatus
            po_statuses = {
                '주문접수': PurchaseOrderStatus.posted,
                '배송중': PurchaseOrderStatus.shipped,
                '미결제마감': PurchaseOrderStatus.payment_past_due,
                '결제완료': PurchaseOrderStatus.paid,
                '상품준비중': PurchaseOrderStatus.paid,
                '주문취소': PurchaseOrderStatus.cancelled,
                '매출취소': PurchaseOrderStatus.cancelled,
                '배송완료': PurchaseOrderStatus.delivered,
                '반품': PurchaseOrderStatus.delivered
            }           
            
            orders = [{
                'id': o['SaleNum'],
                'status': po_statuses[o['OrderStatusName']]
                } for o in json.loads(response.text)['jsonData']]

            return orders
        except HTTPError as ex:
            if '/v2/Common/RedirectPage?rpage=MyAtomyMall%2FGetMyOrderList' in ex.args[0]:
                logger.warning("Can't get any orders for the customer")
                return []
            raise ex
Exemplo n.º 6
0
 def __is_valid_product(self, product_id):
     result = get_document_from_url(
         url="https://www.atomy.kr/v2/Home/Payment/CheckValidOrder",
         encoding='utf-8',
         headers=[{'Cookie': c} for c in self.__session_cookies] + [
             {'Content-Type': 'application/json'}
         ],
         raw_data='{"CartList":[{"MaterialCode":"%s"}]}' % product_id
     )
     result = json.loads(result.text)
     if result['rsCd'] == '200':
         if result['responseText'] == '':
             return True
         if result['responseText'] == ERROR_FOREIGN_ACCOUNT and (
             self.__purchase_order.purchase_restricted_products):
             return True
         self.__logger.warning("Product %s error: %s", product_id, result['responseText'])
         return False
     self.__logger.warning("Product %s unknown error", product_id)
     return False
Exemplo n.º 7
0
 def __send_order_post_request(self):
     self.__logger.debug(self.__po_params)
     try:
         post_order_doc = get_document_from_url(
             url='https://www.atomy.kr/v2/Home/Payment/PayReq_CrossPlatform2',
             encoding='utf-8',
             headers=[{'Cookie': c} for c in self.__session_cookies],
             raw_data='&'.join(["%s=%s" % p for p in self.__po_params.items()])
         )
         return post_order_doc.cssselect('#LGD_OID')[0].attrib['value']
     except KeyError: # Couldn't get order ID
         self.__logger.warning(self.__po_params)
         script = post_order_doc.cssselect('head script')[1].text
         message_match = re.search("var responseMsg = '(.*)';", script)
         if message_match is not None:
             message = message_match.groups()[0]
             raise PurchaseOrderError(self.__purchase_order, self, message)
     except HTTPError as ex:
         self.__logger.warning(self.__po_params)
         self.__logger.warning(ex)
         raise PurchaseOrderError(self.__purchase_order, self, "Unexpected error has occurred")