public PaymentPaypalLib() { if (_paypalStandardPaymentSettings == null) { _paypalStandardPaymentSettings = PayPalStandardPaymentSettings.getSetting(); } }
protected override void Initialize(RequestContext requestContext) { if (_paypalStandardPaymentSettings == null) { _paypalStandardPaymentSettings = PayPalStandardPaymentSettings.getSetting(); } base.Initialize(requestContext); }
/// <summary> /// Generate response signarture to compare /// </summary> /// <param name="item"></param> /// <param name="PaymentId"></param> /// <returns></returns> public string generate_SHA1keyResponse(Order item, int PaymentId) { // get the config PayPalStandardPaymentSettings settings = PayPalStandardPaymentSettings.getSetting(); var Key = string.Format("{0}{1}{2}{3}{4}{5}{6}", settings.iPay88_MerchantKey, settings.iPay88_MerchantCode, PaymentId, item.Order_Number, item.Bill_Total.ToString("0.00").Replace(".", ""), "MYR", "1"); SHA1CryptoServiceProvider objSHA1 = new SHA1CryptoServiceProvider(); objSHA1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(Key.ToCharArray())); byte[] buffer = objSHA1.Hash; string HashValue = System.Convert.ToBase64String(buffer); return(HashValue); }
public ActionResult Response(iPay_ResponseModel model) { // try to log into exception for later debug //Exceptions ex = new Exceptions(); //ex.ExMessage = "iPay88 Calback"; //ex.ExStackTrace = model.ToJson(); //Db.Insert<Exceptions>(ex); // check the RefNo == OderNumber var order = Db.Select <Order>(x => x.Where(m => m.Order_Number == model.RefNo).Limit(1)).FirstOrDefault(); // generate the signature PayPalStandardPaymentSettings settings = PayPalStandardPaymentSettings.getSetting(); if (settings.UseSandbox) { order.Bill_Total = 1; } var signagure = new iPay88Helper().generate_SHA1keyResponse(order, model.PaymentId); if (order != null) { if (model.Status == "1" && signagure == model.Signature && order.PaymentStatusEnum != Enum_PaymentStatus.Paid) { order.AddHistory("Receive callback from iPay88: " + model.ToJson(), "iPay88", 0, true); order.Set_PaymentStatus(Enum_PaymentStatus.Paid); order.AddHistory("Update payment method to iPay88", "System", 0, true); Db.UpdateOnly <Order>(new Order() { Payment_AuthorizationTransactionId = model.TransId, PaymentMethod = Enum_PaymentMethod.iPay88 }, ev => ev.Update(p => new { p.Payment_AuthorizationTransactionId, p.PaymentMethod }).Where(m => m.Id == order.Id)); // return RedirectToAction("OrderInvoiceDetail", "Product", new { id = order.Order_Number }); } return(RedirectToAction("OrderInvoiceDetail", "Product", new { id = order.Order_Number })); } else { return(Redirect("/")); } }
//[Authorize(Roles = "Administrator,Manager")] public ActionResult Edit() { PayPalStandardPaymentSettings model = PayPalStandardPaymentSettings.getSetting(); return(View(model)); }
/// <summary> /// Send transaction to iPay and wait for the response /// </summary> /// <param name="item"></param> /// <returns></returns> public iPay_RequestModel DoTransaction(Order item) { // get the config PayPalStandardPaymentSettings settings = PayPalStandardPaymentSettings.getSetting(); // var p = Db.Select <Product>(x => x.Where(m => m.Id == item.Product_Id).Limit(1)).FirstOrDefault(); var product_name = item.Product_Name; if (p != null) { product_name += " - " + p.Size; } p.Dispose(); var u = Db.Select <ABUserAuth>(x => x.Where(m => m.Id == item.Customer_Id).Limit(1)).FirstOrDefault(); var user_phone = ""; if (u != null && !string.IsNullOrEmpty(u.Phone)) { user_phone = u.Phone; } if (settings.UseSandbox) { item.Bill_Total = 1; } // var ret_url = ConfigurationManager.AppSettings.Get("PaypalWebsiteURL"); //if (ret_url.Contains("http://localhost")) //{ // ret_url = "http://www.YourBackendURL.com/"; //} if (string.IsNullOrEmpty(item.Customer_Name)) { item.Customer_Name = "Order #" + item.Order_Number; } var country = Db.Select <Country>(x => x.Where(m => m.CurrencyCode == item.Shipping_DisplayPriceSign).Limit(1)).FirstOrDefault(); var currentcy_sign = ""; if (country != null) { currentcy_sign = country.Currency3Letter; } string entryUrl = entryURL; var pay88Request = new iPay_RequestModel() { //MerchantKey = settings.iPay88_MerchantKey, MerchantCode = settings.iPay88_MerchantCode, Amount = item.Bill_Total.ToString("0.00"), Currency = currentcy_sign, RefNo = item.Order_Number, ProdDesc = product_name, UserName = item.Customer_Name, UserContact = user_phone, UserEmail = item.Customer_Email, ResponseURL = ret_url + "iPay88/Response", BackendURL = ret_url + "iPay88/Response", PaymentId = "", Remark = "Premier Photo Book Sdn Bhd", Signature = generate_SHA1key(item), }; Db.Close(); return(pay88Request); }
/// <summary> /// Gets Paypal URL /// </summary> /// <returns></returns> public string GetPaypalUrl() { return(PayPalStandardPaymentSettings.getSetting().UseSandbox ? "https://www.sandbox.paypal.com/us/cgi-bin/webscr" : "https://www.paypal.com/us/cgi-bin/webscr"); }