예제 #1
0
def inquire_view(request, classes_id):
    if not(request.user.is_authenticated()):
        return HttpResponse(json.dumps(_make_json_response( False, const.ERROR_HAVE_TO_LOGIN, const.CODE_ERROR_HAVE_TO_LOGIN)), content_type="application/json")
    else:
        classes_inquire = ClassesInquire( classes_id = classes_id, user = request.user, content= request.POST.get('content') )
        try:
            classes_inquire.save()
        except IntegrityError:
            return HttpResponse( json.dumps( _make_json_response( False, const.ERROR_CLASSES_INQUIRE_FAIL, const.CODE_ERROR_CLASSES_INQUIRE_FAIL ) ), content_type="application/json" )

        send_email('classweek:inquire',
                   'username:\n' + request.user.username + '\ncontent:\n' + request.POST.get('content'))
        return HttpResponse( json.dumps( _make_json_response( True, None ) ), content_type="application/json" )
예제 #2
0
def inquire_view(request):
    (error, error_code ) = (None, 0)
    inquire_content = request.POST.get('inquire_content', None)
    if inquire_content is not None:
        if hasattr(request, 'user') and request.user.is_authenticated():
            try:
                UserInquire.objects.create(
                    user=request.user,
                    inquire_content=inquire_content
                )
                send_email('classweek:inquire',
                   'username:\n' + request.user.username + '\ncontent:\n' + inquire_content)
            except IntegrityError as e:
                pass
        else:
            (error, error_code) = (const.ERROR_HAVE_TO_LOGIN, const.CODE_ERROR_HAVE_TO_LOGIN )

    return _HttpJsonResponse( error, error_code )
예제 #3
0
def payment_noti_view(request):

    logger.debug("def payment_noti_view(request):")
    logger.debug(request.GET)
    logger.debug(request.POST)
    logger.debug(request.META.get("REMOTE_ADDR"))

    if request.META.get("REMOTE_ADDR") in (
        "118.129.210.25",
        "211.219.96.165",
        "118.129.210.24",
        "192.168.187.140",
        "172.20.22.40",
    ):

        p_status = request.POST.get("P_STATUS", "")
        p_tid = request.POST.get("P_TID", "")
        p_type = request.POST.get("P_TYPE", "")
        p_auth_dt = request.POST.get("P_AUTH_DT", "")
        p_mid = request.POST.get("P_MID", "")
        p_oid = request.POST.get("P_OID", "")
        p_amt = request.POST.get("P_AMT", "")
        p_uname = request.POST.get("P_UNAME", "")
        p_rmesg1 = request.POST.get("P_RMESG1", "")
        p_rmesg2 = request.POST.get("P_RMESG2", "")
        p_noti = request.POST.get("P_NOTI", "")
        p_noti = str(p_noti).replace("\\", "")
        p_fn_cd1 = request.POST.get("P_FN_CD1", "")
        p_auth_no = request.POST.get("P_AUTH_NO", "")
        p_card_issuer_code = request.POST.get("P_CARD_ISSUER_CODE", "")
        p_card_num = request.POST.get("P_CARD_NUM", "")
        p_card_member_num = request.POST.get("P_CARD_MEMBER_NUM", "")
        p_card_purchase_code = request.POST.get("P_CARD_PURCHASE_CODE", "")
        p_card_prtc_code = request.POST.get("P_CARD_PRTC_CODE", "")
        p_hpp_corp = request.POST.get("P_HPP_CORP", "")
        p_vact_num = request.POST.get("P_VACT_NUM", "")
        p_vact_date = request.POST.get("P_VACT_DATE", "")
        p_vact_time = request.POST.get("P_VACT_TIME", "")
        p_vact_name = request.POST.get("P_VACT_NAME", "")
        p_vact_bank_code = request.POST.get("P_VACT_BANK_CODE", "")

        logger.debug("P_STATUS : " + p_status)
        logger.debug("P_TID : " + p_tid)
        logger.debug("P_TYPE : " + p_type)
        logger.debug("P_AUTH_DT : " + p_auth_dt)
        logger.debug("P_MID : " + p_mid)
        logger.debug("P_OID : " + p_oid)
        logger.debug("P_AMT : " + p_amt)
        logger.debug("P_UNAME : " + p_uname)
        logger.debug("P_RMESG1 : " + p_rmesg1)
        logger.debug("P_RMESG2 : " + p_rmesg2)
        logger.debug("P_NOTI : " + p_noti)
        logger.debug("P_FN_CD1 : " + p_fn_cd1)
        logger.debug("P_AUTH_NO : " + p_auth_no)
        logger.debug("P_CARD_ISSUER_CODE : " + p_card_issuer_code)
        logger.debug("P_CARD_NUM : " + p_card_num)
        logger.debug("P_CARD_MEMBER_NUM : " + p_card_member_num)
        logger.debug("P_CARD_PURCHASE_CODE : " + p_card_purchase_code)
        logger.debug("P_CARD_PRTC_CODE : " + p_card_prtc_code)
        logger.debug("P_HPP_CORP : " + p_hpp_corp)
        logger.debug("P_VACT_NUM : " + p_vact_num)
        logger.debug("P_VACT_DATE : " + p_vact_date)
        logger.debug("P_VACT_TIME : " + p_vact_time)
        logger.debug("P_VACT_NAME : " + p_vact_name)
        logger.debug("P_VACT_BANK_CODE : " + p_vact_bank_code)

        try:
            payment_log = PaymentLog.objects.create(
                p_status=p_status,
                p_tid=p_tid,
                p_type=p_type,
                p_auth_dt=p_auth_dt,
                p_mid=p_mid,
                p_oid=p_oid,
                p_amt=p_amt,
                p_uname=p_uname,
                p_rmesg1=p_rmesg1,
                p_rmesg2=p_rmesg2,
                p_noti=p_noti,
                p_fn_cd1=p_fn_cd1,
                p_auth_no=p_auth_no,
                p_card_issuer_code=p_card_issuer_code,
                p_card_num=p_card_num,
                p_card_member_num=p_card_member_num,
                p_card_purchase_code=p_card_purchase_code,
                p_card_prtc_code=p_card_prtc_code,
                p_hpp_corp=p_hpp_corp,
                p_vact_num=p_vact_num,
                p_vact_date=p_vact_date,
                p_vact_time=p_vact_time,
                p_vact_name=p_vact_name,
                p_vact_bank_code=p_vact_bank_code,
            )
        except Exception, e:
            logger.error(e)

        payment_item_info_json = json.loads(p_noti)

        username = payment_item_info_json.get("username", None)
        user = User.objects.get(username=username) if username is not None else None

        classes_id = payment_item_info_json.get("classes_id", None)
        classes = Classes.objects.get(id=classes_id) if classes_id is not None else None

        schedule_id = payment_item_info_json.get("schedule_id", None)
        schedule = Schedule.objects.get(id=schedule_id) if schedule_id is not None else None

        if user is None:
            logger.error("not authenticated user payment")
        elif classes is None or schedule is None:
            logger.error("payment item info is not correct")
        else:
            purchase = Purchase.objects.create(
                payment_log=payment_log,
                user=user,
                classes=classes,
                schedule=schedule,
                day_or_month=payment_item_info_json.get("day_or_month", ""),
                class_start_datetime=datetime.strptime(
                    payment_item_info_json.get("class_start_datetime", ""), "%Y-%m-%d %H:%M:%S.%f"
                ),
                class_end_datetime=datetime.strptime(
                    payment_item_info_json.get("class_end_datetime", ""), "%Y-%m-%d %H:%M:%S.%f"
                ),
                price=payment_item_info_json.get("price", 0),
            )

            promotion_obj, promotion_resp, promotion_percentage = _check_promotion()

            if promotion_obj is not None:
                PromotionDetail.objects.create(promotion=promotion_obj, purchase=purchase)

            send_email(
                "classweek:purchase",
                "username:\n"
                + user.username
                + "\nclasses_id:\n"
                + str(classes.id)
                + "\nclasses_title:\n"
                + classes.title
                + "\nuser_id:\n"
                + str(user.id)
                + "\nphone_number:\n"
                + user.profile.phonenumber
                + "\nday_or_month:\n"
                + payment_item_info_json.get("day_or_month", ""),
            )
예제 #4
0
def send_mail_test_view(request):
    send_email(
        "test", "aaaaatest content\ntttt", ["*****@*****.**", "*****@*****.**", "*****@*****.**"]
    )

    return HttpResponse("ttt")
예제 #5
0
def payment_next_view(request):

    logger.debug("def payment_next_view(request):")
    logger.debug(request.GET)
    logger.debug(request.POST)

    next_p_status = request.POST.get("P_STATUS", None)

    if next_p_status == "00":
        next_p_tid = request.POST.get("P_TID", None)
        params = {"P_MID": next_p_tid[10:20], "P_TID": next_p_tid}

        # send request and recive response
        next_req_url = request.POST.get("P_REQ_URL", None)
        response = requests.post(next_req_url, data=params)
        response.encoding = "euc-kr"

        # parsing response data
        params_list = response.text.strip().split("&")
        params_dict = {}
        for params_item in params_list:
            params_item_split = params_item.split("=")
            params_item_key = params_item_split[0]
            params_item_value = params_item_split[1]
            params_dict[params_item_key] = params_item_value

        p_status = params_dict.get("P_STATUS", "")
        p_tid = params_dict.get("P_TID", "")
        p_type = params_dict.get("P_TYPE", "")
        p_auth_dt = params_dict.get("P_AUTH_DT", "")
        p_mid = params_dict.get("P_MID", "")
        p_oid = params_dict.get("P_OID", "")
        p_amt = params_dict.get("P_AMT", "")
        p_uname = params_dict.get("P_UNAME", "")
        p_rmesg1 = params_dict.get("P_RMESG1", "")
        p_rmesg2 = params_dict.get("P_RMESG2", "")
        p_noti = params_dict.get("P_NOTI", "")
        p_noti = str(p_noti).replace("\\", "")
        p_fn_cd1 = params_dict.get("P_FN_CD1", "")
        p_auth_no = params_dict.get("P_AUTH_NO", "")
        p_card_issuer_code = params_dict.get("P_CARD_ISSUER_CODE", "")
        p_card_num = params_dict.get("P_CARD_NUM", "")
        p_card_member_num = params_dict.get("P_CARD_MEMBER_NUM", "")
        p_card_purchase_code = params_dict.get("P_CARD_PURCHASE_CODE", "")
        p_card_prtc_code = params_dict.get("P_CARD_PRTC_CODE", "")
        p_hpp_corp = params_dict.get("P_HPP_CORP", "")
        p_vact_num = params_dict.get("P_VACT_NUM", "")
        p_vact_date = params_dict.get("P_VACT_DATE", "")
        p_vact_time = params_dict.get("P_VACT_TIME", "")
        p_vact_name = params_dict.get("P_VACT_NAME", "")
        p_vact_bank_code = params_dict.get("P_VACT_BANK_CODE", "")

        logger.debug("P_STATUS : " + p_status)
        logger.debug("P_TID : " + p_tid)
        logger.debug("P_TYPE : " + p_type)
        logger.debug("P_AUTH_DT : " + p_auth_dt)
        logger.debug("P_MID : " + p_mid)
        logger.debug("P_OID : " + p_oid)
        logger.debug("P_AMT : " + p_amt)
        logger.debug("P_UNAME : " + p_uname)
        logger.debug("P_RMESG1 : " + p_rmesg1)
        logger.debug("P_RMESG2 : " + p_rmesg2)
        logger.debug("P_NOTI : " + p_noti)
        logger.debug("P_FN_CD1 : " + p_fn_cd1)
        logger.debug("P_AUTH_NO : " + p_auth_no)
        logger.debug("P_CARD_ISSUER_CODE : " + p_card_issuer_code)
        logger.debug("P_CARD_NUM : " + p_card_num)
        logger.debug("P_CARD_MEMBER_NUM : " + p_card_member_num)
        logger.debug("P_CARD_PURCHASE_CODE : " + p_card_purchase_code)
        logger.debug("P_CARD_PRTC_CODE : " + p_card_prtc_code)
        logger.debug("P_HPP_CORP : " + p_hpp_corp)
        logger.debug("P_VACT_NUM : " + p_vact_num)
        logger.debug("P_VACT_DATE : " + p_vact_date)
        logger.debug("P_VACT_TIME : " + p_vact_time)
        logger.debug("P_VACT_NAME : " + p_vact_name)
        logger.debug("P_VACT_BANK_CODE : " + p_vact_bank_code)

        try:
            payment_log = PaymentLog.objects.create(
                p_status=p_status,
                p_tid=p_tid,
                p_type=p_type,
                p_auth_dt=p_auth_dt,
                p_mid=p_mid,
                p_oid=p_oid,
                p_amt=p_amt,
                p_uname=p_uname,
                p_rmesg1=p_rmesg1,
                p_rmesg2=p_rmesg2,
                p_noti=p_noti,
                p_fn_cd1=p_fn_cd1,
                p_auth_no=p_auth_no,
                p_card_issuer_code=p_card_issuer_code,
                p_card_num=p_card_num,
                p_card_member_num=p_card_member_num,
                p_card_purchase_code=p_card_purchase_code,
                p_card_prtc_code=p_card_prtc_code,
                p_hpp_corp=p_hpp_corp,
                p_vact_num=p_vact_num,
                p_vact_date=p_vact_date,
                p_vact_time=p_vact_time,
                p_vact_name=p_vact_name,
                p_vact_bank_code=p_vact_bank_code,
            )
        except Exception, e:
            logger.error(e)

        payment_item_info_json = json.loads(p_noti)

        username = payment_item_info_json.get("username", None)
        user = User.objects.get(username=username) if username is not None else None

        classes_id = payment_item_info_json.get("classes_id", None)
        classes = Classes.objects.get(id=classes_id) if classes_id is not None else None

        schedule_id = payment_item_info_json.get("schedule_id", None)
        schedule = Schedule.objects.get(id=schedule_id) if schedule_id is not None else None

        if user is None:
            logger.error("not authenticated user payment")
        elif classes is None or schedule is None:
            logger.error("payment item info is not correct")
        else:
            purchase = Purchase.objects.create(
                payment_log=payment_log,
                user=user,
                classes=classes,
                schedule=schedule,
                day_or_month=payment_item_info_json.get("day_or_month", ""),
                class_start_datetime=datetime.strptime(
                    payment_item_info_json.get("class_start_datetime", ""), "%Y-%m-%d %H:%M:%S.%f"
                ),
                class_end_datetime=datetime.strptime(
                    payment_item_info_json.get("class_end_datetime", ""), "%Y-%m-%d %H:%M:%S.%f"
                ),
                price=payment_item_info_json.get("price", 0),
            )

            promotion_obj, promotion_resp, promotion_percentage = _check_promotion()

            if promotion_obj is not None:
                PromotionDetail.objects.create(promotion=promotion_obj, purchase=purchase)

            send_email(
                "classweek:purchase",
                "username:\n"
                + user.username
                + "\nclasses_id:\n"
                + str(classes.id)
                + "\nclasses_title:\n"
                + classes.title
                + "\nuser_id:\n"
                + str(user.id)
                + "\nphone_number:\n"
                + user.profile.phonenumber
                + "\nday_or_month:\n"
                + payment_item_info_json.get("day_or_month", ""),
            )

        return render(request, "payment_next.html", {"is_success": "true"})