Skip to content

Commit

Permalink
MLPAB-1410 Add page to select fee previously paid (#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Oct 31, 2023
1 parent b6a6bd3 commit 25831cd
Show file tree
Hide file tree
Showing 12 changed files with 502 additions and 34 deletions.
54 changes: 37 additions & 17 deletions internal/page/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,15 @@ const (
RepeatApplicationFee
)

func (i FeeType) Cost() int {
if i.IsFullFee() {
return 8200
}
//go:generate enumerator -type PreviousFee -empty
type PreviousFee uint8

if i.IsHalfFee() {
return 4100
}

return 0
}
const (
PreviousFeeFull PreviousFee = iota + 1
PreviousFeeHalf
PreviousFeeExemption
PreviousFeeHardship
)

// Lpa contains all the data related to the LPA application
type Lpa struct {
Expand All @@ -110,8 +108,6 @@ type Lpa struct {
CertificateProvider actor.CertificateProvider
// Type of LPA being drafted
Type LpaType
// PreviousApplicationNumber if the application is related to an existing application
PreviousApplicationNumber string
// Whether the applicant wants to add replacement attorneys
WantReplacementAttorneys form.YesNo
// When the LPA can be used
Expand Down Expand Up @@ -172,6 +168,10 @@ type Lpa struct {
FeeType FeeType
// Evidence is the documents uploaded by a donor to apply for non-full fees
Evidence Evidence
// PreviousApplicationNumber if the application is related to an existing application
PreviousApplicationNumber string
// PreviousFee is the fee previously paid for an LPA
PreviousFee PreviousFee

HasSentApplicationUpdatedEvent bool
HasSentPreviousApplicationLinkedEvent bool
Expand Down Expand Up @@ -524,18 +524,38 @@ func (l *Lpa) TrustCorporationsNames() []string {
return names
}

func (l *Lpa) Cost() int {
if l.Tasks.PayForLpa.IsDenied() {
return 8200
}

switch l.FeeType {
case FullFee:
return 8200
case HalfFee:
return 4100
case RepeatApplicationFee:
switch l.PreviousFee {
case PreviousFeeFull:
return 4100
case PreviousFeeHalf:
return 2050
default:
return 0
}
default:
return 0
}
}

func (l *Lpa) FeeAmount() int {
paid := 0

for _, payment := range l.PaymentDetails {
paid += payment.Amount
}

if l.Tasks.PayForLpa.IsDenied() {
return FullFee.Cost() - paid
} else {
return l.FeeType.Cost() - paid
}
return l.Cost() - paid
}

func (l *Lpa) HasUnsentReducedFeesEvidence() bool {
Expand Down
49 changes: 40 additions & 9 deletions internal/page/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1031,17 +1031,48 @@ func TestChooseReplacementAttorneysState(t *testing.T) {
}
}

func TestFeeTypeCost(t *testing.T) {
testCases := map[FeeType]int{
FullFee: 8200,
HalfFee: 4100,
NoFee: 0,
HardshipFee: 0,
func TestLpaCost(t *testing.T) {
testCases := map[string]struct {
lpa *Lpa
expected int
}{
"full": {
lpa: &Lpa{FeeType: FullFee},
expected: 8200,
},
"half": {
lpa: &Lpa{FeeType: HalfFee},
expected: 4100,
},
"no fee": {
lpa: &Lpa{FeeType: NoFee},
expected: 0,
},
"hardship": {
lpa: &Lpa{FeeType: HardshipFee},
expected: 0,
},
"repeat full": {
lpa: &Lpa{FeeType: RepeatApplicationFee, PreviousFee: PreviousFeeFull},
expected: 4100,
},
"repeat half": {
lpa: &Lpa{FeeType: RepeatApplicationFee, PreviousFee: PreviousFeeHalf},
expected: 2050,
},
"repeat exemption": {
lpa: &Lpa{FeeType: RepeatApplicationFee, PreviousFee: PreviousFeeExemption},
expected: 0,
},
"repeat hardship": {
lpa: &Lpa{FeeType: RepeatApplicationFee, PreviousFee: PreviousFeeHardship},
expected: 0,
},
}

for feeType, expectedCost := range testCases {
t.Run(feeType.String(), func(t *testing.T) {
assert.Equal(t, expectedCost, feeType.Cost())
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.expected, tc.lpa.Cost())
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/page/donor/previous_application_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func PreviousApplicationNumber(tmpl template.Template, donorStore DonorStore) Ha
}

if lpa.PreviousApplicationNumber[0] == '7' {
return appData.Redirect(w, r, lpa, page.Paths.WhatWasYourOriginalFee.Format(lpa.ID))
return appData.Redirect(w, r, lpa, page.Paths.PreviousFee.Format(lpa.ID))
} else {
return appData.Redirect(w, r, lpa, page.Paths.WhatHappensAfterNoFee.Format(lpa.ID))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/page/donor/previous_application_number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestGetPreviousApplicationNumberWhenTemplateErrors(t *testing.T) {

func TestPostPreviousApplicationNumber(t *testing.T) {
testcases := map[string]page.LpaPath{
"7": page.Paths.WhatWasYourOriginalFee,
"7": page.Paths.PreviousFee,
"M": page.Paths.WhatHappensAfterNoFee,
}

Expand Down
74 changes: 74 additions & 0 deletions internal/page/donor/previous_fee.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package donor

import (
"net/http"

"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)

type previousFeeData struct {
App page.AppData
Errors validation.List
Form *previousFeeForm
Options page.PreviousFeeOptions
}

func PreviousFee(tmpl template.Template, payer Payer, donorStore DonorStore) Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request, lpa *page.Lpa) error {
data := &previousFeeData{
App: appData,
Form: &previousFeeForm{
PreviousFee: lpa.PreviousFee,
},
Options: page.PreviousFeeValues,
}

if r.Method == http.MethodPost {
data.Form = readPreviousFeeForm(r)
data.Errors = data.Form.Validate()

if data.Errors.None() {
if lpa.PreviousFee != data.Form.PreviousFee {
lpa.PreviousFee = data.Form.PreviousFee

if err := donorStore.Put(r.Context(), lpa); err != nil {
return err
}
}

if lpa.PreviousFee.IsPreviousFeeFull() {
return payer.Pay(appData, w, r, lpa)
}

return appData.Redirect(w, r, lpa, page.Paths.EvidenceRequiredForPreviousFee.Format(lpa.ID))
}
}

return tmpl(w, data)
}
}

type previousFeeForm struct {
PreviousFee page.PreviousFee
Error error
}

func readPreviousFeeForm(r *http.Request) *previousFeeForm {
previousFee, err := page.ParsePreviousFee(page.PostFormString(r, "previous-fee"))

return &previousFeeForm{
PreviousFee: previousFee,
Error: err,
}
}

func (f *previousFeeForm) Validate() validation.List {
var errors validation.List

errors.Error("previous-fee", "howMuchYouPreviouslyPaid", f.Error,
validation.Selected())

return errors
}
Loading

0 comments on commit 25831cd

Please sign in to comment.