예제 #1
0
        public IActionResult bookingStep1([FromBody] DataModel data)
        {
            try
            {
                string memUuid = Website.Instance.Configuration["kkdayKey:uuid"];

                string    userAgent = Request.Headers["User-Agent"].ToString();
                UserAgent ua        = new UserAgent(userAgent);

                //B2d分銷商資料
                var aesUserData = User.Identities.SelectMany(i => i.Claims.Where(c => c.Type == ClaimTypes.UserData).Select(c => c.Value)).FirstOrDefault();
                var UserData    = JsonConvert.DeserializeObject <B2dAccount>(AesCryptHelper.aesDecryptBase64(aesUserData, Website.Instance.AesCryptKey));

                string ip = httpContextAccessor.HttpContext.Request.HttpContext.Connection.RemoteIpAddress.ToString().Replace("::1", "127.0.0.1");
                data = BookingRepostory.setCardEncrypt(data);
                //log時把卡號移除
                DataModel dataTemp = data.Clone();
                dataTemp.card = null;
                Website.Instance.logger.Debug($"bookingStep1_inputdata:{ JsonConvert.SerializeObject(dataTemp)}");

                string prodStr = TempData["prod_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(prodStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                ProductModel prod = JsonConvert.DeserializeObject <ProductModel>(prodStr);

                string moduleStr = TempData["module_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(moduleStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                ProductModuleModel module = JsonConvert.DeserializeObject <ProductModuleModel>(moduleStr);

                string pkgStr = TempData["pkg_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(pkgStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                PkgDetailModel pkg = JsonConvert.DeserializeObject <PkgDetailModel>(pkgStr);

                string pkgConfirmStr = TempData["confirm_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(moduleStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                confirmPkgInfo confirm = JsonConvert.DeserializeObject <confirmPkgInfo>(pkgConfirmStr);

                string titleStr = TempData["ProdTitleKeep_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(moduleStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                ProdTitleModel title = JsonConvert.DeserializeObject <ProdTitleModel>(titleStr);

                string discRuleStr = TempData["pkgsDiscRule_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(discRuleStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                DiscountRuleModel rule = JsonConvert.DeserializeObject <DiscountRuleModel>(discRuleStr);

                string pmgwStr = TempData["pmgw_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(pmgwStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                Pmgw pmgw = JsonConvert.DeserializeObject <Pmgw>(pmgwStr);

                string showStr = TempData["prodShow_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(showStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                //BookingShowProdModel show = JsonConvert.DeserializeObject<BookingShowProdModel>(showStr);

                TempData.Keep();
                data = BookingRepostory.setDefaultBookingInfo(memUuid, ua, data, prod, pkg, confirm, UserData, pmgw);

                //排除餐食
                data = BookingRepostory.exculdeFood(prod, data, module);

                data.company_xid = UserData.COMPANY_XID.ToString();
                data.channel_oid = UserData.KKDAY_CHANNEL_OID;
                data.locale      = UserData.LOCALE;
                data.ip          = ip;
                JObject order = ApiHelper.orderNew(data, title);

                string       orderMid = "";
                string       orderOid = "";
                returnStatus status   = new returnStatus();

                Website.Instance.logger.Debug($"bookingStep1_ordernewresponse:" + JsonConvert.SerializeObject(order));//要改
                //要先判斷是不是result='0000'
                if (order["result"].ToString() == "0000")
                {
                    orderMid = order["order_mid"].ToString();
                    orderOid = order["order_oid"].ToString();
                    //upd B2bOrder
                    //BookingRepostory.updB2dOrder(UserData.COMPANY_XID, orderOid, orderMid, b2bOrder, title);

                    status.pmchSslRequest = BookingRepostory.setPaymentInfo2(prod, data, orderMid, UserData, pmgw, memUuid, ip);
                    status.status         = "OK";
                    status.url            = Website.Instance.Configuration["kkUrl:pmchUrl"].ToString() + pmgw.pmchPayURL; //pmchUrl

                    //要把BookingShowProdModel 帶到訂購final頁
                    RedisHelper.SetRedis(showStr, "b2d:ec:order:final:prodShow:" + orderMid, 60);
                    RedisHelper.SetRedis(JsonConvert.SerializeObject(data), "b2d:ec:order:final:orderData:" + orderMid, 60);

                    //要存redis 付款主要資訊,最後訂單 upd時要使用,可和下面整合存一個就
                    BookingRepostory.setPayDtltoRedis(data, orderMid, UserData.UUID, RedisHelper);

                    //要存redis 因為付款後要從這個redis內容再進行payment驗證,可和上面整合存一個就好
                    //CallJsonPay rdsJson = (CallJsonPay)status.pmchSslRequest.json;
                    CallJsonPay2 rdsJson     = (CallJsonPay2)status.pmchSslRequest.json;
                    string       callPmchReq = JsonConvert.SerializeObject(status.pmchSslRequest.json);
                    RedisHelper.SetRedis(callPmchReq, "b2d:ec:pmchSslRequest:" + orderMid, 60);
                }
                else
                {
                    status.status = "Error";
                    status.msgErr = order["content"]["result"].ToString() + order["content"]["msg"].ToString();//要改
                }

                return(Json(status));
                //v1/channel/citi/auth
                //https://pmch.sit.kkday.com/citi/payment/auth
                //https://payment.kkday.com/v1/channel/adyen/auth
            }
            catch (Exception ex)
            {
                Website.Instance.logger.Debug($"bookingStep1_err_ordernew失敗:{ex.Message.ToString()}");
                ViewData["errMsg"] = ex.Message.ToString();
                Website.Instance.logger.Debug($"booking_index_err:{ex.Message.ToString()}");

                //導到錯誤頁
                return(RedirectToAction("Index", "Error", new ErrorViewModel {
                    ErrorType = ErrorType.Order_Fail, ErrorMessage = ex.Message.ToString()
                }));
            }
        }
예제 #2
0
        //新版
        public static PmchSslRequest3 setPaymentInfo2(ProductModel prod, DataModel data, string orderMid, B2dAccount UserData, Pmgw pmgw, string memUuid)
        {
            PmchSslRequest3 pmch = new PmchSslRequest3();

            pmch.api_key   = "kkdayapi";
            pmch.user_oid  = "1";
            pmch.ver       = "1.0.1";
            pmch.lang_code = "zh-tw";
            pmch.ipaddress = "127.0.0.1";

            CallJsonPay2 json = new CallJsonPay2();

            json.pmch_oid      = pmgw.pmchOid;
            json.is_3d         = "0";
            json.pay_currency  = data.currency;
            json.pay_amount    = Convert.ToDouble(data.currPriceTotal);
            json.return_url    = Website.Instance.Configuration["payRtnUrl:returnUrl"].ToString() + orderMid;
            json.cancel_url    = Website.Instance.Configuration["payRtnUrl:returnUrl"].ToString() + orderMid;
            json.user_locale   = UserData.LOCALE;// "zh-tw";
            json.paymentParam1 = "";
            json.paymentParam2 = "";

            if (prod.img_list.Count > 0)
            {
                json.logo_url = Website.Instance.Configuration["kkUrl:imgUrl"].ToString() + prod.img_list[0].img_kkday_url;
            }
            else
            {
                json.logo_url = "";
            }

            payment_source_info pay = new payment_source_info();

            pay.source_type = "KKDAY";
            pay.order_mid   = orderMid;

            json.payment_source_info = pay;
            credit_card_info credit = new credit_card_info();

            credit.card_holder = data.card.cardHolder;
            credit.card_no     = data.card.cardNo.Replace(" ", "");
            credit.card_type   = data.card.cardType;//"VISA";
            credit.card_cvv    = data.card.cardCvv;
            data.card.expiry   = data.card.expiry.Replace(" ", "").Replace("/", "");
            credit.card_exp    = "20" + data.card.expiry.Substring(2, 2) + data.card.expiry.Substring(0, 2);// "202312";

            json.credit_card_info = credit;

            payer_info payer = new payer_info();

            payer.first_name = UserData.NAME_LAST;
            payer.last_name  = UserData.NAME_LAST;
            payer.phone      = UserData.TEL;
            payer.email      = UserData.EMAIL;

            json.payer_info = payer;

            product_info prodInfo = new product_info();

            prodInfo.prod_name = prod.prod_name;
            prodInfo.prod_oid  = prod.prod_no.ToString();

            json.product_info = prodInfo;

            member member = new member();

            member.member_uuid = memUuid;
            member.risk_status = "01";
            member.ip          = "127.0.0.1";

            json.member = member;
            pmch.json   = json;

            return(pmch);// JsonConvert.SerializeObject(pmch);
        }
예제 #3
0
        public IActionResult bookingStep1([FromBody] DataModel data)
        {
            try
            {
                //B2d分銷商資料
                var aesUserData = User.Identities.SelectMany(i => i.Claims.Where(c => c.Type == ClaimTypes.UserData).Select(c => c.Value)).FirstOrDefault();
                var UserData    = JsonConvert.DeserializeObject <B2dAccount>(AesCryptHelper.aesDecryptBase64(aesUserData, Website.Instance.AesCryptKey));

                string ip = httpContextAccessor.HttpContext.Request.HttpContext.Connection.RemoteIpAddress.ToString().Replace("::1", "127.0.0.1");
                data = BookingRepostory.setCardEncrypt(data);
                //log時把卡號移除
                DataModel dataTemp = data.Clone();
                dataTemp.card = null;
                Website.Instance.logger.Debug($"bookingStep1_inputdata:{ JsonConvert.SerializeObject(dataTemp)}");

                ApiSetting api = new ApiSetting();
                api.apiKey    = "kkdayapi";
                api.userOid   = "1";
                api.ver       = "1.0.1";
                api.locale    = UserData.LOCALE;
                api.currency  = UserData.CURRENCY;
                api.ipaddress = ip;

                string prodStr = TempData["prod_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(prodStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                ProductModel prod = JsonConvert.DeserializeObject <ProductModel>(prodStr);

                string moduleStr = TempData["module_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(moduleStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                ProductModuleModel module = JsonConvert.DeserializeObject <ProductModuleModel>(moduleStr);

                string pkgStr = TempData["pkg_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(pkgStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                PkgDetailModel pkg = JsonConvert.DeserializeObject <PkgDetailModel>(pkgStr);

                string pkgConfirmStr = TempData["confirm_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(moduleStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                confirmPkgInfo confirm = JsonConvert.DeserializeObject <confirmPkgInfo>(pkgConfirmStr);

                string titleStr = TempData["ProdTitleKeep_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(moduleStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                ProdTitleModel title = JsonConvert.DeserializeObject <ProdTitleModel>(titleStr);

                string discRuleStr = TempData["pkgsDiscRule_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(discRuleStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                DiscountRuleModel rule = JsonConvert.DeserializeObject <DiscountRuleModel>(discRuleStr);

                string pmgwStr = TempData["pmgw_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(pmgwStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                Pmgw pmgw = JsonConvert.DeserializeObject <Pmgw>(pmgwStr);

                string showStr = TempData["prodShow_" + data.guidNo] as string;
                if (string.IsNullOrEmpty(showStr))
                {
                    throw new Exception("資料錯誤,請重新讀取頁");
                }
                //BookingShowProdModel show = JsonConvert.DeserializeObject<BookingShowProdModel>(showStr);

                TempData.Keep();

                //排除餐食
                data = BookingRepostory.exculdeFood(prod, data, module);

                string b2bOrder = BookingRepostory.insB2dOrder(title, prod, pkg, confirm, data, UserData, rule);

                //轉 ordermodel
                //OrderRepostory res = new OrderRepostory();
                //OrderModel ord = res.setOrderModel(data,pmgw,title);
                //api.json = ord;
                //string orderModelStr = JsonConvert.SerializeObject(api);
                //Website.Instance.logger.Debug($"bookingStep1_ordernewdata:{ JsonConvert.SerializeObject(orderModelStr)}");

                //KKapiHelper kk = new KKapiHelper();
                //JObject order =kk.crtOrder(api);
                JObject order = ApiHelper.orderNew(data, title);

                string       orderMid = "";
                string       orderOid = "";
                returnStatus status   = new returnStatus();

                Website.Instance.logger.Debug($"bookingStep1_ordernewresponse:" + JsonConvert.SerializeObject(order));//要改
                //要先判斷是不是result='0000'
                if (order["content"]["result"].ToString() == "0000")
                {
                    string memUuid = "051794b8-db2a-4fe7-939f-31ab1ee2c719";
                    orderMid = order["content"]["orderMid"].ToString();
                    orderOid = order["content"]["orderOid"].ToString();
                    status.pmchSslRequest = BookingRepostory.setPaymentInfo2(prod, data, orderMid, UserData, pmgw, memUuid);
                    status.status         = "OK";
                    status.url            = Website.Instance.Configuration["kkUrl:pmchUrl"].ToString() + pmgw.pmchPayURL; //pmchUrl

                    //要把BookingShowProdModel 帶到訂購final頁
                    RedisHelper.SetRedis(showStr, "b2d:ec:order:final:prodShow:" + orderMid, 60);
                    RedisHelper.SetRedis(JsonConvert.SerializeObject(data), "b2d:ec:order:final:orderData:" + orderMid, 60);

                    //要存redis 付款主要資訊,最後訂單 upd時要使用,可和下面整合存一個就
                    BookingRepostory.setPayDtltoRedis(data, orderMid, memUuid, RedisHelper);

                    //要存redis 因為付款後要從這個redis內容再進行payment驗證,可和上面整合存一個就好
                    //CallJsonPay rdsJson = (CallJsonPay)status.pmchSslRequest.json;
                    CallJsonPay2 rdsJson     = (CallJsonPay2)status.pmchSslRequest.json;
                    string       callPmchReq = JsonConvert.SerializeObject(status.pmchSslRequest.json);
                    RedisHelper.SetRedis(callPmchReq, "b2d:ec:pmchSslRequest:" + orderMid, 60);
                }
                else
                {
                    status.status = "Error";
                    status.msgErr = order["content"]["result"].ToString() + order["content"]["msg"].ToString();//要改
                }

                return(Json(status));
                //v1/channel/citi/auth
                //https://pmch.sit.kkday.com/citi/payment/auth
                //https://payment.kkday.com/v1/channel/adyen/auth
            }
            catch (Exception ex)
            {
                //error
                Website.Instance.logger.Debug($"bookingStep1_err_ordernew失敗:{ex.Message.ToString()}");
                returnStatus status = new returnStatus();
                status.status = "Error";
                status.msgErr = ex.Message.ToString();

                return(Json(status));
            }
        }