Build a payment method performance analytics model from scratch
harbor run -t snowflake-labs/dbt-payment-analyticsharbor download snowflake-labs/dbt-payment-analyticsCreate a new dbt model that analyzes payment method performance across orders to identify payment patterns, success rates, reliability metrics, and peer comparisons across payment providers.
/app/dbt_models_duckdb/models/marts/sales/rpt_payment_analytics.sql/app/dbt_models_snowflake/models/marts/sales/rpt_payment_analytics.sqlThis task supports both DuckDB and Snowflake. Run echo $DB_TYPE in a shell BEFORE you write any code or spawn any subagents — the live env determines which backend the verifier runs against. Do NOT assume a default from this prose. Both /app/dbt_models_duckdb/ and /app/dbt_models_snowflake/ exist on disk; the verifier only checks the project matching the live $DB_TYPE.
DB_TYPE=duckdb$DUCKDB_PATH (default: /app/database/retail.duckdb)DB_TYPE=snowflakeSNOWFLAKE_ACCOUNTSNOWFLAKE_USERSNOWFLAKE_PASSWORDSNOWFLAKE_DATABASE - The clone database to useSNOWFLAKE_SCHEMASNOWFLAKE_WAREHOUSESNOWFLAKE_ROLE (optional)Note: For Snowflake, the entrypoint automatically creates a clone database and sets SNOWFLAKE_DATABASE. The clone is destroyed when the task completes.
You must configure dbt to connect to the database:
profiles.yml in the dbt project directory with profile name retail_dw_masterDBT_PROFILES_DIR environment variable to the directory containing profiles.ymlConfigure with type: duckdb and the database path from $DUCKDB_PATH.
Configure with type: snowflake using password authentication:
schema: to $SNOWFLAKE_SCHEMA — do NOT leave it blank. A blank or omitted schema makes Snowflake silently default to PUBLIC, so your models get built in the wrong schema and the verifier cannot find them.Use these tables:
int_sales__orders_enriched - Orders with customer info (exclude cancelled orders: status values include both 'CANCELLED' and abbreviation 'C')stg_orders__order_payments - Payment transactions (payment_id, order_id, payment_method, AMOUNT, status)The status column contains: 'AUTHORIZED', 'CAPTURED', 'COMPLETED', 'FAILED', 'PENDING'
| Metric | Description |
|---|---|
| total_transactions | Count of payment transactions |
| total_orders | Distinct orders using this payment method |
| total_amount | Sum of all payment amounts |
| successful_amount | Sum for COMPLETED or CAPTURED payments |
| failed_transactions | Count of FAILED payments |
| pending_transactions | Count of PENDING or AUTHORIZED payments |
| success_rate | Proportion successful (0-1) |
| avg_transaction_amount | Average payment amount |
| failure_rate | Proportion failed (0-1) |
Classify payment methods into provider groups based on the payment method name:
| Metric | Description |
|---|---|
| provider_type | Category: CARD, DIGITAL, BANK, or OTHER |
Classify provider_type using these keyword rules (case-insensitive match against the payment method name):
Compare each payment method against others in the SAME provider_type:
| Metric | Description |
|---|---|
| provider_success_rank | Rank by success_rate within provider (1 = best, no gaps) |
| provider_method_count | Total methods in same provider_type |
| above_provider_avg_success | 1 if above provider average, 0 otherwise |
| provider_volume_percentile | Volume percentile within provider (0-1) |
reliability_score = (success_rate * 0.40 + (1 - failure_rate) * 0.30 + volume_factor * 0.15 + amount_factor * 0.15) * 100
Where:
volume_factor = MIN(total_transactions / 1000, 1.0)amount_factor = MIN(avg_transaction_amount / 500, 1.0)payment_health_tier - Waterfall classification (check conditions in order, first match wins):
'critical' - failure_rate >= 0.15 OR success_rate < 0.70'problematic' - failure_rate >= 0.08 OR below provider avg success'concerning' - failure_rate >= 0.03 OR success_rate < 0.90'excellent' - reliability percentile >= 0.75 within provider AND failure_rate < 0.02'good' - above provider avg success AND reliability_score >= 60'concerning' - default fallback| Column | Type |
|---|---|
| payment_method | varchar |
| provider_type | varchar |
| total_transactions | integer |
| total_orders | integer |
| total_amount | decimal |
| successful_amount | decimal |
| failed_transactions | integer |
| pending_transactions | integer |
| success_rate | decimal |
| avg_transaction_amount | decimal |
| failure_rate | decimal |
| provider_success_rank | integer |
| provider_method_count | integer |
| above_provider_avg_success | integer |
| provider_volume_percentile | decimal |
| reliability_score | decimal |
| payment_health_tier | varchar |
percent_rank() and dense_rank() accordingly