From 2c00bf4f8e2ac82b7acb6b6e9de6e14d9f803e9a Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Mon, 26 Feb 2024 17:24:41 +0100 Subject: [PATCH] improve payment intents --- .../stripe/stg_stripe__payment_intents.sql | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/models/staging/stripe/stg_stripe__payment_intents.sql b/models/staging/stripe/stg_stripe__payment_intents.sql index aedcc39..54591fc 100644 --- a/models/staging/stripe/stg_stripe__payment_intents.sql +++ b/models/staging/stripe/stg_stripe__payment_intents.sql @@ -1,18 +1,28 @@ with raw_payment_intents as (select * from {{ source("stripe_uk", "payment_intents") }}), + stg_seed__currencies as (select * from {{ ref("stg_seed__currencies") }}), stg_stripe__payment_intents as ( select {{ adapter.quote("id") }}, - {{ adapter.quote("amount") }}, + cast( + {{ adapter.quote("amount") }} + / (10 ^ cur.decimal_positions) as numeric(19, 4) + ) as amount, {{ adapter.quote("object") }}, {{ adapter.quote("review") }}, {{ adapter.quote("source") }}, {{ adapter.quote("status") }}, {{ adapter.quote("charges") }}, to_timestamp({{ adapter.quote("created") }}) as created_at_utc, + cast( + to_timestamp({{ adapter.quote("created") }}) as date + ) as created_date_utc, {{ adapter.quote("invoice") }}, to_timestamp({{ adapter.quote("updated") }}) as updated_at_utc, - {{ adapter.quote("currency") }}, + cast( + to_timestamp({{ adapter.quote("updated") }}) as date + ) as updated_date_utc, + upper({{ adapter.quote("currency") }}) as currency, {{ adapter.quote("customer") }}, cast({{ adapter.quote("livemode") }} as bool) as is_livemode, {{ adapter.quote("metadata") }}, @@ -20,6 +30,9 @@ with {{ adapter.quote("processing") }}, {{ adapter.quote("application") }}, to_timestamp({{ adapter.quote("canceled_at") }}) as canceled_at_utc, + cast( + to_timestamp({{ adapter.quote("canceled_at") }}) as date + ) as canceled_date_utc, {{ adapter.quote("description") }}, {{ adapter.quote("next_action") }}, {{ adapter.quote("on_behalf_of") }}, @@ -31,8 +44,14 @@ with {{ adapter.quote("capture_method") }}, {{ adapter.quote("payment_method") }}, {{ adapter.quote("transfer_group") }}, - {{ adapter.quote("amount_received") }}, - {{ adapter.quote("amount_capturable") }}, + cast( + {{ adapter.quote("amount_received") }} + / (10 ^ cur.decimal_positions) as numeric(19, 4) + ) as amount_received, + cast( + {{ adapter.quote("amount_capturable") }} + / (10 ^ cur.decimal_positions) as numeric(19, 4) + ) as amount_capturable, {{ adapter.quote("last_payment_error") }}, {{ adapter.quote("setup_future_usage") }}, {{ adapter.quote("cancellation_reason") }}, @@ -45,9 +64,15 @@ with {{ adapter.quote("automatic_payment_methods") }}, {{ adapter.quote("statement_descriptor_suffix") }}, {{ adapter.quote("payment_method_configuration_details") }}, - {{ adapter.quote("_airbyte_extracted_at") }} as dwh_extracted_at_date + {{ adapter.quote("_airbyte_extracted_at") }} as dwh_extracted_at_utc, + cast( + {{ adapter.quote("_airbyte_extracted_at") }} as date + ) as dwh_extracted_date_utc - from raw_payment_intents + from raw_payment_intents pi + left join + stg_seed__currencies cur + on upper(pi.{{ adapter.quote("currency") }}) = cur.iso_4217_code ) select * from stg_stripe__payment_intents