compucorp / uk.co.compucorp.membershipextras

Membership Extras for CiviCRM
Other
5 stars 8 forks source link

IO-122: Update schedule API response and payment plan toggler UI #341

Closed erawat closed 3 years ago

erawat commented 3 years ago

Overview

This PR changes Payment Schedule API response to include the calculation for total instalments amount for the schedule.

The total amount will be set to two different places when schedule instalments is generated.

The PR also updates payment plan toggler UI that includes:

The PR also includes the unit tests for testing calculation of total amount for fixed membership type, rolling membership type, price field value

Before

The gift shows that the schedule prices do not equal to total price on price value total amount Peek 2021-02-05 15-18

The gift shows the error message when non the price values are selected Peek 2021-02-05 15-20

After

The gift shows that the schedule prices (pro rated price in this case) do not equal to total price on price value total amount Peek 2021-02-05 15-21

The gift shows that no error message appears when none of the price value is selected. Peek 2021-02-05 15-22

Technical Details

This section shows that JSON response looks like before and after this PR.

The response only provides instalments which have already formatted.

{

    "is_error": 0,
    "version": 3,
    "count": 1,
    "id": 0,
    "values": [
        {
            "instalment_no": 1,
            "instalment_date": "1st July 2020",
            "instalment_tax_amount": "£180",
            "instalment_amount": "£900",
            "instalment_status": "Pending"
        }
    ]
}

After this PR.

JSON response if sequential = 0 on the request.

{

    "is_error": 0,
    "version": 3,
    "count": 2,
    "values": {
        "instalments": [
            {
                "instalment_no": 1,
                "instalment_date": "1st July 2020",
                "instalment_tax_amount": "£180",
                "instalment_amount": "£900",
                "instalment_status": "Pending"
            }
        ],
        "total_amount": 1080
    }
}

JSON response if sequential = 1 on the request.

{

    "is_error": 0,
    "version": 3,
    "count": 2,
    "values": [
        [
            {
                "instalment_no": 1,
                "instalment_date": "1st July 2020",
                "instalment_tax_amount": "£180",
                "instalment_amount": "£900",
                "instalment_status": "Pending"
            }
        ],
        1080
    ]
}

The reason that total_amount should return to in the response because