Make An Investment


Contents

Introduction

The app's Make An Investment page is where a user can make an investment. The user views the total monthly contributions they are expected to make, and how much of this will be invested in their different goals. Note that the user cannot invest in goals that are inactive. The user has the option to invest the set amount or a custom amount.

Overview

The Make An Investment page shows get data from the endpoint /api:IaYS-M9j/investment/load_goals whose action is at App\Http\Controllers\Goals\GoalsController@investmentLoadGoals.

API Response Example

Here is an example of the API response:

{
    "result_1": [
        {
            "title": "Emergency Fund",
            "target": 420000,
            "target_desc": "420,000.00",
            "allocation": "79.11%",
            "allocation_amount": 50000,
            "allocation_amount_desc": "50,000.00",
            "amount_invested": 454884.99084922095,
            "amount_invested_desc": "454,884.99",
            "allocation_int": 0.7911,
            "id": 00000,
            "savedSoFar": "418400.0000000000",
            "catchUpData": {
                "catch_up_amount": 362540.9012829918,
                "catch_up_date": "February, 2025",
                "original_maturity_date": "February, 2025",
                "status": "ON TRACK",
                "isOnTrack": true,
                "color": " #7bbf7480"
            }
        },
        {
            "title": "Real estate",
            "target": 3000000,
            "target_desc": "3,000,000.00",
            "allocation": "20.89%",
            "allocation_amount": 13200,
            "allocation_amount_desc": "13,200.00",
            "amount_invested": 318000.64791159454,
            "amount_invested_desc": "318,000.65",
            "allocation_int": 0.2089,
            "id": 00001,
            "savedSoFar": "288083.0000000000",
            "catchUpData": {
                "catch_up_amount": 283520.26721716736,
                "catch_up_date": "December, 2032",
                "original_maturity_date": "December, 2032",
                "status": "ON TRACK",
                "isOnTrack": true,
                "color": " #7bbf7480"
            }
        }
    ],
    "savings": 63200,
    "savings_desc": "63,200.00",
    "ga_array": 2
}

Monthly Contributions

The user can view the total monthly contributions they are expected to make. This is the sum of the monthly allocations for all the goals the user is investing in. It is calculated by running App\Actions\Goals\GetUserMonthlyGoalsAllocationAction::make()->handle(Auth::id()); which sums the savings for all the user's active goals. If the user has no active goals, the total monthly contribution is set to the savings value for the user's App\Models\FinancialFreedom model.

Investment Allocation

Investment allocations are the percentage of the total monthly contribution that will be invested in each goal. The user can view the allocation for each goal and the amount that will be invested in each goal. This data is retrieved at App\Http\Controllers\Goals\GoalsController@investmentLoadGoals and is populated by the following code:

    $goals_array = collect();
    $this->getUserNoneWishlistGoalsBuilder()->each(
        function (Goal $item) use ($goals_array, $total_goal_monthly_allocation) {
            $suggested_allocation = $item->savings->available;
            $goal = [
                'title' => $item->title,
                'target' => $item->target,
                'target_desc' => number_format($item->target, 2),
                'allocation' => round(($suggested_allocation / $total_goal_monthly_allocation) * 100, 2) . "%",
                'allocation_amount' => $suggested_allocation,
                'allocation_amount_desc' => number_format($suggested_allocation, 2),
                'amount_invested' => $item->value,
                'amount_invested_desc' => number_format($item->value, 2),
                'allocation_int' => round($suggested_allocation / $total_goal_monthly_allocation, 4),
                'id' => $item->id,
                'savedSoFar' => $item->principle,
                'catchUpData' => CalculateGoalMaturityDate::run($item),
            ];
            $goals_array->push($goal);
        }
    );
    $response = [
        'result_1' => $goals_array,

Investing

On the UI, clicking Invest first hits /api:IaYS-M9j/goal_calculator/add_0 which is handled by App\Http\Controllers\Billing\PaymentsController@addTransaction. This endpoint validates the data, and runs App\Actions\UserTransaction\AddTransactionRecordAction to add the transaction record. The endpoint retuns a response with the transaction id, transaction ref, together with the allocations. It is important toi note that a user subscription is required to make an investment. If the user does not have a subscription, they are subscribed and billed before the transaction is processed. The user chooses their subscription plan before this endpoint is hit. The subscription plan is part of the allocations.

{
    "result_1": [
        {
            "name": "Emergency Fund",
            "allocation": 50000,
            "percentage": "79.11%",
            "id": 1470
        },
        {
            "name": "Real estate",
            "allocation": 13200,
            "percentage": "20.89%",
            "id": 1549
        }
    ],
    "transaction_ref": "AP6193",
    "transaction_id": "18c6abff-bc2a-4f89-b817-13073fe3d557"
}

As soon as the transaction is successful, the /api:g7w7gqaI/receipt endpoint is hit which is handled by App\Http\Controllers\Billing\PaymentsController@receipt. This endpoint gets the receipt details by running App\Actions\Billing\GetReceiptDetails Action, which returns the transaction details as shown in the json below.

{
    "subscription": 0,
    "joining_fee": 0,
    "investment_amount": 63200,
    "total": 63200,
    "total_desc": "63,200.00",
    "investment_amount_desc": "63,200.00",
    "joining_fee_desc": "0.00",
    "transaction_fee_desc": "0.00",
    "subscription_fee_desc": "0.00",
    "plan": "Yearly Plan"
}

The user is redirected to the payment page.

Payment

The user has the option to Lipa na M-Pesa, or pay via Bank Transfer

Lipa na M-Pesa

Choosing Pay with M-Pesa shows the user the M-Pesa payment interface. The user is required to enter their M-Pesa number to receive a prompt to pay the amount shown on the screen. The user is required to enter their M-Pesa pin to complete the transaction. This entire process hits /api:g7w7gqaI/pay/mpesa which is handled by App\Http\Controllers\Billing\PaymentsController@payMpesa. This endpoint validates the data, and runs App\Actions\Billing\PayMpesa Action to initiate the payment. The logic in the action involves getting the App\Models\UserTransaction model, hitting the M-PESA API and creating a App\Models\LNMTransaction which is linked to the UserTransaction.

Bank Transfer

For Bank Transfer's, The bank details are shown to the user. The user is required to make a bank transfer to the account number shown on the screen. The user is required to enter the transaction reference number on the screen. The user will then be redirected to their mail client to submit details of their payment. Bank Transfers are processed in the Admin end.