protected void btnSubmit_Click(object sender, EventArgs e)
        {
            decimal amount = 0M;

            Decimal.TryParse(txtAmount.Text, out amount);
            if (amount == 0)
            {
                return;
            }

            // create transaction

            // get settings from web.config
            string merchantId       = WebConfigurationManager.AppSettings["MerchantID"];
            string merchantPassword = WebConfigurationManager.AppSettings["MerchantPassword"];
            string preSharedKey     = WebConfigurationManager.AppSettings["PreSharedKey"];
            string serverCallBack   = WebConfigurationManager.AppSettings["ServerCallBackUrl"];
            string callBackUrl      = WebConfigurationManager.AppSettings["CallbackUrl"];
            string postUrl          = "https://mms.cardsaveonlinepayments.com/Pages/PublicPages/PaymentForm.aspx";

            var request = new HostedTransactionRequest {
                Amount           = Convert.ToInt32(amount * 100),
                OrderID          = "123456",
                OrderDescription = "Test Order",
                TransactionType  = TransactionType.SALE,
                CallbackURL      = callBackUrl,
                ServerResultURL  = serverCallBack
            };

            var processor = new HostedPaymentProcessor(merchantId, new HttpContextWrapper(HttpContext.Current));

            processor.SubmitTransaction(request, merchantPassword, preSharedKey, postUrl);
        }
Exemple #2
0
        public ActionResult Pay(WorldpayViewModel model)
        {
            ViewBag.WorldpayModel = model;

            //Retrieve the InstallationID, MD5SecretKey and SiteBaseURL values from the web.config
            int    installationID = Convert.ToInt32(WebConfigurationManager.AppSettings["InstallationID"]);
            string MD5secretKey   = WebConfigurationManager.AppSettings["MD5secretKey"];
            string WebsiteURL     = WebConfigurationManager.AppSettings["WebsiteURL"];
            int    testMode       = Convert.ToInt32(WebConfigurationManager.AppSettings["testMode"]);

            HostedTransactionRequest PRequest = new HostedTransactionRequest();

            PRequest.instId = installationID;
            //amount - A decimal number giving the cost of the purchase in terms of the major currency unit e.g. 12.56
            PRequest.amount = Convert.ToDouble(model.Total);
            //cartId - If your system has created a unique order/cart ID, enter it here.
            PRequest.cartId = string.Format("{0:00}", model.OrderID);//Guid.NewGuid().ToString();
            //desc - enter the description for this order.
            PRequest.desc = model.Description;
            //currency - 3 letter ISO code for the currency of this payment.
            PRequest.currency = "GBP";
            //name, address1/2/3, town, region, postcode & country - Billing address fields
            PRequest.name     = model.CustomerName;
            PRequest.address1 = model.Address;
            //PRequest.address2 = TxtAddress2.Text;
            //PRequest.address3 = TxtAddress3.Text;
            //PRequest.town = "BKK";
            //PRequest.region = TxtRegion.Text;
            PRequest.postcode = model.PostCode;
            //PRequest.country = DdlCountry.SelectedValue;
            ////tel - Shopper's telephone number
            //PRequest.tel = TxtTelephone.Text;
            ////fax - Shopper's fax number
            //PRequest.fax = TxtFax.Text;
            ////email - Shopper's email address
            PRequest.email = model.Email;
            ////If passing delivery details, set withDelivery = true.
            //PRequest.withDelivery = true;
            ////delvName, delvAddress1/2/3, delvTown, delvRegion, delvPostcode & delvCountry - Delivery address fields (NOTE: do not need to be passed/set if "withDelivery" set to false.
            PRequest.delvName     = model.CustomerName;
            PRequest.delvAddress1 = model.Address;
            //PRequest.delvAddress2 = TxtdelvAddress2.Text;
            //PRequest.delvAddress3 = TxtdelvAddress3.Text;
            //PRequest.delvTown = "ABC";
            //PRequest.delvRegion = TxtdelvRegion.Text;
            PRequest.delvPostcode = model.PostCode;
            //PRequest.delvCountry = DdldelvCountry.SelectedValue;
            //authMode - set to TransactionType.A for Authorise & Capture, set to TransactionType.E for Pre-Auth Only.
            PRequest.authMode = TransactionType.A;
            //testMode - set to 0 for Live Mode, set to 100 for Test Mode.
            PRequest.testMode = testMode;
            //hideCurrency - Set to true to hide currency drop down on the hosted payment page.
            PRequest.hideCurrency = false;
            //fixContact - Set to true to stop a shopper from changing their billing/shipping addresses on the hosted payment page.
            PRequest.fixContact = false;
            //hideContact - set to true to hide the billing/shipping address fields on the hosted payment page.
            PRequest.hideContact = false;
            //MC_callback - the URL of the Callback.aspx file. SiteBaseURL is set in the web.config file.
            PRequest.MC_callback = WebsiteURL + "/Payment/WorldPayCallback";

            HttpContext httpa = default(HttpContext);

            httpa = System.Web.HttpContext.Current;
            HostedPaymentProcessor process = new HostedPaymentProcessor(httpa);

            process.SubmitTransaction(PRequest, MD5secretKey);

            return(View());
        }
Exemple #3
0
        public static String GetBankRemotePost(OrderData orderData)
        {
            var objCtrl = new NBrightBuyController();
            var info    = objCtrl.GetPluginSinglePageData("OS_WorldPaypayment", "OS_WorldPayPAYMENT", orderData.Lang);

            var MD5secretKey = info.GetXmlProperty("genxml/textbox/secretkey");
            var installid    = info.GetXmlPropertyInt("genxml/textbox/installid");

            var request = new HostedTransactionRequest();

            var appliedtotal = orderData.PurchaseInfo.GetXmlPropertyRaw("genxml/appliedtotal");

            request.amount   = appliedtotal;
            request.currency = info.GetXmlProperty("genxml/textbox/currencycode");
            request.testMode = 0;  // Not sure what this should be.  Only example I found was 100 for test system??
            request.instId   = installid;
            request.cartId   = orderData.GetInfo().ItemID.ToString();

            var postUrl = info.GetXmlProperty("genxml/textbox/liveurl");

            if (info.GetXmlPropertyBool("genxml/checkbox/preproduction"))
            {
                request.testMode = 100;
                postUrl          = info.GetXmlProperty("genxml/textbox/testurl");
            }

            var requestInputs = request.ToNameValueCollection();

            var rPost = new RemotePostPay();

            rPost.Url = postUrl;

            var callbackhashInputs = new StringBuilder();

            callbackhashInputs.Append(MD5secretKey);
            callbackhashInputs.Append(":");
            callbackhashInputs.Append(request.currency);
            callbackhashInputs.Append(":");
            callbackhashInputs.Append(request.cartId);
            callbackhashInputs.Append(":");
            callbackhashInputs.Append(appliedtotal);

            var signaturehashInputs = new StringBuilder();

            signaturehashInputs.Append(MD5secretKey);
            signaturehashInputs.Append(":");
            signaturehashInputs.Append(request.currency);
            signaturehashInputs.Append(":");
            signaturehashInputs.Append(request.cartId);
            signaturehashInputs.Append(":");
            signaturehashInputs.Append(appliedtotal);

            byte[] callbackhashDigest = new MD5CryptoServiceProvider().ComputeHash(StringToByteArray(callbackhashInputs.ToString()));

            byte[] signaturehashDigest = new MD5CryptoServiceProvider().ComputeHash(StringToByteArray(signaturehashInputs.ToString()));

            rPost.Add("signature", ByteArrayToHexString(signaturehashDigest));
            rPost.Add("MC_callbacksignature", ByteArrayToHexString(callbackhashDigest));

            // add the rest of the form variables
            foreach (var k in requestInputs.AllKeys)
            {
                rPost.Add(k, requestInputs.GetValues(k)[0]);
            }


            //Build the re-direct html
            var rtnStr = "";

            rtnStr = rPost.GetPostHtml();

            if (info.GetXmlPropertyBool("genxml/checkbox/debugmode"))
            {
                File.WriteAllText(PortalSettings.Current.HomeDirectoryMapPath + "\\debug_OS_WorldPaypost.html", rtnStr + " signaturehashInputs:" + signaturehashInputs + " request.amount:" + request.amount + " appliedtotal:" + appliedtotal);
            }
            return(rtnStr);
        }
Exemple #4
0
        //
        // POST: /WorldPay/API

        public void ProcessTransaction(Order order)
        {
            HostedTransactionRequest PRequest = new HostedTransactionRequest();

            PRequest.instId = installationID;
            //amount - A decimal number giving the cost of the purchase in terms of the major currency unit e.g. 12.56
            PRequest.amount = (double)order.Total;  //450.00;
            //cartId - If your system has created a unique order/cart ID, enter it here.
            PRequest.cartId = Guid.NewGuid().ToString();
            //desc - enter the description for this order.
            PRequest.desc = "Test Order from my .net site word";
            //currency - 3 letter ISO code for the currency of this payment.
            PRequest.currency = "GBP";
            //If passing delivery details, set withDelivery = true.
            PRequest.withDelivery = false;
            //name, address1/2/3, town, region, postcode & country - Billing address fields
            PRequest.name     = order.FirstName + ' ' + order.LastName;
            PRequest.address1 = order.Address1;
            PRequest.address2 = order.Address2;
            PRequest.address3 = order.Address3;
            PRequest.town     = order.Town;
            PRequest.region   = order.County;
            PRequest.postcode = order.PostalCode;
            PRequest.country  = order.Country;
            //tel - Shopper's telephone number
            PRequest.tel = order.Phone;
            //fax - Shopper's fax number
            //PRequest.fax = TxtFax.Text;
            //email - Shopper's email address
            PRequest.email = order.Email;
            //If passing delivery details, set withDelivery = true.
            PRequest.withDelivery = false;
            //delvName, delvAddress1/2/3, delvTown, delvRegion, delvPostcode & delvCountry - Delivery address fields (NOTE: do not need to be passed/set if "withDelivery" set to false.
            //PRequest.delvName = TxtdelvName.Text;
            //PRequest.delvAddress1 = TxtdelvAddress1.Text;
            //PRequest.delvAddress2 = TxtdelvAddress2.Text;
            //PRequest.delvAddress3 = TxtdelvAddress3.Text;
            //PRequest.delvTown = TxtdelvTown.Text;
            //PRequest.delvRegion = TxtdelvRegion.Text;
            //PRequest.delvPostcode = TxtdelvPostcode.Text;
            //PRequest.delvCountry = DdldelvCountry.SelectedValue;
            //authMode - set to TransactionType.A for Authorise & Capture, set to TransactionType.E for Pre-Auth Only.
            PRequest.authMode = TransactionType.A;
            //testMode - set to 0 for Live Mode, set to 100 for Test Mode.
            PRequest.testMode = 100;
            //hideCurrency - Set to true to hide currency drop down on the hosted payment page.
            PRequest.hideCurrency = true;
            //fixContact - Set to true to stop a shopper from changing their billing/shipping addresses on the hosted payment page.
            PRequest.fixContact = true;
            //hideContact - set to true to hide the billing/shipping address fields on the hosted payment page.
            PRequest.hideContact = false;
            //MC_callback - the URL of the Callback.aspx file. SiteBaseURL is set in the web.config file.
            PRequest.MC_callback = _websiteUrl + "/Callback.aspx";

            HttpContext httpa = default(HttpContext);

            //httpa = HttpContext.Current;
            httpa = System.Web.HttpContext.Current;
            HostedPaymentProcessor process = new HostedPaymentProcessor(httpa);

            process.SubmitTransaction(PRequest, _md5SecretKey);
        }