bp - billing storage
MODIFY
src/assets/server/rest/v1/schemas/billing/billing-transfers-get.json
src/assets/server/rest/v1/schemas/billing/billing-transfers-get.json
"title": "Get billing transfers Request",
"type": "object",
"properties": {
- "IDs": {
+ "ID": {
"$ref": "common#/definitions/ids"
},
"Status": {

MODIFY
src/storage/mongodb/BillingStorage.ts
src/storage/mongodb/BillingStorage.ts
@@ -214,7 +214,9 @@ export default class BillingStorage {
status: subAccount.status,
businessOwnerID: DatabaseUtils.convertToObjectID(subAccount.businessOwnerID)
};
- // Modify and return the modified document
+ // Check Created/Last Changed By
+ DatabaseUtils.addLastChangedCreatedProps(subAccountMDB, subAccount);
+ // Save
await global.database.getCollection<any>(tenant.id, 'billingsubaccounts').findOneAndUpdate(
{ _id: subAccountMDB._id },
{ $set: subAccountMDB },
@@ -346,8 +348,12 @@ export default class BillingStorage {
transferExternalID: transfer.transferExternalID,
sessions: transfer.sessions.map((session) => ({
transactionID: session.transactionID,
+ invoiceID: session.invoiceID,
+ invoiceNumber: session.invoiceNumber,
+ amountAsDecimal: session.amountAsDecimal,
amount: session.amount,
- platformFee: session.platformFeeStrategy,
+ roundedAmount: session.roundedAmount,
+ platformFeeStrategy: session.platformFeeStrategy,
}))
};
if (transfer.platformFeeData) {
@@ -358,7 +364,9 @@ export default class BillingStorage {
invoiceExternalID: transfer.platformFeeData.invoiceExternalID
};
}
- // Modify and return the modified document
+ // Check Created/Last Changed By
+ DatabaseUtils.addLastChangedCreatedProps(transferMDB, transfer);
+ // Save
await global.database.getCollection<any>(tenant.id, 'billingtransfers').findOneAndUpdate(
{ _id: transferMDB._id },
{ $set: transferMDB },

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -233,6 +233,14 @@ export interface BillingInvoiceAuthorizationActions extends AuthorizationActions
canDownload?: boolean;
}
+export interface BillingAccountAuthorizationActions extends AuthorizationActions {
+ canOnboard?: boolean;
+}
+
+export interface BillingTransferAuthorizationActions extends AuthorizationActions {
+ canTransfer?: boolean;
+}
+
export enum DynamicAuthorizationFilterName {
ASSIGNED_SITES_COMPANIES = 'AssignedSitesCompanies',
SITES_ADMIN = 'SitesAdmin',

MODIFY
src/types/Billing.ts
src/types/Billing.ts
-import { AuthorizationActions, BillingInvoiceAuthorizationActions } from './Authorization';
+import { AuthorizationActions, BillingInvoiceAuthorizationActions, BillingTransferAuthorizationActions } from './Authorization';
import { ActionsResponse } from './GlobalType';
import CreatedUpdatedProps from './CreatedUpdatedProps';
@@ -162,7 +162,7 @@ export interface BillingPlatformFeeStrategy {
percentage: number; // e.g.: 2% per charging session
}
-export interface BillingAccount extends AuthorizationActions {
+export interface BillingAccount extends CreatedUpdatedProps, BillingTransferAuthorizationActions {
id?: string;
businessOwnerID?: string;
status: BillingAccountStatus;
@@ -192,7 +192,7 @@ export interface BillingPlatformFeeData {
invoiceExternalID?: string; // Invoice sent to the CPO
}
-export interface BillingTransfer {
+export interface BillingTransfer extends CreatedUpdatedProps, BillingTransferAuthorizationActions {
id?: string;
status: BillingTransferStatus;
sessions: BillingTransferSession[];

MODIFY
test/api/BillingTest.ts
test/api/BillingTest.ts
@@ -1193,10 +1193,16 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
const transfer = BillingTransferFactory.build();
const transferID = await BillingStorage.saveTransfer(billingTestHelper.tenantContext.getTenant(), transfer);
transfer.id = transferID;
-
- const transfersResponse = await billingTestHelper.userService.billingApi.readTransfers({});
+ // const transfersResponse = await billingTestHelper.userService.billingApi.readTransfers({},{ limit: 1, skip: 0 }, [{ field: '-createdOn' }]);
+ const transfersResponse = await billingTestHelper.userService.billingApi.readTransfers({ ID: transferID });
expect(transfersResponse.status).to.be.eq(StatusCodes.OK);
- expect(transfersResponse.data.result).to.containSubset([transfer]);
+ const savedTransfer = transfersResponse.data.result?.[0];
+ expect(savedTransfer).not.to.be.null;
+ delete savedTransfer.createdOn;
+ delete savedTransfer.createdBy;
+ delete savedTransfer.lastChangedOn;
+ delete savedTransfer.lastChangedBy;
+ expect(savedTransfer).to.containSubset(transfer);
});
});
});

MODIFY
test/api/client/BillingApi.ts
test/api/client/BillingApi.ts
@@ -49,7 +49,7 @@ export default class BillingApi extends CrudApi {
}
public async readInvoices(params, paging = TestConstants.DEFAULT_PAGING, ordering = TestConstants.DEFAULT_ORDERING) {
- return super.readAll(params, paging, ordering, super.buildRestEndpointUrl(RESTServerRoute.REST_BILLING_INVOICES, params));
+ return super.readAll(params, paging, ordering, super.buildRestEndpointUrl(RESTServerRoute.REST_BILLING_INVOICES));
}
public async createSubAccount(params) {

bp - billing storage