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 16 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: true}' --full-refresh --target "$db"
dbt test --target "$db"

dbt run-operation fivetran_utils.drop_schemas_automation --target "$db"
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# dbt_stripe_source version.version
# dbt_stripe_source v0.12.2
fivetran-reneeli 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

## Feature Updates: Optionally convert Amounts to Major Units
fivetran-reneeli marked this conversation as resolved.
Show resolved Hide resolved
- 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.
fivetran-reneeli marked this conversation as resolved.
Show resolved Hide resolved

- This PR introduces a variable `stripe__convert_values` (disabled by default) which allows users the option to divide all amount-based fields by 100.
fivetran-reneeli marked this conversation as resolved.
Show resolved Hide resolved
- For information on how to enable the division, refer to the [README]((https://github.com/fivetran/dbt_stripe_source?tab=readme-ov-file#enabling-cent-to-dollar-conversion)) on configuring the `stripe__convert_values` variable.
- Otherwise, amount-based fields will be brought through in their raw form.
- Examples of currencies using minor units (in which enabling `stripe__convert_values` is relevant) include USD, Euro, and CAD.
fivetran-reneeli marked this conversation as resolved.
Show resolved Hide resolved
- Examples of currencies NOT using minor units (in which is makes more sense to keep the amount-based fields in raw form) include Japanese Yen (JPY), Indonesian Rupiah (IDR), and Korean Won (KRW).
fivetran-reneeli marked this conversation as resolved.
Show resolved Hide resolved

## Under the Hood
- Introduces the `convert_values` macro that holds the logic for enabling the division by 100, referenced by all amount-based fields.
fivetran-reneeli marked this conversation as resolved.
Show resolved Hide resolved
- Updates the `run_models.sh` script to test for when `stripe__convert_values` is set to True.

## Notes
- Note that in a future release, the division by 100 will be enabled by default instead.
fivetran-reneeli marked this conversation as resolved.
Show resolved Hide resolved
- 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

## Documentation
- Updates the descriptions for all amount-based fields to specify the grain of the values and add information about the `stripe__convert_values` variable.
- Corrected references to connectors and connections in the README. ([#88](https://github.com/fivetran/dbt_stripe_source/pull/88))

# dbt_stripe_source v0.12.1
Expand Down
18 changes: 15 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,17 @@ 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
```

#### Enabling 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, 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:

```yml
vars:
stripe__convert_values: true # default is false
```

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.

#### 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.12.2'
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.

10 changes: 5 additions & 5 deletions integration_tests/ci/sample.profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ integration_tests:
pass: "{{ env_var('CI_REDSHIFT_DBT_PASS') }}"
dbname: "{{ env_var('CI_REDSHIFT_DBT_DBNAME') }}"
port: 5439
schema: stripe_source_integrations_tests_6
schema: stripe_source_integrations_tests_8
threads: 8
bigquery:
type: bigquery
method: service-account-json
project: 'dbt-package-testing'
schema: stripe_source_integrations_tests_6
schema: stripe_source_integrations_tests_8
threads: 8
keyfile_json: "{{ env_var('GCLOUD_SERVICE_KEY') | as_native }}"
snowflake:
Expand All @@ -33,7 +33,7 @@ integration_tests:
role: "{{ env_var('CI_SNOWFLAKE_DBT_ROLE') }}"
database: "{{ env_var('CI_SNOWFLAKE_DBT_DATABASE') }}"
warehouse: "{{ env_var('CI_SNOWFLAKE_DBT_WAREHOUSE') }}"
schema: stripe_source_integrations_tests_6
schema: stripe_source_integrations_tests_8
threads: 8
postgres:
type: postgres
Expand All @@ -42,13 +42,13 @@ integration_tests:
pass: "{{ env_var('CI_POSTGRES_DBT_PASS') }}"
dbname: "{{ env_var('CI_POSTGRES_DBT_DBNAME') }}"
port: 5432
schema: stripe_source_integrations_tests_6
schema: stripe_source_integrations_tests_8
threads: 8
databricks:
catalog: "{{ env_var('CI_DATABRICKS_DBT_CATALOG') }}"
host: "{{ env_var('CI_DATABRICKS_DBT_HOST') }}"
http_path: "{{ env_var('CI_DATABRICKS_DBT_HTTP_PATH') }}"
schema: stripe_source_integrations_tests_6
schema: stripe_source_integrations_tests_8
threads: 2
token: "{{ env_var('CI_DATABRICKS_DBT_TOKEN') }}"
type: databricks
6 changes: 3 additions & 3 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
config-version: 2

name: 'stripe_source_integration_tests'
version: '0.12.1'
version: '0.12.2'
fivetran-reneeli marked this conversation as resolved.
Show resolved Hide resolved


profile: 'integration_tests'

vars:
stripe_schema: stripe_source_integrations_tests_6
stripe_schema: stripe_source_integrations_tests_8

stripe_source:
card_pass_through_columns:
- name: "description"
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=var('stripe__convert_values',false), alias=None) %}
{% if 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 kept in its raw form. However, in some currencies, it may be useful to divide the value 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. To invoke the division, set the variable stripe__convert_values to True (False by default). If your currency does not contain minor units (for example the Japanese Yen ¥ which does not use decimals), you can run the package as-is. Note that in a future release, the division by 100 will be enabled by default instead.
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
{%- enddocs %}
Loading