Merged PR 5357: Adapt vr_check_in_cover model for Guest Products

# Description

This PR prepares the existing `int_core__vr_check_in_cover` model for the activation of the Guest Products feature flag.

It creates a second logic path which identifies VRs that have CIH in them ~~through product bundles~~ through looking at `stg_core__verification_request_to_guest_product `, and unions it with the old stuff.

The new CTE only gets called after the FF gets activated. This is defined in a var that we will need to adjust depending on when do we really activate the FF.

Note that these items are still pending:
- update the var to the right value once Lawrence pulls the trigger.
- clarify what the hell happens with CIH being "pushed" or not to ALL old dash hosts. This PR currently assumes this will NOT happen. If it will happen, we will need to change things.

# Checklist

- [X] The edited models and dependants run properly with production data.
- [X] The edited models are sufficiently documented.
- [X] The edited models contain PK tests, and I've ran and passed them.
- [X] I have checked for DRY opportunities with other models and docs.
- [X] I've picked the right materialization for the affected models.

# Other

- [ ] Check if a full-refresh is required after this PR is merged.

Related work items: #30165
This commit is contained in:
Pablo Martin 2025-06-02 14:22:58 +00:00
commit 92b144d78e
3 changed files with 222 additions and 89 deletions

View file

@ -2,9 +2,16 @@ with
int_core__verification_requests as (
select * from {{ ref("int_core__verification_requests") }}
),
stg_core__currency as (select * from {{ ref("stg_core__currency") }}),
stg_core__verification_set_to_verification_type as (
select * from {{ ref("stg_core__verification_set_to_verification_type") }}
),
stg_core__verification_request_to_guest_product as (
select * from {{ ref("stg_core__verification_request_to_guest_product") }}
),
stg_core__guest_product_configuration_price_plan as (
select * from {{ ref("stg_core__guest_product_configuration_price_plan") }}
),
int_core__bookings as (select * from {{ ref("int_core__bookings") }}),
int_core__check_in_cover_prices as (
select * from {{ ref("int_core__check_in_cover_prices") }}
@ -22,90 +29,210 @@ with
amount_without_taxes_in_gbp
from {{ ref("int_core__guest_journey_payments") }}
where product_name = 'CHECKINCOVER' and payment_status in ('PAID', 'REFUNDED')
),
pre_feature_flag_verification_requests as (
select
vr.id_verification_request,
vr.uuid_verification_request,
vr.id_verification_set,
vr.id_superhog_verified_set,
vr.id_payment_validation_set,
vr.id_user_guest,
vr.id_user_host,
b.id_booking,
b.id_accommodation,
vr.is_verification_request_complete,
(
p.total_amount_in_txn_currency is not null
and not b.check_in_sits_in_future
) as is_past_check_in,
(
p.total_amount_in_txn_currency is not null
and b.check_in_sits_in_future
and vr.is_verification_request_complete
) as is_awaiting_check_in,
p.total_amount_in_txn_currency is not null as cover_was_purchased,
(
p.total_amount_in_txn_currency is null
and vr.is_verification_request_complete
) as cover_was_rejected,
vr.verification_url,
vr.callback_url,
vr.redirect_url,
vr.logo,
gu.email as guest_email,
gu.last_name as last_name,
gu.first_name as first_name,
gu.phone_number as guest_phone_number,
vr.telephone_code,
vr.guest_phone_number_2,
b.check_in_at_utc,
b.check_in_date_utc,
b.check_out_at_utc,
b.check_out_date_utc,
vr.verification_estimated_started_at_utc as verification_start_at_utc,
vr.verification_estimated_started_date_utc as verification_start_date_utc,
vr.verification_estimated_completed_at_utc as verification_end_at_utc,
vr.verification_estimated_completed_date_utc as verification_end_date_utc,
vr.link_used_at_utc,
vr.link_used_date_utc,
vr.expire_at_utc,
vr.expire_date_utc,
vr.is_deleted,
vr.redirect_name,
vr.id_one_step_link,
vr.success_message,
vr.summary,
vr.rejection_reason,
vr.has_switched_to_mobile,
vr.is_verifier_rejected,
vr.config,
vr.metadata,
vr.created_at_utc,
vr.created_date_utc,
vr.updated_at_utc,
vr.updated_date_utc,
vr.dwh_extracted_at_utc,
p.currency,
p.payment_status,
p.payment_paid_date_utc,
p.total_amount_in_txn_currency,
p.amount_without_taxes_in_txn_currency,
p.total_amount_in_gbp,
p.amount_without_taxes_in_gbp,
ccp.checkin_cover_limit_amount_local_curr,
(
ccp.checkin_cover_limit_amount_local_curr
* (p.total_amount_in_gbp / p.total_amount_in_txn_currency)
)::numeric(18, 4) as checkin_cover_limit_amount_in_gbp
from int_core__verification_requests vr
left join
int_core__bookings b
on vr.id_verification_request = b.id_verification_request
left join
stg_core__verification_set_to_verification_type vstvt
on vr.id_verification_set = vstvt.id_verification_set
left join
check_in_cover_payments p
on vr.id_verification_request = p.id_verification_request
left join
int_core__check_in_cover_prices ccp
on p.currency = ccp.local_currency_iso_4217
left join int_core__unified_user gu on gu.id_user = vr.id_user_guest
-- 15 is Check-in cover.
-- Adding this condition results in only keeping guest journeys that offered the
-- check-in cover
where vstvt.id_verification_type = 15
),
post_feature_flag_verification_requests as (
select
vr.id_verification_request,
vr.uuid_verification_request,
null as id_verification_set,
null as id_superhog_verified_set,
null as id_payment_validation_set,
vr.id_user_guest,
vr.id_user_host,
b.id_booking,
b.id_accommodation,
vr.is_verification_request_complete,
(
p.total_amount_in_txn_currency is not null
and not b.check_in_sits_in_future
) as is_past_check_in,
(
p.total_amount_in_txn_currency is not null
and b.check_in_sits_in_future
and vr.is_verification_request_complete
) as is_awaiting_check_in,
p.total_amount_in_txn_currency is not null as cover_was_purchased,
(
p.total_amount_in_txn_currency is null
and vr.is_verification_request_complete
) as cover_was_rejected,
vr.verification_url,
vr.callback_url,
vr.redirect_url,
vr.logo,
gu.email as guest_email,
gu.last_name as last_name,
gu.first_name as first_name,
gu.phone_number as guest_phone_number,
vr.telephone_code,
vr.guest_phone_number_2,
b.check_in_at_utc,
b.check_in_date_utc,
b.check_out_at_utc,
b.check_out_date_utc,
vr.verification_estimated_started_at_utc as verification_start_at_utc,
vr.verification_estimated_started_date_utc as verification_start_date_utc,
vr.verification_estimated_completed_at_utc as verification_end_at_utc,
vr.verification_estimated_completed_date_utc as verification_end_date_utc,
vr.link_used_at_utc,
vr.link_used_date_utc,
vr.expire_at_utc,
vr.expire_date_utc,
vr.is_deleted,
vr.redirect_name,
vr.id_one_step_link,
vr.success_message,
vr.summary,
vr.rejection_reason,
vr.has_switched_to_mobile,
vr.is_verifier_rejected,
vr.config,
vr.metadata,
vr.created_at_utc,
vr.created_date_utc,
vr.updated_at_utc,
vr.updated_date_utc,
vr.dwh_extracted_at_utc,
p.currency,
p.payment_status,
p.payment_paid_date_utc,
p.total_amount_in_txn_currency,
p.amount_without_taxes_in_txn_currency,
p.total_amount_in_gbp,
p.amount_without_taxes_in_gbp,
gpcpp.protection_limit_in_local_currency
as checkin_cover_limit_amount_local_curr,
(
gpcpp.protection_limit_in_local_currency
* (p.total_amount_in_gbp / p.total_amount_in_txn_currency)
)::numeric(18, 4) as checkin_cover_limit_amount_in_gbp
from int_core__verification_requests vr
inner join
stg_core__verification_request_to_guest_product vrtogp
on vr.id_verification_request = vrtogp.id_verification_request
inner join
stg_core__guest_product_configuration_price_plan gpcpp
on vrtogp.id_guest_product_configuration_price_plan
= gpcpp.id_guest_product_configuration_price_plan
inner join stg_core__currency c on c.id_currency = gpcpp.id_currency
left join
int_core__bookings b
on vr.id_verification_request = b.id_verification_request
left join
check_in_cover_payments p
on vr.id_verification_request = p.id_verification_request
left join int_core__unified_user gu on gu.id_user = vr.id_user_guest
where
p.currency = c.iso4217_code
and vrtogp.id_guest_product = 2 -- 2 is CIH
and vr.link_used_at_utc
>= {{ var("guest_products_feature_flag_activation_timestamp") }} -- This logic path only applies to VRs started after the FF was activated
)
select
vr.id_verification_request,
vr.uuid_verification_request,
vr.id_verification_set,
vr.id_superhog_verified_set,
vr.id_payment_validation_set,
vr.id_user_guest,
vr.id_user_host,
b.id_booking,
b.id_accommodation,
vr.is_verification_request_complete,
(
p.total_amount_in_txn_currency is not null and not b.check_in_sits_in_future
) as is_past_check_in,
(
p.total_amount_in_txn_currency is not null
and b.check_in_sits_in_future
and vr.is_verification_request_complete
) as is_awaiting_check_in,
p.total_amount_in_txn_currency is not null as cover_was_purchased,
(
p.total_amount_in_txn_currency is null and vr.is_verification_request_complete
) as cover_was_rejected,
vr.verification_url,
vr.callback_url,
vr.redirect_url,
vr.logo,
gu.email as guest_email,
gu.last_name as last_name,
gu.first_name as first_name,
gu.phone_number as guest_phone_number,
vr.telephone_code,
vr.guest_phone_number_2,
b.check_in_at_utc,
b.check_in_date_utc,
b.check_out_at_utc,
b.check_out_date_utc,
vr.verification_estimated_started_at_utc as verification_start_at_utc,
vr.verification_estimated_started_date_utc as verification_start_date_utc,
vr.verification_estimated_completed_at_utc as verification_end_at_utc,
vr.verification_estimated_completed_date_utc as verification_end_date_utc,
vr.link_used_at_utc,
vr.link_used_date_utc,
vr.expire_at_utc,
vr.expire_date_utc,
vr.is_deleted,
vr.redirect_name,
vr.id_one_step_link,
vr.success_message,
vr.summary,
vr.rejection_reason,
vr.has_switched_to_mobile,
vr.is_verifier_rejected,
vr.config,
vr.metadata,
vr.created_at_utc,
vr.created_date_utc,
vr.updated_at_utc,
vr.updated_date_utc,
vr.dwh_extracted_at_utc,
p.currency,
p.payment_status,
p.payment_paid_date_utc,
p.total_amount_in_txn_currency,
p.amount_without_taxes_in_txn_currency,
p.total_amount_in_gbp,
p.amount_without_taxes_in_gbp,
ccp.checkin_cover_limit_amount_local_curr,
(
ccp.checkin_cover_limit_amount_local_curr
* (p.total_amount_in_gbp / p.total_amount_in_txn_currency)
)::numeric(18, 4) as checkin_cover_limit_amount_in_gbp
from int_core__verification_requests vr
left join int_core__bookings b on vr.id_verification_request = b.id_verification_request
left join
stg_core__verification_set_to_verification_type vstvt
on vr.id_verification_set = vstvt.id_verification_set
left join
check_in_cover_payments p on vr.id_verification_request = p.id_verification_request
left join
int_core__check_in_cover_prices ccp on p.currency = ccp.local_currency_iso_4217
left join int_core__unified_user gu on gu.id_user = vr.id_user_guest
-- 15 is Check-in cover.
-- Adding this condition results in only keeping guest journeys that offered the
-- check-in cover
where vstvt.id_verification_type = 15
select *
from pre_feature_flag_verification_requests
{%- if modules.datetime.datetime.now(
modules.pytz.timezone("UTC")
) > modules.datetime.datetime.strptime(
var("guest_products_feature_flag_activation_timestamp"),
"'%Y-%m-%dT%H:%M:%S%z'",
) -%}
union all
select *
from post_feature_flag_verification_requests
{% endif %}

View file

@ -310,8 +310,14 @@ models:
a first level of filtering.
- name: int_core__vr_check_in_cover
description: "This tables holds information on verification requests
with Ckeck-in Hero available for the guests."
description: |
This tables holds information on verification requests with Ckeck-in Hero
available for the guests.
The query has logic paths that cover both the Guest Products data model,
which started on June 2025, and the previous "CIH is a verification step"
model.
columns:
- name: id_verification_request
data_type: bigint