Rank: Advanced Member
Groups: Admin, Developers, Registered, HelpDesk, Authorized User Joined: 10/5/2018(UTC) Posts: 704
Thanks: 5 times Was thanked: 113 time(s) in 112 post(s)
|
Quote:If you work on recording an offline payment enter an amount then change any of the dropdowns, and the amount reverts to the original amount. To fix the issue. 1- Open Website\Areas\Admin\Controllers\OrdersController.cs 2- Search for Code:
[HttpPost]
[ValidateAjax]
[ValidateAntiForgeryToken]
public ActionResult RecordNewPayment(RecordNewPaymentModel model)
{
if (!ModelState.IsValid) return BadRequest();
3- Replace with Code:
[HttpPost]
[ValidateAjax]
[ValidateAntiForgeryToken]
public ActionResult RecordNewPayment(RecordNewPaymentModel model)
{
if (!ModelState.IsValid) return BadRequest();
// check if it is a payment method update request
if (model.IsPaymentMethodUpdate)
{
return RecordNewPaymentForm(model.OrderNumber, model.PaymentMethodId);
}
4- Search for the function Code:public ActionResult RecordNewPaymentForm(int orderNumber, int selectedPaymentMethodId = 0)
{
var order = _orderRepo.LoadForOrderNumber(orderNumber);
var orderId = order.Id;
List<SelectListItem> selPaymentStatus = new List<SelectListItem>();
RecordNewPaymentModel model = new RecordNewPaymentModel
{
OrderId = order.Id,
OrderNumber = order.OrderNumber,
Amount = order.GetBalance(true),
PaymentMethodId = selectedPaymentMethodId,
};
NHibernate.ICriteria criteria = NHibernateHelper.CreateCriteria<PaymentMethod>();
criteria.Add(NHibernate.Criterion.Restrictions.Not(NHibernate.Criterion.Restrictions.Eq("PaymentInstrumentId", (short)PaymentInstrumentType.GiftCertificate)));
criteria.Add(NHibernate.Criterion.Restrictions.Not(NHibernate.Criterion.Restrictions.Eq("PaymentInstrumentId", (short)PaymentInstrumentType.GoogleCheckout)));
var methods = AbleContext.Resolve<IPaymentMethodRepository>().LoadForCriteria(criteria);
PaymentMethod method = methods.FirstOrDefault();
if (selectedPaymentMethodId > 0)
{
method = methods.FirstOrDefault(x => x.Id == selectedPaymentMethodId);
if (method != null)
{
if (method.IsCreditOrDebitCard())
{
foreach (PaymentStatus s in Enum.GetValues(typeof(PaymentStatus)))
{
selPaymentStatus.Add(new SelectListItem { Text = StringHelper.SpaceName(s.ToString()), Value = ((int)s).ToString() });
}
}
else
{
selPaymentStatus.Add(new SelectListItem { Text = StringHelper.SpaceName(PaymentStatus.Unprocessed.ToString()), Value = ((int)PaymentStatus.Unprocessed).ToString() });
selPaymentStatus.Add(new SelectListItem { Text = StringHelper.SpaceName(PaymentStatus.Completed.ToString()), Value = ((int)PaymentStatus.Completed).ToString() });
}
ViewBag.PaymentStatusList = selPaymentStatus;
}
}
else
{
//LOAD PAYMENT STATUSES
selPaymentStatus = new List<SelectListItem>();
selPaymentStatus.Add(new SelectListItem { Text = "", Value = "0" });
foreach (PaymentStatus status in Enum.GetValues(typeof(PaymentStatus)))
{
selPaymentStatus.Add(new SelectListItem { Text = status.ToString(), Value = ((int)status).ToString() });
}
ViewBag.PaymentStatusList = selPaymentStatus;
}
if (method != null)
{
model.PaymentMethodId = method.Id;
}
var paymentmethods = methods.Select(item => new SelectListItem
{
Text = item.Name,
Value = item.Id.ToString(),
Selected = item.Id == model.PaymentMethodId,
}).ToList();
paymentmethods.Insert(0, new SelectListItem { Text = "", Value = "0" });
ViewBag.PaymentMethodList = paymentmethods;
return PartialView("_RecordNewPaymentForm", model);
}
5- Replace with Code:public ActionResult RecordNewPaymentForm(int orderNumber, int selectedPaymentMethodId = -1)
{
var order = _orderRepo.LoadForOrderNumber(orderNumber);
var orderId = order.Id;
List<SelectListItem> selPaymentStatus = new List<SelectListItem>();
RecordNewPaymentModel model = new RecordNewPaymentModel
{
OrderId = order.Id,
OrderNumber = order.OrderNumber,
Amount = order.GetBalance(true),
PaymentMethodId = selectedPaymentMethodId,
};
NHibernate.ICriteria criteria = NHibernateHelper.CreateCriteria<PaymentMethod>();
criteria.Add(NHibernate.Criterion.Restrictions.Not(NHibernate.Criterion.Restrictions.Eq("PaymentInstrumentId", (short)PaymentInstrumentType.GiftCertificate)));
criteria.Add(NHibernate.Criterion.Restrictions.Not(NHibernate.Criterion.Restrictions.Eq("PaymentInstrumentId", (short)PaymentInstrumentType.GoogleCheckout)));
var methods = AbleContext.Resolve<IPaymentMethodRepository>().LoadForCriteria(criteria);
PaymentMethod method = methods.FirstOrDefault();
if (selectedPaymentMethodId > 0)
{
method = methods.FirstOrDefault(x => x.Id == selectedPaymentMethodId);
if (method != null)
{
if (method.IsCreditOrDebitCard())
{
foreach (PaymentStatus s in Enum.GetValues(typeof(PaymentStatus)))
{
selPaymentStatus.Add(new SelectListItem { Text = StringHelper.SpaceName(s.ToString()), Value = ((int)s).ToString() });
}
}
else
{
selPaymentStatus.Add(new SelectListItem { Text = StringHelper.SpaceName(PaymentStatus.Unprocessed.ToString()), Value = ((int)PaymentStatus.Unprocessed).ToString() });
selPaymentStatus.Add(new SelectListItem { Text = StringHelper.SpaceName(PaymentStatus.Completed.ToString()), Value = ((int)PaymentStatus.Completed).ToString() });
}
ViewBag.PaymentStatusList = selPaymentStatus;
}
}
else
{
//LOAD PAYMENT STATUSES
selPaymentStatus = new List<SelectListItem>();
foreach (PaymentStatus status in Enum.GetValues(typeof(PaymentStatus)))
{
selPaymentStatus.Add(new SelectListItem { Text = status.ToString(), Value = ((int)status).ToString() });
}
ViewBag.PaymentStatusList = selPaymentStatus;
}
if (method != null)
{
model.PaymentMethodId = method.Id;
}
var paymentmethods = methods.Select(item => new SelectListItem
{
Text = item.Name,
Value = item.Id.ToString(),
Selected = item.Id == model.PaymentMethodId,
}).ToList();
ViewBag.PaymentMethodList = paymentmethods;
if (selectedPaymentMethodId > -1)
return Json(new { status = "OnChangeRequest", html = RenderRazorViewToString("_RecordNewPaymentForm", model) });
else
return PartialView("_RecordNewPaymentForm", model);
}
6- Open Website\Areas\Admin\Models\OrderModels.cs 7- Find the class RecordNewPaymentModel and add the property below Code:public bool IsPaymentMethodUpdate { get; set; }
8- Open file Website\Areas\Admin\Views\Orders\_RecordNewPaymentForm.cshtml 9- Replace the complete content with the following content. Code:@model RecordNewPaymentModel
@using CommerceBuilder.Utility
@using CommerceBuilder.Extensions
@using (Ajax.BeginForm("RecordNewPayment", "Orders", new AjaxOptions() { HttpMethod = "POST", OnSuccess= "NewPaymentSuccess", UpdateTargetId = "record-payment-container" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(model => model.OrderId)
@Html.HiddenFor(model => model.OrderNumber)
@Html.HiddenFor(model => Model.IsPaymentMethodUpdate)
<div class="ibox">
<div class="ibox-content">
<p>Record a payment that was obtained from an alternate source. The payment will be applied to this order.</p>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label>Payment Method</label>
@Html.DropDownListFor(model => model.PaymentMethodId, (IEnumerable<SelectListItem>)ViewBag.PaymentMethodList, new { @class = "form-control", onchange = "document.getElementById(\"IsPaymentMethodUpdate\").value = \"True\";$(this.form).submit();" })
@Html.ValidationMessageFor(model => Model.PaymentMethodId)
</div>
<div class="form-group">
<label>Amount</label>
@Html.EditorFor(model => Model.Amount, new { @class = "form-control" })
@Html.ValidationMessageFor(model => Model.Amount)
</div>
<div class="form-group">
<label>Payment Note</label>
@Html.TextBoxFor(model => Model.PaymentStatusReason, new { @class = "form-control", placeholder = "Private note about this payment" })
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label>Reference</label>
@Html.TextBoxFor(model => Model.ReferenceNumber, new { @class = "form-control", maxlength=50 })
@Html.ValidationMessageFor(model => Model.ReferenceNumber)
</div>
<div class="form-group">
<label>Status</label>
@Html.DropDownListFor(model => model.PaymentStatusId, (IEnumerable<SelectListItem>)ViewBag.PaymentStatusList, new { @class = "form-control" })
</div>
</div>
</div>
<div class="row center">
@Ajax.ActionLink("Cancel", "OrderPayments",
new { OrderNumber = Model.OrderNumber },
new AjaxOptions
{
UpdateTargetId = "view-order-tab-container",
OnSuccess = "SetActiveTab('Payments')",
}, new { @class = "btn btn-white" })
<button type="submit" id="save" class="btn btn-primary" onclick="document.getElementById('IsPaymentMethodUpdate').value = 'False';">Record Payment</button>
</div>
</div>
</div>
}
<script type="text/javascript">
function NewPaymentSuccess(response)
{
if (response.status && response.status == "OnChangeRequest") {
$("#record-payment-container").html(response.html);
}
else{
toastr.success('New payment saved scuccessfully.', 'Payment Added');
$('#view-order-tab-container').html(response);
}
}
</script>
Edited by user Thursday, July 6, 2023 5:21:34 AM(UTC)
| Reason: Not specified
|