Exemplo n.º 1
0
        // Upload tracking number to ebay.
        //  CompleteSale
        //  https://developer.ebay.com/DevZone/XML/docs/Reference/ebay/CompleteSale.html
        public static bool UploadTrackingNumber(AccountType account, string itemId, string ebayTransId,
                                                string shippingCarrier, string shipmentTrackingNumber)
        {
            CompleteSaleCall completeSaleApiCall = new CompleteSaleCall(account.SellerApiContext);

            completeSaleApiCall.Shipment = new eBay.Service.Core.Soap.ShipmentType();

            ShipmentTrackingDetailsType shippingDetailsType = new ShipmentTrackingDetailsType();

            shippingDetailsType.ShippingCarrierUsed              = shippingCarrier;
            shippingDetailsType.ShipmentTrackingNumber           = shipmentTrackingNumber;
            completeSaleApiCall.Shipment.ShipmentTrackingDetails = new eBay.Service.Core.Soap.ShipmentTrackingDetailsTypeCollection();
            completeSaleApiCall.Shipment.ShipmentTrackingDetails.Add(shippingDetailsType);

            completeSaleApiCall.ItemID        = itemId;
            completeSaleApiCall.TransactionID = ebayTransId;

            bool result = false;

            try
            {
                completeSaleApiCall.Execute();
                result = true;
            }
            catch (System.Exception ex)
            {
                Logger.WriteSystemLog(string.Format("ERROR: UploadTrackingNumber failed with error msg={0}", ex.Message));
            }


            return(result);
        }
Exemplo n.º 2
0
        public void CompleteSale2()
        {
            CompleteSaleCall call = new CompleteSaleCall(this.apiContext);

            call.OrderID  = "436095409011";
            call.Shipment = new ShipmentType();

            ShipmentTrackingDetailsType shipmentTrackingDetails = new ShipmentTrackingDetailsType();

            shipmentTrackingDetails.ShippingCarrierUsed    = "DHL";
            shipmentTrackingDetails.ShipmentTrackingNumber = "6KH8F75870W5916";
            call.Shipment.ShipmentTrackingDetails          = new ShipmentTrackingDetailsTypeCollection();
            call.Shipment.ShipmentTrackingDetails.Add(shipmentTrackingDetails);
            call.Shipment.ShippedTime = DateTime.Now;
            call.Shipped = true;

            try
            {
                call.Execute();
            }
            catch (Exception ex)
            {
                bool err = call.ApiException.containsErrorCode("55");
                Assert.IsFalse(err);
            }
        }
Exemplo n.º 3
0
        public bool UpdateShipmentStatus(String orderid, String TrackingNum, String CarrierName)
        {
            String [] ids = orderid.Split('-');
            if (ids != null && ids.Length == 2)
            {
                CompleteSaleCall api = new CompleteSaleCall();
                api.ApiContext    = context;
                api.ItemID        = ids[0];
                api.TransactionID = ids[1];
                api.Paid          = true;
                api.Shipped       = true;

                api.Shipment = new ShipmentType();
                api.Shipment.ShipmentTrackingDetails = new ShipmentTrackingDetailsTypeCollection();

                ShipmentTrackingDetailsType shpmnt = new ShipmentTrackingDetailsType();
                shpmnt.ShipmentTrackingNumber = TrackingNum;
                shpmnt.ShippingCarrierUsed    = CarrierName;

                api.Shipment.ShipmentTrackingDetails.Add(shpmnt);
                api.Shipment.ShippedTime = DateTime.Now;

                //call the Execute method
                api.Execute();

                return(api.ApiResponse.Ack != AckCodeType.Failure);
            }
            return(false);
        }
Exemplo n.º 4
0
        public static void UploadSingleTrackingNum(string trackingNum, string orderNum, string carrier, string accountName, string token)
        {
            string senderEmail         = ConfigurationManager.AppSettings["senderEmail"];
            string messageFromPassword = ConfigurationManager.AppSettings["messageFromPassword"];
            string messageToEmail      = ConfigurationManager.AppSettings["messageToEmail"];
            string smtpClient          = ConfigurationManager.AppSettings["smtpClient"];
            int    smtpPortNum         = ConvertUtility.ToInt(ConfigurationManager.AppSettings["smtpPortNum"]);

            ApiContext context = new ApiContext();

            context.ApiCredential.eBayToken = token;
            context.SoapApiServerUrl        = "https://api.ebay.com/wsapi";
            context.ApiLogManager           = new ApiLogManager();
            context.ApiLogManager.ApiLoggerList.Add(new FileLogger("log.txt", false, false, true));
            context.ApiLogManager.EnableLogging = true;
            context.Version = "861";
            context.Site    = SiteCodeType.US;
            CompleteSaleCall completeSaleCall = new CompleteSaleCall(context);

            completeSaleCall.OrderID  = orderNum;
            completeSaleCall.Shipped  = true;
            completeSaleCall.Shipment = new ShipmentType();
            completeSaleCall.Shipment.ShipmentTrackingDetails = new ShipmentTrackingDetailsTypeCollection();
            ShipmentTrackingDetailsType shpmnt = new ShipmentTrackingDetailsType();

            shpmnt.ShipmentTrackingNumber = trackingNum;
            shpmnt.ShippingCarrierUsed    = carrier;
            completeSaleCall.Shipment.ShipmentTrackingDetails.Add(shpmnt);
            try
            {
                completeSaleCall.Execute();
                try
                {
                    Db.Db.UpdateShipmentInfoDt(orderNum, accountName, System.DateTime.Now);
                }
                catch (Exception ex)
                {
                    ExceptionUtility exceptionUtility = new ExceptionUtility();
                    exceptionUtility.CatchMethod(ex, accountName + ": completeSaleCall " + orderNum, ex.Message.ToString(), senderEmail, messageFromPassword, messageToEmail, smtpClient, smtpPortNum);
                }
            }
            catch (Exception ex)
            {
                ExceptionUtility exceptionUtility = new ExceptionUtility();
                exceptionUtility.CatchMethod(ex, accountName + ": completeSaleCall " + orderNum, ex.Message.ToString(), senderEmail, messageFromPassword, messageToEmail, smtpClient, smtpPortNum);
            }
        }
        public string FulfillOrder(string OrderLineItemID, string ItemId, string TransactionId, string Carrier, string Tracking)
        {
            try
            {
                ApiContext context = eBayCall.GetContext();

                CompleteSaleCall apicall = new CompleteSaleCall(context);

                //Either ItemID-TransactionID or OrderLineItemID or OrderID is required. If item is part of an order, specify OrderID.
                apicall.OrderLineItemID = OrderLineItemID;
                apicall.ItemID          = ItemId;
                apicall.TransactionID   = TransactionId;

                apicall.Shipped  = true;
                apicall.Shipment = new ShipmentType();
                apicall.Shipment.ShipmentTrackingDetails = new ShipmentTrackingDetailsTypeCollection();

                ShipmentTrackingDetailsType shpmnt = new ShipmentTrackingDetailsType();
                shpmnt.ShipmentTrackingNumber = Tracking;
                shpmnt.ShippingCarrierUsed    = Carrier;

                apicall.Shipment.ShipmentTrackingDetails.Add(shpmnt);

                // Specify time in GMT. This is an optional field.
                // If you don't specify a value for the ShippedTime, it will be defaulted to the time at which the call was made
                apicall.Shipment.ShippedTime = DateTime.Now.ToUniversalTime();

                // call the Execute method
                apicall.Execute();

                return(JsonConvert.SerializeObject(apicall.ApiResponse));
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Exemplo n.º 6
0
        public void CompleteSale2()
        {
            CompleteSaleCall call = new CompleteSaleCall(this.apiContext);
            call.OrderID = "436095409011";
            call.Shipment = new ShipmentType();

            ShipmentTrackingDetailsType shipmentTrackingDetails = new ShipmentTrackingDetailsType();
            shipmentTrackingDetails.ShippingCarrierUsed = "DHL";
            shipmentTrackingDetails.ShipmentTrackingNumber = "6KH8F75870W5916";
            call.Shipment.ShipmentTrackingDetails = new ShipmentTrackingDetailsTypeCollection();
            call.Shipment.ShipmentTrackingDetails.Add(shipmentTrackingDetails);
            call.Shipment.ShippedTime = DateTime.Now;
            call.Shipped = true;

            try
            {
                call.Execute();
            }
            catch (Exception ex)
            {
                bool err = call.ApiException.containsErrorCode("55");
                Assert.IsFalse(err);
            }
        }
    public CompleteSaleResponseType UpdateShippingInfo(string itemID, string transactionID, string trackingNumber, string userToken)
    {
        string callname = "CompleteSale";

        #region Initialise Needed Variables

        //Get the Server to use (Sandbox or Production)
        string serverUrl = ConfigurationManager.AppSettings["TradingService"];

        //SiteID = 0  (US) - UK = 3, Canada = 2, Australia = 15, ....
        string siteID = "0";

        eBayAPIInterfaceService service = new eBayAPIInterfaceService();
        string requestURL = serverUrl + "?callname=" + callname + "&siteid=" + siteID
                            + "&appid=" + AppID + "&version=" + version + "&routing=default";
        service.Url = requestURL;

        // Set credentials
        service.RequesterCredentials = new CustomSecurityHeaderType();
        service.RequesterCredentials.Credentials = new UserIdPasswordType();
        service.RequesterCredentials.Credentials.AppId = AppID;
        service.RequesterCredentials.Credentials.DevId = DevID;
        service.RequesterCredentials.Credentials.AuthCert = CertID;
        service.RequesterCredentials.eBayAuthToken = userToken;
        #endregion

        CompleteSaleRequestType request = new CompleteSaleRequestType();
        request.WarningLevel = WarningLevelCodeType.High;
        request.ItemID = itemID;
        request.TransactionID = transactionID;

        ShipmentType shipment = new ShipmentType();
        ShipmentTrackingDetailsType shipmentDetails = new ShipmentTrackingDetailsType();
        shipmentDetails.ShipmentTrackingNumber = trackingNumber;
        shipmentDetails.ShippingCarrierUsed = ConfigurationManager.AppSettings["ShippingCarrier"];
        shipment.ShipmentTrackingDetails = new ShipmentTrackingDetailsType[] { shipmentDetails };
        request.Shipment = shipment;
        request.Version = version;

        try
        {
            CompleteSaleResponseType response = service.CompleteSale(request);
            return response;
        }
        catch (Exception ex)
        {
            if (ex.Message.ToLower().Contains("auth token"))
                throw new InvalidEbayCredentialsException();
            else
                throw ex;
        }
    }
Exemplo n.º 8
0
        public static List <EbayTransactionType> GetAllOrders(AccountType account, TimeFilter timeFilter, StringCollection orderIds)
        {
            List <EbayTransactionType> transList = new List <EbayTransactionType>();

            GetOrdersCall getOrdersApiCall = new GetOrdersCall(account.SellerApiContext);

            getOrdersApiCall.IncludeFinalValueFee = true;
            DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] { DetailLevelCodeType.ReturnAll };
            getOrdersApiCall.DetailLevelList = new DetailLevelCodeTypeCollection(detailLevels);
            if (orderIds != null)
            {
                getOrdersApiCall.OrderIDList = orderIds;
            }

            try
            {
                OrderTypeCollection orders = getOrdersApiCall.GetOrders(timeFilter, TradingRoleCodeType.Seller, OrderStatusCodeType.All);

                foreach (OrderType order in orders)
                {
                    AddressType addressType            = order.ShippingAddress;
                    String      shippingAddress        = GetShippingAddressString(addressType);
                    String      shippingAddressCompact = GetShippingAddressCompactString(addressType);

                    bool completed = order.OrderStatus == OrderStatusCodeType.Completed;

                    foreach (TransactionType trans in order.TransactionArray)
                    {
                        #region Process each ebay transaction
                        // Check if this transaction has already be recorded in system.
                        String transId = trans.TransactionID;
                        if (transId == null || transId == "")
                        {
                            Logger.WriteSystemLog("GetAllOrders: Invalid transaction id, skip and continue.");
                            continue;
                        }

                        EbayTransactionType ebayTrans = new EbayTransactionType();
                        ebayTrans.SellerName        = account.ebayAccount;
                        ebayTrans.OrderId           = order.OrderID;
                        ebayTrans.OrderLineItemId   = trans.OrderLineItemID;
                        ebayTrans.EbayTransactionId = trans.TransactionID;
                        ebayTrans.EbayRecordId      = order.ShippingDetails.SellingManagerSalesRecordNumberSpecified ? order.ShippingDetails.SellingManagerSalesRecordNumber : -1;
                        ebayTrans.BuyerId           = order.BuyerUserID;

                        GetUserCall getUserApiCall = new GetUserCall(account.SellerApiContext);
                        getUserApiCall.UserID = order.BuyerUserID;
                        UserType user = getUserApiCall.GetUser();

                        // BuyerRating
                        if (user.FeedbackScoreSpecified)
                        {
                            ebayTrans.BuyerRating = user.FeedbackScore;
                        }
                        else
                        {
                            ebayTrans.BuyerRating = -1;
                        }

                        // BuyerCountryEbayCode
                        ebayTrans.BuyerCountryEbayCode = addressType.Country.ToString();
                        // BuyerCountry4PXCode
                        ebayTrans.BuyerCountry4PXCode = "";

                        // BuyerCountry
                        ebayTrans.BuyerCountry = addressType.CountryName;
                        // BuyerCompanyName
                        ebayTrans.BuyerCompanyName = StringUtil.GetSafeString(addressType.CompanyName);
                        // BuyerName
                        ebayTrans.BuyerName = addressType.Name;
                        // BuyerStateOrProvince
                        ebayTrans.BuyerStateOrProvince = addressType.StateOrProvince;
                        // BuyerCity
                        ebayTrans.BuyerCity = addressType.CityName;
                        // BuyerTel
                        ebayTrans.BuyerTel = addressType.Phone;
                        // BuyerMail
                        ebayTrans.BuyerMail = trans.Buyer.Email;
                        // BuyerPostalCode
                        ebayTrans.BuyerPostalCode = addressType.PostalCode;

                        // BuyerAddress
                        ebayTrans.BuyerAddress = shippingAddress;
                        // BuyerAddressCompact
                        ebayTrans.BuyerAddressCompact = shippingAddressCompact;
                        // BuyerAddressLine1
                        ebayTrans.BuyerAddressLine1 = addressType.Street1;
                        // BuyerAddressLine2
                        ebayTrans.BuyerAddressLine2 = addressType.Street2;
                        // BuyerPayPal
                        ebayTrans.BuyerPayPal = trans.Buyer.Email;

                        // ItemId
                        ebayTrans.ItemId = trans.Item.ItemID;

                        // What is the valid way to determine if there is a variation.
                        if (trans.Variation != null && trans.Variation.VariationTitle != null && trans.Variation.VariationTitle.Trim() != "")
                        {
                            // ItemTitle
                            ebayTrans.ItemTitle = trans.Variation.VariationTitle;
                            // ItemSKU
                            ebayTrans.ItemSKU = trans.Variation.SKU;
                        }
                        else
                        {
                            // ItemTitle
                            ebayTrans.ItemTitle = trans.Item.Title;
                            // ItemSKU
                            ebayTrans.ItemSKU = trans.Item.SKU;
                        }

                        // ItemPrice
                        if (trans.TransactionPrice != null)
                        {
                            ebayTrans.ItemPrice = trans.TransactionPrice.Value;
                        }
                        // SaleQuantity
                        ebayTrans.SaleQuantity = trans.QuantityPurchased;

                        if (trans.TransactionPrice != null)
                        {
                            // SalePrice
                            ebayTrans.SalePrice = trans.TransactionPrice.Value * trans.QuantityPurchased;
                            // TotalPrice
                            ebayTrans.TotalPrice = trans.TransactionPrice.Value * trans.QuantityPurchased;
                        }

                        // TODO: there may be multiple transactions in one order.
                        if (order.Total != null)
                        {
                            ebayTrans.TotalPrice = order.Total.Value;
                            ebayTrans.CurrencyId = order.Total.currencyID.ToString();
                        }
                        else
                        {
                            // Set a default value.
                            ebayTrans.TotalPrice = 0.0;
                            ebayTrans.CurrencyId = "";
                        }

                        // SaleDate
                        ebayTrans.SaleDate = order.CreatedTime;
                        // SaleDateCN
                        ebayTrans.SaleDateCN = order.CreatedTime.ToLocalTime();
                        // IsPaid
                        ebayTrans.IsPaid = order.PaidTimeSpecified;

                        // order.AmountPaid
                        // order.CheckoutStatus
                        //      ebayPaymentStatus
                        //      Status
                        // orderStatus
                        if (ebayTrans.IsPaid == false)
                        {
                            // Some payment is paid using credit card, and while PayPal is processing the payment,
                            // the transaction is marked as unpaid. we should view it as paid.
                            if (order.OrderStatusSpecified && order.OrderStatus == OrderStatusCodeType.Completed)
                            {
                                ebayTrans.IsPaid = true;
                            }
                        }

                        if (ebayTrans.IsPaid == false)
                        {
                            if (order.CheckoutStatus.StatusSpecified && order.CheckoutStatus.Status == CompleteStatusCodeType.Complete)
                            {
                                ebayTrans.IsPaid = true;
                            }
                        }

                        // PaidDate
                        ebayTrans.PaidDate = StringUtil.GetSafeDateTime(order.PaidTime);
                        // IsShipped
                        ebayTrans.IsShipped = order.ShippedTimeSpecified;
                        if (order.ShippedTimeSpecified)
                        {
                            ebayTrans.ShippedDate = StringUtil.GetSafeDateTime(order.ShippedTime);
                        }
                        else
                        {
                            ebayTrans.ShippedDate = DateTime.Now.AddYears(-10);
                        }

                        // Store the shippedDate as the local date time.
                        ebayTrans.ShippedDate = ebayTrans.ShippedDate.ToLocalTime();

                        // ShippingServiceCode
                        ebayTrans.ShippingServiceCode = "";
                        // ShippingService
                        ebayTrans.ShippingService = "";
                        // ShippingTrackingNo
                        ebayTrans.ShippingTrackingNo = "";
                        // ShippingCost
                        ebayTrans.ShippingCost = 0.0;
                        // FinalValueFee
                        if (trans.FinalValueFee != null)
                        {
                            ebayTrans.FinalValueFee = trans.FinalValueFee.Value;
                        }
                        else
                        {
                            ebayTrans.FinalValueFee = 0.0;
                        }
                        // PayPalFee
                        ebayTrans.PayPalFee = 0.034 * ebayTrans.TotalPrice + 0.3;

                        // IsReceived
                        ebayTrans.IsReceived             = false;
                        ebayTrans.IsBuyerLeftFeedback    = false;
                        ebayTrans.IsSellerLeftFeedback   = false;
                        ebayTrans.IsNeedAttention        = false;
                        ebayTrans.MessageStatus          = TransactionMessageStatus.NoMessage;
                        ebayTrans.IsContactedBuyer       = false;
                        ebayTrans.LastContactedBuyerDate = DateTime.Now.AddYears(-10);
                        ebayTrans.IsResendReplacement    = false;
                        ebayTrans.UserComment            = "";

                        GetFeedbackCall getFeedbackApiCall = new GetFeedbackCall(account.SellerApiContext);
                        //DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] { DetailLevelCodeType.ReturnAll };
                        getFeedbackApiCall.DetailLevelList = new DetailLevelCodeTypeCollection(detailLevels);
                        getFeedbackApiCall.OrderLineItemID = trans.OrderLineItemID;
                        FeedbackDetailTypeCollection feedbacks = getFeedbackApiCall.GetFeedback();
                        foreach (FeedbackDetailType feedback in feedbacks)
                        {
                            if (feedback.CommentingUser == account.ebayAccount)
                            {
                                ebayTrans.IsSellerLeftFeedback = true;
                            }

                            if (feedback.CommentingUser == ebayTrans.BuyerId)
                            {
                                ebayTrans.IsBuyerLeftFeedback = true;
                            }
                        }

                        if (trans.ShippingDetails != null)
                        {
                            if (trans.ShippingDetails.ShipmentTrackingDetails.Count == 1)
                            {
                                ShipmentTrackingDetailsType shipmentDetails = trans.ShippingDetails.ShipmentTrackingDetails[0];
                                ebayTrans.ShippingTrackingNo = shipmentDetails.ShipmentTrackingNumber;
                            }
                        }

                        transList.Add(ebayTrans);

                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteSystemLog(string.Format("Unexpected expection : {0}", ex.Message));
            }

            return(transList);
        }   // GetAllOrders
Exemplo n.º 9
0
        // Upload tracking number to ebay.
        //  CompleteSale
        //  https://developer.ebay.com/DevZone/XML/docs/Reference/ebay/CompleteSale.html
        public static bool UploadTrackingNumber(AccountType account, string itemId, string ebayTransId, 
            string shippingCarrier, string shipmentTrackingNumber)
        {
            CompleteSaleCall completeSaleApiCall = new CompleteSaleCall(account.SellerApiContext);
            completeSaleApiCall.Shipment = new eBay.Service.Core.Soap.ShipmentType();

            ShipmentTrackingDetailsType shippingDetailsType = new ShipmentTrackingDetailsType();
            shippingDetailsType.ShippingCarrierUsed = shippingCarrier;
            shippingDetailsType.ShipmentTrackingNumber = shipmentTrackingNumber;
            completeSaleApiCall.Shipment.ShipmentTrackingDetails = new eBay.Service.Core.Soap.ShipmentTrackingDetailsTypeCollection();
            completeSaleApiCall.Shipment.ShipmentTrackingDetails.Add(shippingDetailsType);

            completeSaleApiCall.ItemID = itemId;
            completeSaleApiCall.TransactionID = ebayTransId;

            bool result = false;
            try
            {
                completeSaleApiCall.Execute();
                result = true;
            }
            catch (System.Exception ex)
            {
                Logger.WriteSystemLog(string.Format("ERROR: UploadTrackingNumber failed with error msg={0}", ex.Message));
            }

            return result;
        }