Skip to content

Commit

Permalink
[master] - Ledger summaries for parent and subaccounts (2600hz#5738)
Browse files Browse the repository at this point in the history
* * Added new MODB view, `ledgers/summary_by_account` to return parent and subaccount ledger summaries.

* Added new crossbar endpoint to `cb_ledgers` to return current modb ledger summary from `../ledgers/summary/{YYYYMM}`.

* Example Payload

```
{
  "page_size": 1,
  "start_key": "g24FAO1KPdYO",
  "data": {
    "summary": {
      "rollovers": {
        "amount": 6.2329,
        "usage": {
          "quantity": 0
        }
      },
      "prorations": {
        "amount": -5.1309,
        "usage": {
          "quantity": 0
        }
      },
      "payments": {
        "amount": 35.0,
        "usage": {
          "quantity": 0
        }
      }
    },
    "account_summary": [
      {
        "cc580f94d7da53816a94b87b2a1d25f8": {
          "account": {
            "id": "cc580f94d7da53816a94b87b2a1d25f8",
            "name": "Account 1"
          },
          "ledgers": {
            "payments": {
              "amount": 35.0,
              "usage": {
                "quantity": 0
              }
            },
            "prorations": {
              "amount": -4.0649,
              "usage": {
                "quantity": 0
              }
            },
            "rollovers": {
              "amount": 6.2329,
              "usage": {
                "quantity": 0
              }
            }
          },
          "total": 37.168
        },
        "de6fd29a54407cfe46e6c9d3828ab0d8": {
          "account": {
            "id": "de6fd29a54407cfe46e6c9d3828ab0d8",
            "name": "Account A"
          },
          "ledgers": {
            "prorations": {
              "amount": -1.066,
              "usage": {
                "quantity": 0
              }
            }
          },
          "total": -1.066
        }
      }
    ]
  },
  "revision": "98804f3d59185d64a59ff7f9e47d1ae9",
  "timestamp": "2019-04-30T22:40:45Z",
  "version": "4.3.1",
  "node": "0ozIxbX-rup7AnGvNSM8JQ",
  "request_id": "051ff47be34fbdf6cb14ed08f4af8415",
  "status": "success",
  "auth_token": "Y2M1ODBmOTRkN2RhNTM4MTZhOTRiODdiMmExZDI1Zjg6NzNlZmY2Mzg2Y2UyMDkxYjVjYTcwMmZjMDA3ZTFkYTk="
}
```

* api and doc updates

* Revert "api and doc updates"

This reverts commit 30cf6bb.

* api and doc fixup

* payload shape change and other requests

* formatting

* requested refactor and view changes

* doc example
  • Loading branch information
mk1s authored and icehess committed May 14, 2019
1 parent 8fb9d34 commit 33e752a
Show file tree
Hide file tree
Showing 6 changed files with 366 additions and 20 deletions.
128 changes: 128 additions & 0 deletions applications/crossbar/doc/ledgers.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,131 @@ curl -v -X GET \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/ledgers/{SOURCE_SERVICE}/{LEDGER_ID}
```

## Fetch Ledger and Account Summary Breakdown

Fetches the account ledger summary as well as a breakdown of ledgers per account for a given YYYYMM.

> GET /v2/accounts/{ACCOUNT_ID}/ledgers/summary/{MODB_SUFFIX}
```shell
curl -v -X GET \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/ledgers/summary/{MODB_SUFFIX}
```

### Example

```shell
curl -v -X GET \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/ledgers/summary/201905
```

```json
"data": {
"summary": {
"per-minute-voip": {
"amount": -880.0,
"usage": {
"type": "voice",
"quantity": 232320,
"unit": "sec"
}
},
"payments": {
"amount": 251970.82,
"usage": {
"type": "debit",
"quantity": 0,
"unit": "dollars"
}
},
"prorations": {
"amount": -1.9258,
"usage": {
"quantity": 0
}
},
"rollovers": {
"amount": 36.102,
"usage": {
"quantity": 0
}
}
},
"breakdown": [
{
"account": {
"id": "de6fd29a54407cfe46e6c9d3828ab0d8",
"name": "Account A"
},
"ledgers": {
"payments": {
"amount": -1250000.0,
"usage": {
"type": "debit",
"quantity": 0,
"unit": "dollars"
}
},
"per-minute-voip": {
"amount": -385.0,
"usage": {
"type": "voice",
"quantity": 101640,
"unit": "sec"
}
}
},
"total": -1250385.0
},
{
"account": {
"id": "cc580f94d7da53816a94b87b2a1d25f8",
"name": "Account 1"
},
"ledgers": {
"payments": {
"amount": 1501970.82,
"usage": {
"type": "credit",
"quantity": 0,
"unit": "dollars"
}
},
"prorations": {
"amount": -1.9258,
"usage": {
"quantity": 0
}
},
"rollovers": {
"amount": 36.102,
"usage": {
"quantity": 0
}
}
},
"total": 1500004.9962
},
{
"account": {
"id": "a71a670531d7dc92d2a4f9fc6774df36",
"name": "Account B"
},
"ledgers": {
"per-minute-voip": {
"amount": -495.0,
"usage": {
"type": "voice",
"quantity": 130680,
"unit": "sec"
}
}
},
"total": -495.0
}
]
}
```
10 changes: 10 additions & 0 deletions applications/crossbar/doc/ref/ledgers.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,13 @@ curl -v -X GET \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/ledgers/{SOURCE_SERVICE}/{LEDGER_ID}
```

## Fetch

> GET /v2/accounts/{ACCOUNT_ID}/ledgers/summary/{MODB_SUFFIX}
```shell
curl -v -X GET \
-H "X-Auth-Token: {AUTH_TOKEN}" \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/ledgers/summary/{MODB_SUFFIX}
```

29 changes: 29 additions & 0 deletions applications/crossbar/priv/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -36791,6 +36791,15 @@
"required": true,
"type": "string"
},
"MODB_SUFFIX": {
"in": "path",
"maxLength": 6,
"minLength": 6,
"name": "MODB_SUFFIX",
"pattern": "^[0-9]{6}",
"required": true,
"type": "string"
},
"MODULE": {
"in": "path",
"name": "MODULE",
Expand Down Expand Up @@ -40750,6 +40759,26 @@
}
}
},
"/accounts/{ACCOUNT_ID}/ledgers/summary/{MODB_SUFFIX}": {
"get": {
"parameters": [
{
"$ref": "#/parameters/auth_token_header"
},
{
"$ref": "#/parameters/MODB_SUFFIX"
},
{
"$ref": "#/parameters/ACCOUNT_ID"
}
],
"responses": {
"200": {
"description": "request succeeded"
}
}
}
},
"/accounts/{ACCOUNT_ID}/ledgers/total": {
"get": {
"parameters": [
Expand Down
Loading

0 comments on commit 33e752a

Please sign in to comment.