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

convert cent based fields to major currency unit based #87

Merged
merged 36 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8e3c320
convert cent based fields to major currency unit based
fivetran-reneeli Dec 18, 2024
f676339
add changelog and version up to breaking change
fivetran-reneeli Dec 19, 2024
11b4843
update readmes
fivetran-reneeli Dec 19, 2024
9865584
docs
fivetran-reneeli Dec 19, 2024
677b5f2
add blanket divide variable, add docs to readme and changelog, add to…
fivetran-reneeli Dec 27, 2024
9ea9eb3
update stg.yml documentation
fivetran-reneeli Jan 7, 2025
ebb88e3
add convert_value macro, change variable name
fivetran-reneeli Jan 7, 2025
41a2cf3
update docs
fivetran-reneeli Jan 7, 2025
ffee358
update convert macro
fivetran-reneeli Jan 13, 2025
4fe8270
update relevant documentation now that default is false
fivetran-reneeli Jan 13, 2025
5af2ed5
schema and docs
fivetran-reneeli Jan 13, 2025
816f94a
downgrade version
fivetran-reneeli Jan 14, 2025
d4a391d
reamde
fivetran-reneeli Jan 14, 2025
4d8fe6d
Merge branch 'main' into feature/standardize_cent_conversions
fivetran-reneeli Jan 14, 2025
e1354bd
changelog
fivetran-reneeli Jan 14, 2025
d481009
schema
fivetran-reneeli Jan 15, 2025
27a7b5e
updates
fivetran-reneeli Jan 16, 2025
a150a3d
Update CHANGELOG.md
fivetran-reneeli Jan 16, 2025
ce47548
Update CHANGELOG.md
fivetran-reneeli Jan 16, 2025
dc657b9
Update CHANGELOG.md
fivetran-reneeli Jan 16, 2025
5010d7a
Update CHANGELOG.md
fivetran-reneeli Jan 16, 2025
c4a8bae
Update CHANGELOG.md
fivetran-reneeli Jan 16, 2025
77ab32c
update macro
fivetran-reneeli Jan 16, 2025
254019e
schema
fivetran-reneeli Jan 16, 2025
dd223d6
Update CHANGELOG.md
fivetran-reneeli Jan 21, 2025
ba36b57
Update CHANGELOG.md
fivetran-reneeli Jan 21, 2025
e4de4f4
Update CHANGELOG.md
fivetran-reneeli Jan 21, 2025
94e2852
Update CHANGELOG.md
fivetran-reneeli Jan 21, 2025
1ed1537
Update integration_tests/dbt_project.yml
fivetran-reneeli Jan 21, 2025
305ec7d
Update CHANGELOG.md
fivetran-reneeli Jan 21, 2025
c1e285f
Update CHANGELOG.md
fivetran-reneeli Jan 21, 2025
3970a6a
updates
fivetran-reneeli Jan 21, 2025
92a784d
versioning and docs
fivetran-reneeli Jan 21, 2025
2854b49
fix
fivetran-reneeli Jan 21, 2025
79658db
put back aliases and fix some docs, regen docs
fivetran-reneeli Jan 22, 2025
9a3ad8d
update macro and docs
fivetran-reneeli Jan 22, 2025
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_invoice_line_sub_filter: false, stripe__using_credit_notes: true, stripe__using_price: false, stripe__using_subscription_history: false}' --full-refresh --target "$db"
dbt run --vars '{stripe__using_invoice_line_sub_filter: false, stripe__using_credit_notes: true, stripe__using_price: false, stripe__using_subscription_history: false, stripe__convert_values: false}' --full-refresh --target "$db"
dbt test --target "$db"

dbt run-operation fivetran_utils.drop_schemas_automation --target "$db"
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# dbt_stripe_source v0.13.0
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
[PR [#87](https://github.com/fivetran/dbt_stripe_source/pull/87)] includes the following updates:
fivetran-reneeli marked this conversation as resolved.
Show resolved Hide resolved

## Breaking Change
- This package assumes that amount-based fields, such as `amount`, `net`, and `fee`, which in raw form are represented in the smallest denomination in Stripe, are cent-based (minor units). Therefore, for example, an amount of 100 cents would be equal to 1 dollar (major unit).

- This PR shifts the existing conversion from cents to dollars to further upstream. Previously, amount-based fields were automatically converted in downstream models, but they are now converted directly in the staging models, with an option to disable this behavior. As the values of amount-based fields have changed, this introduces a breaking change.

- If your Stripe data is *not* using a currency involving minor units, you may want to disable this default conversion in order to retain the amount-based fields as raw form. For information on how to do so, refer to the [README]((https://github.com/fivetran/dbt_stripe_source?tab=readme-ov-file#disabling-cent-to-dollar-conversion)) on disabling the `stripe__convert_values` variable.
- Examples of currencies using minor units include USD, Euro, and CAD.
- Examples of currencies NOT using minor units include Japanese Yen (JPY), Indonesian Rupiah (IDR), and Korean Won (KRW).

- Currently this package does not support multiple currencies, but we have created a [feature flag to support multiple currencies](https://github.com/fivetran/dbt_stripe/issues/102) where you are welcome to provide feedback or contribute to the discussion.
fivetran-reneeli marked this conversation as resolved.
Show resolved Hide resolved

# dbt_stripe_source v0.12.1

## Feature Updates
Expand Down
16 changes: 13 additions & 3 deletions README.md
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<p align="center">
# Stripe Source dbt Package ([Docs](https://fivetran.github.io/dbt_stripe_source/))

<p align="left">
<a alt="License"
href="https://github.com/fivetran/dbt_stripe_source/blob/main/LICENSE">
<img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" /></a>
Expand All @@ -13,7 +15,6 @@
<img src="https://img.shields.io/badge/Fivetran_Quickstart_Compatible%3F-yes-green.svg" /></a>
</p>

# Stripe Source dbt Package ([Docs](https://fivetran.github.io/dbt_stripe_source/))
## What does this dbt package do?
<!--section="stripe_source_model"-->
- Materializes [Stripe staging tables](https://fivetran.github.io/dbt_stripe_source/#!/overview/stripe_source/models/?g_v=1&g_e=seeds) which leverage data in the format described by [this ERD](https://fivetran.com/docs/applications/stripe/#schemainformation). These staging tables clean, test, and prepare your Stripe data from [Fivetran's connector](https://fivetran.com/docs/applications/stripe) for analysis by doing the following:
Expand Down Expand Up @@ -45,7 +46,7 @@ If you are **not** using the [Stripe transformation package](https://github.com
```yaml
packages:
- package: fivetran/stripe_source
version: [">=0.12.0", "<0.13.0"]
version: [">=0.13.0", "<0.14.0"]
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
```
### Step 3: Define database and schema variables
By default, this package runs using your destination and the `stripe` schema. If this is not where your stripe data is (for example, if your stripe schema is named `stripe_fivetran`), add the following configuration to your root `dbt_project.yml` file:
Expand Down Expand Up @@ -178,6 +179,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 major units (dollars for USD) by dividing by `100.0`. However, you may want to disable this default conversion if you are working in a currency that does not have minor units, such as JPY or KRW. To disable this conversion and retain the values in their smallest denomination, set the `stripe__convert_values` variable to `False` as shown below.

```yml
vars:
stripe__convert_values: False
```

#### Passing Through Additional Fields
This package includes all source columns defined in the macros folder. You can add more columns using our pass-through column variables. These variables allow for the pass-through fields to be aliased (`alias`) and casted (`transform_sql`) if desired, but not required. Datatype casting is configured via a sql snippet within the `transform_sql` key. You may add the desired sql while omitting the `as field_name` at the end and your custom pass-though fields will be casted accordingly. Use the below format for declaring the respective pass-through variables:

Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
config-version: 2
name: 'stripe_source'
version: '0.12.1'
version: '0.13.0'
require-dbt-version: [">=1.3.0", "<2.0.0"]

models:
Expand Down
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

47 changes: 37 additions & 10 deletions docs/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/manifest.json

Large diffs are not rendered by default.

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_source_integration_tests'
version: '0.12.1'
version: '0.13.0'


profile: 'integration_tests'
Expand Down
7 changes: 7 additions & 0 deletions macros/convert_values.sql
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% macro convert_values(field_name, divide_by=100.0, divide_var='stripe__convert_values', alias=None) %}
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
{% if var(divide_var, True) %}
{{ field_name }} / {{ divide_by }} as {{ alias if alias else field_name }}
{% else %}
{{ field_name }} as {{ alias if alias else field_name }}
{% endif %}
{% endmacro %}
4 changes: 4 additions & 0 deletions models/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ ZIP or postal code.
{% docs state -%}
State, county, province, or region.
{%- enddocs %}

{% docs convert_values -%}
By default, this value is divided by 100 to get the major currency unit. This works for scenarios in which the currency has a minor unit, which is displayed in the raw data, and major unit. For example, if in USD, if the raw value is 100, this represents 100 cents which then gets converted to $1 dollar, the major currency unit. If your currency does not contain minor units (for example the Japanese Yen ¥ which does not use decimals), then you should disable the variable `stripe__convert_values` to turn off the division by 100 (so that the raw value of 100 remains ¥100).
{%- enddocs %}
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
Loading