コード例 #1
0
        public ActionResult Confirm()
        {
            //Assign value to form field from session
            CustomCart cart       = new CustomCart().Current();
            CustomForm customForm = new CustomForm();

            customForm.FirstName = cart.BillingFirstnames;
            customForm.LastName  = cart.BillingSurname;
            customForm.Address1  = cart.BillingAddress1;
            customForm.Address2  = cart.BillingAddress2;
            customForm.City      = cart.BillingCity;
            customForm.PostCode  = cart.BillingPostCode;
            customForm.Country   = cart.BillingCountry;
            customForm.Phone     = cart.Phone;
            customForm.DOB       = Convert.ToDateTime(cart.DOB);

            SagePayFormIntegration sagePayFormIntegration = new SagePayFormIntegration();

            IFormPayment request = sagePayFormIntegration.FormPaymentRequest();

            SetSagePayAPIData(request);

            var errors = sagePayFormIntegration.Validation(request);

            if (errors == null || errors.Count == 0)
            {
                sagePayFormIntegration.ProcessRequest(request);
                ViewBag.Crypt = request.Crypt;
            }
            else
            {
                ViewBag.Error = "Some error occurred";
            }
            return(View(customForm));
        }
コード例 #2
0
        public IFormPayment ProcessRequest(IFormPayment formPayment)
        {
            RequestQueryString = BuildQueryString(ConvertSagePayMessageToNameValueCollection(ProtocolMessage.FORM_PAYMENT, typeof(IFormPayment), formPayment, _settings.ProtocolVersion));

            formPayment.Crypt = Cryptography.EncryptAndEncode(RequestQueryString, _settings.EncryptionPassword);

            return(formPayment);
        }
コード例 #3
0
        public IFormPayment ProcessRequest(IFormPayment formPayment)
        {
            RequestQueryString = BuildQueryString(ConvertSagePayMessageToNameValueCollection(ProtocolMessage.FORM_PAYMENT, typeof(IFormPayment), formPayment, _settings.ProtocolVersion));

            formPayment.Crypt = Cryptography.EncryptAndEncode(RequestQueryString, _settings.EncryptionPassword);

            return formPayment;
        }
コード例 #4
0
 public NameValueCollection Validation(IFormPayment formPayment)
 {
     if (SagePaySettings.EnableClientValidation)
     {
         return(Validation(ProtocolMessage.FORM_PAYMENT, typeof(IFormPayment), formPayment, SagePaySettings.ProtocolVersion));
     }
     return(null);
 }
コード例 #5
0
        private void SetSagePayAPIData(IFormPayment request)
        {
            var        isCollectRecipientDetails = SagePaySettings.IsCollectRecipientDetails;
            CustomCart cart = new CustomCart().Current();

            request.VpsProtocol     = SagePaySettings.ProtocolVersion;
            request.TransactionType = SagePaySettings.DefaultTransactionType;
            request.Vendor          = SagePaySettings.VendorName;
            request.VendorTxCode    = SagePayFormIntegration.GetNewVendorTxCode();

            request.Amount            = 1; //Custom value set
            request.Currency          = SagePaySettings.Currency;
            request.SuccessUrl        = SagePaySettings.SiteFqdn + "Payment/Result?customParams=Transaction Details For Success";
            request.FailureUrl        = SagePaySettings.SiteFqdn + "Payment/Result?customParams=Transaction Details For Failure";
            request.Description       = cart.Description;
            request.BillingSurname    = cart.BillingSurname;
            request.BillingFirstnames = cart.BillingFirstnames;
            request.BillingAddress1   = cart.BillingAddress1 + " " + cart.BillingAddress2;
            request.BillingCity       = cart.BillingCity;
            request.BillingCountry    = cart.BillingCountry;

            request.DeliverySurname    = cart.DeliverySurname;
            request.DeliveryFirstnames = cart.DeliveryFirstnames;
            request.DeliveryAddress1   = cart.DeliveryAddress1 + " " + cart.DeliveryAddress2;
            request.DeliveryCity       = cart.DeliveryCity;
            request.DeliveryCountry    = cart.DeliveryCountry;

            //Optional
            request.BillingPostCode  = cart.BillingPostCode;
            request.DeliveryPostCode = cart.DeliveryPostCode;
            request.BasketXml        = cart.BasketXml;

            request.VendorEmail  = SagePaySettings.VendorEmail;
            request.SendEmail    = SagePaySettings.SendEmail;
            request.EmailMessage = SagePaySettings.EmailMessage;

            request.AllowGiftAid     = SagePaySettings.AllowGiftAid;
            request.ApplyAvsCv2      = SagePaySettings.ApplyAvsCv2;
            request.Apply3dSecure    = SagePaySettings.Apply3dSecure;
            request.BillingAgreement = "";
            request.ReferrerId       = SagePaySettings.ReferrerID;
            request.SurchargeXml     = SagePaySettings.SurchargeXML;
            //set vendor data
            request.VendorData = "";
        }
コード例 #6
0
 public NameValueCollection Validation(IFormPayment formPayment)
 {
     return Validation(ProtocolMessage.FORM_PAYMENT, typeof(IFormPayment), formPayment, _settings.ProtocolVersion);
 }
コード例 #7
0
        //TODO: refactor away to a Service that wraps the SagePay kit horribleness
        private void SetSagePayApiData(IFormPayment request, IInvoice invoice, IPayment payment)
        {
            // Get Merchello data
            var billingAddress  = invoice.GetBillingAddress();
            var shippingAddress = billingAddress;

            // Shipment - only use a shipping address if there is shipment info in the invoice
            var shipmentLineItem = invoice.ShippingLineItems().FirstOrDefault();

            if (shipmentLineItem != null)
            {
                var shipment = shipmentLineItem.ExtendedData.GetShipment <InvoiceLineItem>();
                shippingAddress = shipment.GetDestinationAddress();
            }

            // SagePay details
            request.VpsProtocol     = Settings.ProtocolVersion;
            request.TransactionType = Settings.TransactionType;
            request.Vendor          = Settings.VendorName;
            request.VendorTxCode    = SagePayFormIntegration.GetNewVendorTxCode();
            request.Amount          = payment.Amount;
            request.Currency        = invoice.CurrencyCode();
            request.Description     = "Goods from " + Settings.VendorName;

            // TODO:  Is there a basket summary I can access?  Or convert the Basket to a sagepay format

            // Set ReturnUrl and CancelUrl of SagePay request to SagePayApiController.
            Func <string, string> adjustUrl = (url) =>
            {
                if (!url.StartsWith("http"))
                {
                    url = GetWebsiteUrl() + (url[0] == '/' ? "" : "/") + url;
                }
                url = url.Replace("{invoiceKey}", invoice.Key.ToString(), StringComparison.InvariantCultureIgnoreCase);
                url = url.Replace("{paymentKey}", payment.Key.ToString(), StringComparison.InvariantCultureIgnoreCase);
                return(url);
            };

            request.SuccessUrl = adjustUrl("/umbraco/MerchelloSagePay/SagePayApi/SuccessPayment?InvoiceKey={invoiceKey}&PaymentKey={paymentKey}");
            request.FailureUrl = adjustUrl("/umbraco/MerchelloSagePay/SagePayApi/AbortPayment?InvoiceKey={invoiceKey}&PaymentKey={paymentKey}");

            // Billing details
            request.BillingSurname    = billingAddress.TrySplitLastName();
            request.BillingFirstnames = billingAddress.TrySplitFirstName();
            request.BillingAddress1   = billingAddress.Address1;
            request.BillingAddress2   = billingAddress.Address2;
            request.BillingPostCode   = billingAddress.PostalCode;
            request.BillingCity       = billingAddress.Locality;
            request.BillingCountry    = invoice.BillToCountryCode;
            request.CustomerEmail     = billingAddress.Email;

            // Shipping details
            request.DeliverySurname    = shippingAddress.TrySplitLastName();
            request.DeliveryFirstnames = shippingAddress.TrySplitFirstName();
            request.DeliveryAddress1   = shippingAddress.Address1;
            request.DeliveryCity       = shippingAddress.Locality;
            request.DeliveryCountry    = shippingAddress.CountryCode;
            request.DeliveryPostCode   = shippingAddress.PostalCode;

            //Optional
            //request.CustomerName = cart.Billing.FirstNames + " " + cart.Billing.Surname;

            //request.VendorEmail = Settings.VendorEmail;
            //request.SendEmail = Settings.SendEmail;

            //request.EmailMessage = Settings.EmailMessage;
            //request.BillingAddress2 = billingAddress.Address2;
            //request.BillingPostCode = billingAddress.PostalCode;
            //request.BillingState = billingAddress.Region;
            //request.BillingPhone = billingAddress.Phone;
            //request.DeliveryAddress2 = shippingAddress.Address2;
            //request.DeliveryPostCode = shippingAddress.PostalCode;
            //request.DeliveryState = shippingAddress.Region;
            //request.DeliveryPhone = shippingAddress.Phone;
        }
コード例 #8
0
 public NameValueCollection Validation(IFormPayment formPayment)
 {
     return(Validation(ProtocolMessage.FORM_PAYMENT, typeof(IFormPayment), formPayment, _settings.ProtocolVersion));
 }
        //TODO: refactor away to a Service that wraps the SagePay kit horribleness
        private void SetSagePayApiData(IFormPayment request, IInvoice invoice, IPayment payment)
        {
            // Get Merchello data
            var billingAddress = invoice.GetBillingAddress();
            var shippingAddress = billingAddress;

            // Shipment - only use a shipping address if there is shipment info in the invoice
            var shipmentLineItem = invoice.ShippingLineItems().FirstOrDefault();
            if (shipmentLineItem != null)
            {
                var shipment = shipmentLineItem.ExtendedData.GetShipment<InvoiceLineItem>();
                shippingAddress = shipment.GetDestinationAddress();
            }
            
            // SagePay details
            request.VpsProtocol = Settings.ProtocolVersion;
            request.TransactionType = Settings.TransactionType;
            request.Vendor = Settings.VendorName;
            request.VendorTxCode = SagePayFormIntegration.GetNewVendorTxCode();
            request.Amount = payment.Amount;
            request.Currency = invoice.CurrencyCode();
            request.Description = "Goods from " + Settings.VendorName;
            
            // TODO:  Is there a basket summary I can access?  Or convert the Basket to a sagepay format

            // Set ReturnUrl and CancelUrl of SagePay request to SagePayApiController.
            Func<string, string> adjustUrl = (url) =>
            {
                if (!url.StartsWith("http")) url = GetWebsiteUrl() + (url[0] == '/' ? "" : "/") + url;
                url = url.Replace("{invoiceKey}", invoice.Key.ToString(), StringComparison.InvariantCultureIgnoreCase);
                url = url.Replace("{paymentKey}", payment.Key.ToString(), StringComparison.InvariantCultureIgnoreCase);
                return url;
            };

            request.SuccessUrl = adjustUrl("/umbraco/MerchelloSagePay/SagePayApi/SuccessPayment?InvoiceKey={invoiceKey}&PaymentKey={paymentKey}");
            request.FailureUrl = adjustUrl("/umbraco/MerchelloSagePay/SagePayApi/AbortPayment?InvoiceKey={invoiceKey}&PaymentKey={paymentKey}");

            // Billing details
            request.BillingSurname = billingAddress.TrySplitLastName();
            request.BillingFirstnames = billingAddress.TrySplitFirstName();
            request.BillingAddress1 = billingAddress.Address1;
            request.BillingAddress2 = billingAddress.Address2;
            request.BillingPostCode = billingAddress.PostalCode;
            request.BillingCity = billingAddress.Locality;
            request.BillingCountry = invoice.BillToCountryCode;
            request.CustomerEmail = billingAddress.Email;

            // Shipping details
            request.DeliverySurname = shippingAddress.TrySplitLastName();
            request.DeliveryFirstnames = shippingAddress.TrySplitFirstName();
            request.DeliveryAddress1 = shippingAddress.Address1;
            request.DeliveryCity = shippingAddress.Locality;
            request.DeliveryCountry = shippingAddress.CountryCode;
            request.DeliveryPostCode = shippingAddress.PostalCode;

            //Optional
            //request.CustomerName = cart.Billing.FirstNames + " " + cart.Billing.Surname;
            
            //request.VendorEmail = Settings.VendorEmail;
            //request.SendEmail = Settings.SendEmail;

            //request.EmailMessage = Settings.EmailMessage;
            //request.BillingAddress2 = billingAddress.Address2;
            //request.BillingPostCode = billingAddress.PostalCode;
            //request.BillingState = billingAddress.Region;
            //request.BillingPhone = billingAddress.Phone;
            //request.DeliveryAddress2 = shippingAddress.Address2;
            //request.DeliveryPostCode = shippingAddress.PostalCode;
            //request.DeliveryState = shippingAddress.Region;
            //request.DeliveryPhone = shippingAddress.Phone;

        }