Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void ProcessRequest(HttpContext context)
        {
            string merchantId = WebConfigurationManager.AppSettings["MerchantId"];

            var processor = new HostedPaymentProcessor(merchantId, new HttpContextWrapper(context));

            try
            {
                if (!processor.ValidateRequest())
                {
                    throw new InvalidOperationException("Request came from an invalid source");
                }

                var result = new ServerTransactionResult(context.Request.Form);

                processor.ValidateResult(result); // will throw if merchant ids do not match

                // at this point we can get order and work with the result
                if (result.Successful)
                {
                    // update our order to say payment sucessful
                }

                // now we need to let Cardsave know we've received the result
                context.Response.Write(
                    processor.CreateServerResponseString(TransactionStatus.Successful));
            }
            catch (Exception ex)
            {
                // let cardsave know there was a problem
                context.Response.Write(
                    processor.CreateServerResponseString(TransactionStatus.Exception, ex.Message));
            }
        }
Esempio n. 3
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());
        }
Esempio n. 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);
        }