Esempio n. 1
0
        public TransactionRegistrationRequest(DonationRow donationRow)
        {
            this.VendorTxCode = donationRow.VendorTxCode;
            this.Amount       = donationRow.Amount;
            this.AllowGiftAid = donationRow.GiftAid;

            this.BillingSurname    = donationRow.LastName;
            this.BillingFirstnames = donationRow.FirstName;

            this.BillingAddress1 = donationRow.Address1;
            this.BillingAddress2 = donationRow.Address2;
            this.BillingCity     = donationRow.TownCity;
            this.BillingCountry  = "GB";
            this.BillingPostCode = donationRow.Postcode;

            this.DeliverySurname    = donationRow.LastName;
            this.DeliveryFirstnames = donationRow.FirstName;

            this.DeliveryAddress1 = donationRow.Address1;
            this.DeliveryAddress2 = donationRow.Address2;
            this.DeliveryCity     = donationRow.TownCity;
            this.DeliveryCountry  = "GB";
            this.DeliveryPostCode = donationRow.Postcode;

            // if member known, then populate customer email
            if (donationRow.MemberId.HasValue)
            {
                this.CustomerEmail = ((IPartier) new MembershipHelper(UmbracoContext.Current).GetById((int)donationRow.MemberId)).Email;
            }
        }
Esempio n. 2
0
        private bool IsSignatureValid(DonationRow donationRow, NotificationRequest notificationRequest)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(notificationRequest.VPSTxId);
            stringBuilder.Append(notificationRequest.VendorTxCode);
            stringBuilder.Append(notificationRequest.Status.ToString());
            stringBuilder.Append(notificationRequest.TxAuthNo);
            stringBuilder.Append(WebConfigurationManager.AppSettings["SagePay:Vendor"].ToLower());  // local value used in conjunction with sent data
            stringBuilder.Append(notificationRequest.AVSCV2);
            stringBuilder.Append(donationRow.SecurityKey);                                          // local value used in conjunction with sent data
            stringBuilder.Append(notificationRequest.AddressResult);
            stringBuilder.Append(notificationRequest.PostCodeResult);
            stringBuilder.Append(notificationRequest.CV2Result);
            stringBuilder.Append(Convert.ToInt32(notificationRequest.GiftAid));
            stringBuilder.Append(notificationRequest.ThreeDSecureStatus);
            stringBuilder.Append(notificationRequest.CAVV);
            stringBuilder.Append(notificationRequest.AddressStatus);
            stringBuilder.Append(notificationRequest.PayerStatus);
            stringBuilder.Append(notificationRequest.CardType);
            stringBuilder.Append(notificationRequest.Last4Digits);
            stringBuilder.Append(notificationRequest.DeclineCode);
            stringBuilder.Append(notificationRequest.ExpiryDate);
            stringBuilder.Append(notificationRequest.FraudResponse);
            stringBuilder.Append(notificationRequest.BankAuthCode);

            string hash = FormsAuthentication.HashPasswordForStoringInConfigFile(stringBuilder.ToString(), "MD5");

            //return notificationRequest.VPSSignature == hash;

            return(true); // HACK !!! hash calculation fails when using the test card data (although works correctly when cancelling in Sage Pay)
        }
        public override ActionResult Index(RenderModel renderModel)
        {
            Donate model = (Donate)renderModel.Content;

            // if VendorTxCode can be found on the querystring, then get party guid from transaction table
            Guid vendorTxCode;

            if (Guid.TryParse(this.Request.QueryString["VendorTxCode"], out vendorTxCode))
            {
                DonationRow donationRow = this.DatabaseContext.Database.Fetch <DonationRow>("SELECT TOP 1 * FROM wonderlandDonation WHERE VendorTxCode = @0", vendorTxCode).SingleOrDefault();

                if (donationRow != null)
                {
                    model.PartyHost   = this.Members.GetPartyHost(donationRow.PartyGuid);
                    model.DonationRow = donationRow;

                    if (donationRow.Success)
                    {
                        return(this.View("Donate/Complete", model));
                    }
                    else if (donationRow.Cancelled)
                    {
                        return(this.View("Donate/Cancelled", model));
                    }
                    else
                    {
                        return(this.View("Donate/Failed", model));
                    }
                }
                else
                {
                    return(this.View("Donate/UnknownTransaction", model));
                }
            }

            Guid partyGuid;

            if (Guid.TryParse(this.Request.QueryString["partyGuid"], out partyGuid))
            {
                model.PartyHost = this.Members.GetPartyHost(partyGuid);
            }

            // if a party wasn't found via the query string, then attempt to find party associated with the current login
            if (model.PartyHost == null && this.Members.IsLoggedInPartier())
            {
                model.PartyHost = this.Members.GetPartyHost(((IPartier)this.Members.GetCurrentMember()).PartyGuid);
            }

            if (model.PartyHost != null)
            {
                return(this.View("Donate/Donate", model));
            }

            // couldn't find a party host for this donation, so go to Macmillan
            return(this.View("Donate/Macmillan", model));
        }
Esempio n. 4
0
        public ActionResult HandleDonateForm(DonateForm donateForm)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.CurrentUmbracoPage());
            }

            int?memberId = null;

            if (this.Members.IsLoggedInPartier())
            {
                memberId = this.Members.GetCurrentMemberId();
            }

            DonationRow donationRow = new DonationRow()
            {
                PartyGuid      = donateForm.PartyGuid,
                Amount         = donateForm.Amount,
                GiftAid        = donateForm.AllowGiftAid,
                MemberId       = memberId,
                FirstName      = donateForm.FirstName,
                LastName       = donateForm.LastName,
                Address1       = donateForm.Address1,
                Address2       = donateForm.Address2,
                TownCity       = donateForm.TownCity,
                Postcode       = donateForm.Postcode,
                PaymentJourney = PaymentJourney.Donate,
                Success        = false
            };

            // insert new record
            this.DatabaseContext.Database.Insert(donationRow);

            // build new obj containing data for sage pay
            TransactionRegistrationRequest transactionRegistrationRequest = new TransactionRegistrationRequest(donationRow);

            // send to sage pay and get respone
            TransactionRegistrationResponse transactionRegistrationResponse = TransactionRegistration.Send(transactionRegistrationRequest);

            // based on response, we redirect the user to...
            if (transactionRegistrationResponse.Status == TransactionRegistrationStatus.OK)
            {
                // update database
                donationRow.VPSTxId     = transactionRegistrationResponse.VPSTxId;
                donationRow.SecurityKey = transactionRegistrationResponse.SecurityKey;

                this.DatabaseContext.Database.Update(donationRow);

                return(this.Redirect(transactionRegistrationResponse.NextURL));
            }

            this.ViewData["errorMessage"] = transactionRegistrationResponse.StatusDetail;

            return(this.View("Donate/Failed", this.CurrentPage));
        }
Esempio n. 5
0
        internal PartyWallItem(DonationRow donation)
        {
            IPartier partier = (IPartier) new MembershipHelper(UmbracoContext.Current).GetById((int)donation.MemberId);

            this.Id = -1;
            this.PartyWallItemType = PartyWallItemType.Donation;
            this.ThumbnailUrl      = partier.ProfileImageUrl;
            this.IsPartyHost       = partier is PartyHost && donation.PartyGuid == partier.PartyGuid;
            this.Name      = partier.FirstName + " " + partier.LastName;
            this.Text      = donation.Amount.ToString();
            this.Timestamp = donation.Timestamp.ToUniversalTime();
        }
Esempio n. 6
0
        private void SendPaymentConfirmationEmail(DonationRow donationRow)
        {
            if (donationRow.MemberId.HasValue)
            {
                Donate donate = (Donate)this.Umbraco.TypedContentSingleAtXPath("//" + Donate.Alias);

                IPartier partier = (IPartier)this.Members.GetById(donationRow.MemberId.Value);

                PartyHost partyhost = this.Members.GetPartyHost(donationRow.PartyGuid);

                MailMessage mailMessage = new MailMessage();

                mailMessage.From = new MailAddress(donate.ServerEmailAddress);
                mailMessage.To.Add(new MailAddress(partier.Email));
                mailMessage.Subject    = donate.EmailSubject;
                mailMessage.IsBodyHtml = true;

                mailMessage.Body = donate.EmailBody
                                   .Replace("[%FIRST_NAME%]", partier.FirstName)
                                   .Replace("[%LAST_NAME%]", partier.LastName)
                                   .Replace("[%PARTY_HOST%]", partyhost.FirstName + " " + partyhost.LastName)
                                   .Replace("[%EMAIL%]", partier.Email)
                                   .Replace("[%AMOUNT%]", "£" + donationRow.Amount.ToString("F"))
                                   .Replace("[%DONATION_TIMESTAMP%]", donationRow.Timestamp.ToShortDateString())
                                   .Replace("[%VENDOR_TX_CODE%]", donationRow.VendorTxCode.ToString());

                // Fire and forget
                Task.Run(() =>
                {
                    using (SmtpClient smtpClient = new SmtpClient())
                    {
                        smtpClient.Send(mailMessage);
                    }
                });
            }
        }
Esempio n. 7
0
        public ActionResult HandleRegisterGuestBillingForm(RegisterGuestBillingForm registerGuestBillingForm)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.CurrentUmbracoPage());
            }

            PartyGuest partyGuest = (PartyGuest)this.Members.GetCurrentMember();

            if (partyGuest.FirstName != registerGuestBillingForm.FirstName)
            {
                partyGuest.FirstName = registerGuestBillingForm.FirstName;
            }

            if (partyGuest.LastName != registerGuestBillingForm.LastName)
            {
                partyGuest.LastName = registerGuestBillingForm.LastName;
            }

            Address address = new Address(
                registerGuestBillingForm.Address1,
                registerGuestBillingForm.Address2,
                registerGuestBillingForm.TownCity,
                registerGuestBillingForm.Postcode);

            partyGuest.BillingAddress = address;

            if (!string.IsNullOrWhiteSpace(registerGuestBillingForm.Message))
            {
                // post message to party wall
                this.DatabaseContext.Database.Insert(new MessageRow()
                {
                    MemberId = this.Members.GetCurrentMemberId(),
                    Text     = registerGuestBillingForm.Message,
                    Image    = null
                });
            }

            if (registerGuestBillingForm.Amount == 0)
            {
                // update dot mailer to indicate guest has fully registered
                DotMailerService.GuestRegistrationCompleted((Contact)partyGuest);

                return(this.Redirect(partyGuest.PartyUrl));
            }

            DonationRow donationRow = new DonationRow()
            {
                PartyGuid      = registerGuestBillingForm.PartyGuid,
                Amount         = registerGuestBillingForm.Amount,
                GiftAid        = registerGuestBillingForm.AllowGiftAid,
                MemberId       = this.Members.GetCurrentMemberId(),
                FirstName      = registerGuestBillingForm.FirstName,
                LastName       = registerGuestBillingForm.LastName,
                Address1       = registerGuestBillingForm.Address1,
                Address2       = registerGuestBillingForm.Address2,
                TownCity       = registerGuestBillingForm.TownCity,
                Postcode       = registerGuestBillingForm.Postcode,
                PaymentJourney = PaymentJourney.RegisterGuest,
                Success        = false
            };

            // insert new record
            this.DatabaseContext.Database.Insert(donationRow);

            // build new obj containing data for sage pay
            TransactionRegistrationRequest transactionRegistrationRequest = new TransactionRegistrationRequest(donationRow);

            // send to sage pay and get respone
            TransactionRegistrationResponse transactionRegistrationResponse = TransactionRegistration.Send(transactionRegistrationRequest);

            // based on response, we redirect the user to...
            if (transactionRegistrationResponse.Status == TransactionRegistrationStatus.OK)
            {
                // update database
                donationRow.VPSTxId     = transactionRegistrationResponse.VPSTxId;
                donationRow.SecurityKey = transactionRegistrationResponse.SecurityKey;

                this.DatabaseContext.Database.Update(donationRow);

                return(this.Redirect(transactionRegistrationResponse.NextURL));
            }

            this.ViewData["errorMessage"] = transactionRegistrationResponse.StatusDetail;

            return(this.View("RegisterGuest/Failed", this.CurrentPage));
        }
Esempio n. 8
0
        public HttpResponseMessage Notifcation([FromBody] NotificationRequest notificationRequest)
        {
            // create response obj to send back to Sage Pay (defaulting to error)
            NotificationResponse notificationResponse = new NotificationResponse();

            notificationResponse.Status = NotificationStatus.ERROR;

            // get associated transaction details from the database
            DonationRow donationRow = this.DatabaseContext.Database.Fetch <DonationRow>("SELECT TOP 1 * FROM wonderlandDonation WHERE VendorTxCode = @0", notificationRequest.VendorTxCode).Single();

            // safety checks
            if (notificationRequest.VPSTxId != donationRow.VPSTxId)
            {
                notificationResponse.StatusDetail += "VPSTxID Invalid" + Environment.NewLine;
            }
            else if (!this.IsSignatureValid(donationRow, notificationRequest))
            {
                notificationResponse.StatusDetail += "Signature Invalid" + Environment.NewLine;
            }
            else
            {
                // change response status from Error to OK, as valid inbound data is valid
                notificationResponse.Status = NotificationStatus.OK;

                switch (notificationRequest.Status)
                {
                case NotificationStatus.OK:
                    donationRow.Success = true;
                    this.SendPaymentConfirmationEmail(donationRow);
                    break;

                case NotificationStatus.ABORT:
                    donationRow.Cancelled = true;
                    break;
                }

                this.DatabaseContext.Database.Update(donationRow);
            }

            // determine redirect url
            string redirectUrl = WebConfigurationManager.AppSettings["SagePay:RedirectDomain"];

            switch (donationRow.PaymentJourney)
            {
            case PaymentJourney.RegisterGuest:

                // safety check (memberId should always have a value)
                if (donationRow.MemberId.HasValue)
                {
                    // update dot mailer to indicate guest has fully registered
                    DotMailerService.GuestRegistrationCompleted((Contact)(PartyGuest)this.Members.GetById(donationRow.MemberId.Value));
                }

                redirectUrl += this.Umbraco.TypedContentSingleAtXPath("//" + RegisterGuest.Alias).Url;
                break;

            case PaymentJourney.Donate:

                redirectUrl += this.Umbraco.TypedContentSingleAtXPath("//" + Donate.Alias).Url;
                break;
            }

            //update dot mailer donation_amount and guest_count for associated party host
            DotMailerService.UpdateContact((Contact)this.Members.GetPartyHost(donationRow.PartyGuid));

            notificationResponse.RedirectURL = redirectUrl;

            if (donationRow.Success)
            {
                notificationResponse.RedirectURL += "complete/";
            }

            if (donationRow.Cancelled)
            {
                notificationResponse.RedirectURL += "cancelled/";
            }

            notificationResponse.RedirectURL += "?VendorTxCode=" + notificationRequest.VendorTxCode;

            // ensure the return type is plain text
            return(new HttpResponseMessage(System.Net.HttpStatusCode.OK)
            {
                Content = new StringContent(
                    SagePaySerializer.SerializeResponse(notificationResponse),
                    Encoding.UTF8,
                    "text/plain")
            });
        }
        public override ActionResult Index(RenderModel renderModel)
        {
            RegisterGuest model = (RegisterGuest)renderModel.Content;

            // if VendorTxCode can be found on the querystring, then get party guid from transaction table
            Guid vendorTxCode;

            if (Guid.TryParse(this.Request.QueryString["VendorTxCode"], out vendorTxCode))
            {
                DonationRow donationRow = this.DatabaseContext.Database.Fetch <DonationRow>("SELECT TOP 1 * FROM wonderlandDonation WHERE VendorTxCode = @0", vendorTxCode).SingleOrDefault();

                if (donationRow != null)
                {
                    model.PartyHost   = this.Members.GetPartyHost(donationRow.PartyGuid);
                    model.DonationRow = donationRow;

                    if (donationRow.Success)
                    {
                        return(this.View("RegisterGuest/Complete", model));
                    }
                    else if (donationRow.Cancelled)
                    {
                        return(this.View("RegisterGuest/Cancelled", model));
                    }
                    else
                    {
                        return(this.View("RegisterGuest/Failed", model));
                    }
                }
                else
                {
                    return(this.View("RegisterGuest/UnknownTransaction", model));
                }
            }

            Guid partyGuid;

            if (Guid.TryParse(this.Request.QueryString["partyGuid"], out partyGuid))
            {
                model.PartyHost = this.Members.GetPartyHost(partyGuid);

                if (model.PartyHost != null)
                {
                    if (this.Members.IsLoggedInPartier())
                    {
                        if (this.Members.GetCurrentMember() is PartyGuest)
                        {
                            PartyGuest partyGuest = (PartyGuest)this.Members.GetCurrentMember();

                            return(this.View("RegisterGuest/RegisterGuestBilling", model));
                        }
                        else
                        {
                            return(this.Redirect(Home.GetCurrentHome(model).Url));
                        }
                    }

                    return(View("RegisterGuest/RegisterGuest", model));
                }
            }

            // fallback
            return(this.Redirect(Home.GetCurrentHome(model).Url));
        }
Esempio n. 10
0
 public void AddDonationRow(DonationRow row) {
     this.Rows.Add(row);
 }
Esempio n. 11
0
 public DonationRowChangeEvent(DonationRow row, System.Data.DataRowAction action) {
     this.eventRow = row;
     this.eventAction = action;
 }
Esempio n. 12
0
 public void RemoveDonationRow(DonationRow row) {
     this.Rows.Remove(row);
 }