banco-alimentar / alimentestaideia.pt

Site doações alimente esta ideia
http://alimentestaideia.pt
Other
10 stars 0 forks source link

Referral code is not working in some cases #717

Closed tiagonmas closed 1 year ago

tiagonmas commented 1 year ago

Describe the bug Same people have reported that using the referral code, the overview page is not updated.

To Reproduce Steps to reproduce the behavior:

  1. Go to Campaign page
  2. On another browser, in anonymous mode complete a donation using this link
  3. Complete donation
  4. Check if campaign page updated with your new donation

Expected behavior The campaign overview page should update reflecting the new donation

tiagonmas commented 1 year ago

Referral is set in referral page, as a cookie and then redirected to Donation page.

        /// <summary>
        /// Add cookie and redirect to donations.
        /// </summary>
        /// <param name="text">The referal code.</param>
        /// <returns>Redirect to the donations page.</returns>
        public ActionResult OnGet(string text)
        {
            if (!string.IsNullOrEmpty(text))
            {
                this.Response.Cookies.Append(
                  "Referral",
                  text,
                  new CookieOptions()
                  {
                      HttpOnly = true,
                      IsEssential = true,
                      Expires = DateTimeOffset.Now.AddMonths(1),
                  });
                return this.RedirectToPage("./Donation", new { referral = text });
            }
            else
            {
                return this.RedirectToPage("./Donation");
            }

Apparently having the referral in the query string is not enough. So if you use a link like https://www.alimentestaideia.pt/Donation?referral=EDPDEZ22& and not pass on the referral page (and set the cookie) the referral is not set.

tiagonmas commented 1 year ago

as a workaround for this, try and set the referral from the query string too

tiagonmas commented 1 year ago

apparently donation.cshtml.cs it's already looking into the query string for referral ...

        private (string, AlimentaEstaIdeia.Model.Referral) GetReferral()
        {
            StringValues queryValue;
            string result = null;
            if (this.Request.Query.TryGetValue("Referral", out queryValue))
            {
                result = queryValue.ToString();
            }
            else
            {
                if (this.Request.Cookies.TryGetValue("Referral", out result))
                {
                }
            }

            AlimentaEstaIdeia.Model.Referral referral = null;

            if (!string.IsNullOrWhiteSpace(result))
            {
                referral = this.context.ReferralRepository.GetActiveCampaignsByCode(result);
            }

            return (result, referral);
        }
tiagonmas commented 1 year ago

we are looking at the referral in the POST and not the Get. When we look at the query string in the POST, the Query string is empty, so the referral is not being picked up.