Skip to content

Commit

Permalink
Remove some cookies set by the checkout
Browse files Browse the repository at this point in the history
I've removed the following as they're no longer used:
* gu_recurring_contributor
* gu_digital_subscriber
* gu.contributions.recurring.contrib-timestamp.<billing period>

I've refactored the cookie setting code a bit to consolidate things and
make it clear where products set the same cookie(s).
  • Loading branch information
tjmw committed Jan 22, 2025
1 parent de60a81 commit 52c10d8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import io.circe.syntax._
import lib.PlayImplicits._
import models.identity.responses.IdentityErrorResponse._
import org.apache.pekko.actor.{ActorSystem, Scheduler}
import org.joda.time.DateTime
import play.api.http.Writeable
import play.api.libs.circe.Circe
import play.api.mvc._
Expand Down Expand Up @@ -343,7 +344,7 @@ class CreateSubscriptionController(

private def cookies(product: ProductType, userEmail: String): Future[List[Cookie]] = {
val productCookiesCreator = SubscriptionProductCookiesCreator(guardianDomain)
val productCookies = productCookiesCreator.createCookiesForProduct(product)
val productCookies = productCookiesCreator.createCookiesForProduct(product, DateTime.now())
checkoutCompleteCookies(product, userEmail).map(_ ++ productCookies)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,47 +32,25 @@ case class SubscriptionProductCookiesCreator(domain: GuardianDomain) {
)
}

def createCookiesForProduct(product: ProductType): List[Cookie] = {
def createCookiesForProduct(product: ProductType, now: DateTime): List[Cookie] = {
// Setting the user attributes cookies used by frontend. See:
// https://github.com/guardian/dotcom-rendering/blob/3c4700cae532993ace6f40c3b59c337f3efe2247/dotcom-rendering/src/client/userFeatures/user-features.ts
val standardCookies: List[SupportCookie] = List(
SessionCookie("gu_user_features_expiry", DateTime.now.plusDays(1).getMillis.toString),
SessionCookie("gu_user_features_expiry", now.plusDays(1).getMillis.toString),
SessionCookie("gu_hide_support_messaging", true.toString),
)

val oneWeekInSeconds = 604800

val productCookies: List[SupportCookie] = product match {
case Contribution(_, _, billingPeriod) =>
List(
SessionCookie(
s"gu.contributions.recurring.contrib-timestamp.$billingPeriod",
DateTime.now.getMillis.toString,
),
SessionCookie("gu_recurring_contributor", true.toString),
)
case _: SupporterPlus =>
List(
SessionCookie("gu_digital_subscriber", true.toString),
// "gu_supporter_plus" -> true.toString, // TODO: add this and remove the digisub one now that the CMP cookie list has been updated
SessionCookie("GU_AF1", DateTime.now().plusDays(1).getMillis.toString),
)
case _: TierThree =>
List(
SessionCookie("gu_digital_subscriber", true.toString),
// SessionCookie("gu_supporter_plus", true.toString), // TODO: add this and remove the digisub one now that the CMP cookie list has been updated
SessionCookie("GU_AF1", DateTime.now().plusDays(1).getMillis.toString),
)
case _: DigitalPack =>
List(
SessionCookie("gu_digital_subscriber", true.toString),
SessionCookie("GU_AF1", DateTime.now().plusDays(1).getMillis.toString),
)
case _: SupporterPlus | _: TierThree | _: DigitalPack =>
List(SessionCookie("GU_AF1", now.plusDays(1).getMillis.toString))

case p: Paper if p.productOptions.hasDigitalSubscription =>
List(
SessionCookie("gu_digital_subscriber", true.toString),
SessionCookie("GU_AF1", DateTime.now().plusDays(1).getMillis.toString),
)
case _: Paper => List.empty
case _: GuardianWeekly => List.empty
List(SessionCookie("GU_AF1", now.plusDays(1).getMillis.toString))

case _: Contribution | _: Paper | _: GuardianWeekly => List.empty

case _: GuardianAdLite => List(PersistentCookie("gu_allow_reject_all", true.toString, oneWeekInSeconds))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import config.Configuration.GuardianDomain
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import play.api.mvc.Cookie
import org.joda.time.DateTime

class SubscriptionProductCookiesCreatorTest extends AnyFlatSpec with Matchers {
"createCookiesForProduct" should "set the gu_allow_reject_all cookie for GuardianAdLite" in {
val guardianAdLite = GuardianAdLite(GBP)
val creator = SubscriptionProductCookiesCreator(GuardianDomain("thegulocal.com"))

val cookies = creator.createCookiesForProduct(guardianAdLite)
val now = DateTime.now()
val cookies = creator.createCookiesForProduct(guardianAdLite, now)

val expectedCookie = Cookie(
name = "gu_allow_reject_all",
Expand All @@ -29,11 +31,12 @@ class SubscriptionProductCookiesCreatorTest extends AnyFlatSpec with Matchers {
val supporterPlus = SupporterPlus(BigDecimal(12), GBP, Monthly)
val creator = SubscriptionProductCookiesCreator(GuardianDomain("thegulocal.com"))

val cookies = creator.createCookiesForProduct(supporterPlus)
val now = new DateTime("2025-01-01T00:00:00")
val cookies = creator.createCookiesForProduct(supporterPlus, now)

val expectedCookie = Cookie(
name = "gu_digital_subscriber",
value = "true",
name = "GU_AF1",
value = "1735776000000", // Jan 2nd 2024 millis
secure = true,
httpOnly = false,
domain = Some("thegulocal.com"),
Expand Down

0 comments on commit 52c10d8

Please sign in to comment.