Skip to content

Commit ec24e58

Browse files
Merge pull request #101 from fivetran/feature/standardize_cent_conversions
move cent conversions upstream to source package
2 parents cd9fe63 + e6f2c4b commit ec24e58

15 files changed

+289
-129
lines changed

.buildkite/scripts/run_models.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dbt deps
1919
dbt seed --target "$db" --full-refresh
2020
dbt run --target "$db" --full-refresh
2121
dbt test --target "$db"
22-
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"
22+
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__convert_values: true}' --target "$db"
2323
dbt test --target "$db"
2424

2525
dbt run-operation fivetran_utils.drop_schemas_automation --target "$db"

CHANGELOG.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
1-
# dbt_stripe version.version
1+
# dbt_stripe v0.16.0
2+
## Breaking Change - Potential Change in Values May Impact Downstream Queries
3+
- The aggregated net, gross, sale, charge, refund, and fee amount-based fields in `stripe__daily_overview` and `stripe__customer_overview` now reflect the raw smallest units (e.g., cents), following Stripe's raw data, instead of converted dollar amounts. This change standardizes values across all models.
4+
- Customers using these models should note that the values will appear inflated compared to the previous dollar-based representation.
5+
- The cent-to-dollar conversion has been moved upstream and is now controlled by a new variable: `stripe__convert_values` which is disabled by default.
6+
- See the below Feature Update notes for more context behind these changes and for detailed setup instructions, see the [README](https://github.com/fivetran/dbt_stripe?tab=readme-ov-file#enabling-cent-to-dollar-conversion).
7+
8+
## Feature Update: Optional Conversion to Major Units
9+
Stripe passes amount-based fields, such as `amount`, `net`, and `fee`, in the smallest denomination as raw form. This means, if your currency has minor and major units such as USD, 100 represents 100 cents, the minor unit, or 1 USD, the major unit. Alternatively, if your currency doesn't use minor units such as JPY, 100 represents 100 JPY.
10+
11+
- This PR introduces a variable `stripe__convert_values` (disabled by default) upstream in the staging models which allows users the option to divide all amount-based fields by 100.
12+
- For information on how to enable the division, refer to the [README](https://github.com/fivetran/dbt_stripe?tab=readme-ov-file#enabling-cent-to-dollar-conversion) on configuring the `stripe__convert_values` variable.
13+
- Otherwise, amount-based fields will be brought through in their raw form.
14+
- Examples of currencies using minor units (in which enabling `stripe__convert_values` is relevant) include United States Dollar (USD), Euro (EUR), and the Canadian Dollar (CAD).
15+
- Examples of currencies NOT using minor units (in which it makes more sense to keep the amount-based fields in raw form) include Japanese Yen (JPY), Indonesian Rupiah (IDR), and Korean Won (KRW).
16+
17+
## Notes
18+
- This update is not providing multiple currency support; however, we're interested in exploring this functionality if there's a need. As such, we have created a [feature request to support multiple currencies](https://github.com/fivetran/dbt_stripe/issues/102) where you are welcome to provide feedback or contribute to the discussion.
19+
20+
## Under the Hood
21+
- Updated the `run_models.sh` script to test for when `stripe__convert_values` is set to True.
22+
- Added a consistency test for `stripe__customer_overview`.
223

324
## Documentation
25+
- Updated the descriptions for all amount-based fields to specify the grain of the values and add information about the `stripe__convert_values` variable.
426
- Added Quickstart model counts to README. ([#103](https://github.com/fivetran/dbt_stripe/pull/103))
527
- Corrected references to connectors and connections in the README. ([#103](https://github.com/fivetran/dbt_stripe/pull/103))
628

README.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<p align="center">
1+
# Stripe Transformation dbt Package ([Docs](https://fivetran.github.io/dbt_stripe/))
2+
3+
<p align="left">
24
<a alt="License"
35
href="https://github.com/fivetran/dbt_stripe/blob/main/LICENSE">
46
<img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" /></a>
@@ -13,7 +15,6 @@
1315
<img src="https://img.shields.io/badge/Fivetran_Quickstart_Compatible%3F-yes-green.svg" /></a>
1416
</p>
1517

16-
# Stripe Transformation dbt Package ([Docs](https://fivetran.github.io/dbt_stripe/))
1718
## What does this dbt package do?
1819
- Produces modeled tables that leverage Stripe data from [Fivetran's connector](https://fivetran.com/docs/applications/stripe) in the format described by [this ERD](https://fivetran.com/docs/applications/stripe#schemainformation) and build off the output of our [stripe source package](https://github.com/fivetran/dbt_stripe_source).
1920
- Enables you to better understand your Stripe transactions. The package achieves this by performing the following:
@@ -74,7 +75,7 @@ Include the following stripe package version in your `packages.yml` file:
7475
```yaml
7576
packages:
7677
- package: fivetran/stripe
77-
version: [">=0.15.0", "<0.16.0"]
78+
version: [">=0.16.0", "<0.17.0"]
7879
```
7980
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.
8081

@@ -222,6 +223,17 @@ vars:
222223
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
223224
```
224225

226+
#### Enabling Cent to Dollar Conversion
227+
228+
Amount-based fields, such as `amount` and `net`, are typically displayed in the smallest denomination (e.g., cents for USD). By default, amount-based fields will be in this raw form. However, some currencies use major and minor units (for example, cents and dollars when using USD). In these cases, it may be useful to divide the amounts by 100, converting amounts to major units (dollars for USD). To enable the division, configure the `stripe__convert_values` to `true` in your project.yml:
229+
230+
```yml
231+
vars:
232+
stripe__convert_values: true # default is false
233+
```
234+
235+
If you are working in a currency that does not differentiate between minor and major units, such as JPY or KRW, it may make more sense to keep the amount-based fields in raw form and therefore the package can be ran without configuration. As `stripe__convert_values` is disabled by default, these fields will not be impacted.
236+
225237
#### Change the build schema
226238
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:
227239

@@ -256,7 +268,7 @@ This dbt package is dependent on the following dbt packages. These dependencies
256268
```yml
257269
packages:
258270
- package: fivetran/stripe_source
259-
version: [">=0.12.0", "<0.13.0"]
271+
version: [">=0.13.0", "<0.14.0"]
260272
261273
- package: fivetran/fivetran_utils
262274
version: [">=0.4.0", "<0.5.0"]

dbt_project.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
config-version: 2
22
name: 'stripe'
33

4-
version: '0.15.1'
4+
version: '0.16.0'
55
require-dbt-version: [">=1.3.0", "<2.0.0"]
66
models:
77
stripe:

docs/catalog.json

+1-1
Large diffs are not rendered by default.

docs/index.html

+32-5
Large diffs are not rendered by default.

docs/manifest.json

+1-1
Large diffs are not rendered by default.

integration_tests/ci/sample.profiles.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ integration_tests:
1616
pass: "{{ env_var('CI_REDSHIFT_DBT_PASS') }}"
1717
dbname: "{{ env_var('CI_REDSHIFT_DBT_DBNAME') }}"
1818
port: 5439
19-
schema: stripe_integrations_tests_15
19+
schema: stripe_integrations_tests_19
2020
threads: 8
2121
bigquery:
2222
type: bigquery
2323
method: service-account-json
2424
project: 'dbt-package-testing'
25-
schema: stripe_integrations_tests_15
25+
schema: stripe_integrations_tests_19
2626
threads: 8
2727
keyfile_json: "{{ env_var('GCLOUD_SERVICE_KEY') | as_native }}"
2828
snowflake:
@@ -33,7 +33,7 @@ integration_tests:
3333
role: "{{ env_var('CI_SNOWFLAKE_DBT_ROLE') }}"
3434
database: "{{ env_var('CI_SNOWFLAKE_DBT_DATABASE') }}"
3535
warehouse: "{{ env_var('CI_SNOWFLAKE_DBT_WAREHOUSE') }}"
36-
schema: stripe_integrations_tests_15
36+
schema: stripe_integrations_tests_19
3737
threads: 8
3838
postgres:
3939
type: postgres
@@ -42,13 +42,13 @@ integration_tests:
4242
pass: "{{ env_var('CI_POSTGRES_DBT_PASS') }}"
4343
dbname: "{{ env_var('CI_POSTGRES_DBT_DBNAME') }}"
4444
port: 5432
45-
schema: stripe_integrations_tests_15
45+
schema: stripe_integrations_tests_19
4646
threads: 8
4747
databricks:
4848
catalog: "{{ env_var('CI_DATABRICKS_DBT_CATALOG') }}"
4949
host: "{{ env_var('CI_DATABRICKS_DBT_HOST') }}"
5050
http_path: "{{ env_var('CI_DATABRICKS_DBT_HTTP_PATH') }}"
51-
schema: stripe_integrations_tests_15
51+
schema: stripe_integrations_tests_19
5252
threads: 8
5353
token: "{{ env_var('CI_DATABRICKS_DBT_TOKEN') }}"
5454
type: databricks

integration_tests/dbt_project.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
config-version: 2
22

33
name: 'stripe_integration_tests'
4-
version: '0.15.1'
4+
version: '0.16.0'
55

66
profile: 'integration_tests'
77

88
# For use with validations
99
models:
1010
+schema: "stripe_{{ var('directed_schema','dev') }}"
1111

12-
vars:
13-
stripe_schema: stripe_integrations_tests_15
12+
vars:
13+
stripe_schema: stripe_integrations_tests_19
1414
stripe__standardized_billing_model_enabled: true
1515
stripe__using_credit_notes: true
1616
stripe_source:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{{ config(
2+
tags="fivetran_validations",
3+
enabled=var('fivetran_validation_tests_enabled', false)
4+
) }}
5+
6+
-- this test ensures the customer_overview end model matches the prior version by comparing the aggregated fields
7+
-- the below iterates through the prod and dev names to reduce redundancy of logic
8+
with
9+
{% for prod_or_dev in ('prod', 'dev') %}
10+
{% set cols = [
11+
'total_sales',
12+
'total_refunds',
13+
'total_gross_transaction_amount',
14+
'total_fees',
15+
'total_net_transaction_amount',
16+
'total_sales_count',
17+
'total_refund_count',
18+
'sales_this_month',
19+
'refunds_this_month',
20+
'gross_transaction_amount_this_month',
21+
'fees_this_month',
22+
'net_transaction_amount_this_month',
23+
'sales_count_this_month',
24+
'refund_count_this_month',
25+
'total_failed_charge_count',
26+
'total_failed_charge_amount',
27+
'failed_charge_count_this_month',
28+
'failed_charge_amount_this_month'
29+
] %}
30+
31+
{{ prod_or_dev }} as (
32+
select
33+
{% for col in cols %}
34+
{% if not loop.first %}, {% endif %}
35+
floor(sum({{ col }})) as summed_{{ col }} -- floor and sum is to keep consistency between dev and prod aggs
36+
{% endfor %}
37+
from {{ target.schema }}_stripe_{{ prod_or_dev }}.stripe__customer_overview
38+
),
39+
{% endfor %}
40+
41+
prod_not_in_dev as (
42+
-- rows from prod not found in dev
43+
select * from prod
44+
except distinct
45+
select * from dev
46+
),
47+
48+
dev_not_in_prod as (
49+
-- rows from dev not found in prod
50+
select * from dev
51+
except distinct
52+
select * from prod
53+
),
54+
55+
final as (
56+
select
57+
*,
58+
'from prod' as source
59+
from prod_not_in_dev
60+
61+
union all -- union since we only care if rows are produced
62+
63+
select
64+
*,
65+
'from dev' as source
66+
from dev_not_in_prod
67+
)
68+
69+
select *
70+
from final

models/docs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
{% docs source_relation -%} The source where this data was pulled from. If you are making use of the `union_schemas` variable, this will be the source schema. If you are making use of the `union_databases` variable, this will be the source database. If you are not unioning together multiple sources, this will be an empty string.
2-
{%- enddocs %}
2+
{%- enddocs %}

models/intermediate/int_stripe__account_daily.sql

+11-11
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,21 @@ select
8181
daily_account_balance_transactions.date_day,
8282
daily_account_balance_transactions.account_id,
8383
daily_account_balance_transactions.source_relation,
84-
coalesce(daily_account_balance_transactions.total_daily_sales_amount/100.0,0) as total_daily_sales_amount,
85-
coalesce(daily_account_balance_transactions.total_daily_refunds_amount/100.0,0) as total_daily_refunds_amount,
86-
coalesce(daily_account_balance_transactions.total_daily_adjustments_amount/100.0,0) as total_daily_adjustments_amount,
87-
coalesce(daily_account_balance_transactions.total_daily_other_transactions_amount/100.0,0) as total_daily_other_transactions_amount,
88-
coalesce(daily_account_balance_transactions.total_daily_gross_transaction_amount/100.0,0) as total_daily_gross_transaction_amount,
89-
coalesce(daily_account_balance_transactions.total_daily_net_transactions_amount/100.0,0) as total_daily_net_transactions_amount,
90-
coalesce(daily_account_balance_transactions.total_daily_payout_fee_amount/100.0,0) as total_daily_payout_fee_amount,
91-
coalesce(daily_account_balance_transactions.total_daily_gross_payout_amount/100.0,0) as total_daily_gross_payout_amount,
92-
coalesce(daily_account_balance_transactions.daily_net_activity_amount/100.0,0) as daily_net_activity_amount,
93-
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,
84+
coalesce(daily_account_balance_transactions.total_daily_sales_amount,0) as total_daily_sales_amount,
85+
coalesce(daily_account_balance_transactions.total_daily_refunds_amount,0) as total_daily_refunds_amount,
86+
coalesce(daily_account_balance_transactions.total_daily_adjustments_amount,0) as total_daily_adjustments_amount,
87+
coalesce(daily_account_balance_transactions.total_daily_other_transactions_amount,0) as total_daily_other_transactions_amount,
88+
coalesce(daily_account_balance_transactions.total_daily_gross_transaction_amount,0) as total_daily_gross_transaction_amount,
89+
coalesce(daily_account_balance_transactions.total_daily_net_transactions_amount,0) as total_daily_net_transactions_amount,
90+
coalesce(daily_account_balance_transactions.total_daily_payout_fee_amount,0) as total_daily_payout_fee_amount,
91+
coalesce(daily_account_balance_transactions.total_daily_gross_payout_amount,0) as total_daily_gross_payout_amount,
92+
coalesce(daily_account_balance_transactions.daily_net_activity_amount,0) as daily_net_activity_amount,
93+
coalesce((daily_account_balance_transactions.daily_net_activity_amount + daily_account_balance_transactions.total_daily_gross_payout_amount), 0) as daily_end_balance_amount,
9494
coalesce(daily_account_balance_transactions.total_daily_sales_count, 0) as total_daily_sales_count,
9595
coalesce(daily_account_balance_transactions.total_daily_payouts_count, 0) as total_daily_payouts_count,
9696
coalesce(daily_account_balance_transactions.total_daily_adjustments_count, 0) as total_daily_adjustments_count,
9797
coalesce(daily_failed_charges.total_daily_failed_charge_count, 0) as total_daily_failed_charge_count,
98-
coalesce(daily_failed_charges.total_daily_failed_charge_amount/100, 0) as total_daily_failed_charge_amount
98+
coalesce(daily_failed_charges.total_daily_failed_charge_amount, 0) as total_daily_failed_charge_amount
9999

100100
from daily_account_balance_transactions
101101
left join daily_failed_charges

0 commit comments

Comments
 (0)