public DomainPaymentTransaction(Guid id, Guid paymentMethodId, string orderCode, long amount , string ipAddress, Guid languageId, string siteDomainUrl) { DateTime createdDate = DateTime.Now; PaymentMethod pm; Language lang = null; using (var db = new CoreEcommerceDbContext()) { pm = db.PaymentMethods.SingleOrDefault(i => i.Id == paymentMethodId); lang = db.Languages.SingleOrDefault(i => i.Id == languageId); } var type = AssemblyExtesions.FindType(pm.AssemblyType); if (type == null) { throw new Exception("Can not load assembly " + pm.AssemblyType); } var amountByCurrencyCode = (long)(amount * lang.CurrencyExchangeRate); var p = Activator.CreateInstance(type) as IPaymentMethod; var urlRedirect = p.GetRedirectUrl(pm, id, orderCode, amountByCurrencyCode, ipAddress, languageId, siteDomainUrl); ApplyChange(new PaymentTransactionCreated(id, orderCode, amountByCurrencyCode, paymentMethodId, createdDate, urlRedirect, ipAddress)); }
public JsonResult QueryDr(string orderCode) { PaymentTransaction pt; PaymentMethod pm; using (var db = new CoreEcommerceDbContext()) { pt = db.PaymentTransactions .SingleOrDefault(i => i.OrderCode.Equals(orderCode, StringComparison.OrdinalIgnoreCase)); pm = db.PaymentMethods.SingleOrDefault(i => i.Id == pt.PaymentMethodId); } if (pt == null || pm == null) { return(Json(new { Ok = true, Data = new { Id = pt.Id }, Message = "Not found" }, JsonRequestBehavior.AllowGet)); } var type = AssemblyExtesions.FindType(pm.AssemblyType); if (type == null) { throw new Exception("Can not load assembly " + pm.AssemblyType); } var p = Activator.CreateInstance(type) as IPaymentMethod; var result = p.QueryDr(pt.Id); return(Json(new { Ok = result == Enums.ShoppingCartPayStatus.PaymentSuccess, Data = new { Id = pt.Id, Status = result } , Message = result.ToString() }, JsonRequestBehavior.AllowGet)); }
public static long CalculateValue(Guid shoppingCartId, string voucherCode, long amount, Guid?userId) { VoucherCode code; VoucherMethod method = null; using (var db = new CoreEcommerceDbContext()) { code = db.VoucherCodes.SingleOrDefault( i => i.Code.Equals(voucherCode, StringComparison.OrdinalIgnoreCase)); if (code != null) { method = db.VoucherMethods.SingleOrDefault(i => i.Id == code.VoucherMethodId); } } if (method == null || string.IsNullOrEmpty(method.AssemblyType)) { return(0); } var type = AssemblyExtesions.FindType(method.AssemblyType); if (type == null) { throw new Exception("Can not load assembly " + method.AssemblyType); } var vm = Activator.CreateInstance(type) as IVoucherCodeMethod; return(vm.CalculateValue(shoppingCartId, amount, code, userId)); }
public static long ShippingCost(Guid shoppingCartId, Guid shippingMethodId, string address, double latitude, double longitude) { ShippingMethod methodInfo; using (var db = new CoreEcommerceDbContext()) { methodInfo = db.ShippingMethods.SingleOrDefault(i => i.Id == shippingMethodId); } if (methodInfo == null || string.IsNullOrEmpty(methodInfo.AssemblyType)) { return(0); } var type = AssemblyExtesions.FindType(methodInfo.AssemblyType); if (type == null) { throw new Exception("Can not load assembly " + methodInfo.AssemblyType); } var method = Activator.CreateInstance(type) as IShippingMethod; var result = method.CalculateCost(shoppingCartId, methodInfo, address, latitude, longitude); return(result); }