implicit def dateToDateTime()

in membership-common/src/main/scala/com/gu/services/model/PaymentDetails.scala [29:64]


  implicit def dateToDateTime(date: LocalDate): DateTime = date.toDateTimeAtStartOfDay()

  def fromSubAndPaymentData(
      sub: Subscription,
      paymentMethod: Option[PaymentMethod],
      nextPayment: Option[Payment],
      nextInvoiceDate: Option[LocalDate],
      lastPaymentDate: Option[LocalDate],
      catalog: Catalog,
  )(implicit logPrefix: LogPrefix): PaymentDetails = {

    val firstPaymentDate = sub.firstPaymentDate
    val timeUntilPaying = Days.daysBetween(new LocalDate(DateTime.now()), new LocalDate(firstPaymentDate)).getDays
    import scala.math.BigDecimal.RoundingMode._

    val plan = sub.plan(catalog)
    PaymentDetails(
      pendingCancellation = sub.isCancelled,
      startDate = sub.contractEffectiveDate,
      chargedThroughDate = plan.chargedThroughDate,
      customerAcceptanceDate = sub.customerAcceptanceDate,
      nextPaymentPrice = nextPayment.map(p => (BigDecimal.decimal(p.price.amount) * 100).setScale(2, HALF_UP).intValue),
      lastPaymentDate = lastPaymentDate,
      nextPaymentDate = nextPayment.map(_.date),
      nextInvoiceDate = nextInvoiceDate,
      termEndDate = sub.termEndDate,
      paymentMethod = paymentMethod,
      plan = PersonalPlan(
        name = plan.productName,
        price = plan.chargesPrice.prices.head,
        interval = plan.billingPeriod.leftMap(e => logger.warn("unknown billing period: " + e)).map(_.noun).getOrElse("unknown_billing_period"),
      ),
      subscriberId = sub.subscriptionNumber.getNumber,
      remainingTrialLength = timeUntilPaying,
    )
  }