# Charge Pricings

Contains pricing and payment information for charging sessions. This model 
combines charge pricing data with related financial attributes like costs,
payment methods, and pricing details.

**SQL:** `charge_pricings`

## Schema

| Column Name              | Data Type     | Description                                                                                                                 |
|:-------------------------|:--------------|:----------------------------------------------------------------------------------------------------------------------------|
| **Primary ID**           |               |                                                                                                                             |
| id                       | INTEGER       | Primary key                                                                                                                 |
| **Other IDs**            |               |                                                                                                                             |
| charge_id                | INTEGER       | References the associated charging session                                                                                  |
| tariff_id                | INTEGER       | References the applied pricing tariff                                                                                       |
| currency_id              | INTEGER       | References the currency for the charge price                                                                                |
| cost_price_group_id      | INTEGER       | References the cost price group configuration                                                                               |
| paying_team_id           | INTEGER       | References the team responsible for payment                                                                                 |
| paying_operator_id       | INTEGER       | References the operator responsible for payment                                                                             |
| sponsor_team_id          | INTEGER       | References the team sponsoring or subsidizing the charge                                                                    |
| promotion_code_id        | INTEGER       | References any applied promotional discount code                                                                            |
| price_group_id           | INTEGER       | References the price group determining the rate structure                                                                   |
| **Timestamps**           |               |                                                                                                                             |
| created_at               | TIMESTAMP_NTZ | Timestamp when the pricing record was created                                                                               |
| updated_at               | TIMESTAMP_NTZ | Timestamp when the pricing record was last modified                                                                         |
| paying_at                | TIMESTAMP_NTZ | Timestamp when payment was processed                                                                                        |
| **Attributes**           |               |                                                                                                                             |
| price                    | NUMBER        | Final price charged for the session                                                                                         |
| reservation_price        | NUMBER        | Price allocated for the charging reservation                                                                                |
| estimated_price          | NUMBER        | Projected cost before charging session completion                                                                           |
| original_price           | NUMBER        | Base price before any adjustments or discounts                                                                              |
| cost                     | NUMBER        | Actual cost incurred for providing the charging service                                                                     |
| payment_method           | VARCHAR       | Method used for payment (e.g., 'free', 'team_has_funds', 'team_has_auto_refill', or 'payment')                              |
| payment_method_type      | VARCHAR       | Further categorization of the payment method (e.g., 'team_wallet', 'free', 'card', 'google_pay', 'apple_pay', 'adyen', etc) |
| payment_type             | VARCHAR       | Further classification of payment types if applicable (e.g., stripe charge, wallet payment, adyen payment, etc.)            |
| estimated_charge_minutes | INTEGER       | Projected duration of charging session in minutes                                                                           |
| payment_failed           | VARCHAR       | Error message of a failed one-time payment; NULL unless a one-time payment failed. Not a boolean: test it with `payment_failed is not null` |
| price_limit              | NUMBER        | Maximum price threshold set for the charging session                                                                        |
| source_failed            | BOOLEAN       | Indicates whether the payment source encountered an error                                                                   |
| source_type              | VARCHAR       | Classification of the payment source or origin (e.g., stripe source)                                                                              |

## Inclusion Criteria

-- requires that `charge_id`is among ids in `charges`

```sql
where charge_id in (select id from charges)
```

## Data Flow

| Upstream tables   | Upstream tables |
| :---------------- | :-------------- |
| `charges` | none            |

## Changes from last Version
### Summary

- Documentation fix: `payment_failed` was documented as BOOLEAN, but the column holds the error message of a failed one-time payment (VARCHAR), and is NULL otherwise. Use `payment_failed is not null` to find failed payments. The data itself is unchanged.
