{
  "key": "utility-bill-card-payments-v1",
  "name": "Utility payment processing: collect bills after credits",
  "chartOfAccounts": {
    "defaultCurrency": {
      "code": "USD"
    },
    "defaultCurrencyMode": "single",
    "defaultConsistencyConfig": {
      "totalBalanceUpdates": "strong"
    },
    "accounts": [
      {
        "key": "assets",
        "type": "asset",
        "children": [
          {
            "key": "payments",
            "payment": {
              "enabled": true
            }
          },
          {
            "key": "receivables",
            "template": true,
            "children": [
              {
                "key": "outstanding"
              }
            ]
          }
        ]
      },
      {
        "key": "income",
        "type": "income",
        "children": [
          {
            "key": "utility-services",
            "template": true
          }
        ]
      },
      {
        "key": "expenses",
        "type": "expense",
        "children": [
          {
            "key": "payment-fees"
          }
        ]
      }
    ]
  },
  "payments": {
    "types": [
      {
        "type": "utility_bill",
        "typeVersion": 1,
        "status": "active",
        "payment": {
          "amount": "{{amount}}",
          "direction": "payin"
        },
        "accounting": {
          "settled": {
            "description": "Card receipt for utility bill {{bill_id}}",
            "lines": [
              {
                "key": "settlement",
                "account": {
                  "path": "assets/payments"
                },
                "amount": "{{settled_amount}}",
                "system": "payment_settlement_line"
              },
              {
                "key": "fee",
                "account": {
                  "path": "assets/payments"
                },
                "amount": "-{{fragment_fee_amount}}",
                "system": "payment_fee_line"
              },
              {
                "key": "receipt",
                "account": {
                  "path": "assets/receivables:{{bill_id}}/outstanding"
                },
                "amount": "-{{settled_amount}}"
              },
              {
                "key": "fee-expense",
                "account": {
                  "path": "expenses/payment-fees"
                },
                "amount": "{{fragment_fee_amount}}"
              }
            ]
          }
        }
      }
    ]
  },
  "ledgerEntries": {
    "types": [
      {
        "type": "utility_bill_approve",
        "description": "Record approved utility bill {{bill_id}}",
        "lines": [
          {
            "key": "source",
            "account": {
              "path": "assets/receivables:{{bill_id}}/outstanding"
            },
            "amount": "{{amount}}"
          },
          {
            "key": "destination",
            "account": {
              "path": "income/utility-services:{{bill_id}}"
            },
            "amount": "{{amount}}"
          }
        ]
      }
    ]
  }
}
