private void RenderBasket(BasketDecorator basket) { if (basket != null && phBasket.Visible) { //If you can see this, you can't see the summary StateInfo.NotifyHideBasketSummary(null); try { ArrayList lines = basket.GetStandardItems(); rBasket.DataSource = lines; rBasket.DataBind(); //Now put in the quantities and translated alt text on the buttons if (rBasket.Items.Count == lines.Count) { for (int i = 0; i < lines.Count; i++) { TextBox txtQuantity = (TextBox)rBasket.Items[i].FindControl("txtQuantity"); if (txtQuantity != null) { txtQuantity.Text = ((IBasketLine)lines[i]).Quantity.ToString(); } DecorateUpdateButtons(i); } } } catch (Exception ex) { LogManager.GetLogger(GetType()).Error(ex); } } }
public void PopulatePayment(IElectronicPayment payment, IBasket order, ITextTranslator translator) { BasketDecorator basket = new BasketDecorator(order); payment.LocalRequestReference = basket.OrderHeader.OrderHeaderID.ToString(); payment.Description = string.Format(translator.GetText("web_store_purchase{0}"), payment.LocalRequestReference); payment.PaymentAmount = basket.GrandTotal; payment.PaymentDate = DateTime.Now; IUserDetails userDetails = (order.UserDetails != null) ? new UserDecorator(order.UserDetails) : order.AltUserDetails; //payment.UserInfo.UserDetails. = userDetails.FirstName + " " + userDetails.LastName; -- Is this needed? if(payment.UserInfo.UserDetails == null){ payment.UserInfo.UserDetails = userDetails; } IAddress invoiceAddress = basket.OrderHeader.InvoiceAddress; payment.UserInfo.UserAddress = invoiceAddress; if (invoiceAddress.AddressLine3 != null && invoiceAddress.AddressLine3.Length > 0) { payment.UserInfo.UserAddress.AddressLine2 = invoiceAddress.AddressLine2 + ", " + invoiceAddress.AddressLine3; } else { payment.UserInfo.UserAddress.AddressLine2 = invoiceAddress.AddressLine2; } payment.UserInfo.UserAddress.City = invoiceAddress.City; payment.UserInfo.UserAddress.Region = invoiceAddress.Region; payment.UserInfo.UserAddress.Postcode = invoiceAddress.Postcode; ITextTranslator ccTrans = TranslatorUtils.GetTextTranslator(typeof(CountryCode), translator.CultureCode); payment.UserInfo.UserAddress.CountryCode = invoiceAddress.CountryCode; }
protected virtual void RenderBasket(IBasket basket) { try { if (basket != null) { BasketDecorator decoratedBasket = new BasketDecorator(basket); litBasketTotal.Text = HtmlFormatUtils.FormatMoney(decoratedBasket.StandardItemPrice); ArrayList standardItems = decoratedBasket.GetStandardItems(); if (standardItems.Count > 0) { int itemCounter = 0; for (int i = 0; i < standardItems.Count; i++) { itemCounter += ((IBasketLine)standardItems[i]).Quantity; } ItemCount = itemCounter; } } } catch (System.Threading.ThreadAbortException) { } catch (Exception ex) { LogManager.GetLogger(GetType()).Error(ex); } }
public void BindOrder(IBasket order) { ECommerceModule mod = Module as ECommerceModule; Order = new BasketDecorator(order); Header = order.OrderHeader; rptBasketLines.DataSource = Order.GetStandardItems(); rptBasketLines.DataBind(); }
public BasketDecorator ProcessReceivedPayment(IElectronicPayment ccPayment, ITextTranslator translator) { try { long orderID = Int64.Parse(ccPayment.LocalRequestReference); IBasket basket = _dao.FindOrder(orderID); BasketDecorator order; if (basket != null) { order = new BasketDecorator(basket); } else { throw new InvalidOperationException("Could not find order for local ccPayment ref [" + ccPayment.LocalRequestReference + "]"); } //Make a record in the database about this ccPayment RecordPayment(basket, ccPayment); //Make sure this isn't already purchased if (order.IsPurchased) { throw new InvalidOperationException("Paid for order [" + order.OrderHeader.OrderHeaderID + "] more than once"); } //Make sure the amount is correct (assume the same currency) if (order.GrandTotal.Amount != (decimal) ccPayment.PaymentAmount.Amount) { throw new InvalidOperationException("Invalid ccPayment amount - expected " + order.GrandTotal.Amount + ", recieved " + ccPayment.PaymentAmount.Amount + " " + ccPayment.PaymentAmount.CurrencyCode); } //Either PO or successful credit card if (order.OrderHeader.PaymentMethod == PaymentMethodType.PurchaseOrderInvoice || ccPayment != null && (ccPayment.TransactionStatus == PaymentStatus.Approved || ccPayment.TransactionStatus == PaymentStatus.Referred)) { //This is a purchase order, or a direct credit card order return order; } } catch (Exception f) { LogManager.GetLogger(GetType()).Error(f); } return null; }
private void RetrieveBasketAndLastOrder(IStoreContext context) { if (context.CurrentBasket == null && context.BasketID > 0) { context.CurrentBasket = GetBasket(context.BasketID); //If we can't find the basket, no point looking again in future if (context.CurrentBasket == null) SetCurrentBasket(context, null); } //Set this as the last order, if necessary if (context.CurrentBasket != null) { BasketDecorator cbd = new BasketDecorator(context.CurrentBasket); if (cbd.IsPurchased || cbd.IsAwaitingAccountPaymentApproval) { //Update the order with basket details context.LastOrder = context.CurrentBasket; context.CurrentBasket = null; return; } } if (context.LastOrder == null && context.LastOrderID > 0) { context.LastOrder = GetBasket(context.LastOrderID); //If we can't find the last order, no point looking again in future if (context.LastOrder == null) context.LastOrderID = StoreContext.ID_NULL; } //Make sure this order is still current if (context.LastOrder != null) { BasketDecorator lod = new BasketDecorator(context.LastOrder); if (!lod.IsPurchased && !lod.IsAwaitingAccountPaymentApproval) { context.CurrentBasket = context.LastOrder; context.LastOrder = null; } } }
private void DisplayContents(IBasket basket) { Visible = true; if (basket != null) { BasketDecorator decorator = basket as BasketDecorator; if (decorator == null) { decorator = new BasketDecorator(basket); } if (!decorator.IsEmpty) { RenderBasket(CurrentBasket); pnlDetails.Visible = true; } } pnlEmpty.Visible = !pnlDetails.Visible; }
public void Process(IBasket order) { BasketDecorator dec = order as BasketDecorator; if (dec == null) { dec = new BasketDecorator(order); } //Remove any existing delivery charge dec.RemoveItems(BasketItemType.DeliveryCharge); decimal totalWeight = 0; foreach (IBasketLine line in order.BasketItemList) { BasketItem item = line as BasketItem; if (item != null && item.Product != null) { totalWeight += line.Quantity * GetProductWeight(item.Product.ProductID); } } string countryCode = "GB"; if (order.OrderHeader != null && (order.OrderHeader.DeliveryAddress != null || order.OrderHeader.InvoiceAddress != null)) { if (order.OrderHeader.DeliveryAddress != null) { countryCode = order.OrderHeader.DeliveryAddress.CountryCode; } else { countryCode = order.OrderHeader.InvoiceAddress.CountryCode; } } decimal cost = GetDeliveryChargeByWeight(countryCode, totalWeight); if (cost > 0 && order.BasketItemList.Count > 0) { //Where does this magic item come from? // We should have a variable in order header / basket that stores Delivery Charges. Not bodging it as an item. order.AddItem(BasketItemType.DeliveryCharge, "Delivery Charge", cost); } }
protected BasketDecorator GetLastOrder() { //Gets the last order placed in this session, usually the result of having just completed //a credit card order IBasket order = EModule.CommerceService.GetLastOrder(WebStoreContext.Current); if (order == null) { return null; } BasketDecorator decorator = order as BasketDecorator; if (decorator == null) { decorator = new BasketDecorator(order); } return decorator; }
protected BasketDecorator GetCurrentBasket() { IBasket basket = EModule.CommerceService.GetCurrentBasket(WebStoreContext.Current); if (basket == null) { return null; } BasketDecorator decorator = basket as BasketDecorator; if (decorator == null) { decorator = new BasketDecorator(basket); } return decorator; }
protected virtual void PopulateOrderDetailsFromForm(BasketDecorator basketOrder) { if (basketOrder.OrderHeader == null) { new BasketDecorator(basketOrder).ConvertToOrder(EModule.CommerceDao, EModule.CommonDao); basketOrder.OrderHeader.InvoiceAddress = EModule.CommerceDao.CreateAddress(); basketOrder.OrderHeader.DeliveryAddress = EModule.CommerceDao.CreateAddress(); basketOrder.OrderHeader.PaymentMethod = (IsAccountPayment) ? PaymentMethodType.PurchaseOrderInvoice : PaymentMethodType.CreditCard; } if (basketOrder.UserDetails == null) { basketOrder.UserDetails = WebStoreContext.Current.CurrentUser; } if (ctlInvoiceAddress != null) { AddressHelper.CopyAddress(ctlInvoiceAddress, basketOrder.OrderHeader.InvoiceAddress); } if (ctlDeliveryAddress != null && ctlDeliveryAddress.Enabled) { if (basketOrder.OrderHeader.DeliveryAddress == null) { basketOrder.OrderHeader.DeliveryAddress = EModule.CommerceDao.CreateAddress(); } AddressHelper.CopyAddress(ctlDeliveryAddress, basketOrder.OrderHeader.DeliveryAddress); } else { basketOrder.OrderHeader.DeliveryAddress = null; } if (ctlUser != null && basketOrder.AltUserDetails != null) { UserDetailsHelper.CopyUserDetails(ctlUser, basketOrder.AltUserDetails); } //Might need to set other things from the entered details, //or force a final price/availability for all items UpdateExtraDetails(); //See if any of these details have changed anything EModule.CommerceService.RefreshBasket(WebStoreContext.Current); if (ctlUser != null && basketOrder.AltUserDetails == null) { UserDetail userDetail = new UserDetail(); userDetail.AccountType = (IsAccountPayment) ? AccountType.StandardAccount : AccountType.CreditCard; basketOrder.AltUserDetails = userDetail; UserDetailsHelper.CopyUserDetails(ctlUser, basketOrder.AltUserDetails); EModule.CommonDao.SaveOrUpdateObject(userDetail); EModule.CommerceService.RefreshBasket(WebStoreContext.Current); } //Show saved details ctlOrderViewComposite.BindOrder(basketOrder); }
protected virtual void SubmitAccountOrder(BasketDecorator basketOrder) { //probably redundant, but must ensure it is true IsAccountPayment = true; if (basketOrder.OrderHeader == null) { new BasketDecorator(basketOrder).ConvertToOrder(EModule.CommerceDao, EModule.CommonDao); basketOrder.OrderHeader.PaymentMethod = PaymentMethodType.PurchaseOrderInvoice; } if (ctlUserAcct != null && basketOrder.AltUserDetails != null) { UserDetail userDetails = basketOrder.AltUserDetails as UserDetail; CopyUserDetailsInfo(ctlUserAcct, userDetails); } //See if any of these details have changed anything EModule.CommerceService.RefreshBasket(WebStoreContext.Current); if (ctlUserAcct != null && basketOrder.AltUserDetails == null) { UserDetail userDetail = new UserDetail(); basketOrder.AltUserDetails = userDetail; CopyUserDetailsInfo(ctlUserAcct, userDetail); EModule.CommonDao.SaveOrUpdateObject(userDetail); EModule.CommerceService.RefreshBasket(WebStoreContext.Current); } if (EModule.CommerceService.SubmitCurrentOrder(WebStoreContext.Current, this)) { WebStoreContext.Current.NotifyBasketChanged(null); } }
protected virtual void CollectPayment(BasketDecorator basketOrder) { IElectronicPayment payment = new PaymentHelper(EModule.CommerceDao).CreatePayment(basketOrder, this); IPaymentProvider provider = EModule.PaymentProvider;//HACK to get it to compile MUST FIX IWebFormPaymentProvider webProvider = provider as IWebFormPaymentProvider; if (webProvider != null) { webProvider.TransferClientToPaymentPage(payment, PaymentRequestTypes.ImmediatePayment); } else { if (provider != null) { provider.RequestAuthPayment(payment); IBasket order = new PaymentHelper(EModule.CommerceDao).ProcessReceivedPayment(payment, this); if (order != null) { EModule.CommerceService.CloseOrder(order, TranslatorUtils.GetTextTranslator(GetType(), order.CultureCode)); } } else { //What?? PopulateOrderDetailsFromForm(basketOrder); } } }
/// <summary> /// Action performed before the order is closed and confirmation is shown /// </summary> protected virtual void CloseOrder(BasketDecorator basketOrder) { if (!basketOrder.IsPurchased) { EModule.CommerceService.CloseCurrentOrder(WebStoreContext.Current, this); } }
protected virtual void PerformStepActions(CheckoutStep oldStep, CheckoutStep newStep, BasketDecorator basketOrder) { //Hide all of the steps phStep1.Visible = phStep1a.Visible = phStep2a.Visible = phStep2b.Visible = phStep3a.Visible = phStep3b.Visible = false; btnPrevious.Visible = (newStep != CheckoutStep.SelectPaymentMethod); switch (newStep) { case CheckoutStep.ShowCompletedOrder: if (IsAccountPayment) { phStep3a.Visible = true; } else { phStep3b.Visible = true; } CloseOrder(basketOrder); ShowCompletedOrder(); btnNext.Visible = false; btnPrevious.Visible = false; break; case CheckoutStep.ConfirmDetails: if (IsAccountPayment) { phStep3a.Visible = true; btnNext.Text = GetText("submit order request"); } else { phStep3b.Visible = true; btnNext.Text = GetText("proceed to payment"); } PopulateOrderDetailsFromForm(basketOrder); break; case CheckoutStep.ProceedToPayment: if (IsAccountPayment) { phStep2a.Visible = true; } else { phStep2b.Visible = true; } CollectPayment(basketOrder); break; case CheckoutStep.EnterAddressDetails: if (IsAccountPayment) { phStep2a.Visible = true; } else { phStep2b.Visible = true; } btnNext.Text = GetText("proceed to step 3"); break; case CheckoutStep.SelectPaymentMethod: phStep1.Visible = true; btnNext.Text = GetText("proceed to step 2"); break; case CheckoutStep.EnterAccountDetails: phStep2a.Visible = true; btnNext.Text = GetText("submit order request"); break; case CheckoutStep.ShowSubmittedOrder: phStep3a.Visible = true; SubmitAccountOrder(basketOrder); btnNext.Visible = false; btnPrevious.Visible = false; break; case CheckoutStep.Login: phStep1a.Visible = true; btnNext.Visible = false; btnPrevious.Visible = false; ctlLogin.RedirectTo = this.Page.Request.RawUrl; break; } }
private void SetAndActionNewStep(CheckoutStep newStep, BasketDecorator basketOrder) { CheckoutStep oldStep = Step; Step = newStep; PerformStepActions(oldStep, Step, basketOrder); }
protected virtual void PopulateExtraDetails(BasketDecorator basketOrder) { if (basketOrder.OrderHeader == null || basketOrder.OrderHeader.InvoiceAddress == null) { //See if the user has any address details IAddress defaultAddress = basketOrder.UserDetails as IAddress; if (defaultAddress != null) { ctlInvoiceAddress.BindAddress(defaultAddress); ctlDeliveryAddress.CountryCode = ctlInvoiceAddress.CountryCode; } } }
private void PopulateUserDetails(BasketDecorator basketOrder, IStoreContext context) { if (basketOrder.UserDetails != null || basketOrder.AltUserDetails != null) { UserDetail userDetails = ((basketOrder.UserDetails != null) ? new UserDecorator(basketOrder.UserDetails) : basketOrder.AltUserDetails) as UserDetail; if (ctlUser != null && userDetails != null) { ctlUser.BindUserDetails(userDetails); } if (ctlUserAcct != null && basketOrder.UserDetails != null) { ctlUserAcct.BindUserDetails(userDetails); txtAccountNumber.Text = userDetails.AccountNumber; txtCompanyName.Text = userDetails.CompanyName; } } else { if (context != null && context.WebStoreUser != null) { if (ctlUser != null && context.WebStoreUser.UserDetails != null) { ctlUser.BindUserDetails(context.WebStoreUser.UserDetails); } } } }
//Make a note of whether this payment worked private void RecordPayment(IBasket order, IElectronicPayment ccPayment) { IPaymentRecord payment = _dao.CreatePaymentRecord(order); BasketDecorator basketOrder = new BasketDecorator(order); payment.Basket = order; payment.PaymentMethod = order.OrderHeader.PaymentMethod; payment.PaymentAmount = basketOrder.GrandTotal; payment.PaymentDate = System.DateTime.Now; payment.TransactionReference = ccPayment.TransactionReference; payment.TransactionStatus = ccPayment.TransactionStatus; payment.PaymentProviderID = 1; // provider.PaymentProviderID; _dao.Save(payment); }
protected virtual CheckoutStep GetNextStep(CheckoutStep currentStep, BasketDecorator basketOrder) { //Can't move on unless the current page is valid if (!Page.IsValid) { return currentStep; } switch (currentStep) { case CheckoutStep.SelectPaymentMethod: return (!IsAccountPayment) ? CheckoutStep.EnterAddressDetails : CheckoutStep.EnterAccountDetails; case CheckoutStep.EnterAccountDetails: return CheckoutStep.ShowSubmittedOrder; case CheckoutStep.EnterAddressDetails: return CheckoutStep.ConfirmDetails; default: if (basketOrder.OrderHeader != null && basketOrder.OrderHeader.PaymentMethod == PaymentMethodType.PurchaseOrderInvoice) { return CheckoutStep.ShowCompletedOrder; } else { return CheckoutStep.ProceedToPayment; } } }
public bool CloseOrder(IBasket order, ITextTranslator translator) { BasketDecorator b = new BasketDecorator(order); if (b.IsPurchased) { throw new InvalidOperationException("Cannot close an order that is already purchased"); } order.OrderHeader.Status = Util.Enums.OrderStatus.OrderedPaid; order.OrderHeader.OrderedDate = DateTime.Now; IOrderProcessor processor = _processorFactory.GetCloseProcessor(); if (processor != null) { processor.Process(order); } //And save the results _dao.Save(order); return true; }
public bool SubmitOrder(IBasket order, ITextTranslator translator) { BasketDecorator b = new BasketDecorator(order); if (b.IsPurchased || b.OrderHeader.Status == OrderStatus.OrderedSubmittedForAccountPayment) { throw new InvalidOperationException("Cannot close an order that is already purchased or submitted"); } order.OrderHeader.Status = Util.Enums.OrderStatus.OrderedSubmittedForAccountPayment; order.OrderHeader.OrderedDate = DateTime.Now; IOrderProcessor processor = _processorFactory.GetProcessor("order.submit"); if (processor != null) { processor.Process(order); } //And save the results _dao.Save(order); return true; }
public void EmptyBasket(IStoreContext context) { BasketDecorator basket = new BasketDecorator(GetCurrentBasket(context)); basket.Empty(); }
private XmlDocument CreatePaymentXml(IElectronicPayment payment, string transactionType) { CreditCardPayment ccPayment = (CreditCardPayment) payment; XmlNode orderFormDoc = CreateOrderFormDoc(); AppendCcApiStringField(ref orderFormDoc, XML_TAG_ID, payment.LocalRequestReference); AppendCcApiStringField(ref orderFormDoc, XML_TAG_PAYMENT_MODE, PaymentMode); AppendCcApiStringField(ref orderFormDoc, XML_TAG_COMMENTS, Comments); //Consumer XmlNode consumer = AppendCcApiRecord(ref orderFormDoc, XML_TAG_CONSUMER); AppendCcApiStringField(ref consumer, XML_TAG_EMAIL, ccPayment.UserInfo.UserDetails.EmailAddress); XmlNode paymentMech = AppendCcApiRecord(ref consumer, XML_TAG_PAYMENT_MECHANISM); //Address verification information if (payment.UserInfo.UserAddress.AddressLine1.Length > 0 && payment.UserInfo.UserAddress.Postcode.Length > 0) { AppendAvsElements(ref consumer, payment); } //Credit card XmlNode creditCard = AppendCcApiRecord(ref paymentMech, XML_TAG_CREDIT_CARD); AppendCcApiStringField(ref creditCard, XML_TAG_CREDIT_CARD_NUMBER, ccPayment.CardNumber); AppendCcApiStartDateField(ref creditCard, XML_TAG_CREDIT_CARD_START_DATE, ccPayment.CardValidFromMonth, ccPayment.CardValidFromYear, ccPayment.PaymentAmount.Currency.CurrencyCodeNumeric); AppendCcApiExpirationDateField(ref creditCard, XML_TAG_CREDIT_CARD_EXPIRES, ccPayment.CardExpiresEndMonth, ccPayment.CardExpiresEndYear, ccPayment.PaymentAmount.Currency.CurrencyCodeNumeric); if (ccPayment.CardIssueNumber.Length > 0) { AppendCcApiStringField(ref creditCard, XML_TAG_CREDIT_CARD_ISSUE_NUMBER, ccPayment.CardIssueNumber); } //CVM Stuff if (ccPayment.CardCvmNumber.Length > 0) { AppendCcApiStringField(ref creditCard, XML_TAG_CVM_VALUE, ccPayment.CardCvmNumber); AppendCcApiStringField(ref creditCard, XML_TAG_CVM_INDICATOR, "" + CVM_VALUE_SUBMITTED_BY_STORE); } //Transaction XmlNode transaction = AppendCcApiRecord(ref orderFormDoc, XML_TAG_TRANSACTION); AppendCcApiStringField(ref transaction, XML_TAG_TRANSACTION_TYPE, transactionType); //Totals XmlNode currentTotals = AppendCcApiRecord(ref transaction, XML_TAG_CURRENT_TOTALS); XmlNode totals = AppendCcApiRecord(ref currentTotals, XML_TAG_TOTALS); AppendCcApiMoneyField(ref totals, XML_TAG_TOTAL, ccPayment.PaymentAmount); if (ccPayment.Basket != null) { BasketDecorator basket = new BasketDecorator(ccPayment.Basket); AppendCcApiMoneyField(ref totals, XML_TAG_SHIPPING_CHARGE, basket.DeliveryPrice); AppendCcApiMoneyField(ref totals, XML_TAG_VAT, basket.TaxPrice); AppendOrderItems(ref orderFormDoc, ccPayment.Basket); } return orderFormDoc.OwnerDocument; }
private void PopulateAddressDetails(BasketDecorator basketOrder, IStoreContext context) { //Sort out the country list IList countryList = EModule.AccountService.GetCountries(); if (ctlInvoiceAddress != null) { ctlInvoiceAddress.SetAvailableCountries(countryList); } if (ctlDeliveryAddress != null) { ctlDeliveryAddress.SetAvailableCountries(countryList); } //Populate any details already in the order if (basketOrder.OrderHeader != null) { if (ctlInvoiceAddress != null && basketOrder.OrderHeader.InvoiceAddress != null) { ctlInvoiceAddress.BindAddress(basketOrder.OrderHeader.InvoiceAddress); } if (ctlDeliveryAddress != null && basketOrder.OrderHeader.DeliveryAddress != null) { ctlDeliveryAddress.BindAddress(basketOrder.OrderHeader.DeliveryAddress); } } else { if (context != null && context.WebStoreUser != null) { if (ctlDeliveryAddress != null && context.WebStoreUser.UserDetails != null) { ctlInvoiceAddress.BindAddress(context.WebStoreUser.UserAddress); ctlDeliveryAddress.BindAddress(context.WebStoreUser.UserAddress); } } } }