예제 #1
0
        public static void SendOrderCancelConfirmation(tbl_Orders order)
        {
            if (order != null && !string.IsNullOrEmpty(order.CustomerEMail))
            {
                var templateData = new Dictionary<string, object>();
                templateData.Add("$ORDERNO", order.OrderID.ToString());

                string template = GetTemplate(EmailVariables.OrderCancelConfirmation, templateData);

                var recipients = new List<string>() { order.CustomerEMail };
                MailSender.Instance.SendEmail(recipients, null, null, "Order Canceled", template);
            }
        }
예제 #2
0
        public PayPalPaymentStatus DoExpressCheckoutPayment(tbl_Orders order, string token, string payerId, string payPalCurrencyCode, string payPalReturnUrl, string payPalCancelUrl, string payPalUser, string payPalPassword, string payPalSignature, string payPalNvpSetExpressUrl, string invoiceID)
        {
            string resultToLog;

            NVPCodec encoder = InitializeEncoder(order);
            encoder[PayPalConsts.Method] = "DoExpressCheckoutPayment";
            encoder[PayPalConsts.Token] = token;
            encoder[PayPalConsts.PaymentAction] = "Sale";
            encoder[PayPalConsts.PayerId] = payerId;
            encoder[PayPalConsts.CurrencyCode] = payPalCurrencyCode;
            encoder[PayPalConsts.ReturnUrl] = payPalReturnUrl;
            encoder[PayPalConsts.CancelUrl] = payPalCancelUrl;
            encoder[PayPalConsts.User] = payPalUser;
            encoder[PayPalConsts.Pwd] = payPalPassword;
            encoder[PayPalConsts.Signature] = payPalSignature;
            encoder[PayPalConsts.InvoiceID] = invoiceID;

            string encoded = encoder.Encode();
            string result = resultToLog = HttpPost(payPalNvpSetExpressUrl, encoded, 30000);

            NVPCodec decoder = new NVPCodec();
            decoder.Decode(result);

            PayPalPaymentStatus payPalStatus = new PayPalPaymentStatus();

            payPalStatus.TransactionID = decoder[PayPalConsts.TransactionID];
            payPalStatus.Token = decoder[PayPalConsts.Token];
            payPalStatus.ACK = decoder[PayPalConsts.ACK];
            payPalStatus.PaymentStatus = decoder[PayPalConsts.PaymentStatus];
            payPalStatus.PendingReason = decoder[PayPalConsts.PendingReason];
            payPalStatus.ErrorCode = decoder[PayPalConsts.ErrorCode];
            payPalStatus.ErrorMessage = decoder[PayPalConsts.ErrorMessage];

            if (payPalStatus.ACK.ToLower() != "success")
            {
                ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.PayPal_DoExpressCheckout_Failure);
                resultToLog = Server.UrlDecode(resultToLog).Replace("&", Environment.NewLine);
                Log.Error(String.Format("PayPal payment - DoExpressCheckoutPayment failed: {0}", resultToLog));
            }

            return payPalStatus;
        }
예제 #3
0
        private string SetExpressCheckout(tbl_Orders order, string payPalReturnUrl, string payPalCancelUrl, string payPalUser, string payPalPassword, string payPalSignature, string payPalCurrencyCode, string payPalNvpSetExpressUrl, string payPalHost, string invoiceID, string languageCode)
        {
            string resultToLog;

            NVPCodec encoder = InitializeEncoder(order);
            encoder[PayPalConsts.Method] = "SetExpressCheckout";
            encoder[PayPalConsts.NoShipping] = "1";
            encoder[PayPalConsts.ReturnUrl] = payPalReturnUrl;
            encoder[PayPalConsts.CancelUrl] = payPalCancelUrl;
            encoder[PayPalConsts.User] = payPalUser;
            encoder[PayPalConsts.Pwd] = payPalPassword;
            encoder[PayPalConsts.Signature] = payPalSignature;
            encoder[PayPalConsts.CurrencyCode] = payPalCurrencyCode;
            encoder[PayPalConsts.InvoiceID] = invoiceID;

            if (!string.IsNullOrEmpty(languageCode))
            {
                encoder[PayPalConsts.LocaleCode] = languageCode;
            }

            string settings = encoder.GetSettings();
            Log.Info(settings);

            string encoded = encoder.Encode();
            string result = resultToLog = HttpPost(payPalNvpSetExpressUrl, encoded, 30000);

            NVPCodec decoder = new NVPCodec();
            decoder.Decode(result);

            string token = decoder[PayPalConsts.Token];
            if (decoder[PayPalConsts.ACK].ToLower() == "success" || decoder[PayPalConsts.ACK].ToLower() == "successwithwarning")
            {
                ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.PayPal_SetExpressCheckout_Success);
                ECommerceService.UpdateOrderSecurityKey(token, order.OrderID);
                return String.Format("{0}?cmd=_express-checkout&{1}={2}&{3}={4}", payPalHost, PayPalConsts.Token.ToLower(), token, PayPalConsts.Useraction, PayPalConsts.Commit);
            }
            else
            {
                ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.PayPal_SetExpressCheckout_Failure);
                resultToLog = Server.UrlDecode(resultToLog).Replace("&", Environment.NewLine);
                Log.Error(String.Format("PayPal payment - SetExpressCheckout failed: {0}", resultToLog));
            }

            return String.Empty;
        }
예제 #4
0
        private NVPCodec InitializeEncoder(tbl_Orders order)
        {
            decimal totalItemsPrice = order.tbl_OrderContent.Sum(oc => oc.OC_TotalPrice) + order.DependentOrders.Sum(o => o.TotalAmount);

            string totalAmount = Math.Round(order.TotalAmountToPay, 2).ToString().Replace(',', '.');
            string totalTaxAmount = Math.Round(order.TotalTaxAmount, 2).ToString().Replace(',', '.');
            string totalItemsAmount = order.O_IsCustomAmount ? order.TotalAmountToPay.ToString().Replace(',', '.') : Math.Round(totalItemsPrice, 2).ToString().Replace(',', '.');
            string totalShippingAmount = Math.Round(order.TotalDeliveryAmount, 2).ToString().Replace(',', '.');

            NVPCodec encoder = new NVPCodec();
            encoder[PayPalConsts.Version] = "98.0";
            encoder[PayPalConsts.TotalAmount] = totalAmount;
            encoder[PayPalConsts.DeliveryAmount] = totalShippingAmount;
            encoder[PayPalConsts.ItemsTotalAmount] = totalItemsAmount;

            if (order.DiscountAmount != 0)
            {
                decimal discount = order.DiscountAmount > totalItemsPrice ? totalItemsPrice : order.DiscountAmount;
                encoder[PayPalConsts.DiscountAmount] = Math.Round(-Math.Abs(discount), 2).ToString().Replace(',', '.');
            }

            // if order items should be listed in order details displayed on PayPal account
            if (DomainService.GetSettingsValueAsBool(BL.SettingsKey.payPalSendOrderItems, this.DomainID) && !order.O_IsCustomAmount)
            {
                int i = 0;
                foreach (var oc in order.tbl_OrderContent)
                {
                    encoder[PayPalConsts.GetItemNumberKey(i)] = oc.tbl_Products==null ? oc.tbl_ProductPrice.PR_ProductID.ToString() : oc.tbl_Products.P_ProductCode;
                    encoder[PayPalConsts.GetItemNameKey(i)] = oc.OC_Title ?? "";
                    encoder[PayPalConsts.GetItemDescriptionKey(i)] = oc.OC_Description ?? "";
                    encoder[PayPalConsts.GetItemQuantityKey(i)] = oc.OC_Quantity.ToString();
                    encoder[PayPalConsts.GetItemsTotalAmountKey(i)] = Math.Round(oc.OC_TotalPrice / oc.OC_Quantity.GetValueOrDefault(1), 2).ToString().Replace(',', '.');

                    i++;
                }
                if (order.DependentOrders.Any())
                {
                    foreach (var donation in order.DependentOrders)
                    {
                        encoder[PayPalConsts.GetItemNumberKey(i)] = donation.OrderID.ToString();
                        encoder[PayPalConsts.GetItemNameKey(i)] = String.Format("Donation to order {0}", order.OrderID);
                        encoder[PayPalConsts.GetItemDescriptionKey(i)] = "donation";
                        encoder[PayPalConsts.GetItemQuantityKey(i)] = "1";
                        encoder[PayPalConsts.GetItemsTotalAmountKey(i)] = Math.Round(donation.TotalAmount, 2).ToString().Replace(',', '.');

                        i++;
                    }
                }
            }

            return encoder;
        }
예제 #5
0
 private bool IncreaseStock(tbl_Orders order)
 {
     return ProductPriceRepository.IncreaseStockUnits(order.tbl_OrderContent);
 }
예제 #6
0
        public static void SendOrderConfirmation(tbl_Orders order)
        {
            if (order != null && !string.IsNullOrEmpty(order.CustomerEMail))
            {
                var templateData = new Dictionary<string, object>();
                templateData.Add("ORDERDATE", order.O_Timestamp.GetValueOrDefault());
                templateData.Add("DELIVERYDATE", order.O_DeliveryDate ?? String.Empty);
                templateData.Add("DOMAIN", order.tbl_Domains.DO_Domain);
                templateData.Add("ORDERID", order.OrderID);
                templateData.Add("INSTRUCTION", order.O_DeliveryNotes ?? String.Empty);
                templateData.Add("ISDISCOUNT", order.O_DiscountID.GetValueOrDefault(0) != 0);
                templateData.Add("ISDONATION", order.DependentOrders.Any());
                templateData.Add("DISCOUNTAMOUNT", order.GetDiscountAmountString());
                templateData.Add("DELIVERYAMOUNT", order.GetDeliveryAmountString());
                templateData.Add("TOTALAMOUNT", order.GetPriceString());
                templateData.Add("TOTALAMOUNTPAID", order.TotalAmountToPay.ToString("C"));

                templateData.Add("BADDRESS1", order.BillingAddress1 ?? String.Empty);
                templateData.Add("BADDRESS2", order.BillingAddress2 ?? String.Empty);
                templateData.Add("BADDRESS3", order.BillingAddress3 ?? String.Empty);
                templateData.Add("BNAME", order.BillingFirstnames + " " + order.BillingSurname);
                templateData.Add("BTOWN", order.BillingCity ?? String.Empty);
                templateData.Add("BCOUNTY", order.BillingState ?? String.Empty);
                templateData.Add("BPOSTCODE", order.BillingPostCode ?? String.Empty);
                templateData.Add("BCOUNTRY", order.BillingCountry ?? String.Empty);
                templateData.Add("BPHONE", order.BillingPhone ?? String.Empty);

                templateData.Add("DADDRESS1", order.DeliveryAddress1 ?? String.Empty);
                templateData.Add("DADDRESS2", order.DeliveryAddress2 ?? String.Empty);
                templateData.Add("DADDRESS3", order.DeliveryAddress3 ?? String.Empty);
                templateData.Add("DNAME", order.DeliveryFirstnames + " " + order.DeliverySurname);
                templateData.Add("DTOWN", order.DeliveryCity ?? String.Empty);
                templateData.Add("DCOUNTY", order.DeliveryState ?? String.Empty);
                templateData.Add("DPOSTCODE", order.DeliveryPostCode ?? String.Empty);
                templateData.Add("DCOUNTRY", order.DeliveryCountry ?? String.Empty);
                templateData.Add("DPHONE", order.DeliveryPhone ?? String.Empty);

                var products = order.tbl_OrderContent.Select(oc => new
                {
                    Name = oc.OC_Title ?? String.Empty,
                    Price = oc.GetItemPriceString(),
                    Quantity = oc.OC_Quantity.GetValueOrDefault(0),
                    TotalPrice = oc.GetPriceString()
                }).ToList();

                if (order.DependentOrders.Any())
                {
                    products.AddRange(order.DependentOrders.Select(o => new
                    {
                        Name = "Donation",
                        Price = o.TotalAmount.ToString(),
                        Quantity = (short)1,
                        TotalPrice = o.TotalAmount.ToString()
                    }));
                }
                templateData.Add("PRODUCTS", products);

                // switch between donations, products and events templates
                string template = order.O_ProductTypeID.HasValue && order.tbl_ProductTypes.PT_Name == ProductType.Donation.ToString() ?
                    GetTemplate(EmailVariables.DonationConfirmation, templateData) :
                    GetTemplate(EmailVariables.OrderConfirmation, templateData);

                // change email title accordingly
                string title = order.O_ProductTypeID.HasValue && order.tbl_ProductTypes.PT_Name == ProductType.Donation.ToString() ? "Donation Confirmation" : "Order Confirmation";

                var recipients = new List<string>() { order.CustomerEMail };
                MailSender.Instance.SendEmail(recipients, null, null, title, template);
            }
        }
예제 #7
0
 /// <summary>
 /// Deprecated Method for adding a new object to the tbl_Orders EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTotbl_Orders(tbl_Orders tbl_Orders)
 {
     base.AddObject("tbl_Orders", tbl_Orders);
 }
예제 #8
0
        private static Tuple<decimal, decimal> GetOrderPriceAndTax(tbl_Orders table)
        {
            if (table == null || table.tbl_OrderContent.Count == 0)
                return new Tuple<decimal, decimal>(0, 0);

            decimal totalPrice = 0, totalTaxAmount = 0;
            foreach (var content in table.tbl_OrderContent)
            {
                Tuple<decimal, decimal> priceAndTax = PriceManager.GetPrice(content.OC_Price.GetValueOrDefault(), content.OC_Tax.GetValueOrDefault(0), (int)content.OC_Quantity.GetValueOrDefault(0), table.O_DomainID);
                totalPrice += priceAndTax.Item1;
                totalTaxAmount += priceAndTax.Item2;
            }

            if (table.tbl_Discount != null)
            {
                Tuple<decimal, decimal> priceAndTax = PriceManager.AddDiscountToPrice(table.tbl_Discount, totalPrice, totalTaxAmount, table.O_DomainID);
                totalPrice = priceAndTax.Item1;
                totalTaxAmount = priceAndTax.Item2;
            }

            if (table.tbl_Postage != null)
            {
                decimal maxTax = table.tbl_OrderContent.Max(bc => bc.GetTaxValue());
                Tuple<decimal, decimal> postagePriceAndTax = PriceManager.GetPostagePriceAndTax(table.tbl_Postage, maxTax, table.O_DomainID);
                totalPrice += postagePriceAndTax.Item1;
                totalTaxAmount += postagePriceAndTax.Item2;
            }

            return new Tuple<decimal, decimal>(totalPrice, totalTaxAmount);
        }
예제 #9
0
 /// <summary>
 /// Create a new tbl_Orders object.
 /// </summary>
 /// <param name="orderID">Initial value of the OrderID property.</param>
 /// <param name="vendorTxCode">Initial value of the VendorTxCode property.</param>
 /// <param name="txType">Initial value of the TxType property.</param>
 /// <param name="amount">Initial value of the Amount property.</param>
 /// <param name="currency">Initial value of the Currency property.</param>
 /// <param name="txAuthNo">Initial value of the TxAuthNo property.</param>
 /// <param name="o_Exported">Initial value of the O_Exported property.</param>
 /// <param name="o_Weight">Initial value of the O_Weight property.</param>
 /// <param name="o_PaymentStatusID">Initial value of the O_PaymentStatusID property.</param>
 /// <param name="totalTaxAmount">Initial value of the TotalTaxAmount property.</param>
 /// <param name="totalDeliveryAmount">Initial value of the TotalDeliveryAmount property.</param>
 /// <param name="discountAmount">Initial value of the DiscountAmount property.</param>
 /// <param name="totalAmount">Initial value of the TotalAmount property.</param>
 /// <param name="o_DomainID">Initial value of the O_DomainID property.</param>
 /// <param name="o_IsCashSale">Initial value of the O_IsCashSale property.</param>
 /// <param name="o_IsCustomAmount">Initial value of the O_IsCustomAmount property.</param>
 public static tbl_Orders Createtbl_Orders(global::System.Int32 orderID, global::System.String vendorTxCode, global::System.String txType, global::System.Decimal amount, global::System.String currency, global::System.Int64 txAuthNo, global::System.Boolean o_Exported, global::System.Int16 o_Weight, global::System.Int32 o_PaymentStatusID, global::System.Decimal totalTaxAmount, global::System.Decimal totalDeliveryAmount, global::System.Decimal discountAmount, global::System.Decimal totalAmount, global::System.Int32 o_DomainID, global::System.Boolean o_IsCashSale, global::System.Boolean o_IsCustomAmount)
 {
     tbl_Orders tbl_Orders = new tbl_Orders();
     tbl_Orders.OrderID = orderID;
     tbl_Orders.VendorTxCode = vendorTxCode;
     tbl_Orders.TxType = txType;
     tbl_Orders.Amount = amount;
     tbl_Orders.Currency = currency;
     tbl_Orders.TxAuthNo = txAuthNo;
     tbl_Orders.O_Exported = o_Exported;
     tbl_Orders.O_Weight = o_Weight;
     tbl_Orders.O_PaymentStatusID = o_PaymentStatusID;
     tbl_Orders.TotalTaxAmount = totalTaxAmount;
     tbl_Orders.TotalDeliveryAmount = totalDeliveryAmount;
     tbl_Orders.DiscountAmount = discountAmount;
     tbl_Orders.TotalAmount = totalAmount;
     tbl_Orders.O_DomainID = o_DomainID;
     tbl_Orders.O_IsCashSale = o_IsCashSale;
     tbl_Orders.O_IsCustomAmount = o_IsCustomAmount;
     return tbl_Orders;
 }
예제 #10
0
파일: Stripe.cs 프로젝트: nhtera/CrowdCMS
        private StripeCustomer CreateStripeCustomer(string apiKey, tbl_Orders order, StripeCheckoutModel model)
        {
            var myCustomer = new StripeCustomerCreateOptions
            {
                Email = order.CustomerEMail,
                Description = order.BillingFullName,
                CardNumber = model.CreditCardNumber,
                CardExpirationYear = model.ExpiryYear.ToString(),
                CardExpirationMonth = model.ExpiryMonth.ToString()
            };

            var customerService = new StripeCustomerService(apiKey);
            var stripeCustomer = customerService.Create(myCustomer);

            return stripeCustomer;
        }
예제 #11
0
 private string UrlConstructor(tbl_Orders order)
 {
     string currencyCode = DomainService.GetSettingsValue(SettingsKey.secureTradingCurrencyCode, this.DomainID);
     NVPCodec encoder = InitializeEncoder(order, currencyCode);
     return "https://payments.securetrading.net/process/payments/choice?" + encoder.Encode();
 }
예제 #12
0
        private NVPCodec InitializeEncoder(tbl_Orders order, string currencyCode)
        {
            NVPCodec encoder = new NVPCodec();

            encoder[SecureTradingConsts.SiteReference] = GetReferenceSite(order.O_DomainID);
            encoder[SecureTradingConsts.CurrencyIso3a] = currencyCode;
            encoder[SecureTradingConsts.MainAmount] = order.TotalAmountToPay.ToString("C");
            encoder[SecureTradingConsts.Version] = "1";

            encoder[SecureTradingConsts.OrderReference] = order.OrderID.ToString();

            //encoder[SecureTradingConsts.BillingPremise]
            if (order.BillingAddress1 != null)
                encoder[SecureTradingConsts.BillingStreet] = order.BillingAddress1;
            if (order.BillingCity != null)
                encoder[SecureTradingConsts.BillingTown] = order.BillingCity;
            if (order.BillingState != null)
                encoder[SecureTradingConsts.BillingCounty] = order.BillingState;
            if (order.BillingPostCode != null)
                encoder[SecureTradingConsts.BillingPostCode] = order.BillingPostCode;

            if (order.BillingFirstnames != null)
                encoder[SecureTradingConsts.BillingFirstName] = order.BillingFirstnames;
            if (order.BillingSurname != null)
                encoder[SecureTradingConsts.BillingLastName] = order.BillingSurname;
            if (order.BillingCountry != null)
                encoder[SecureTradingConsts.BillingCountryIso2a] = order.BillingCountry;
            if (order.CustomerEMail != null)
                encoder[SecureTradingConsts.BillingEmail] = order.CustomerEMail;

            if (order.DeliveryAddress1 != null)
                encoder[SecureTradingConsts.CustomerStreet] = order.IsDeliverable ? order.DeliveryAddress1 : order.BillingAddress1;
            if (order.DeliveryCity != null)
                encoder[SecureTradingConsts.CustomerTown] = order.IsDeliverable ? order.DeliveryCity : order.BillingCity;
            if (order.DeliveryState != null)
                encoder[SecureTradingConsts.CustomerCounty] = order.IsDeliverable ? order.DeliveryState : order.BillingState;
            if (order.DeliveryPostCode != null)
                encoder[SecureTradingConsts.CustomerPostCode] = order.IsDeliverable ? order.DeliveryPostCode : order.BillingPostCode;
            if (order.DeliveryCountry != null)
                encoder[SecureTradingConsts.CustomerCountryIso2a] = order.IsDeliverable ? order.DeliveryCountry : order.BillingCountry;

            encoder[SecureTradingConsts.SiteSecurity] = CreateRequestSecurityCode(order, currencyCode);

            return encoder;
        }
예제 #13
0
        private string CreateRequestSecurityCode(tbl_Orders order, string currencyCode)
        {
            StringBuilder s = new StringBuilder();
            s.Append(order.TotalAmountToPay.ToString("C"))
            .Append(currencyCode)
            .Append(order.OrderID)
            .Append(GetReferenceSite(order.O_DomainID))
            .Append(DomainService.GetSettingsValue(SettingsKey.secureTradingRedirectPassword, this.DomainID));

            return Sha256.GetSHA256Hash(s.ToString());
        }