private void CheckPartyPageComplete(PartyHost partyHost)
        {
            if (!partyHost.DotMailerPartyPageComplete)
            {
                if (partyHost.PartyImage != null &&
                    partyHost.FundraisingTarget > 0 &&
                    !string.IsNullOrWhiteSpace(partyHost.PartyAddress.ToString()))
                {
                    partyHost.DotMailerPartyPageComplete = true;

                    // update the host to indicate that their party page is now complete
                    DotMailerService.UpdateContact((Contact)partyHost);
                }
            }
        }
Esempio n. 2
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")
            });
        }