protected void gvSubscriptions_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "CancelSubscription") { var lineItemId = Convert.ToInt64(e.CommandArgument); var lineItem = CurrentOrder.Items.SingleOrDefault(y => y.Id == lineItemId); var payManager = new OrderPaymentManager(CurrentOrder, HccApp); var res = payManager.RecurringSubscriptionCancel(lineItemId); if (res.Succeeded) { lineItem.RecurringBilling.LoadPaymentInfo(HccApp); ucMessageBox.ShowOk(Localization.GetString("CancelledSuccessfully")); var handler = OrderEdited; if (handler != null) { handler(this, EventArgs.Empty); } } else { foreach (var error in res.Errors) { ucMessageBox.ShowError(error.Description); } } } }
public override bool Execute(OrderTaskContext context) { var result = true; if (context.Order.IsRecurring) { _app = context.HccApp; _payManager = new OrderPaymentManager(context.Order, _app); var infoList = _payManager.RecurringSubscriptionInfoListAll(); var transactions = _app.OrderServices.Transactions.FindForOrder(context.Order.bvin); foreach (var info in infoList) { info.CreditCard.SecurityCode = context.Inputs.GetProperty("hcc", "CardSecurityCode"); foreach (var li in context.Order.Items) { if (HasSuccessfulLinkedAction(transactions, info, li.Id)) { var note = new OrderNote("Skipping creation of subscription. Transaction " + info.Id); context.Order.Notes.Add(note); } else { result &= ProcessTransaction(context, info, li); } } } } return(result); }
public void AddUpdateOrderPaymentToNebim(string orderNumber, int paymentType, string creditCardTypeCode, byte installment, string maskedCCNo, string provisionNo) { _logger.Warning("OrderPaymentManager opm = new OrderPaymentManager(_NebimIntegrationSettings);"); OrderPaymentManager opm = new OrderPaymentManager(_NebimIntegrationSettings); opm.SavePayment(orderNumber, (myPaymentTypes)paymentType, creditCardTypeCode, installment, maskedCCNo, provisionNo); }
public static bool ChargeSingleOrder(HotcakesApplication app, Order o) { if (o == null) { return(false); } var payManager = new OrderPaymentManager(o, app); payManager.GiftCardCompleteAllGiftCards(); app.OrderServices.Orders.Update(o); payManager = new OrderPaymentManager(o, app); payManager.CreditCardCompleteAllCreditCards(); payManager.PayPalExpressCompleteAllPayments(); if (o.PaymentStatus == OrderPaymentStatus.Paid || o.PaymentStatus == OrderPaymentStatus.Overpaid) { if (o.ShippingStatus == OrderShippingStatus.FullyShipped) { o.StatusCode = OrderStatusCode.Completed; o.StatusName = "Completed"; } else { o.StatusCode = OrderStatusCode.ReadyForShipping; o.StatusName = "Ready to Ship"; } app.OrderServices.Orders.Update(o); return(true); } return(false); }
protected void gridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { var gridView = sender as GridView; var Id = (long)gridView.DataKeys[e.RowIndex].Value; var lineItem = CurrentOrder.Items.SingleOrDefault(y => y.Id == Id); if (lineItem != null) { // Before removing lineitem try to cancel subscription if (CurrentOrder.IsRecurring && !lineItem.RecurringBilling.IsCancelled) { var payManager = new OrderPaymentManager(CurrentOrder, HccApp); var res = payManager.RecurringSubscriptionCancel(lineItem.Id); } lineItem.QuantityReserved = lineItem.Quantity; HccApp.CatalogServices.InventoryLineItemUnreserveInventory(lineItem); CurrentOrder.Items.Remove(lineItem); HccApp.CalculateOrder(CurrentOrder); HccApp.OrderServices.EvaluatePaymentStatus(CurrentOrder); HccApp.OrderServices.Orders.Update(CurrentOrder); } var handler = OrderEdited; if (handler != null) { handler(this, EventArgs.Empty); } }
private void CreateOrder(HotcakesApplication app, DateTime timeOfOrder, string[] skus, int[] quantities = null, bool isPlaced = true) { var o = new Order { StoreId = app.CurrentStore.Id, TimeOfOrderUtc = timeOfOrder, IsPlaced = isPlaced }; for (var i = 0; i < skus.Length; i++) { var qty = 1; if (quantities != null && i < quantities.Length) { qty = quantities[i]; } AddProductToCart(app, o, skus[i], qty); } app.CalculateOrderAndSave(o); // Place order o.IsPlaced = isPlaced; app.OrderServices.Orders.Update(o); if (isPlaced) { // Pay for order var pm = new OrderPaymentManager(o, app); pm.OfflinePaymentAddInfo(o.TotalGrand, "Cash"); CashReceive(app, pm, o.TotalGrand, o); } }
static void Main(string[] args) { var paymentManager = new OrderPaymentManager(); //Validate all payment processors var validationResult = paymentManager.Validate(); if (!validationResult.Success) { Console.WriteLine("Validation failed"); } //Process all payments (both deposit and authorization) var processResult = paymentManager.Process(); if (!processResult.Success) { // if fails, rollback paymentManager.Rollback(); Console.WriteLine("Rollback process"); } //Commit all processor result if (processResult.Success) { paymentManager.Commit(); Console.WriteLine("Committed process"); } }
public JsonResult CancelSubscription(string orderId, long lineItemId) { var o = HccApp.OrderServices.Orders.FindForCurrentStore(orderId); var payManager = new OrderPaymentManager(o, HccApp); var res = payManager.RecurringSubscriptionCancel(lineItemId); return(GetStatusMessage(res)); }
public override bool Execute(OrderTaskContext context) { bool result = true; if (context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth > 0) { CustomerPointsManager pointsManager = new CustomerPointsManager(context.HccApp.CurrentRequestContext); OrderPaymentManager payManager = new OrderPaymentManager(context.Order, context.HccApp); List <OrderTransaction> transactions = context.HccApp.OrderServices.Transactions .FindForOrder(context.Order.bvin) .OrderByDescending(x => x.TimeStampUtc) .ToList(); decimal dueAmount = context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth; foreach (OrderTransaction p in transactions) { if (p.Action == ActionType.RewardPointsInfo) { // if we already have an auth or charge on the card, skip if (p.HasSuccessfulLinkedAction(ActionType.RewardPointsDecrease, transactions) || p.HasSuccessfulLinkedAction(ActionType.RewardPointsHold, transactions)) { continue; } try { int points = pointsManager.PointsNeededForPurchaseAmount(p.Amount); if (context.HccApp.CurrentRequestContext.CurrentStore.Settings.PaymentCreditCardAuthorizeOnly) { payManager.RewardsPointsHold(p, points); } else { payManager.RewardsPointsCharge(p, points); } } catch (Exception ex) { context.Errors.Add(new WorkflowMessage("Exception During Receive Rewards Points", ex.Message + ex.StackTrace, false)); } dueAmount = context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth; //Amount required in order is already charged. No need to charge on other transactions if (dueAmount <= 0) { break; } } } } return(result); }
public HttpResponseMessage CapturePayment(string orderId, string transactionId, string amount) { var order = HccApp.OrderServices.Orders.FindForCurrentStore(orderId); var payManager = new OrderPaymentManager(order, HccApp); var authTrans = payManager.FindTransactionById(transactionId); var dAmount = Convert.ToDecimal(amount); var status = payManager.CreditCardCapture(transactionId, dAmount); return(Request.CreateResponse(HttpStatusCode.OK, status)); }
private bool ProcessTransaction(OrderTaskContext context, OrderTransaction p) { bool result = true; try { var payManager = new OrderPaymentManager(context.Order, context.HccApp); var orderNumber = !string.IsNullOrEmpty(p.OrderNumber) ? p.OrderNumber : context.Order.OrderNumber; Transaction t = payManager.CreateEmptyTransaction(); t.Card = p.CreditCard; t.Card.SecurityCode = context.Inputs.GetProperty("hcc", "CardSecurityCode"); t.Amount = p.Amount; t.Items = GetLineItemsForTransaction(context, orderNumber); if (context.HccApp.CurrentStore.Settings.PaymentCreditCardAuthorizeOnly) { t.Action = ActionType.CreditCardHold; } else { t.Action = ActionType.CreditCardCharge; } PaymentGateway proc = PaymentGateways.CurrentPaymentProcessor(context.HccApp.CurrentStore); proc.ProcessTransaction(t); OrderTransaction ot = new OrderTransaction(t); ot.LinkedToTransaction = p.IdAsString; context.HccApp.OrderServices.AddPaymentTransactionToOrder(context.Order, ot); if (!t.Result.Succeeded || t.Action == ActionType.CreditCardIgnored) { foreach (var m in t.Result.Messages) { if (m.Severity == MessageType.Error || m.Severity == MessageType.Warning) { context.Errors.Add(new WorkflowMessage("Payment Error:", m.Description, true)); } } result = false; } } catch (Exception ex) { context.Errors.Add(new WorkflowMessage("Exception During Receive Credit Card", ex.Message + ex.StackTrace, false)); OrderNote note = new OrderNote(); note.IsPublic = false; note.Note = "EXCEPTION: " + ex.Message + " | " + ex.StackTrace; context.Order.Notes.Add(note); } return(result); }
private void CashReceive(HotcakesApplication app, OrderPaymentManager pm, decimal amount, Order o) { var t = pm.CreateEmptyTransaction(); t.Amount = amount; t.Action = ActionType.CashReceived; var ot = new OrderTransaction(t) { Success = true, TimeStampUtc = o.TimeOfOrderUtc }; app.OrderServices.AddPaymentTransactionToOrder(o, ot); }
private void SavePaymentSelections(CheckoutViewModel model) { OrderPaymentManager payManager = new OrderPaymentManager(model.CurrentOrder, MTApp); payManager.ClearAllNonStoreCreditTransactions(); bool found = false; if (model.PaymentViewModel.SelectedPayment == "creditcard") { found = true; payManager.CreditCardAddInfo(model.PaymentViewModel.DataCreditCard, model.CurrentOrder.TotalGrandAfterStoreCredits(MTApp.OrderServices)); } if ((found == false) && (model.PaymentViewModel.SelectedPayment == "check")) { found = true; payManager.OfflinePaymentAddInfo(model.CurrentOrder.TotalGrandAfterStoreCredits(MTApp.OrderServices), "Customer will pay by check."); } if ((found == false) && (model.PaymentViewModel.SelectedPayment == "telephone")) { found = true; payManager.OfflinePaymentAddInfo(model.CurrentOrder.TotalGrandAfterStoreCredits(MTApp.OrderServices), "Customer will call with payment info."); } if ((found == false) && (model.PaymentViewModel.SelectedPayment == "purchaseorder")) { found = true; payManager.PurchaseOrderAddInfo(model.PaymentViewModel.DataPurchaseOrderNumber.Trim(), model.CurrentOrder.TotalGrandAfterStoreCredits(MTApp.OrderServices)); } if ((found == false) && (model.PaymentViewModel.SelectedPayment == "companyaccount")) { found = true; payManager.CompanyAccountAddInfo(model.PaymentViewModel.DataCompanyAccountNumber.Trim(), model.CurrentOrder.TotalGrandAfterStoreCredits(MTApp.OrderServices)); } if ((found == false) && (model.PaymentViewModel.SelectedPayment == "cod")) { found = true; payManager.OfflinePaymentAddInfo(model.CurrentOrder.TotalGrandAfterStoreCredits(MTApp.OrderServices), "Customer will pay cash on delivery."); } if ((found == false) && (model.PaymentViewModel.SelectedPayment == "paypal")) { found = true; // Need token and id before we can add this to the order // Handled on the checkout page. //payManager.PayPalExpressAddInfo(o.TotalGrand); } }
private void SavePaymentInfo(CheckoutViewModel model) { var token = model.PayPalToken; var payerId = model.PayPalPayerId; if (!string.IsNullOrEmpty(payerId)) { // This is to fix a bug with paypal returning multiple payerId's payerId = payerId.Split(',')[0]; } var payManager = new OrderPaymentManager(model.CurrentOrder, HccApp); payManager.PayPalExpressAddInfo(model.CurrentOrder.TotalGrand, token, payerId); }
public Order Get(string id) { var data = HccApp.OrderServices.Orders.FindForCurrentStore(id); if (data != null) { var order = HccApp.OrderServices.Orders.FindForCurrentStore(data.bvin); var payManager = new OrderPaymentManager(order, HccApp); var auths = payManager.CreditCardHoldListAll(); var paySummary = HccApp.OrderServices.PaymentSummary(order); return(new Order { OrderId = data.bvin, OrderDate = DateHelper.ConvertUtcToStoreTime(HccApp, data.TimeOfOrderUtc), CustomerName = string.Format("{0} {1}", data.BillingAddress.FirstName, data.BillingAddress.LastName), CustomerEmail = data.UserEmail, CustomerPhone = data.BillingAddress.Phone, TotalDiscounts = TotalOrderDiscounts(data), Total = data.TotalGrand, OrderNumber = data.OrderNumber, StatusCode = data.StatusName, PaymentStatus = data.PaymentStatus.ToString(), ShippingStatus = data.ShippingStatus.ToString(), ShippingPrice = data.TotalShippingBeforeDiscounts, Tax = data.TotalTax, Items = data.Items.Select(i => new OrderItem { ProductName = i.ProductName, PricePerItem = i.BasePricePerItem, Quantity = i.Quantity }).ToList(), PendingHolds = auths.Select(a => new HoldTransaction { CardInfo = a.CreditCard.CardTypeName + "-" + a.CreditCard.CardNumberLast4Digits + " - " + a.Amount.ToString("c"), TransactionId = a.IdAsString }).ToList(), SpecialInstructions = data.Instructions, PaymentAmountAuthorized = paySummary.AmountAuthorized, PaymentAmountCharged = paySummary.AmountCharged, PaymentAmountRefunded = paySummary.AmountRefunded, PaymentAmountDue = paySummary.AmountDue }); } return(null); }
public JsonResult Save(FormCollection form) { var model = new EditBillingViewModel(); if (TryUpdateModel(model)) { var orderId = model.OrderId; var o = HccApp.OrderServices.Orders.FindForCurrentStore(orderId); var payManager = new OrderPaymentManager(o, HccApp); model.AddressModel.CopyTo(o.BillingAddress); HccApp.OrderServices.Orders.Update(o); var cardForm = model.PaymentModel.CreditCardForm; var cardData = new CardData { CardNumber = cardForm.CardNumber, ExpirationMonth = cardForm.ExpirationMonth, ExpirationYear = cardForm.ExpirationYear, SecurityCode = cardForm.SecurityCode, CardHolderName = cardForm.CardHolderName }; foreach (var li in o.Items) { li.RecurringBilling.LoadPaymentInfo(HccApp); if (!li.RecurringBilling.IsCancelled) { var result = payManager.RecurringSubscriptionUpdate(li.Id, cardData); if (!result.Succeeded) { ModelState.AddModelError("rbUpdate", string.Format("Subscription '{0}' update failed.", li.ProductName)); } } } if (ModelState.IsValid) { return(Json(new { Status = "OK", Message = string.Empty })); } } return(Json(new { Status = "Invalid", Message = GetValidationSummaryMessage() })); }
private void SavePaymentInfo() { var payManager = new OrderPaymentManager(CurrentOrder, HccApp); payManager.ClearAllNonStoreCreditTransactions(); // Don't add payment info if gift cards or points cover the entire order. var total = CurrentOrder.TotalGrandAfterStoreCredits(HccApp.OrderServices); if (total <= 0 && !CurrentOrder.IsRecurring) { return; } if (rbCreditCard.Checked) { var creditCardData = ucCreditCardInput.GetCardData(); if (!CurrentOrder.IsRecurring) { payManager.CreditCardAddInfo(creditCardData, total); } else { payManager.RecurringSubscriptionAddCardInfo(creditCardData); } } else if (rbPurchaseOrder.Checked) { payManager.PurchaseOrderAddInfo(txtPurchaseOrder.Text.Trim(), total); } else if (rbCompanyAccount.Checked) { payManager.CompanyAccountAddInfo(txtAccountNumber.Text.Trim(), total); } else if (rbCheck.Checked) { payManager.OfflinePaymentAddInfo(total, Localization.GetFormattedString("CustomerPayByCheck")); } else if (rbTelephone.Checked) { payManager.OfflinePaymentAddInfo(total, Localization.GetString("CustomerPayByPhone")); } else if (rbCashOnDelivery.Checked) { payManager.OfflinePaymentAddInfo(total, Localization.GetString("CustomerPayCod")); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); PayManager = new OrderPaymentManager(CurrentOrder, HccApp); if (CurrentOrder != null) { currentOrderTransactions = HccApp.OrderServices.Transactions.FindForOrder(CurrentOrder.bvin); paySummary = HccApp.OrderServices.PaymentSummary(CurrentOrder); } if (!Page.IsPostBack) { mvPayments.SetActiveView(viewCreditCards); LoadCreditCardLists(); } }
private void SavePaymentInfo(Order o) { OrderPaymentManager payManager = new OrderPaymentManager(o, MTApp); payManager.ClearAllNonStoreCreditTransactions(); bool found = false; if (this.rbCreditCard.Checked == true) { found = true; payManager.CreditCardAddInfo(this.CreditCardInput1.GetCardData(), o.TotalGrandAfterStoreCredits(MTApp.OrderServices)); } if ((found == false) && (this.rbCheck.Checked == true)) { found = true; payManager.OfflinePaymentAddInfo(o.TotalGrandAfterStoreCredits(MTApp.OrderServices), "Customer will pay by check."); } if ((found == false) && (this.rbTelephone.Checked == true)) { found = true; payManager.OfflinePaymentAddInfo(o.TotalGrandAfterStoreCredits(MTApp.OrderServices), "Customer will call with payment info."); } if ((found == false) && (this.rbPurchaseOrder.Checked == true)) { found = true; payManager.PurchaseOrderAddInfo(this.PurchaseOrderField.Text.Trim(), o.TotalGrandAfterStoreCredits(MTApp.OrderServices)); } if ((found == false) && (this.rbCompanyAccount.Checked == true)) { found = true; payManager.CompanyAccountAddInfo(this.accountnumber.Text.Trim(), o.TotalGrandAfterStoreCredits(MTApp.OrderServices)); } if ((found == false) && (this.rbCOD.Checked == true)) { found = true; payManager.OfflinePaymentAddInfo(o.TotalGrandAfterStoreCredits(MTApp.OrderServices), "Customer will pay cash on delivery."); } MTApp.OrderServices.Orders.Update(o); }
private void LoadPaymentModel(EditBillingViewModel model, Order order) { var payManager = new OrderPaymentManager(order, HccApp); var pModel = new PaymentViewModel { PaymentMethods = PaymentMethods.EnabledMethods(HccApp.CurrentStore, true), CreditCardForm = { AcceptedCardTypes = HccApp.CurrentStore.Settings.PaymentAcceptedCards } }; var trInfo = payManager.GetLastCreditCardTransaction(); pModel.CreditCardForm.ExpirationMonth = trInfo.CreditCard.ExpirationMonth; pModel.CreditCardForm.ExpirationYear = trInfo.CreditCard.ExpirationYear; pModel.CreditCardForm.CardHolderName = trInfo.CreditCard.CardHolderName; pModel.CreditCardForm.CardNumber = "XXXXXXXXXXXX" + trInfo.CreditCard.CardNumberLast4Digits; model.PaymentModel = pModel; }
public void LoadPaymentInfo(HotcakesApplication app) { var o = app.OrderServices.Orders.FindForCurrentStore(_li.OrderBvin); var payMan = new OrderPaymentManager(o, app); var payments = payMan.RecurringPaymentsGetByLineItem(_li.Id); TotalPayed = payments.Sum(t => t.Amount); var paymentsCount = payments.Count; StartsOn = o.TimeOfOrderUtc; if (IntervalType == RecurringIntervalType.Days) { NextPaymentDate = StartsOn.AddDays(Interval * paymentsCount); } else if (IntervalType == RecurringIntervalType.Months) { NextPaymentDate = StartsOn.AddMonths(Interval * paymentsCount); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); orderId = Request.QueryString["id"]; o = MyPage.MTApp.OrderServices.Orders.FindForCurrentStore(orderId); payManager = new OrderPaymentManager(o, MyPage.MTApp); if (!Page.IsPostBack) { this.mvPayments.SetActiveView(this.viewCreditCards); LoadCreditCardLists(); if (MyPage.MTApp.CurrentStore.PlanId < 2) { //this.lnkCash.Visible = false; this.lnkCheck.Visible = false; this.lnkPO.Visible = false; } } }
public void UpdateGiftCardsStatus(Order o, bool enabled, HotcakesApplication app) { var payManager = new OrderPaymentManager(o, app); foreach (var item in o.Items.Where(i => i.IsGiftCard)) { var cards = app.CatalogServices.GiftCards.FindByLineItem(item.Id); foreach (var card in cards) { if (enabled) { payManager.GiftCardActivate(card.CardNumber); } else { payManager.GiftCardDeactivate(card.CardNumber); } } } }
static void Main(string[] args) { PaymentManager payment = new OrderPaymentManager(); Random random = new Random(); double total = random.Next(50, 100); Console.Write("1. Nakit Ödeme\n2. Kredi Kartı ile Ödeme\n3. Kupon ile Ödeme\n\n{0} Tutarında ki ödemenizi nasıl ödemek isteriniz: ", total); while (true) { int operation = Convert.ToInt32(Console.ReadLine()); switch (operation) { case 1: payment._payment = new CashPayment(); break; case 2: payment._payment = new CartPayment(); break; case 3: payment._payment = new CouponPayment(); break; } if (payment._payment != null) { break; } Console.Write("Lütfen doğru bir ödeme yöntemi seçiniz: "); } Console.WriteLine("\n\n***********\n"); payment.Pay(total); Console.ReadKey(); }
private void ApplyRewardsPoints(CheckoutViewModel model) { // Remove any current points info transactions foreach (OrderTransaction t in MTApp.OrderServices.Transactions.FindForOrder(model.CurrentOrder.bvin)) { if (t.Action == MerchantTribe.Payment.ActionType.RewardPointsInfo) { MTApp.OrderServices.Transactions.Delete(t.Id); } } // Don't add if we're not using points if (!model.UseRewardsPoints) { return; } // Apply Info to Order OrderPaymentManager payManager = new OrderPaymentManager(model.CurrentOrder, MTApp); payManager.RewardsPointsAddInfo(RewardsPotentialCredit(model)); }
public static void CollectPaymentAndShipPendingOrders(HotcakesApplication app) { var criteria = new OrderSearchCriteria(); criteria.IsPlaced = true; criteria.StatusCode = OrderStatusCode.ReadyForPayment; var pageSize = 1000; var totalCount = 0; var orders = app.OrderServices.Orders.FindByCriteriaPaged(criteria, 1, pageSize, ref totalCount); if (orders != null) { foreach (var os in orders) { var o = app.OrderServices.Orders.FindForCurrentStore(os.bvin); var payManager = new OrderPaymentManager(o, app); payManager.GiftCardCompleteAllGiftCards(); payManager.CreditCardCompleteAllCreditCards(); payManager.PayPalExpressCompleteAllPayments(); if (o.PaymentStatus == OrderPaymentStatus.Paid || o.PaymentStatus == OrderPaymentStatus.Overpaid) { if (o.ShippingStatus == OrderShippingStatus.FullyShipped) { o.StatusCode = OrderStatusCode.Completed; o.StatusName = "Completed"; } else { o.StatusCode = OrderStatusCode.ReadyForShipping; o.StatusName = "Ready for Shipping"; } app.OrderServices.Orders.Update(o); } } } }
public override bool Execute(OrderTaskContext context) { var result = true; if (context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth > 0) { List <OrderTransaction> transactions = context.HccApp.OrderServices.Transactions .FindForOrder(context.Order.bvin) .OrderByDescending(x => x.TimeStampUtc) .ToList(); decimal dueAmount = context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth; foreach (OrderTransaction p in transactions) { if (p.Action == ActionType.GiftCardInfo) { // if we already have an auth or charge on the card, skip if (p.HasSuccessfulLinkedAction(ActionType.GiftCardDecrease, transactions) || p.HasSuccessfulLinkedAction(ActionType.GiftCardCapture, transactions) || p.HasSuccessfulLinkedAction(ActionType.GiftCardHold, transactions)) { var note = new OrderNote(); note.IsPublic = false; note.Note = "Skipping receive for gift card info because auth or charge already exists. Transaction " + p.Id; context.Order.Notes.Add(note); continue; } try { var payManager = new OrderPaymentManager(context.Order, context.HccApp); var storeSettings = context.HccApp.CurrentStore.Settings; Transaction t = payManager.CreateEmptyTransaction(); t.GiftCard.CardNumber = p.GiftCard.CardNumber; t.Amount = p.Amount; GiftCardGateway proc = storeSettings.PaymentCurrentGiftCardProcessor(); if (storeSettings.PaymentGiftCardAuthorizeOnly && proc.CanAuthorize) { t.Action = ActionType.GiftCardHold; } else { t.Action = ActionType.GiftCardDecrease; } proc.ProcessTransaction(t); OrderTransaction ot = new OrderTransaction(t); ot.LinkedToTransaction = p.IdAsString; context.HccApp.OrderServices.AddPaymentTransactionToOrder(context.Order, ot); if (t.Result.Succeeded == false) { result = false; } } catch (Exception ex) { context.Errors.Add(new WorkflowMessage("Exception During Receive Gift Card", ex.Message + ex.StackTrace, false)); OrderNote note = new OrderNote(); note.IsPublic = false; note.Note = "EXCEPTION: " + ex.Message + " | " + ex.StackTrace; context.Order.Notes.Add(note); } dueAmount = context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth; //Amount required in order is already charged. No need to charge on other transactions if (dueAmount <= 0) { break; } } } } else { var note = new OrderNote(); note.IsPublic = false; note.Note = "Amount due was less than zero. Skipping receive gift cards"; context.Order.Notes.Add(note); } if (!result) { string errorString = "An error occurred while attempting to process your gift card. Please check your payment information and try again"; context.Errors.Add(new WorkflowMessage("Receive Gift Card Failed", errorString, true)); // Failure Status Code string failCode = OrderStatusCode.OnHold; OrderStatusCode c = OrderStatusCode.FindByBvin(failCode); if (c != null) { context.Order.StatusCode = c.Bvin; context.Order.StatusName = c.StatusName; } } return(result); }
public override bool Execute(OrderTaskContext context) { bool result = true; if (context.MTApp.OrderServices.PaymentSummary(context.Order).AmountDue > 0) { foreach (OrderTransaction p in context.MTApp.OrderServices.Transactions.FindForOrder(context.Order.bvin)) { List <OrderTransaction> transactions = context.MTApp.OrderServices.Transactions.FindForOrder(context.Order.bvin); if (p.Action == MerchantTribe.Payment.ActionType.PayPalExpressCheckoutInfo) { // if we already have an auth or charge on the card, skip if (p.HasSuccessfulLinkedAction(MerchantTribe.Payment.ActionType.PayPalHold, transactions) || p.HasSuccessfulLinkedAction(MerchantTribe.Payment.ActionType.PayPalCharge, transactions)) { continue; } try { Orders.OrderPaymentManager payManager = new OrderPaymentManager(context.Order, context.MTApp); bool transactionSuccess = false; if (context.MTApp.CurrentRequestContext.CurrentStore.Settings.PayPal.ExpressAuthorizeOnly) { transactionSuccess = payManager.PayPalExpressHold(p, context.MTApp.OrderServices.PaymentSummary(context.Order).AmountDue); } else { transactionSuccess = payManager.PayPalExpressCharge(p, context.MTApp.OrderServices.PaymentSummary(context.Order).AmountDue); } if (transactionSuccess == false) { result = false; } } catch (Exception ex) { context.Errors.Add(new WorkflowMessage("Exception During Receive Paypal Express Payments", ex.Message + ex.StackTrace, false)); } finally { Orders.OrderPaymentStatus previousPaymentStatus = context.Order.PaymentStatus; context.MTApp.OrderServices.EvaluatePaymentStatus(context.Order); context.Inputs.Add("bvsoftware", "PreviousPaymentStatus", previousPaymentStatus.ToString()); BusinessRules.Workflow.RunByName(context, WorkflowNames.PaymentChanged); } } } } if (result == false) { // Add Error bool throwErrors = true; //throwErrors = this.SettingsManager.GetBooleanSetting("ThrowErrors"); if (throwErrors == true) { if (result == false) { string errorString = string.Empty; // this.SettingsManager.GetSetting("CustomerErrorMessage"); if (errorString == string.Empty) { errorString = "An error occured while attempting to process your Paypal Express payment. Please check your payment information and try again"; } context.Errors.Add(new WorkflowMessage("Receive Card Failed", errorString, true)); } } else { // Hide Error result = true; } // Failure Status Code bool SetStatus = false; SetStatus = true; // this.SettingsManager.GetBooleanSetting("SetStatusOnFail"); if (SetStatus == true) { string failCode = Orders.OrderStatusCode.OnHold; Orders.OrderStatusCode c = Orders.OrderStatusCode.FindByBvin(failCode); if (c != null) { context.Order.StatusCode = c.Bvin; context.Order.StatusName = c.StatusName; } } } return(result); }
public override bool Execute(OrderTaskContext context) { bool result = true; if (context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth > 0) { //Use the last transaction entered by customer first List <OrderTransaction> transactions = context.HccApp.OrderServices.Transactions .FindForOrder(context.Order.bvin) .OrderByDescending(x => x.TimeStampUtc) .ToList(); decimal dueAmount = context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth; foreach (OrderTransaction p in transactions) { if (p.Action == ActionType.PayPalExpressCheckoutInfo) { // if we already have an auth or charge on the card, skip if (p.HasSuccessfulLinkedAction(ActionType.PayPalHold, transactions) || p.HasSuccessfulLinkedAction(ActionType.PayPalCharge, transactions)) { continue; } try { OrderPaymentManager payManager = new OrderPaymentManager(context.Order, context.HccApp); decimal amount = context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth; result = context.HccApp.CurrentRequestContext.CurrentStore.Settings.PayPal.ExpressAuthorizeOnly ? payManager.PayPalExpressHold(p, amount) : payManager.PayPalExpressCharge(p, amount); if (result == true) { dueAmount = context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth; //Amount required in order is already charged. No need to charge on other transactions if (dueAmount <= 0) { break; } } } catch (Exception ex) { context.Errors.Add(new WorkflowMessage("Exception During Receive Paypal Express Payments", ex.Message + ex.StackTrace, false)); } } } } if (result == false) { var errorString = "An error occurred while attempting to process your Paypal Express payment. Please check your payment information and try again"; context.Errors.Add(new WorkflowMessage("Receive Card Failed", errorString, true)); // Failure Status Code var failCode = OrderStatusCode.OnHold; var c = OrderStatusCode.FindByBvin(failCode); if (c != null) { context.Order.StatusCode = c.Bvin; context.Order.StatusName = c.StatusName; } } return(result); }
/// <summary> /// Adds the new gift card. /// </summary> /// <param name="context">The context.</param> /// <param name="lineItem">The line item.</param> private static void AddNewGiftCard(OrderTaskContext context, LineItem lineItem) { var paymentManager = new OrderPaymentManager(context.Order, context.HccApp); var store = context.HccApp.CurrentStore; var giftCard = new GiftCardData { LineItemId = lineItem.Id, CardNumber = context.HccApp.CatalogServices.GenerateGiftCardNumber(), Amount = Money.RoundCurrency(lineItem.AdjustedPricePerItem), RecipientEmail = lineItem.CustomPropGiftCardEmail, RecipientName = lineItem.CustomPropGiftCardName, ExpirationDate = DateTime.UtcNow.AddMonths(store.Settings.GiftCard.ExpirationPeriodMonths) }; var gcNumber = paymentManager.GiftCardCreate(giftCard); if (string.IsNullOrEmpty(gcNumber)) { var message = new WorkflowMessage( "Gift Certificate Insert Failed", "Gift Certificate for line item " + lineItem.Id + " in order " + context.Order.OrderNumber + " failed.", false); context.Errors.Add(message); } else { if (string.IsNullOrEmpty(lineItem.CustomPropGiftCardNumber)) { lineItem.CustomPropGiftCardNumber = gcNumber; } else { lineItem.CustomPropGiftCardNumber = lineItem.CustomPropGiftCardNumber + "<br/>" + gcNumber; } context.HccApp.OrderServices.Orders.Update(context.Order); var gc = new GiftCard(giftCard, lineItem.CustomPropGiftCardMessage); if (string.IsNullOrEmpty(gc.RecipientEmail)) { gc.RecipientEmail = context.Order.UserEmail; if (string.IsNullOrEmpty(gc.RecipientName)) { gc.RecipientName = context.Order.ShippingAddress.FirstName; } } try { context.HccApp.ContentServices.SendGiftCardNotification(gc, context.Order, lineItem); } catch (Exception ex) { context.Errors.Add(new WorkflowMessage("Exception Sending Gift Card", ex.Message + ex.StackTrace, false)); var note = new OrderNote(); note.IsPublic = false; note.Note = "EXCEPTION: " + ex.Message + " | " + ex.StackTrace; context.Order.Notes.Add(note); EventLog.LogEvent(ex); } } }