improve payment intents

This commit is contained in:
Pablo Martin 2024-02-26 17:24:41 +01:00
parent f2d01290fc
commit 2c00bf4f8e

View file

@ -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