From 92c8331ae4810639c32a7130d3fe21c998d6c9c3 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Mon, 19 May 2025 15:44:06 +0200 Subject: [PATCH 1/4] refactor --- .../core/int_core__guest_product_payments.sql | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/models/intermediate/core/int_core__guest_product_payments.sql b/models/intermediate/core/int_core__guest_product_payments.sql index 9e14f83..9fd6cae 100644 --- a/models/intermediate/core/int_core__guest_product_payments.sql +++ b/models/intermediate/core/int_core__guest_product_payments.sql @@ -4,12 +4,24 @@ {{ config(materialized="table") }} with stg_core__verification_to_payment as ( - select * from {{ ref("stg_core__verification_to_payment") }} + select * + from {{ ref("stg_core__verification_to_payment") }} + where + created_date_utc + <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) + and id_verification_payment_type + = {{ check_in_cover_as_id_verification_payment }} ), stg_core__verification_payment_type as ( select * from {{ ref("stg_core__verification_payment_type") }} ), - stg_core__verification as (select * from {{ ref("stg_core__verification") }}), + stg_core__verification as ( + select * + from {{ ref("stg_core__verification") }} + where + created_date_utc + <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) + ), stg_core__verification_request as ( select * from {{ ref("stg_core__verification_request") }} ), @@ -54,6 +66,7 @@ with upper(coalesce(ps.payment_status, 'UNKNOWN')) as payment_status, p.notes from stg_core__verification_to_payment vtp + left join stg_core__verification v on vtp.id_verification = v.id_verification inner join stg_core__verification_payment_type vpt on vtp.id_verification_payment_type = vpt.id_verification_payment_type @@ -65,23 +78,9 @@ with on vtp.payment_due_date_utc = r.rate_date_utc and p.currency = r.from_currency and r.to_currency = 'GBP' - left join stg_core__verification v on vtp.id_verification = v.id_verification left join stg_core__verification_request vr on v.id_verification_request = vr.id_verification_request - where - vtp.id_verification_payment_type - = {{ check_in_cover_as_id_verification_payment }} - -- Following is to enhance the performance of the query once Guest Product - -- payment data follows exclusively the dedicated Guest Product models - and v.created_date_utc - <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) - and vtp.created_date_utc - <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) - and p.created_date_utc - <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) - and vr.created_date_utc - <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) ), guest_product_payments_from_guest_product_flow as ( select From 128d12d3724942522618110d51f143d4c6850b38 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Mon, 19 May 2025 15:48:13 +0200 Subject: [PATCH 2/4] put the new stuff into a v2 --- .../int_core__guest_product_payments_v2.sql | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 models/intermediate/core/int_core__guest_product_payments_v2.sql diff --git a/models/intermediate/core/int_core__guest_product_payments_v2.sql b/models/intermediate/core/int_core__guest_product_payments_v2.sql new file mode 100644 index 0000000..9fd6cae --- /dev/null +++ b/models/intermediate/core/int_core__guest_product_payments_v2.sql @@ -0,0 +1,143 @@ +{% set check_in_cover_as_id_verification_payment = "5" %} +{% set cut_off_date_check_in_cover_as_id_verification_payment = "'2025-06-08'" %} + +{{ config(materialized="table") }} +with + stg_core__verification_to_payment as ( + select * + from {{ ref("stg_core__verification_to_payment") }} + where + created_date_utc + <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) + and id_verification_payment_type + = {{ check_in_cover_as_id_verification_payment }} + ), + stg_core__verification_payment_type as ( + select * from {{ ref("stg_core__verification_payment_type") }} + ), + stg_core__verification as ( + select * + from {{ ref("stg_core__verification") }} + where + created_date_utc + <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) + ), + stg_core__verification_request as ( + select * from {{ ref("stg_core__verification_request") }} + ), + stg_core__payment as (select * from {{ ref("stg_core__payment") }}), + stg_core__payment_status as (select * from {{ ref("stg_core__payment_status") }}), + int_simple_exchange_rates as (select * from {{ ref("int_simple_exchange_rates") }}), + stg_core__verification_request_guest_product_to_payment as ( + select * + from {{ ref("stg_core__verification_request_guest_product_to_payment") }} + ), + stg_core__verification_request_to_guest_product as ( + select * from {{ ref("stg_core__verification_request_to_guest_product") }} + ), + int_core__guest_products as (select * from {{ ref("int_core__guest_products") }}), + guest_product_payments_from_verification_flow as ( + select + -- Tags Guest Product Payments that come from the legacy flow, namely + -- CheckInCover from Verification To Payment. + 'leg_' + || cast(vtp.id_verification_to_payment as text) as id_guest_product_payment, + vtp.id_payment, + vtp.created_at_utc, + vtp.updated_at_utc, + vtp.payment_due_at_utc, + vtp.payment_due_date_utc, + p.paid_at_utc as payment_paid_at_utc, + p.paid_date_utc as payment_paid_date_utc, + p.payment_reference, + vtp.refund_due_at_utc, + vtp.refund_due_date_utc, + p.refunded_at_utc as payment_refunded_at_utc, + p.refunded_date_utc as payment_refunded_date_utc, + p.refund_payment_reference, + vr.id_user_host, + vtp.id_guest_user as id_user_guest, + v.id_verification_request, + upper(vpt.verification_payment_type) as guest_product_name, + 'VERIFICATION_PAYMENT' as guest_product_payment_source, + p.currency, + p.amount as total_amount_in_txn_currency, + p.amount * r.rate as total_amount_in_gbp, + upper(coalesce(ps.payment_status, 'UNKNOWN')) as payment_status, + p.notes + from stg_core__verification_to_payment vtp + left join stg_core__verification v on vtp.id_verification = v.id_verification + inner join + stg_core__verification_payment_type vpt + on vtp.id_verification_payment_type = vpt.id_verification_payment_type + left join stg_core__payment p on vtp.id_payment = p.id_payment + inner join + stg_core__payment_status ps on p.id_payment_status = ps.id_payment_status + inner join + int_simple_exchange_rates r + on vtp.payment_due_date_utc = r.rate_date_utc + and p.currency = r.from_currency + and r.to_currency = 'GBP' + left join + stg_core__verification_request vr + on v.id_verification_request = vr.id_verification_request + ), + guest_product_payments_from_guest_product_flow as ( + select + cast( + vrgptp.id_verification_request_guest_product_to_payment as text + ) as id_guest_product_payment, + vrgptp.id_payment, + vrgptp.created_at_utc, + vrgptp.updated_at_utc, + -- For the new Guest Product flow, there's no concept of Due Date, as we + -- take the payment up front and if the payment fails, then they aren't + -- able to complete the Journey. + p.paid_at_utc as payment_due_at_utc, + p.paid_date_utc as payment_due_date_utc, + p.paid_at_utc as payment_paid_at_utc, + p.paid_date_utc as payment_paid_date_utc, + p.payment_reference, + -- Same comment regarding Due Date + At the moment, Guest Products are not + -- refundable, but these could be in the future + p.refunded_at_utc as refund_due_at_utc, + p.refunded_date_utc as refund_due_date_utc, + p.refunded_at_utc as payment_refunded_at_utc, + p.refunded_date_utc as payment_refunded_date_utc, + p.refund_payment_reference, + vr.id_user_host as id_user_host, + vr.id_user_guest as id_user_guest, + vrtgp.id_verification_request, + gp.guest_product_name, + 'GUEST_PRODUCT_PAYMENT' as guest_product_payment_source, + p.currency, + p.amount as total_amount_in_txn_currency, + p.amount * r.rate as total_amount_in_gbp, + upper(coalesce(ps.payment_status, 'UNKNOWN')) as payment_status, + p.notes + from stg_core__verification_request_guest_product_to_payment vrgptp + left join stg_core__payment p on vrgptp.id_payment = p.id_payment + inner join + stg_core__payment_status ps on p.id_payment_status = ps.id_payment_status + inner join + int_simple_exchange_rates r + -- Note that the following conversion is made on Paid date, not Due Date, + -- as Due Date does not make sense for Guest Products + on p.paid_date_utc = r.rate_date_utc + and p.currency = r.from_currency + and r.to_currency = 'GBP' + left join + stg_core__verification_request_to_guest_product vrtgp + on vrgptp.id_verification_request_to_guest_product + = vrtgp.id_verification_request_to_guest_product + left join + int_core__guest_products gp on vrtgp.id_guest_product = gp.id_guest_product + left join + stg_core__verification_request vr + on vrtgp.id_verification_request = vr.id_verification_request + ) +select * +from guest_product_payments_from_verification_flow +union all +select * +from guest_product_payments_from_guest_product_flow From cf0c9fd3fa095e6486e3354e00444fa75889d797 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Mon, 19 May 2025 15:48:55 +0200 Subject: [PATCH 3/4] bring v1 back to starting code --- .../core/int_core__guest_product_payments.sql | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/models/intermediate/core/int_core__guest_product_payments.sql b/models/intermediate/core/int_core__guest_product_payments.sql index 9fd6cae..9e14f83 100644 --- a/models/intermediate/core/int_core__guest_product_payments.sql +++ b/models/intermediate/core/int_core__guest_product_payments.sql @@ -4,24 +4,12 @@ {{ config(materialized="table") }} with stg_core__verification_to_payment as ( - select * - from {{ ref("stg_core__verification_to_payment") }} - where - created_date_utc - <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) - and id_verification_payment_type - = {{ check_in_cover_as_id_verification_payment }} + select * from {{ ref("stg_core__verification_to_payment") }} ), stg_core__verification_payment_type as ( select * from {{ ref("stg_core__verification_payment_type") }} ), - stg_core__verification as ( - select * - from {{ ref("stg_core__verification") }} - where - created_date_utc - <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) - ), + stg_core__verification as (select * from {{ ref("stg_core__verification") }}), stg_core__verification_request as ( select * from {{ ref("stg_core__verification_request") }} ), @@ -66,7 +54,6 @@ with upper(coalesce(ps.payment_status, 'UNKNOWN')) as payment_status, p.notes from stg_core__verification_to_payment vtp - left join stg_core__verification v on vtp.id_verification = v.id_verification inner join stg_core__verification_payment_type vpt on vtp.id_verification_payment_type = vpt.id_verification_payment_type @@ -78,9 +65,23 @@ with on vtp.payment_due_date_utc = r.rate_date_utc and p.currency = r.from_currency and r.to_currency = 'GBP' + left join stg_core__verification v on vtp.id_verification = v.id_verification left join stg_core__verification_request vr on v.id_verification_request = vr.id_verification_request + where + vtp.id_verification_payment_type + = {{ check_in_cover_as_id_verification_payment }} + -- Following is to enhance the performance of the query once Guest Product + -- payment data follows exclusively the dedicated Guest Product models + and v.created_date_utc + <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) + and vtp.created_date_utc + <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) + and p.created_date_utc + <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) + and vr.created_date_utc + <= date({{ cut_off_date_check_in_cover_as_id_verification_payment }}) ), guest_product_payments_from_guest_product_flow as ( select From cf2d7251db714cdc3551c73228b1abc689896ba8 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Mon, 19 May 2025 15:51:59 +0200 Subject: [PATCH 4/4] add version metadata in schema file --- models/intermediate/core/schema.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index 4beaba5..ce0b1db 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -5798,6 +5798,7 @@ models: - not_null - name: int_core__guest_product_payments + latest_version: 1 description: | A model that holds guest products payments with details around when they happen, what service was being paid, what was the related @@ -5809,6 +5810,12 @@ models: (!) At this moment, this model only includes Check In Cover payments made as Verification Payments. + versions: + - v: 1 + - v: 2 + columns: + - include: all + columns: - name: id_guest_product_payment data_type: text