public async Task Validate_TestStartCalled_ISmokeTestProviderRegistered_Returns_NvpCodecValues() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); TestHttpRequest httpRequest = new TestHttpRequest(); httpRequest.Path = "/smokeTest/Start/"; TestHttpResponse httpResponse = new TestHttpResponse(); IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>(); IServiceCollection serviceCollection = new ServiceCollection() as IServiceCollection; NVPCodec codecValues = new NVPCodec(); codecValues.Add("username", "admin"); MockSmokeTestProvider smokeTestProvider = new MockSmokeTestProvider(codecValues); serviceCollection.AddSingleton <ISmokeTestProvider>(smokeTestProvider); TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse, serviceCollection.BuildServiceProvider()); ILogger logger = new Logger(); bool nextDelegateCalled = false; RequestDelegate requestDelegate = async(context) => { nextDelegateCalled = true; await Task.Delay(0); }; using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(requestDelegate, pluginHelperServices, pluginTypesService, settingsProvider, logger)) { List <WebSmokeTestItem> smokeTests = sut.SmokeTests; Assert.IsTrue(smokeTests.Count > 1); await sut.Invoke(httpContext); Assert.IsFalse(nextDelegateCalled); Assert.AreEqual(200, httpResponse.StatusCode); Assert.IsNull(httpResponse.ContentType); Assert.IsTrue(smokeTestProvider.StartCalled); byte[] data = new byte[httpResponse.Body.Length]; httpResponse.Body.Position = 0; httpResponse.Body.Read(data, 0, data.Length); string test = Decrypt(Encoding.UTF8.GetString(data), EncryptionKey); Assert.IsFalse(String.IsNullOrEmpty(test)); NVPCodec codec = new NVPCodec(); codec.Decode(test); Assert.AreEqual(1, codec.AllKeys.Length); Assert.IsTrue(codec.AllKeys.Contains("username")); Assert.AreEqual("admin", codec["username"]); } }
public JsonResult SetExpressCheckout(decimal amount, string currency_code, string item_name, string return_false_url, string webtype) { string hots = Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port + "/"; NVPCodec encoder = new NVPCodec(); encoder.Add("PAYMENTACTION", "Sale"); //不允许客户改地址 encoder.Add("ADDROVERRIDE", "1"); encoder.Add("CURRENCYCODE", currency_code); encoder.Add("L_NAME0", item_name); //encoder.Add("L_NUMBER0", item_name); //encoder.Add("L_DESC0", item_name); encoder.Add("L_AMT0", amount.ToString()); encoder.Add("L_QTY0", "1"); double ft = double.Parse(amount.ToString()); double amt = System.Math.Round(ft + 5.00f + 2.00f + 1.00f, 2); double maxamt = System.Math.Round(amt + 25.00f, 2); encoder.Add("AMT", ft.ToString()); encoder.Add("RETURNURL", hots + "/Statistics/Return?orderid=" + item_name + "&price=" + amount + "&type=sadmincz"); encoder.Add("CANCELURL", return_false_url); return(Json(return_false_url)); //NVPCodec decoder = PaypalController.SetExpressCheckout(encoder); //string ack = decoder["ACK"]; //if (!string.IsNullOrEmpty(ack) && (ack.Equals("Success", System.StringComparison.OrdinalIgnoreCase) || ack.Equals("SuccessWithWarning", System.StringComparison.OrdinalIgnoreCase))) //{ // Session["TOKEN"] = decoder["token"]; // return Json(ConfigurationManager.AppSettings["RedirectURL"] + decoder["token"]); //} //else //{ // return Json(return_false_url); // //LSGKE52H5FW236597 SGM7151LAAA //} }
public async Task Validate_TestEndCalled_ISmokeTestProviderRegistered_Void() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); TestHttpRequest httpRequest = new TestHttpRequest(); httpRequest.Path = "/SmokeTest/End/"; TestHttpResponse httpResponse = new TestHttpResponse(); IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>(); IServiceCollection serviceCollection = new ServiceCollection() as IServiceCollection; NVPCodec codecValues = new NVPCodec(); codecValues.Add("username", "admin"); MockSmokeTestProvider smokeTestProvider = new MockSmokeTestProvider(codecValues); serviceCollection.AddSingleton <ISmokeTestProvider>(smokeTestProvider); TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse, serviceCollection.BuildServiceProvider()); ILogger logger = new Logger(); bool nextDelegateCalled = false; RequestDelegate requestDelegate = async(context) => { nextDelegateCalled = true; await Task.Delay(0); }; using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(requestDelegate, pluginHelperServices, pluginTypesService, settingsProvider, logger)) { List <WebSmokeTestItem> smokeTests = sut.SmokeTests; Assert.IsTrue(smokeTests.Count > 1); await sut.Invoke(httpContext); Assert.IsFalse(nextDelegateCalled); Assert.AreEqual(200, httpResponse.StatusCode); Assert.IsNull(httpResponse.ContentType); Assert.IsTrue(smokeTestProvider.EndCalled); } }
public ActionResult PaymentInfo() { var model = new PaymentSagePayServerModel(); //First validate if this is the response of failed transaction (Status INVALID) var StatusDetail = Request.QueryString["StatusDetail"]; if (StatusDetail != null) { model.Warnings.Add(StatusDetail); return View("Nop.Plugin.Payments.SagePayServer.Views.PaymentSagePayServer.PaymentInfo", model); } var webClient = new WebClient(); var data = new NVPCodec(); data.Add("VPSProtocol", SagePayHelper.GetProtocol()); data.Add("TxType", _sagePayServerPaymentSettings.TransactType); data.Add("Vendor", _sagePayServerPaymentSettings.VendorName.ToLower()); var orderGuid = Guid.NewGuid(); data.Add("VendorTxCode", orderGuid.ToString()); if (!String.IsNullOrWhiteSpace(_sagePayServerPaymentSettings.PartnerID)) data.Add("ReferrerID", _sagePayServerPaymentSettings.PartnerID); var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList(); decimal? shoppingCartTotalBase = _orderTotalCalculationService.GetShoppingCartTotal(cart); var OrderTotal = shoppingCartTotalBase.GetValueOrDefault(); data.Add("Amount", OrderTotal.ToString("F2", CultureInfo.InvariantCulture)); if (_workContext.WorkingCurrency != null) data.Add("Currency", _workContext.WorkingCurrency.CurrencyCode); else if (_workContext.CurrentCustomer.CurrencyId.HasValue && _workContext.CurrentCustomer.Currency != null) data.Add("Currency", _workContext.CurrentCustomer.Currency.CurrencyCode); else data.Add("Currency", _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode); data.Add("Description", "DescriptionText"); // The Notification URL is the page to which Server calls back when a transaction completes var notificationUrl = _sagePayServerPaymentSettings.NotificationFullyQualifiedDomainName; data.Add("NotificationURL", notificationUrl + "Plugins/PaymentSagePayServer/NotificationPage"); // Billing Details data.Add("BillingSurname", _workContext.CurrentCustomer.BillingAddress.LastName); data.Add("BillingFirstnames", _workContext.CurrentCustomer.BillingAddress.FirstName); data.Add("BillingAddress1", _workContext.CurrentCustomer.BillingAddress.Address1); if (!String.IsNullOrWhiteSpace(_workContext.CurrentCustomer.BillingAddress.Address2)) data.Add("BillingAddress2", _workContext.CurrentCustomer.BillingAddress.Address2); data.Add("BillingCity", _workContext.CurrentCustomer.BillingAddress.City); data.Add("BillingPostCode", _workContext.CurrentCustomer.BillingAddress.ZipPostalCode); data.Add("BillingCountry", _workContext.CurrentCustomer.BillingAddress.Country.TwoLetterIsoCode); //TODO: Verify if it is ISO 3166-1 country code if (_workContext.CurrentCustomer.BillingAddress.StateProvince != null) data.Add("BillingState", _workContext.CurrentCustomer.BillingAddress.StateProvince.Abbreviation); if (!String.IsNullOrWhiteSpace(_workContext.CurrentCustomer.BillingAddress.PhoneNumber)) data.Add("BillingPhone", _workContext.CurrentCustomer.BillingAddress.PhoneNumber); // Delivery Details if (_workContext.CurrentCustomer.ShippingAddress != null) { data.Add("DeliverySurname", _workContext.CurrentCustomer.ShippingAddress.LastName); data.Add("DeliveryFirstnames", _workContext.CurrentCustomer.ShippingAddress.FirstName); data.Add("DeliveryAddress1", _workContext.CurrentCustomer.ShippingAddress.Address1); if (!String.IsNullOrWhiteSpace(_workContext.CurrentCustomer.ShippingAddress.Address2)) data.Add("DeliveryAddress2", _workContext.CurrentCustomer.ShippingAddress.Address2); data.Add("DeliveryCity", _workContext.CurrentCustomer.ShippingAddress.City); data.Add("DeliveryPostCode", _workContext.CurrentCustomer.ShippingAddress.ZipPostalCode); if (_workContext.CurrentCustomer.ShippingAddress.Country != null) { data.Add("DeliveryCountry", _workContext.CurrentCustomer.ShippingAddress.Country.TwoLetterIsoCode); } if (_workContext.CurrentCustomer.ShippingAddress.StateProvince != null) data.Add("DeliveryState", _workContext.CurrentCustomer.ShippingAddress.StateProvince.Abbreviation); if (!String.IsNullOrWhiteSpace(_workContext.CurrentCustomer.ShippingAddress.PhoneNumber)) data.Add("DeliveryPhone", _workContext.CurrentCustomer.ShippingAddress.PhoneNumber); } else { //Thanks to 'nomisit' for pointing this out. http://www.nopcommerce.com/p/258/sagepay-server-integration-iframe-and-redirect-methods.aspx data.Add("DeliverySurname", ""); data.Add("DeliveryFirstnames", ""); data.Add("DeliveryAddress1", ""); data.Add("DeliveryAddress2", ""); data.Add("DeliveryCity", ""); data.Add("DeliveryPostCode", ""); data.Add("DeliveryCountry", ""); data.Add("DeliveryState", ""); data.Add("DeliveryPhone", ""); } data.Add("CustomerEMail", _workContext.CurrentCustomer.Email); //var strBasket = String.Empty; //strBasket = cart.Count + ":"; //for (int i = 0; i < cart.Count; i++) //{ // ShoppingCartItem item = cart[i]; // strBasket += item.ProductVariant.FullProductName) + ":" + // item.Quantity + ":" + item.ProductVariant.Price + ":" + // item.ProductVariant.TaxCategoryId; //}; //data.Add("Basket", strBasket); data.Add("AllowGiftAid", "0"); // Allow fine control over AVS/CV2 checks and rules by changing this value. 0 is Default if (_sagePayServerPaymentSettings.TransactType != "AUTHENTICATE") data.Add("ApplyAVSCV2", "0"); // Allow fine control over 3D-Secure checks and rules by changing this value. 0 is Default data.Add("Apply3DSecure", "0"); if (String.Compare(_sagePayServerPaymentSettings.Profile, "LOW", true) == 0) { data.Add("Profile", "LOW"); //simpler payment page version. } var postURL = SagePayHelper.GetSageSystemUrl(_sagePayServerPaymentSettings.ConnectTo, "purchase"); string strResponse = string.Empty; try { Byte[] responseData = webClient.UploadValues(postURL, data); strResponse = Encoding.ASCII.GetString(responseData); } catch (WebException ex) { return Content(String.Format( @"Your server was unable to register this transaction with Sage Pay. Check that you do not have a firewall restricting the POST and that your server can correctly resolve the address {0}. <br/> The Status Number is: {1}<br/> The Description given is: {2}", postURL, ex.Status, ex.Message)); } if (string.IsNullOrWhiteSpace(strResponse)) return Content(String.Format( @"Your server was unable to register this transaction with Sage Pay. Check that you do not have a firewall restricting the POST and that your server can correctly resolve the address {0}.", postURL)); var strStatus = SagePayHelper.FindField("Status", strResponse); var strStatusDetail = SagePayHelper.FindField("StatusDetail", strResponse); switch (strStatus) { case "OK": var strVPSTxId = SagePayHelper.FindField("VPSTxId", strResponse); var strSecurityKey = SagePayHelper.FindField("SecurityKey", strResponse); var strNextURL = SagePayHelper.FindField("NextURL", strResponse); var transx = new SagePayServerTransaction() { CreatedOnUtc = DateTime.UtcNow, VPSTxId = strVPSTxId, SecurityKey = strSecurityKey, NotificationResponse = strResponse, VendorTxCode = orderGuid.ToString() }; //Store this record in DB _sagePayServerTransactionService.InsertSagePayServerTransaction(transx); ViewBag.UseOnePageCheckout = UseOnePageCheckout(); if (_sagePayServerPaymentSettings.Profile == SagePayServerPaymentSettings.ProfileValues.LOW || ViewBag.UseOnePageCheckout) {//Iframe model.FrameURL = strNextURL; return View("Nop.Plugin.Payments.SagePayServer.Views.PaymentSagePayServer.PaymentInfo", model); } else { HttpContext.Response.Redirect(strNextURL); HttpContext.Response.End(); return null; } case "MALFORMED": return Content(string.Format("Error ({0}: {1}) <br/> {2}", strStatus, strStatusDetail, data.Encode())); case "INVALID": return Content(string.Format("Error ({0}: {1}) <br/> {2}", strStatus, strStatusDetail, data.Encode())); default: return Content(string.Format("Error ({0}: {1})", strStatus, strStatusDetail)); } }
/// <summary> /// 付款操作 /// </summary> /// <param name="nvp"></param> /// <returns></returns> public NVPCodec DoExpressCheckoutPayment(NVPCodec nvp) { nvp.Add("METHOD", "DoExpressCheckoutPayment"); return(SendExpressCheckoutCommand(nvp)); }
/// <summary> /// 得到用户在paypay中填写的详细信息 /// </summary> /// <param name="nvp"></param> /// <returns></returns> public NVPCodec GetExpressCheckoutDetails(NVPCodec nvp) { nvp.Add("METHOD", "GetExpressCheckoutDetails"); return(SendExpressCheckoutCommand(nvp)); }
/// <summary> /// 发送支付请求 /// </summary> /// <param name="nvp"></param> /// <returns></returns> public NVPCodec SetExpressCheckout(NVPCodec nvp) { nvp.Add("METHOD", "SetExpressCheckout"); return(SendExpressCheckoutCommand(nvp)); }
//发送请求支付请求 public JsonResult SetExpressCheckout(decimal amount, string currency_code, string item_name, string return_false_url, string webtype, string fq = "") { PaypalController paypal = new PaypalController(); string hots = Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port + "/"; NVPCodec encoder = new NVPCodec(); encoder.Add("PAYMENTACTION", "Sale"); //不允许客户改地址 //encoder.Add("ADDROVERRIDE", "1"); encoder.Add("CURRENCYCODE", currency_code); encoder.Add("L_NAME0", item_name); encoder.Add("L_NUMBER0", item_name); encoder.Add("L_DESC0", item_name); encoder.Add("L_AMT0", amount.ToString()); encoder.Add("L_QTY0", "1"); double ft = double.Parse(amount.ToString()); encoder.Add("AMT", ft.ToString()); if (!string.IsNullOrEmpty(webtype)) { encoder.Add("RETURNURL", hots + "/Pay/Return?orderid=" + item_name + "&price=" + amount + "&type=webzf&fq=" + fq + "&paymodel=paypal"); } else { encoder.Add("RETURNURL", hots + "/Pay/Return?orderid=" + item_name + "&price=" + amount + "&type=webcz&fq=" + fq + "&paymodel=paypal"); } encoder.Add("CANCELURL", return_false_url); NVPCodec decoder = paypal.SetExpressCheckout(encoder); string ack = decoder["ACK"]; if (!string.IsNullOrEmpty(ack) && (ack.Equals("Success", System.StringComparison.OrdinalIgnoreCase) || ack.Equals("SuccessWithWarning", System.StringComparison.OrdinalIgnoreCase))) { //Session["TOKEN"] = decoder["token"]; return(Json(ConfigurationManager.AppSettings["RedirectURL"] + decoder["token"])); } else { return(Json(return_false_url)); } }
public ActionResult PaymentInfo() { var model = new PaymentSagePayServerModel(); //First validate if this is the response of failed transaction (Status INVALID) var StatusDetail = Request.QueryString["StatusDetail"]; if (StatusDetail != null) { model.Warnings.Add(StatusDetail); return(View("Nop.Plugin.Payments.SagePayServer.Views.PaymentSagePayServer.PaymentInfo", model)); } var webClient = new WebClient(); var data = new NVPCodec(); data.Add("VPSProtocol", SagePayHelper.GetProtocol()); data.Add("TxType", _sagePayServerPaymentSettings.TransactType); data.Add("Vendor", _sagePayServerPaymentSettings.VendorName.ToLower()); var orderGuid = Guid.NewGuid(); data.Add("VendorTxCode", orderGuid.ToString()); if (!String.IsNullOrWhiteSpace(_sagePayServerPaymentSettings.PartnerID)) { data.Add("ReferrerID", _sagePayServerPaymentSettings.PartnerID); } var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList(); decimal?shoppingCartTotalBase = _orderTotalCalculationService.GetShoppingCartTotal(cart); var OrderTotal = shoppingCartTotalBase.GetValueOrDefault(); data.Add("Amount", OrderTotal.ToString("F2", CultureInfo.InvariantCulture)); if (_workContext.WorkingCurrency != null) { data.Add("Currency", _workContext.WorkingCurrency.CurrencyCode); } else if (_workContext.CurrentCustomer.CurrencyId.HasValue && _workContext.CurrentCustomer.Currency != null) { data.Add("Currency", _workContext.CurrentCustomer.Currency.CurrencyCode); } else { data.Add("Currency", _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode); } data.Add("Description", "eCommerce Order from " + _sagePayServerPaymentSettings.VendorName); // The Notification URL is the page to which Server calls back when a transaction completes var notificationUrl = _sagePayServerPaymentSettings.NotificationFullyQualifiedDomainName; data.Add("NotificationURL", notificationUrl + "Plugins/PaymentSagePayServer/NotificationPage"); // Billing Details data.Add("BillingSurname", _workContext.CurrentCustomer.BillingAddress.LastName); data.Add("BillingFirstnames", _workContext.CurrentCustomer.BillingAddress.FirstName); data.Add("BillingAddress1", _workContext.CurrentCustomer.BillingAddress.Address1); if (!String.IsNullOrWhiteSpace(_workContext.CurrentCustomer.BillingAddress.Address2)) { data.Add("BillingAddress2", _workContext.CurrentCustomer.BillingAddress.Address2); } data.Add("BillingCity", _workContext.CurrentCustomer.BillingAddress.City); data.Add("BillingPostCode", _workContext.CurrentCustomer.BillingAddress.ZipPostalCode); data.Add("BillingCountry", _workContext.CurrentCustomer.BillingAddress.Country.TwoLetterIsoCode); //TODO: Verify if it is ISO 3166-1 country code if (_workContext.CurrentCustomer.BillingAddress.StateProvince != null) { data.Add("BillingState", _workContext.CurrentCustomer.BillingAddress.StateProvince.Abbreviation); } if (!String.IsNullOrWhiteSpace(_workContext.CurrentCustomer.BillingAddress.PhoneNumber)) { data.Add("BillingPhone", _workContext.CurrentCustomer.BillingAddress.PhoneNumber); } // Delivery Details if (_workContext.CurrentCustomer.ShippingAddress != null) { data.Add("DeliverySurname", _workContext.CurrentCustomer.ShippingAddress.LastName); data.Add("DeliveryFirstnames", _workContext.CurrentCustomer.ShippingAddress.FirstName); data.Add("DeliveryAddress1", _workContext.CurrentCustomer.ShippingAddress.Address1); if (!String.IsNullOrWhiteSpace(_workContext.CurrentCustomer.ShippingAddress.Address2)) { data.Add("DeliveryAddress2", _workContext.CurrentCustomer.ShippingAddress.Address2); } data.Add("DeliveryCity", _workContext.CurrentCustomer.ShippingAddress.City); data.Add("DeliveryPostCode", _workContext.CurrentCustomer.ShippingAddress.ZipPostalCode); if (_workContext.CurrentCustomer.ShippingAddress.Country != null) { data.Add("DeliveryCountry", _workContext.CurrentCustomer.ShippingAddress.Country.TwoLetterIsoCode); } if (_workContext.CurrentCustomer.ShippingAddress.StateProvince != null) { data.Add("DeliveryState", _workContext.CurrentCustomer.ShippingAddress.StateProvince.Abbreviation); } if (!String.IsNullOrWhiteSpace(_workContext.CurrentCustomer.ShippingAddress.PhoneNumber)) { data.Add("DeliveryPhone", _workContext.CurrentCustomer.ShippingAddress.PhoneNumber); } } else { //Thanks to 'nomisit' for pointing this out. http://www.nopcommerce.com/p/258/sagepay-server-integration-iframe-and-redirect-methods.aspx data.Add("DeliverySurname", ""); data.Add("DeliveryFirstnames", ""); data.Add("DeliveryAddress1", ""); data.Add("DeliveryAddress2", ""); data.Add("DeliveryCity", ""); data.Add("DeliveryPostCode", ""); data.Add("DeliveryCountry", ""); data.Add("DeliveryState", ""); data.Add("DeliveryPhone", ""); } data.Add("CustomerEMail", _workContext.CurrentCustomer.Email); //var strBasket = String.Empty; //strBasket = cart.Count + ":"; //for (int i = 0; i < cart.Count; i++) //{ // ShoppingCartItem item = cart[i]; // strBasket += item.ProductVariant.FullProductName) + ":" + // item.Quantity + ":" + item.ProductVariant.Price + ":" + // item.ProductVariant.TaxCategoryId; //}; //data.Add("Basket", strBasket); data.Add("AllowGiftAid", "0"); // Allow fine control over AVS/CV2 checks and rules by changing this value. 0 is Default if (_sagePayServerPaymentSettings.TransactType != "AUTHENTICATE") { data.Add("ApplyAVSCV2", "0"); } // Allow fine control over 3D-Secure checks and rules by changing this value. 0 is Default data.Add("Apply3DSecure", "0"); if (String.Compare(_sagePayServerPaymentSettings.Profile, "LOW", true) == 0) { data.Add("Profile", "LOW"); //simpler payment page version. } var postURL = SagePayHelper.GetSageSystemUrl(_sagePayServerPaymentSettings.ConnectTo, "purchase"); string strResponse = string.Empty; try { Byte[] responseData = webClient.UploadValues(postURL, data); strResponse = Encoding.ASCII.GetString(responseData); } catch (WebException ex) { return(Content(String.Format( @"Your server was unable to register this transaction with Sage Pay. Check that you do not have a firewall restricting the POST and that your server can correctly resolve the address {0}. <br/> The Status Number is: {1}<br/> The Description given is: {2}", postURL, ex.Status, ex.Message))); } if (string.IsNullOrWhiteSpace(strResponse)) { return(Content(String.Format( @"Your server was unable to register this transaction with Sage Pay. Check that you do not have a firewall restricting the POST and that your server can correctly resolve the address {0}.", postURL))); } var strStatus = SagePayHelper.FindField("Status", strResponse); var strStatusDetail = SagePayHelper.FindField("StatusDetail", strResponse); switch (strStatus) { case "OK": var strVPSTxId = SagePayHelper.FindField("VPSTxId", strResponse); var strSecurityKey = SagePayHelper.FindField("SecurityKey", strResponse); var strNextURL = SagePayHelper.FindField("NextURL", strResponse); var transx = new SagePayServerTransaction() { CreatedOnUtc = DateTime.UtcNow, VPSTxId = strVPSTxId, SecurityKey = strSecurityKey, NotificationResponse = strResponse, VendorTxCode = orderGuid.ToString() }; //Store this record in DB _sagePayServerTransactionService.InsertSagePayServerTransaction(transx); ViewBag.UseOnePageCheckout = UseOnePageCheckout(); if (_sagePayServerPaymentSettings.Profile == SagePayServerPaymentSettings.ProfileValues.LOW || ViewBag.UseOnePageCheckout) { //Iframe model.FrameURL = strNextURL; return(View("Nop.Plugin.Payments.SagePayServer.Views.PaymentSagePayServer.PaymentInfo", model)); } else { HttpContext.Response.Redirect(strNextURL); HttpContext.Response.End(); return(null); } case "MALFORMED": return(Content(string.Format("Error ({0}: {1}) <br/> {2}", strStatus, strStatusDetail, data.Encode()))); case "INVALID": return(Content(string.Format("Error ({0}: {1}) <br/> {2}", strStatus, strStatusDetail, data.Encode()))); default: return(Content(string.Format("Error ({0}: {1})", strStatus, strStatusDetail))); } }
public string ECSetExpressCheckout(Cart cart) { Settings settings = new Settings(); NVPCallerServices caller = new NVPCallerServices(); IAPIProfile profile = getProfile(); caller.APIProfile = profile; NVPCodec encoder = new NVPCodec(); encoder.Add("VERSION", "84.0"); encoder.Add("METHOD", "SetExpressCheckout"); // Add request-specific fields to the request. encoder.Add("RETURNURL", getSiteURL() + "Payment/CompletePayPalCheckout"); encoder.Add("CANCELURL", getSiteURL() + "Payment"); encoder.Add("PAYMENTREQUEST_0_AMT", String.Format("{0:N2}", cart.getTotal())); encoder.Add("PAYMENTREQUEST_0_PAYMENTACTION", "Sale"); encoder.Add("PAYMENTREQUEST_0_CURRENCYCODE", "USD"); encoder.Add("BRANDNAME", settings.Get("SiteName") + " eCommerce Platform"); encoder.Add("LOGIN", "Login"); encoder.Add("HDRIMG", settings.Get("EmailLogo")); encoder.Add("CUSTOMERSERVICENUMBER", "888-894-4824"); encoder.Add("PAYMENTREQUEST_0_SHIPPINGAMT", String.Format("{0:N2}", cart.shipping_price)); encoder.Add("PAYMENTREQUEST_0_DESC", "Your " + settings.Get("SiteName") + " Order"); encoder.Add("ALLOWNOTE", "0"); encoder.Add("NOSHIPPING", "1"); int count = 0; decimal total = 0; foreach (CartItem item in cart.CartItems) { encoder.Add("L_PAYMENTREQUEST_0_NUMBER" + count, item.partID.ToString()); encoder.Add("L_PAYMENTREQUEST_0_NAME" + count, item.shortDesc); encoder.Add("L_PAYMENTREQUEST_0_AMT" + count, String.Format("{0:N2}", item.price)); encoder.Add("L_PAYMENTREQUEST_0_QTY" + count, item.quantity.ToString()); encoder.Add("L_PAYMENTREQUEST_0_ITEMCATEGORY" + count, "Physical"); encoder.Add("L_PAYMENTREQUEST_0_ITEMURL" + count, settings.Get("SiteURL") + "part/" + item.partID); total += item.price * item.quantity; count++; } encoder.Add("PAYMENTREQUEST_0_TAXAMT", String.Format("{0:N2}", cart.tax)); encoder.Add("PAYMENTREQUEST_0_ITEMAMT", String.Format("{0:N2}", total)); // Execute the API operation and obtain the response. string pStrrequestforNvp = encoder.Encode(); string pStresponsenvp = caller.Call(pStrrequestforNvp); NVPCodec decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); if (decoder["TOKEN"] != null) { return decoder["TOKEN"]; } else { string errors = " CorrelationID: " + decoder["CORRELATIONID"] + " error code: " + decoder["L_ERRORCODE0"] + " Messages: " + decoder["L_SHORTMESSAGE0"] + ", " + decoder["L_SHORTMESSAGE2"] + ", " + decoder["L_LONGMESSAGE0"] + ", " + decoder["L_LONGMESSAGE1"]; return decoder["ACK"] + errors; } }
public string ECDoExpressCheckout(string token, string payerID, string amount, Cart cart) { Settings settings = new Settings(); NVPCallerServices caller = new NVPCallerServices(); IAPIProfile profile = getProfile(); caller.APIProfile = profile; NVPCodec encoder = new NVPCodec(); encoder.Add("VERSION","84.0"); encoder.Add("METHOD","DoExpressCheckoutPayment"); // Add request-specific fields to the request. encoder.Add("TOKEN",token); encoder.Add("PAYERID",payerID); encoder.Add("RETURNURL",getSiteURL() + "Payment/PayPalCheckout"); encoder.Add("CANCELURL",getSiteURL() + "Payment"); encoder.Add("PAYMENTREQUEST_0_AMT",amount); encoder.Add("PAYMENTREQUEST_0_PAYMENTACTION","Sale"); encoder.Add("PAYMENTREQUEST_0_CURRENCYCODE","USD"); encoder.Add("BRANDNAME",settings.Get("SiteName")); encoder.Add("LOGIN","Login"); encoder.Add("HDRIMG",settings.Get("EmailLogo")); encoder.Add("CUSTOMERSERVICENUMBER",settings.Get("PhoneNumber")); encoder.Add("PAYMENTREQUEST_0_SHIPPINGAMT",cart.shipping_price.ToString()); encoder.Add("PAYMENTREQUEST_0_DESC","Your " + settings.Get("SiteName") + " Order"); encoder.Add("ALLOWNOTE","0"); encoder.Add("NOSHIPPING","1"); int count = 0; decimal total = 0; foreach (CartItem item in cart.CartItems) { encoder.Add("L_PAYMENTREQUEST_0_NUMBER" + count, item.partID.ToString()); encoder.Add("L_PAYMENTREQUEST_0_NAME" + count, item.shortDesc); encoder.Add("L_PAYMENTREQUEST_0_AMT" + count, String.Format("{0:N2}", item.price)); encoder.Add("L_PAYMENTREQUEST_0_QTY" + count, item.quantity.ToString()); encoder.Add("L_PAYMENTREQUEST_0_ITEMCATEGORY" + count, "Physical"); encoder.Add("L_PAYMENTREQUEST_0_ITEMURL" + count, settings.Get("SiteURL") + "part/" + item.partID); total += item.price * item.quantity; count++; } encoder.Add("PAYMENTREQUEST_0_TAXAMT", String.Format("{0:N2}", cart.tax)); encoder.Add("PAYMENTREQUEST_0_ITEMAMT", String.Format("{0:N2}", total)); // Execute the API operation and obtain the response. string pStrrequestforNvp = encoder.Encode(); string pStresponsenvp = caller.Call(pStrrequestforNvp); NVPCodec decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); return decoder["ACK"]; }