casual-simulation / casualos

Casual Open Simulation for the Web
https://ab1.bot
MIT License
48 stars 9 forks source link

Implement `xpCreateInvoice` procedure #510

Open KallynGowdy opened 1 month ago

KallynGowdy commented 1 month ago

Name: xpCreateInvoice HTTP: POST /api/v2/xp/invoice Authentication: REQUIRED - sessionKey Input:

{
    contractId: z.string(),
    amount: z.number().int().nonnegative(),
    note: z.string()
}

Operation: Create an invoice for the contract with contract.id === input.contractId && contract.holdingUserId === sessionKey.userId. The amount also cannot be more than the balance in the contract's account.

The returned information should be limited to the information specified below. Success Output:

{
    success: true,

    // Same contract output as xpGetUserIssuedContracts
    contract: {
        id: 'contract-id',
        issuerUserId: 'issuer-user-id',
        holdingUserId: 'holding-user-id',
        accountBalance: 123,
        accountCurrency: 'usd',
        accountEntries: [
            {
                id: 'entry-id',
                amount: 123,
                balance: 456,
                timeMs: 123,
                transactionId: 'transaction-id',
                note: 'string'
            }
        ],
        rate: 123,
        description: 'desc',
        status: 'open',
        accountId: 'account-id',
        createdAtMs: 123,
        updatedAtMs: 123
    }
}