-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MLPAB-1410 Add page to select fee previously paid (#812)
- Loading branch information
Showing
12 changed files
with
502 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.