# Billing objects and flows

> The objects behind Shoplazza billing and how they flow: ApplicationCharge, RecurringCharge, UsageCharge, Transaction, Refund, SettlementBill, and merchant invoices.

# Data Flow

![](https://cnres.appracle.com/ec6b93243ceddcc044c38f905c7f4666.png)

# Data Structures

## ApplicationCharge

| Field          | Description                          | Type     |
| -------------- | ------------------------------------ | -------- |
| id             | Primary key ID                       | bigint   |
| store_id       | Store ID                             | bigint   |
| application_id | Application ID                       | varchar  |
| name           | Payment name                         | varchar  |
| price          | Payment amount                       | decimal  |
| confirm_url    | Confirmation payment page URL        | varchar  |
| return_url     | Redirect URL after payment or denial | varchar  |
| status         | Payment status                       | varchar  |
| test           | Whether it is a test mode            | tinyint  |
| created_at     | Creation time                        | datetime |
| updated_at     | Update time                          | datetime |

## RecurringCharge

| Field                  | Description                                                                | Type     |
| ---------------------- | -------------------------------------------------------------------------- | -------- |
| id                     | Bill ID                                                                    | bigint   |
| store_id               | Store ID                                                                   | bigint   |
| application_id         | Application ID                                                             | varchar  |
| name                   | Bill Name                                                                  | varchar  |
| price                  | Bill Amount                                                                | decimal  |
| capped_amount          | Capped Amount for Usage-Based Billing                                      | decimal  |
| terms                  | Terms of Usage-Based Billing                                               | varchar  |
| return_url             | App Homepage                                                               | varchar  |
| confirmation_url       | Merchant Confirmation Page                                                 | varchar  |
| status                 | Current Bill Status (pending, accepted, declined, active, expired, frozen) | varchar  |
| trial_days             | Trial Days                                                                 | bigint   |
| activated_on           | Activation Time                                                            | datetime |
| trial_ends_on          | Trial End Time                                                             | datetime |
| billing_on             | Next Billing Time                                                          | datetime |
| cancelled_on           | Bill Cancellation Time                                                     | datetime |
| test                   | Test Mode Indicator                                                        | tinyint  |
| created_at             | Creation Time                                                              | datetime |
| updated_at             | Update Time                                                                | datetime |
| cancel_sub_on          | Subscription Cancellation Time                                             | datetime |
| charge_times           | Number of Charges, 0 Represents Unlimited                                  | int      |
| charge_interval_days   | Billing Interval in Days                                                   | int      |
| remaining_charge_times | Remaining Charges, for Unlimited this Value is Always 1                    | int      |

## UsageCharge

| Field               | Description                    | Type     |
| ------------------- | ------------------------------ | -------- |
| id                  | Primary key ID                 | bigint   |
| created_at          | Creation Time                  | datetime |
| updated_at          | Update Time                    | datetime |
| store_id            | Store ID                       | bigint   |
| recurring_charge_id | Associated Recurring Charge ID | bigint   |
| terms               | Terms of Charge                | varchar  |
| price               | Price                          | decimal  |
| application_id      | Application ID                 | varchar  |
| pay_status          | Payment Status                 | varchar  |
| transaction_id      | Associated Transaction ID      | bigint   |

## Transaction

| Field                 | Description                                                | Type     |
| --------------------- | ---------------------------------------------------------- | -------- |
| id                    | Primary key ID                                             | bigint   |
| store_id              | Store ID                                                   | bigint   |
| charge_id             | ID associated with ApplicationCharge/RecurringCharge       | bigint   |
| price                 | Charge price                                               | decimal  |
| status                | Current transaction status (pending, paying, paid, failed) | varchar  |
| paid_at               | Payment time                                               | datetime |
| created_at            | Creation time                                              | datetime |
| updated_at            | Update time                                                | datetime |
| usage_price           | Usage fee                                                  | decimal  |
| file_url              | Invoice URL                                                | varchar  |
| bill_id               | ID from settlement_bills                                   | bigint   |
| commission_rate       | Commission rate                                            | decimal  |
| pay_channel           | Payment channel                                            | varchar  |
| payment_serial_number | Payment serial number                                      | varchar  |
| application_id        | Application ID                                             | varchar  |
| test                  | Whether it is a test bill                                  | tinyint  |

## Refund

| Field               | Description                                   | Type     |
| ------------------- | --------------------------------------------- | -------- |
| id                  | Primary key                                   | bigint   |
| settlement_bills.id | Associated Settlement Bill ID                 | bigint   |
| transaction_id      | Associated Transaction Order ID               | bigint   |
| store_id            | Store ID                                      | bigint   |
| charge_type         | Current Bill Type (one-time/recurring charge) | varchar  |
| application_id      | Application ID                                | varchar  |
| amount_refund       | Refund Amount                                 | decimal  |
| voucher_path        | Payment Voucher Path                          | varchar  |
| created_at          | Creation Time                                 | datetime |
| updated_at          | Update Time                                   | datetime |

## SettlementBill

| Field                      | Description                           | Type     |
| -------------------------- | ------------------------------------- | -------- |
| id                         | Primary key ID                        | bigint   |
| created_at                 | Creation Time                         | datetime |
| updated_at                 | Update Time                           | datetime |
| partner_id                 | Partner ID                            | bigint   |
| application_id             | Application ID                        | varchar  |
| start_time                 | Start Time of the Bill Cycle          | datetime |
| end_time                   | End Time of the Bill Cycle            | datetime |
| before_total_charge_amount | Total Charge Amount before Settlement | decimal  |
| free_commission_limit      | Free Commission Limit                 | decimal  |
| amount                     | Total Amount of the Order             | decimal  |
| amount_payable             | Amount Payable on the Bill            | decimal  |
| commission_amount          | Commission Amount on the Bill         | decimal  |
| amount_refund              | Refund Amount on the Bill             | decimal  |
| commission_rate            | Commission Rate                       | decimal  |
| status                     | Status                                | varchar  |
| reject_reason              | Reason for Rejection                  | varchar  |

## Invoice for merchants

![](https://cnres.appracle.com/1c171f858275c28280fc2dc3da0f54fa.png)
