Beispiel #1
0
        private async Task <string> TradeInfo(StatusNotification sn)
        {
            SearchOrders so = new SearchOrders
            {
                MerchantID        = sn.MerchantID,
                AllPayLogisticsID = sn.AllPayLogisticsID,
                TimeStamp         = (Int32)DateTimeOffset.Now.ToUnixTimeSeconds(),
                HashKey           = Merchant.HashKey,
                HashIV            = Merchant.HashIV,
                PlatformID        = string.Empty
            };

            _searchOrder.EnableSecurityProtocol = true;
            var request = await _searchOrder.PostAsyncForECPay(Links.TradeInfo, so);

            if (request.Success)
            {
                if (request.Response.Substring(0, 1) != "0")
                {
                    var json = ObjectConvert <TradeInfoResponse> .QueryStringToJson(request.Response);

                    return(json.HandlingCharge.ToString());
                }
                else
                {
                    return(request.Response);
                }
            }
            else
            {
                return(request.Message);
            }
        }
Beispiel #2
0
        public async Task <HttpResponseMessage> test()
        {
            var sp = new StorePickup
            {
                MerchantID        = "2000132",
                GoodsAmount       = 110,
                IsCollection      = "N",
                LogisticsSubType  = "UNIMART",
                LogisticsType     = "CVS",
                MerchantTradeDate = $"{DateTime.Now.ToString()}",
                ReceiverCellPhone = "0983337029",
                ReceiverName      = "Superuser",
                ReceiverStoreID   = "991182",
                SenderCellPhone   = "0912345678",
                SenderName        = "六加天",
                SenderPhone       = "041234567",
                ServerReplyURL    = "http://example.com",
                HashKey           = "5294y06JbISpM5x9",
                HashIV            = "v77hoKGq4kWxNNIS",
                PlatformID        = ""
            };

            _storePickup.EnableSecurityProtocol = true;
            var html = await _storePickup.PostAsyncForECPay(ECPayTestURL.SHIPPING_ORDER, sp);

            var result = ObjectConvert <StatusNotification> .QueryStringToJson(html.Response);

            return(Request.CreateResponse(new { result }));
        }
Beispiel #3
0
        public async Task <HttpResponseMessage> StorePickup(int orderId, StorePickup value)
        {
            //預設值 不能做更改
            value.MerchantID        = Merchant.MerchantID;
            value.HashKey           = Merchant.HashKey;
            value.HashIV            = Merchant.HashIV;
            value.SenderName        = Merchant.SenderName;
            value.SenderPhone       = Merchant.SenderPhone;
            value.SenderCellPhone   = Merchant.SenderCellphone;
            value.MerchantTradeDate = DateTime.Now.ToString();
            value.IsCollection      = Merchant.IsCollection ? "Y" : "N";
            value.ServerReplyURL    = $"{Http}://{Host}/api/ECPay/ECPay/Message?orderId={orderId}";

            _storePickup.EnableSecurityProtocol = true;
            var request = await _storePickup.PostAsyncForECPay(Links.Create, value);

            if (request.Success)
            {
                if (request.Response.Substring(0, 1) != "0" && request.Response.Substring(0, 2) != "10")
                {
                    var json = ObjectConvert <StatusNotification> .QueryStringToJson(request.Response);

                    if (json.RtnCode == 300)
                    {
                        string info = await TradeInfo(json);

                        if (int.TryParse(info, out int temp))
                        {
                            _orderRepository.UpdateOrder(orderId, json.AllPayLogisticsID, "080", temp);
                        }

                        var ptd = new PrintTradeDocument
                        {
                            MerchantID        = Merchant.MerchantID,
                            AllPayLogisticsID = json.AllPayLogisticsID,
                            PlatformID        = "",
                            HashKey           = Merchant.HashKey,
                            HashIV            = Merchant.HashIV
                        };

                        string printHtml = _tradeDocument.PrintForECPay(Links.TradeDocument, ptd);

                        return(Request.CreateResponse(new { html = printHtml }));
                    }
                    else
                    {
                        return(Request.CreateResponse(new { message = json.RtnMsg }));
                    }
                }
                else
                {
                    return(Request.CreateResponse(new { message = request.Response }));
                }
            }
            else
            {
                return(Request.CreateResponse(new { message = request.Message }));
            }
        }
Beispiel #4
0
        public async Task <HttpResponseMessage> HelloWorld()
        {
            var sp = new SearchOrders
            {
                MerchantID        = "2000132",
                AllPayLogisticsID = "158805",
                TimeStamp         = (Int32)DateTimeOffset.Now.ToUnixTimeSeconds(),
                HashKey           = "5294y06JbISpM5x9",
                HashIV            = "v77hoKGq4kWxNNIS",
                PlatformID        = ""
            };

            if (ModelState.IsValid)
            {
                _searchOrder.EnableSecurityProtocol = true;
                var response = await _searchOrder.PostAsyncForECPay(ECPayTestURL.QUERY_LOGISTICS_INFO, sp);

                if (response.Success)
                {
                    if (response.Response.Substring(0, 1) != "0")
                    {
                        var json = ObjectConvert <TradeInfoResponse> .QueryStringToJson(response.Response);

                        return(Request.CreateResponse(new { json }));
                    }
                    else
                    {
                        var result = new
                        {
                            message = response.Response.Substring(2)
                        };
                        return(Request.CreateResponse(new { result }));
                    }
                }
                else
                {
                    return(Request.CreateResponse(new { response }));
                }
            }

            else
            {
                return(Request.CreateResponse(new { message = false }));
            }
        }