Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move cent conversions upstream to source package #101

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildkite/scripts/run_models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dbt deps
dbt seed --target "$db" --full-refresh
dbt run --target "$db" --full-refresh
dbt test --target "$db"
dbt run --vars '{stripe__using_invoices: false, stripe__using_payment_method: false, stripe__using_subscriptions: false, stripe_timezone: "America/New_York", stripe__using_subscription_history: false, stripe__using_price: false}' --target "$db"
dbt run --vars '{stripe__using_invoices: false, stripe__using_payment_method: false, stripe__using_subscriptions: false, stripe_timezone: "America/New_York", stripe__using_subscription_history: false, stripe__using_price: false, stripe__amount_divide: false}' --target "$db"
dbt test --target "$db"

dbt run-operation fivetran_utils.drop_schemas_automation --target "$db"
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# dbt_stripe v0.16.0

## Breaking Changes
- This package assumes that amount-based fields, which as raw values are represented in the smallest denomination in Stripe, are cent-based. This PR shifts the existing conversion from cents to dollars to further upstream. Previously, currency-related fields were converted in downstream models, but now have been converted directly in staging models. Since currency-related fields now have different values, this is a breaking change.

To disable this default conversion, refer to the [README]((https://github.com/fivetran/dbt_stripe/blob/main/README.md#disabling-cent-to-dollar-conversion)) on disabling the `stripe__amount_divide` variable.

# dbt_stripe v0.15.1

## Bug Fixes
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Include the following stripe package version in your `packages.yml` file:
```yaml
packages:
- package: fivetran/stripe
version: [">=0.15.0", "<0.16.0"]
version: [">=0.16.0", "<0.17.0"]
```
Do **NOT** include the `stripe_source` package in this file. The transformation package itself has a dependency on it and will install the source package as well.

Expand Down Expand Up @@ -220,6 +220,15 @@ vars:
stripe__subscription_metadata: ['the', 'list', 'of', 'property', 'fields'] # Note: this is case-SENSITIVE and must match the casing of the property as it appears in the JSON
```

#### Disabling Cent to Dollar Conversion

Amount-based fields, such as `amount` and `net`, are typically displayed in the smallest denomination (e.g., cents for USD). By default, these values are automatically converted to dollars by dividing by `100.0`. To disable this conversion and retain the values in their smallest denomination, set the `stripe__amount_divide` variable to `False` as shown below:

```yml
vars:
stripe__amount_divide: False
```

#### Change the build schema
By default, this package builds the stripe staging models within a schema titled (`<target_schema>` + `_stg_stripe`) in your destination. If this is not where you would like your stripe staging data to be written to, add the following configuration to your root `dbt_project.yml` file:

Expand Down Expand Up @@ -254,7 +263,7 @@ This dbt package is dependent on the following dbt packages. These dependencies
```yml
packages:
- package: fivetran/stripe_source
version: [">=0.12.0", "<0.13.0"]
version: [">=0.13.0", "<0.14.0"]

- package: fivetran/fivetran_utils
version: [">=0.4.0", "<0.5.0"]
Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
config-version: 2
name: 'stripe'

version: '0.15.1'
version: '0.16.0'
require-dbt-version: [">=1.3.0", "<2.0.0"]
models:
stripe:
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
config-version: 2

name: 'stripe_integration_tests'
version: '0.15.1'
version: '0.16.0'

profile: 'integration_tests'

Expand Down
20 changes: 10 additions & 10 deletions models/intermediate/int_stripe__account_daily.sql
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ select
daily_account_balance_transactions.date_day,
daily_account_balance_transactions.account_id,
daily_account_balance_transactions.source_relation,
coalesce(daily_account_balance_transactions.total_daily_sales_amount/100.0,0) as total_daily_sales_amount,
coalesce(daily_account_balance_transactions.total_daily_refunds_amount/100.0,0) as total_daily_refunds_amount,
coalesce(daily_account_balance_transactions.total_daily_adjustments_amount/100.0,0) as total_daily_adjustments_amount,
coalesce(daily_account_balance_transactions.total_daily_other_transactions_amount/100.0,0) as total_daily_other_transactions_amount,
coalesce(daily_account_balance_transactions.total_daily_gross_transaction_amount/100.0,0) as total_daily_gross_transaction_amount,
coalesce(daily_account_balance_transactions.total_daily_net_transactions_amount/100.0,0) as total_daily_net_transactions_amount,
coalesce(daily_account_balance_transactions.total_daily_payout_fee_amount/100.0,0) as total_daily_payout_fee_amount,
coalesce(daily_account_balance_transactions.total_daily_gross_payout_amount/100.0,0) as total_daily_gross_payout_amount,
coalesce(daily_account_balance_transactions.daily_net_activity_amount/100.0,0) as daily_net_activity_amount,
coalesce((daily_account_balance_transactions.daily_net_activity_amount + daily_account_balance_transactions.total_daily_gross_payout_amount)/100.0, 0) as daily_end_balance_amount,
coalesce(daily_account_balance_transactions.total_daily_sales_amount,0) as total_daily_sales_amount,
coalesce(daily_account_balance_transactions.total_daily_refunds_amount,0) as total_daily_refunds_amount,
coalesce(daily_account_balance_transactions.total_daily_adjustments_amount,0) as total_daily_adjustments_amount,
coalesce(daily_account_balance_transactions.total_daily_other_transactions_amount,0) as total_daily_other_transactions_amount,
coalesce(daily_account_balance_transactions.total_daily_gross_transaction_amount,0) as total_daily_gross_transaction_amount,
coalesce(daily_account_balance_transactions.total_daily_net_transactions_amount,0) as total_daily_net_transactions_amount,
coalesce(daily_account_balance_transactions.total_daily_payout_fee_amount,0) as total_daily_payout_fee_amount,
coalesce(daily_account_balance_transactions.total_daily_gross_payout_amount,0) as total_daily_gross_payout_amount,
coalesce(daily_account_balance_transactions.daily_net_activity_amount,0) as daily_net_activity_amount,
coalesce((daily_account_balance_transactions.daily_net_activity_amount + daily_account_balance_transactions.total_daily_gross_payout_amount), 0) as daily_end_balance_amount,
coalesce(daily_account_balance_transactions.total_daily_sales_count, 0) as total_daily_sales_count,
coalesce(daily_account_balance_transactions.total_daily_payouts_count, 0) as total_daily_payouts_count,
coalesce(daily_account_balance_transactions.total_daily_adjustments_count, 0) as total_daily_adjustments_count,
Expand Down
8 changes: 4 additions & 4 deletions models/stripe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ models:
- name: balance_transaction_currency
description: Three-letter ISO currency code, in lowercase.
- name: balance_transaction_amount
description: Gross amount of the transaction, in cents.
description: Gross amount of the transaction, in currency units.
- name: balance_transaction_fee
description: Fees (in cents) paid for this transaction.
description: Fees (in currency units) paid for this transaction.
- name: balance_transaction_net
description: Net amount of the transaction, in cents. Gross amount minus fees, refunds, and disputes
description: Net amount of the transaction, in currency units. Gross amount minus fees, refunds, and disputes
- name: balance_transaction_type
description: The type of transaction. Possible values are adjustment, advance, advance_funding, application_fee, application_fee_refund, charge, connect_collection_transfer, issuing_authorization_hold, issuing_authorization_release, issuing_dispute, issuing_transaction, payment, payment_failure_refund, payment_refund, payout, payout_cancel, payout_failure, refund, refund_failure, reserve_transaction, reserved_funds, stripe_fee, stripe_fx_fee, tax_fee, topup, topup_reversal, transfer, transfer_cancel, transfer_failure, or transfer_refund.
- name: balance_transaction_reporting_category
Expand Down Expand Up @@ -430,7 +430,7 @@ models:
- name: price_plan_is_active
description: Boolean indicating if the plan or price is active (true) or in-active (false).
- name: price_plan_amount
description: The unit amount in cents to be charged, represented as a whole integer if possible.
description: The unit amount in currency units to be charged, represented as a whole integer if possible.
- name: price_plan_interval
description: The frequency at which a subscription is billed. One of day, week, month or year.
- name: price_plan_interval_count
Expand Down
40 changes: 20 additions & 20 deletions models/stripe__customer_overview.sql
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,18 @@ with balance_transaction_joined as (
customer.created_at as customer_created_at,
customer.currency as customer_currency,
{{ dbt_utils.star(from=ref('stg_stripe__customer'), relation_alias='customer', except=['customer_id','description','created_at','currency','metadata','source_relation']) }},
coalesce(transactions_grouped.total_sales/100.0, 0) as total_sales,
coalesce(transactions_grouped.total_refunds/100.0, 0) as total_refunds,
coalesce(transactions_grouped.total_gross_transaction_amount/100.0, 0) as total_gross_transaction_amount,
coalesce(transactions_grouped.total_fees/100.0, 0) as total_fees,
coalesce(transactions_grouped.total_net_transaction_amount/100.0, 0) as total_net_transaction_amount,
coalesce(transactions_grouped.total_sales, 0) as total_sales,
coalesce(transactions_grouped.total_refunds, 0) as total_refunds,
coalesce(transactions_grouped.total_gross_transaction_amount, 0) as total_gross_transaction_amount,
coalesce(transactions_grouped.total_fees, 0) as total_fees,
coalesce(transactions_grouped.total_net_transaction_amount, 0) as total_net_transaction_amount,
coalesce(transactions_grouped.total_sales_count, 0) as total_sales_count,
coalesce(transactions_grouped.total_refund_count, 0) as total_refund_count,
coalesce(transactions_grouped.sales_this_month/100.0, 0) as sales_this_month,
coalesce(transactions_grouped.refunds_this_month/100.0, 0) as refunds_this_month,
coalesce(transactions_grouped.gross_transaction_amount_this_month/100.0, 0) as gross_transaction_amount_this_month,
coalesce(transactions_grouped.fees_this_month/100.0, 0) as fees_this_month,
coalesce(transactions_grouped.net_transaction_amount_this_month/100.0, 0) as net_transaction_amount_this_month,
coalesce(transactions_grouped.sales_this_month, 0) as sales_this_month,
coalesce(transactions_grouped.refunds_this_month, 0) as refunds_this_month,
coalesce(transactions_grouped.gross_transaction_amount_this_month, 0) as gross_transaction_amount_this_month,
coalesce(transactions_grouped.fees_this_month, 0) as fees_this_month,
coalesce(transactions_grouped.net_transaction_amount_this_month, 0) as net_transaction_amount_this_month,
coalesce(transactions_grouped.sales_count_this_month, 0) as sales_count_this_month,
coalesce(transactions_grouped.refund_count_this_month, 0) as refund_count_this_month,
transactions_grouped.first_sale_date,
Expand All @@ -185,18 +185,18 @@ with balance_transaction_joined as (
customer.created_at as customer_created_at,
customer.currency as customer_currency,
{{ dbt_utils.star(from=ref('stg_stripe__customer'), relation_alias='customer', except=['customer_id','description','created_at','currency','metadata','source_relation']) }},
coalesce(transactions_grouped.total_sales/100.0, 0) as total_sales,
coalesce(transactions_grouped.total_refunds/100.0, 0) as total_refunds,
coalesce(transactions_grouped.total_gross_transaction_amount/100.0, 0) as total_gross_transaction_amount,
coalesce(transactions_grouped.total_fees/100.0, 0) as total_fees,
coalesce(transactions_grouped.total_net_transaction_amount/100.0, 0) as total_net_transaction_amount,
coalesce(transactions_grouped.total_sales, 0) as total_sales,
coalesce(transactions_grouped.total_refunds, 0) as total_refunds,
coalesce(transactions_grouped.total_gross_transaction_amount, 0) as total_gross_transaction_amount,
coalesce(transactions_grouped.total_fees, 0) as total_fees,
coalesce(transactions_grouped.total_net_transaction_amount, 0) as total_net_transaction_amount,
coalesce(transactions_grouped.total_sales_count, 0) as total_sales_count,
coalesce(transactions_grouped.total_refund_count, 0) as total_refund_count,
coalesce(transactions_grouped.sales_this_month/100.0, 0) as sales_this_month,
coalesce(transactions_grouped.refunds_this_month/100.0, 0) as refunds_this_month,
coalesce(transactions_grouped.gross_transaction_amount_this_month/100.0, 0) as gross_transaction_amount_this_month,
coalesce(transactions_grouped.fees_this_month/100.0, 0) as fees_this_month,
coalesce(transactions_grouped.net_transaction_amount_this_month/100.0, 0) as net_transaction_amount_this_month,
coalesce(transactions_grouped.sales_this_month, 0) as sales_this_month,
coalesce(transactions_grouped.refunds_this_month, 0) as refunds_this_month,
coalesce(transactions_grouped.gross_transaction_amount_this_month, 0) as gross_transaction_amount_this_month,
coalesce(transactions_grouped.fees_this_month, 0) as fees_this_month,
coalesce(transactions_grouped.net_transaction_amount_this_month, 0) as net_transaction_amount_this_month,
coalesce(transactions_grouped.sales_count_this_month, 0) as sales_count_this_month,
coalesce(transactions_grouped.refund_count_this_month, 0) as refund_count_this_month,
transactions_grouped.first_sale_date,
Expand Down
8 changes: 6 additions & 2 deletions packages.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
packages:
- package: fivetran/stripe_source
version: [">=0.12.0", "<0.13.0"]
# - package: fivetran/stripe_source
# version: [">=0.13.0", "<0.14.0"]

- git: https://github.com/fivetran/dbt_stripe_source.git
revision: feature/standardize_cent_conversions
warn-unpinned: false