diff --git a/internal/app/donor_store_test.go b/internal/app/donor_store_test.go index 3bf6390aad..192a1b1546 100644 --- a/internal/app/donor_store_test.go +++ b/internal/app/donor_store_test.go @@ -11,6 +11,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/uid" "github.com/stretchr/testify/assert" @@ -476,7 +477,7 @@ func TestDonorStorePutWhenReducedFeeRequestedAndUnsentDocuments(t *testing.T) { ID: "5", UID: "M-1111", UpdatedAt: now, - FeeType: page.HalfFee, + FeeType: pay.HalfFee, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, HasSentApplicationUpdatedEvent: true, }). @@ -508,7 +509,7 @@ func TestDonorStorePutWhenReducedFeeRequestedAndUnsentDocuments(t *testing.T) { SK: "#DONOR#an-id", ID: "5", UID: "M-1111", - FeeType: page.HalfFee, + FeeType: pay.HalfFee, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, HasSentApplicationUpdatedEvent: true, }) @@ -614,7 +615,7 @@ func TestDonorStorePutWhenReducedFeeRequestedAndUnsentDocumentsWhenEventClientSe SK: "#DONOR#an-id", ID: "5", UID: "M-1111", - FeeType: page.HalfFee, + FeeType: pay.HalfFee, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, HasSentApplicationUpdatedEvent: true, }) @@ -661,7 +662,7 @@ func TestDonorStorePutWhenReducedFeeRequestedAndUnsentDocumentsWhenDocumentStore SK: "#DONOR#an-id", ID: "5", UID: "M-1111", - FeeType: page.HalfFee, + FeeType: pay.HalfFee, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, HasSentApplicationUpdatedEvent: true, }) diff --git a/internal/page/data.go b/internal/page/data.go index 9fae0a2552..8b460c1d93 100644 --- a/internal/page/data.go +++ b/internal/page/data.go @@ -19,6 +19,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" + "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "golang.org/x/exp/slices" ) @@ -66,27 +67,6 @@ const ( ReplacementAttorneysStepInAnotherWay // other ) -//go:generate enumerator -type FeeType -type FeeType uint8 - -const ( - FullFee FeeType = iota - HalfFee - NoFee - HardshipFee - RepeatApplicationFee -) - -//go:generate enumerator -type PreviousFee -empty -type PreviousFee uint8 - -const ( - PreviousFeeFull PreviousFee = iota + 1 - PreviousFeeHalf - PreviousFeeExemption - PreviousFeeHardship -) - // Lpa contains all the data related to the LPA application type Lpa struct { PK, SK string @@ -167,11 +147,13 @@ type Lpa struct { WitnessCodeLimiter *Limiter // FeeType is the type of fee the user is applying for - FeeType FeeType + FeeType pay.FeeType + // EvidenceDelivery is the method by which the user wants to send evidence + EvidenceDelivery pay.EvidenceDelivery // PreviousApplicationNumber if the application is related to an existing application PreviousApplicationNumber string // PreviousFee is the fee previously paid for an LPA - PreviousFee PreviousFee + PreviousFee pay.PreviousFee HasSentApplicationUpdatedEvent bool HasSentPreviousApplicationLinkedEvent bool @@ -477,23 +459,7 @@ func (l *Lpa) Cost() int { 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 - } + return pay.Cost(l.FeeType, l.PreviousFee) } func (l *Lpa) FeeAmount() int { diff --git a/internal/page/data_test.go b/internal/page/data_test.go index d0b377c959..3184c86faf 100644 --- a/internal/page/data_test.go +++ b/internal/page/data_test.go @@ -8,6 +8,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" + "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/stretchr/testify/assert" ) @@ -1036,38 +1037,14 @@ func TestLpaCost(t *testing.T) { lpa *Lpa expected int }{ - "full": { - lpa: &Lpa{FeeType: FullFee}, + "denied": { + lpa: &Lpa{FeeType: pay.HalfFee, Tasks: Tasks{PayForLpa: actor.PaymentTaskDenied}}, expected: 8200, }, "half": { - lpa: &Lpa{FeeType: HalfFee}, + lpa: &Lpa{FeeType: pay.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 name, tc := range testCases { @@ -1082,41 +1059,21 @@ func TestFeeAmount(t *testing.T) { Lpa *Lpa ExpectedCost int }{ - "full fee - not paid": { - Lpa: &Lpa{FeeType: FullFee}, - ExpectedCost: 8200, - }, - "half fee - not paid": { - Lpa: &Lpa{FeeType: HalfFee}, + "not paid": { + Lpa: &Lpa{FeeType: pay.HalfFee}, ExpectedCost: 4100, }, - "no fee": { - Lpa: &Lpa{FeeType: NoFee}, + "fully paid": { + Lpa: &Lpa{FeeType: pay.HalfFee, PaymentDetails: []Payment{{Amount: 4100}}}, ExpectedCost: 0, }, - "hardship fee": { - Lpa: &Lpa{FeeType: HardshipFee}, - ExpectedCost: 0, - }, - "full fee - paid": { - Lpa: &Lpa{FeeType: FullFee, PaymentDetails: []Payment{{Amount: 8200}}}, - ExpectedCost: 0, - }, - "half fee - paid": { - Lpa: &Lpa{FeeType: HalfFee, PaymentDetails: []Payment{{Amount: 4100}}}, - ExpectedCost: 0, - }, - "half fee - paid, denied": { - Lpa: &Lpa{FeeType: HalfFee, PaymentDetails: []Payment{{Amount: 4100}}, Tasks: Tasks{PayForLpa: actor.PaymentTaskDenied}}, + "denied partially paid": { + Lpa: &Lpa{FeeType: pay.HalfFee, PaymentDetails: []Payment{{Amount: 4100}}, Tasks: Tasks{PayForLpa: actor.PaymentTaskDenied}}, ExpectedCost: 4100, }, - "no fee - paid, denied": { - Lpa: &Lpa{FeeType: NoFee, Tasks: Tasks{PayForLpa: actor.PaymentTaskDenied}}, - ExpectedCost: 8200, - }, - "hardship fee - paid, denied": { - Lpa: &Lpa{FeeType: HardshipFee, Tasks: Tasks{PayForLpa: actor.PaymentTaskDenied}}, - ExpectedCost: 8200, + "denied fully paid": { + Lpa: &Lpa{FeeType: pay.HalfFee, PaymentDetails: []Payment{{Amount: 4100}, {Amount: 4100}}, Tasks: Tasks{PayForLpa: actor.PaymentTaskDenied}}, + ExpectedCost: 0, }, } diff --git a/internal/page/donor/how_would_you_like_to_send_evidence.go b/internal/page/donor/how_would_you_like_to_send_evidence.go index ac51d16e82..196c8a3fdc 100644 --- a/internal/page/donor/how_would_you_like_to_send_evidence.go +++ b/internal/page/donor/how_would_you_like_to_send_evidence.go @@ -6,28 +6,21 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) -//go:generate enumerator -type EvidenceDelivery -linecomment -empty -type EvidenceDelivery uint8 - -const ( - Upload EvidenceDelivery = iota + 1 // upload - Post // post -) - type howWouldYouLikeToSendEvidenceData struct { App page.AppData Errors validation.List - Options EvidenceDeliveryOptions + Options pay.EvidenceDeliveryOptions } -func HowWouldYouLikeToSendEvidence(tmpl template.Template) Handler { +func HowWouldYouLikeToSendEvidence(tmpl template.Template, donorStore DonorStore) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, lpa *page.Lpa) error { data := &howWouldYouLikeToSendEvidenceData{ App: appData, - Options: EvidenceDeliveryValues, + Options: pay.EvidenceDeliveryValues, } if r.Method == http.MethodPost { @@ -35,10 +28,16 @@ func HowWouldYouLikeToSendEvidence(tmpl template.Template) Handler { data.Errors = form.Validate() if data.Errors.None() { - if form.EvidenceDelivery.IsUpload() { + lpa.EvidenceDelivery = form.EvidenceDelivery + + if err := donorStore.Put(r.Context(), lpa); err != nil { + return err + } + + if lpa.EvidenceDelivery.IsUpload() { return appData.Redirect(w, r, lpa, page.Paths.UploadEvidence.Format(lpa.ID)) } else { - return appData.Redirect(w, r, lpa, page.Paths.HowToEmailOrPostEvidence.Format(lpa.ID)) + return appData.Redirect(w, r, lpa, page.Paths.SendUsYourEvidenceByPost.Format(lpa.ID)) } } } @@ -48,7 +47,7 @@ func HowWouldYouLikeToSendEvidence(tmpl template.Template) Handler { } type evidenceDeliveryForm struct { - EvidenceDelivery EvidenceDelivery + EvidenceDelivery pay.EvidenceDelivery Error error ErrorLabel string } @@ -63,7 +62,7 @@ func (f *evidenceDeliveryForm) Validate() validation.List { } func readHowWouldYouLikeToSendEvidenceForm(r *http.Request) *evidenceDeliveryForm { - evidenceDelivery, err := ParseEvidenceDelivery(form.PostFormString(r, "evidence-delivery")) + evidenceDelivery, err := pay.ParseEvidenceDelivery(form.PostFormString(r, "evidence-delivery")) return &evidenceDeliveryForm{ EvidenceDelivery: evidenceDelivery, diff --git a/internal/page/donor/how_would_you_like_to_send_evidence_test.go b/internal/page/donor/how_would_you_like_to_send_evidence_test.go index 897fd1156b..32d306c5bb 100644 --- a/internal/page/donor/how_would_you_like_to_send_evidence_test.go +++ b/internal/page/donor/how_would_you_like_to_send_evidence_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -21,11 +22,11 @@ func TestGetHowWouldYouLikeToSendEvidence(t *testing.T) { template. On("Execute", w, &howWouldYouLikeToSendEvidenceData{ App: testAppData, - Options: EvidenceDeliveryValues, + Options: pay.EvidenceDeliveryValues, }). Return(nil) - err := HowWouldYouLikeToSendEvidence(template.Execute)(testAppData, w, r, &page.Lpa{}) + err := HowWouldYouLikeToSendEvidence(template.Execute, nil)(testAppData, w, r, &page.Lpa{}) resp := w.Result() assert.Nil(t, err) @@ -40,11 +41,11 @@ func TestGetHowWouldYouLikeToSendEvidenceFromStore(t *testing.T) { template. On("Execute", w, &howWouldYouLikeToSendEvidenceData{ App: testAppData, - Options: EvidenceDeliveryValues, + Options: pay.EvidenceDeliveryValues, }). Return(nil) - err := HowWouldYouLikeToSendEvidence(template.Execute)(testAppData, w, r, &page.Lpa{}) + err := HowWouldYouLikeToSendEvidence(template.Execute, nil)(testAppData, w, r, &page.Lpa{}) resp := w.Result() assert.Nil(t, err) @@ -60,7 +61,7 @@ func TestGetHowWouldYouLikeToSendEvidenceWhenTemplateErrors(t *testing.T) { On("Execute", w, mock.Anything). Return(expectedError) - err := HowWouldYouLikeToSendEvidence(template.Execute)(testAppData, w, r, &page.Lpa{}) + err := HowWouldYouLikeToSendEvidence(template.Execute, nil)(testAppData, w, r, &page.Lpa{}) resp := w.Result() assert.Equal(t, expectedError, err) @@ -68,9 +69,9 @@ func TestGetHowWouldYouLikeToSendEvidenceWhenTemplateErrors(t *testing.T) { } func TestPostHowWouldYouLikeToSendEvidence(t *testing.T) { - testcases := map[EvidenceDelivery]page.LpaPath{ - Upload: page.Paths.UploadEvidence, - Post: page.Paths.HowToEmailOrPostEvidence, + testcases := map[pay.EvidenceDelivery]page.LpaPath{ + pay.Upload: page.Paths.UploadEvidence, + pay.Post: page.Paths.SendUsYourEvidenceByPost, } for evidenceDelivery, redirect := range testcases { @@ -83,7 +84,12 @@ func TestPostHowWouldYouLikeToSendEvidence(t *testing.T) { r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) - err := HowWouldYouLikeToSendEvidence(nil)(testAppData, w, r, &page.Lpa{ID: "lpa-id"}) + donorStore := newMockDonorStore(t) + donorStore. + On("Put", r.Context(), &page.Lpa{ID: "lpa-id", EvidenceDelivery: evidenceDelivery}). + Return(nil) + + err := HowWouldYouLikeToSendEvidence(nil, donorStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id"}) resp := w.Result() assert.Nil(t, err) @@ -93,6 +99,24 @@ func TestPostHowWouldYouLikeToSendEvidence(t *testing.T) { } } +func TestPostHowWouldYouLikeToSendEvidenceWhenStoreErrors(t *testing.T) { + form := url.Values{ + "evidence-delivery": {pay.Upload.String()}, + } + + w := httptest.NewRecorder() + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r.Header.Add("Content-Type", page.FormUrlEncoded) + + donorStore := newMockDonorStore(t) + donorStore. + On("Put", r.Context(), mock.Anything). + Return(expectedError) + + err := HowWouldYouLikeToSendEvidence(nil, donorStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id"}) + assert.Equal(t, expectedError, err) +} + func TestPostHowWouldYouLikeToSendEvidenceWhenValidationErrors(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader("")) @@ -105,7 +129,7 @@ func TestPostHowWouldYouLikeToSendEvidenceWhenValidationErrors(t *testing.T) { })). Return(nil) - err := HowWouldYouLikeToSendEvidence(template.Execute)(testAppData, w, r, &page.Lpa{}) + err := HowWouldYouLikeToSendEvidence(template.Execute, nil)(testAppData, w, r, &page.Lpa{}) resp := w.Result() assert.Nil(t, err) diff --git a/internal/page/donor/payment_confirmation.go b/internal/page/donor/payment_confirmation.go index f51e1c31e8..fec92ecff9 100644 --- a/internal/page/donor/payment_confirmation.go +++ b/internal/page/donor/payment_confirmation.go @@ -11,6 +11,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -19,7 +20,9 @@ type paymentConfirmationData struct { App page.AppData Errors validation.List PaymentReference string - FeeType page.FeeType + FeeType pay.FeeType + PreviousFee pay.PreviousFee + EvidenceDelivery pay.EvidenceDelivery } func PaymentConfirmation(logger Logger, tmpl template.Template, payClient PayClient, donorStore DonorStore, sessionStore sessions.Store, evidenceS3Client S3Client, now func() time.Time, documentStore DocumentStore) Handler { @@ -47,6 +50,8 @@ func PaymentConfirmation(logger Logger, tmpl template.Template, payClient PayCli App: appData, PaymentReference: payment.Reference, FeeType: lpa.FeeType, + PreviousFee: lpa.PreviousFee, + EvidenceDelivery: lpa.EvidenceDelivery, } if err := sesh.ClearPayment(sessionStore, r, w); err != nil { diff --git a/internal/page/donor/payment_confirmation_test.go b/internal/page/donor/payment_confirmation_test.go index 9d2c0ea1ff..0a4d1b06f2 100644 --- a/internal/page/donor/payment_confirmation_test.go +++ b/internal/page/donor/payment_confirmation_test.go @@ -29,7 +29,7 @@ func TestGetPaymentConfirmationFullFee(t *testing.T) { On("Execute", w, &paymentConfirmationData{ App: testAppData, PaymentReference: "123456789012", - FeeType: page.FullFee, + FeeType: pay.FullFee, }). Return(nil) @@ -40,7 +40,7 @@ func TestGetPaymentConfirmationFullFee(t *testing.T) { donorStore := newMockDonorStore(t) donorStore. On("Put", r.Context(), &page.Lpa{ - FeeType: page.FullFee, + FeeType: pay.FullFee, CertificateProvider: actor.CertificateProvider{ Email: "certificateprovider@example.com", }, @@ -56,7 +56,7 @@ func TestGetPaymentConfirmationFullFee(t *testing.T) { Return(nil) err := PaymentConfirmation(newMockLogger(t), template.Execute, payClient, donorStore, sessionStore, nil, nil, nil)(testAppData, w, r, &page.Lpa{ - FeeType: page.FullFee, + FeeType: pay.FullFee, CertificateProvider: actor.CertificateProvider{ Email: "certificateprovider@example.com", }, @@ -79,7 +79,7 @@ func TestGetPaymentConfirmationHalfFee(t *testing.T) { On("Execute", w, &paymentConfirmationData{ App: testAppData, PaymentReference: "123456789012", - FeeType: page.HalfFee, + FeeType: pay.HalfFee, }). Return(nil) @@ -92,7 +92,7 @@ func TestGetPaymentConfirmationHalfFee(t *testing.T) { donorStore := newMockDonorStore(t) donorStore. On("Put", r.Context(), &page.Lpa{ - FeeType: page.HalfFee, + FeeType: pay.HalfFee, CertificateProvider: actor.CertificateProvider{ Email: "certificateprovider@example.com", }, @@ -126,7 +126,7 @@ func TestGetPaymentConfirmationHalfFee(t *testing.T) { Return(nil) err := PaymentConfirmation(newMockLogger(t), template.Execute, payClient, donorStore, sessionStore, s3Client, func() time.Time { return now }, documentStore)(testAppData, w, r, &page.Lpa{ - FeeType: page.HalfFee, + FeeType: pay.HalfFee, CertificateProvider: actor.CertificateProvider{ Email: "certificateprovider@example.com", }, @@ -236,7 +236,7 @@ func TestGetPaymentConfirmationHalfFeeWhenDocumentStoreGetAllError(t *testing.T) Return(page.Documents{}, expectedError) err := PaymentConfirmation(nil, nil, payClient, nil, sessionStore, nil, func() time.Time { return now }, documentStore)(testAppData, w, r, &page.Lpa{ - FeeType: page.HalfFee, + FeeType: pay.HalfFee, CertificateProvider: actor.CertificateProvider{ Email: "certificateprovider@example.com", }, @@ -275,7 +275,7 @@ func TestGetPaymentConfirmationHalfFeeWhenS3ClientPutTaggingObjectError(t *testi On("Print", fmt.Sprintf("error tagging evidence: %s", expectedError)) err := PaymentConfirmation(logger, nil, payClient, nil, sessionStore, s3Client, func() time.Time { return now }, documentStore)(testAppData, w, r, &page.Lpa{ - FeeType: page.HalfFee, + FeeType: pay.HalfFee, CertificateProvider: actor.CertificateProvider{ Email: "certificateprovider@example.com", }, @@ -313,7 +313,7 @@ func TestGetPaymentConfirmationHalfFeeWhenDocumentStorePutError(t *testing.T) { Return(nil) err := PaymentConfirmation(nil, nil, payClient, nil, sessionStore, s3Client, func() time.Time { return now }, documentStore)(testAppData, w, r, &page.Lpa{ - FeeType: page.HalfFee, + FeeType: pay.HalfFee, CertificateProvider: actor.CertificateProvider{ Email: "certificateprovider@example.com", }, @@ -360,7 +360,7 @@ func TestGetPaymentConfirmationHalfFeeWhenDonorStorePutError(t *testing.T) { On("Print", fmt.Sprintf("unable to update lpa in donorStore: %s", expectedError)) err := PaymentConfirmation(logger, nil, payClient, donorStore, sessionStore, s3Client, func() time.Time { return now }, documentStore)(testAppData, w, r, &page.Lpa{ - FeeType: page.HalfFee, + FeeType: pay.HalfFee, CertificateProvider: actor.CertificateProvider{ Email: "certificateprovider@example.com", }, diff --git a/internal/page/donor/previous_fee.go b/internal/page/donor/previous_fee.go index 7ebccb820d..f571b17718 100644 --- a/internal/page/donor/previous_fee.go +++ b/internal/page/donor/previous_fee.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -12,7 +13,7 @@ type previousFeeData struct { App page.AppData Errors validation.List Form *previousFeeForm - Options page.PreviousFeeOptions + Options pay.PreviousFeeOptions } func PreviousFee(tmpl template.Template, payer Payer, donorStore DonorStore) Handler { @@ -22,7 +23,7 @@ func PreviousFee(tmpl template.Template, payer Payer, donorStore DonorStore) Han Form: &previousFeeForm{ PreviousFee: lpa.PreviousFee, }, - Options: page.PreviousFeeValues, + Options: pay.PreviousFeeValues, } if r.Method == http.MethodPost { @@ -51,12 +52,12 @@ func PreviousFee(tmpl template.Template, payer Payer, donorStore DonorStore) Han } type previousFeeForm struct { - PreviousFee page.PreviousFee + PreviousFee pay.PreviousFee Error error } func readPreviousFeeForm(r *http.Request) *previousFeeForm { - previousFee, err := page.ParsePreviousFee(page.PostFormString(r, "previous-fee")) + previousFee, err := pay.ParsePreviousFee(page.PostFormString(r, "previous-fee")) return &previousFeeForm{ PreviousFee: previousFee, diff --git a/internal/page/donor/previous_fee_test.go b/internal/page/donor/previous_fee_test.go index 05598920fe..3c207f9c61 100644 --- a/internal/page/donor/previous_fee_test.go +++ b/internal/page/donor/previous_fee_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -22,7 +23,7 @@ func TestGetPreviousFee(t *testing.T) { On("Execute", w, &previousFeeData{ App: testAppData, Form: &previousFeeForm{}, - Options: page.PreviousFeeValues, + Options: pay.PreviousFeeValues, }). Return(nil) @@ -42,13 +43,13 @@ func TestGetPreviousFeeFromStore(t *testing.T) { On("Execute", w, &previousFeeData{ App: testAppData, Form: &previousFeeForm{ - PreviousFee: page.PreviousFeeHalf, + PreviousFee: pay.PreviousFeeHalf, }, - Options: page.PreviousFeeValues, + Options: pay.PreviousFeeValues, }). Return(nil) - err := PreviousFee(template.Execute, nil, nil)(testAppData, w, r, &page.Lpa{PreviousFee: page.PreviousFeeHalf}) + err := PreviousFee(template.Execute, nil, nil)(testAppData, w, r, &page.Lpa{PreviousFee: pay.PreviousFeeHalf}) resp := w.Result() assert.Nil(t, err) @@ -73,7 +74,7 @@ func TestGetPreviousFeeWhenTemplateErrors(t *testing.T) { func TestPostPreviousFeeWhenFullFee(t *testing.T) { form := url.Values{ - "previous-fee": {page.PreviousFeeFull.String()}, + "previous-fee": {pay.PreviousFeeFull.String()}, } w := httptest.NewRecorder() @@ -82,7 +83,7 @@ func TestPostPreviousFeeWhenFullFee(t *testing.T) { lpa := &page.Lpa{ ID: "lpa-id", - PreviousFee: page.PreviousFeeFull, + PreviousFee: pay.PreviousFeeFull, } donorStore := newMockDonorStore(t) @@ -101,7 +102,7 @@ func TestPostPreviousFeeWhenFullFee(t *testing.T) { func TestPostPreviousFeeWhenOtherFee(t *testing.T) { form := url.Values{ - "previous-fee": {page.PreviousFeeHalf.String()}, + "previous-fee": {pay.PreviousFeeHalf.String()}, } w := httptest.NewRecorder() @@ -112,7 +113,7 @@ func TestPostPreviousFeeWhenOtherFee(t *testing.T) { donorStore. On("Put", r.Context(), &page.Lpa{ ID: "lpa-id", - PreviousFee: page.PreviousFeeHalf, + PreviousFee: pay.PreviousFeeHalf, }). Return(nil) @@ -126,7 +127,7 @@ func TestPostPreviousFeeWhenOtherFee(t *testing.T) { func TestPostPreviousFeeWhenNotChanged(t *testing.T) { form := url.Values{ - "previous-fee": {page.PreviousFeeHalf.String()}, + "previous-fee": {pay.PreviousFeeHalf.String()}, } w := httptest.NewRecorder() @@ -135,7 +136,7 @@ func TestPostPreviousFeeWhenNotChanged(t *testing.T) { err := PreviousFee(nil, nil, nil)(testAppData, w, r, &page.Lpa{ ID: "lpa-id", - PreviousFee: page.PreviousFeeHalf, + PreviousFee: pay.PreviousFeeHalf, }) resp := w.Result() @@ -146,7 +147,7 @@ func TestPostPreviousFeeWhenNotChanged(t *testing.T) { func TestPostPreviousFeeWhenStoreErrors(t *testing.T) { form := url.Values{ - "previous-fee": {page.PreviousFeeHalf.String()}, + "previous-fee": {pay.PreviousFeeHalf.String()}, } w := httptest.NewRecorder() @@ -184,14 +185,14 @@ func TestPostPreviousFeeWhenValidationErrors(t *testing.T) { func TestReadPreviousFeeForm(t *testing.T) { form := url.Values{ - "previous-fee": {page.PreviousFeeHalf.String()}, + "previous-fee": {pay.PreviousFeeHalf.String()}, } r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) result := readPreviousFeeForm(r) - assert.Equal(t, page.PreviousFeeHalf, result.PreviousFee) + assert.Equal(t, pay.PreviousFeeHalf, result.PreviousFee) } func TestPreviousFeeFormValidate(t *testing.T) { diff --git a/internal/page/donor/register.go b/internal/page/donor/register.go index b9dec4b5d7..6b85c548c0 100644 --- a/internal/page/donor/register.go +++ b/internal/page/donor/register.go @@ -319,17 +319,19 @@ func Register( handleWithLpa(page.Paths.EvidenceRequired, CanGoBack, Guidance(tmpls.Get("evidence_required.gohtml"))) handleWithLpa(page.Paths.HowWouldYouLikeToSendEvidence, CanGoBack, - HowWouldYouLikeToSendEvidence(tmpls.Get("how_would_you_like_to_send_evidence.gohtml"))) + HowWouldYouLikeToSendEvidence(tmpls.Get("how_would_you_like_to_send_evidence.gohtml"), donorStore)) handleWithLpa(page.Paths.UploadEvidence, CanGoBack, UploadEvidence(tmpls.Get("upload_evidence.gohtml"), payer, documentStore)) - handleWithLpa(page.Paths.EvidenceSuccessfullyUploaded, None, - Guidance(tmpls.Get("evidence_successfully_uploaded.gohtml"))) - handleWithLpa(page.Paths.HowToEmailOrPostEvidence, CanGoBack, - HowToEmailOrPostEvidence(tmpls.Get("how_to_email_or_post_evidence.gohtml"), payer)) + handleWithLpa(page.Paths.SendUsYourEvidenceByPost, CanGoBack, + SendUsYourEvidenceByPost(tmpls.Get("send_us_your_evidence_by_post.gohtml"), payer)) handleWithLpa(page.Paths.FeeDenied, None, FeeDenied(tmpls.Get("fee_denied.gohtml"), payer)) handleWithLpa(page.Paths.PaymentConfirmation, None, PaymentConfirmation(logger, tmpls.Get("payment_confirmation.gohtml"), payClient, donorStore, sessionStore, evidenceS3Client, time.Now, documentStore)) + handleWithLpa(page.Paths.EvidenceSuccessfullyUploaded, None, + Guidance(tmpls.Get("evidence_successfully_uploaded.gohtml"))) + handleWithLpa(page.Paths.WhatHappensNextPostEvidence, None, + Guidance(tmpls.Get("what_happens_next_post_evidence.gohtml"))) handleWithLpa(page.Paths.HowToConfirmYourIdentityAndSign, None, Guidance(tmpls.Get("how_to_confirm_your_identity_and_sign.gohtml"))) @@ -479,6 +481,15 @@ type payHelper struct { func (p *payHelper) Pay(appData page.AppData, w http.ResponseWriter, r *http.Request, lpa *page.Lpa) error { if lpa.FeeType.IsNoFee() || lpa.FeeType.IsHardshipFee() || lpa.Tasks.PayForLpa.IsMoreEvidenceRequired() { + lpa.Tasks.PayForLpa = actor.PaymentTaskPending + if err := p.donorStore.Put(r.Context(), lpa); err != nil { + return err + } + + if lpa.EvidenceDelivery.IsPost() { + return appData.Redirect(w, r, lpa, page.Paths.WhatHappensNextPostEvidence.Format(lpa.ID)) + } + documents, err := p.documentStore.GetAll(r.Context()) if err != nil { return err @@ -500,11 +511,6 @@ func (p *payHelper) Pay(appData page.AppData, w http.ResponseWriter, r *http.Req } } - lpa.Tasks.PayForLpa = actor.PaymentTaskPending - if err := p.donorStore.Put(r.Context(), lpa); err != nil { - return err - } - return appData.Redirect(w, r, lpa, page.Paths.EvidenceSuccessfullyUploaded.Format(lpa.ID)) } @@ -528,7 +534,7 @@ func (p *payHelper) Pay(appData page.AppData, w http.ResponseWriter, r *http.Req } if lpa.Tasks.PayForLpa.IsDenied() { - lpa.FeeType = page.FullFee + lpa.FeeType = pay.FullFee lpa.Tasks.PayForLpa = actor.PaymentTaskInProgress if err := p.donorStore.Put(r.Context(), lpa); err != nil { return err diff --git a/internal/page/donor/register_test.go b/internal/page/donor/register_test.go index fa1f1500db..78f693593a 100644 --- a/internal/page/donor/register_test.go +++ b/internal/page/donor/register_test.go @@ -415,7 +415,7 @@ func TestPayHelperPay(t *testing.T) { payClient: payClient, appPublicURL: "http://example.org", randomString: func(int) string { return "123456789012" }, - }).Pay(testAppData, w, r, &page.Lpa{ID: "lpa-id", Donor: actor.Donor{Email: "a@b.com"}, FeeType: page.FullFee}) + }).Pay(testAppData, w, r, &page.Lpa{ID: "lpa-id", Donor: actor.Donor{Email: "a@b.com"}, FeeType: pay.FullFee}) resp := w.Result() assert.Nil(t, err) @@ -426,9 +426,9 @@ func TestPayHelperPay(t *testing.T) { } func TestPayHelperPayWhenPaymentNotRequired(t *testing.T) { - testCases := []page.FeeType{ - page.NoFee, - page.HardshipFee, + testCases := []pay.FeeType{ + pay.NoFee, + pay.HardshipFee, } for _, feeType := range testCases { @@ -454,9 +454,10 @@ func TestPayHelperPayWhenPaymentNotRequired(t *testing.T) { donorStore := newMockDonorStore(t) donorStore. On("Put", r.Context(), &page.Lpa{ - ID: "lpa-id", - FeeType: feeType, - Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, + ID: "lpa-id", + FeeType: feeType, + Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, + EvidenceDelivery: pay.Upload, }). Return(nil) @@ -473,8 +474,9 @@ func TestPayHelperPayWhenPaymentNotRequired(t *testing.T) { evidenceS3Client: s3Client, documentStore: documentStore, }).Pay(testAppData, w, r, &page.Lpa{ - ID: "lpa-id", - FeeType: feeType, + ID: "lpa-id", + FeeType: feeType, + EvidenceDelivery: pay.Upload, }) resp := w.Result() @@ -485,6 +487,46 @@ func TestPayHelperPayWhenPaymentNotRequired(t *testing.T) { } } +func TestPayHelperPayWhenPostingEvidence(t *testing.T) { + testCases := []pay.FeeType{ + pay.NoFee, + pay.HardshipFee, + } + + for _, feeType := range testCases { + t.Run(feeType.String(), func(t *testing.T) { + w := httptest.NewRecorder() + r, _ := http.NewRequest(http.MethodPost, "/", nil) + + now := time.Now() + + donorStore := newMockDonorStore(t) + donorStore. + On("Put", r.Context(), &page.Lpa{ + ID: "lpa-id", + FeeType: feeType, + Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, + EvidenceDelivery: pay.Post, + }). + Return(nil) + + err := (&payHelper{ + donorStore: donorStore, + now: func() time.Time { return now }, + }).Pay(testAppData, w, r, &page.Lpa{ + ID: "lpa-id", + FeeType: feeType, + EvidenceDelivery: pay.Post, + }) + resp := w.Result() + + assert.Nil(t, err) + assert.Equal(t, http.StatusFound, resp.StatusCode) + assert.Equal(t, page.Paths.WhatHappensNextPostEvidence.Format("lpa-id"), resp.Header.Get("Location")) + }) + } +} + func TestPayHelperPayWhenMoreEvidenceProvided(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodPost, "/", nil) @@ -507,9 +549,10 @@ func TestPayHelperPayWhenMoreEvidenceProvided(t *testing.T) { donorStore := newMockDonorStore(t) donorStore. On("Put", r.Context(), &page.Lpa{ - ID: "lpa-id", - FeeType: page.FullFee, - Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, + ID: "lpa-id", + FeeType: pay.HalfFee, + Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, + EvidenceDelivery: pay.Upload, }). Return(nil) @@ -526,9 +569,10 @@ func TestPayHelperPayWhenMoreEvidenceProvided(t *testing.T) { evidenceS3Client: s3Client, documentStore: documentStore, }).Pay(testAppData, w, r, &page.Lpa{ - ID: "lpa-id", - FeeType: page.FullFee, - Tasks: page.Tasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, + ID: "lpa-id", + FeeType: pay.HalfFee, + Tasks: page.Tasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, + EvidenceDelivery: pay.Upload, }) resp := w.Result() @@ -541,14 +585,19 @@ func TestPayHelperPayWhenPaymentNotRequiredWhenDocumentStoreGetAllError(t *testi w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodPost, "/", nil) + donorStore := newMockDonorStore(t) + donorStore. + On("Put", r.Context(), mock.Anything). + Return(nil) + documentStore := newMockDocumentStore(t) documentStore. On("GetAll", r.Context()). Return(page.Documents{}, expectedError) - err := (&payHelper{documentStore: documentStore}).Pay(testAppData, w, r, &page.Lpa{ + err := (&payHelper{documentStore: documentStore, donorStore: donorStore}).Pay(testAppData, w, r, &page.Lpa{ ID: "lpa-id", - FeeType: page.NoFee, + FeeType: pay.NoFee, }) resp := w.Result() @@ -562,6 +611,11 @@ func TestPayHelperPayWhenPaymentNotRequiredWhenS3ClientPutObjectTaggingError(t * now := time.Now() + donorStore := newMockDonorStore(t) + donorStore. + On("Put", r.Context(), mock.Anything). + Return(nil) + documentStore := newMockDocumentStore(t) documentStore. On("GetAll", r.Context()). @@ -584,11 +638,12 @@ func TestPayHelperPayWhenPaymentNotRequiredWhenS3ClientPutObjectTaggingError(t * err := (&payHelper{ logger: logger, now: func() time.Time { return now }, + donorStore: donorStore, evidenceS3Client: s3Client, documentStore: documentStore, }).Pay(testAppData, w, r, &page.Lpa{ ID: "lpa-id", - FeeType: page.NoFee, + FeeType: pay.NoFee, }) resp := w.Result() @@ -602,6 +657,11 @@ func TestPayHelperPayWhenPaymentNotRequiredWhenDocumentStorePutError(t *testing. now := time.Now() + donorStore := newMockDonorStore(t) + donorStore. + On("Put", r.Context(), mock.Anything). + Return(nil) + documentStore := newMockDocumentStore(t) documentStore. On("GetAll", r.Context()). @@ -624,11 +684,12 @@ func TestPayHelperPayWhenPaymentNotRequiredWhenDocumentStorePutError(t *testing. err := (&payHelper{ now: func() time.Time { return now }, + donorStore: donorStore, evidenceS3Client: s3Client, documentStore: documentStore, }).Pay(testAppData, w, r, &page.Lpa{ ID: "lpa-id", - FeeType: page.NoFee, + FeeType: pay.NoFee, }) resp := w.Result() @@ -642,43 +703,21 @@ func TestPayHelperPayWhenPaymentNotRequiredWhenDonorStorePutError(t *testing.T) now := time.Now() - documentStore := newMockDocumentStore(t) - documentStore. - On("GetAll", r.Context()). - Return(page.Documents{ - {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf", Sent: now}, - {Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png"}, - }, nil) - documentStore. - On("Put", r.Context(), page.Document{ - Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png", Sent: now, - }). - Return(nil) - donorStore := newMockDonorStore(t) donorStore. On("Put", r.Context(), &page.Lpa{ ID: "lpa-id", - FeeType: page.NoFee, + FeeType: pay.NoFee, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, }). Return(expectedError) - s3Client := newMockS3Client(t) - s3Client. - On("PutObjectTagging", r.Context(), "lpa-uid/evidence/another-uid", []types.Tag{ - {Key: aws.String("replicate"), Value: aws.String("true")}, - }). - Return(nil) - err := (&payHelper{ - donorStore: donorStore, - now: func() time.Time { return now }, - evidenceS3Client: s3Client, - documentStore: documentStore, + donorStore: donorStore, + now: func() time.Time { return now }, }).Pay(testAppData, w, r, &page.Lpa{ ID: "lpa-id", - FeeType: page.NoFee, + FeeType: pay.NoFee, }) resp := w.Result() @@ -730,7 +769,7 @@ func TestPayHelperPayWhenFeeDenied(t *testing.T) { On("Put", r.Context(), &page.Lpa{ ID: "lpa-id", Donor: actor.Donor{Email: "a@b.com"}, - FeeType: page.FullFee, + FeeType: pay.FullFee, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskInProgress}, PaymentDetails: []page.Payment{{Amount: 4100}}, }). @@ -745,7 +784,7 @@ func TestPayHelperPayWhenFeeDenied(t *testing.T) { }).Pay(testAppData, w, r, &page.Lpa{ ID: "lpa-id", Donor: actor.Donor{Email: "a@b.com"}, - FeeType: page.HalfFee, + FeeType: pay.HalfFee, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskDenied}, PaymentDetails: []page.Payment{{Amount: 4100}}, }) @@ -800,7 +839,7 @@ func TestPayHelperPayWhenFeeDeniedAndPutStoreError(t *testing.T) { On("Put", r.Context(), &page.Lpa{ ID: "lpa-id", Donor: actor.Donor{Email: "a@b.com"}, - FeeType: page.FullFee, + FeeType: pay.FullFee, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskInProgress}, PaymentDetails: []page.Payment{{Amount: 4100}}, }). @@ -815,7 +854,7 @@ func TestPayHelperPayWhenFeeDeniedAndPutStoreError(t *testing.T) { }).Pay(testAppData, w, r, &page.Lpa{ ID: "lpa-id", Donor: actor.Donor{Email: "a@b.com"}, - FeeType: page.HalfFee, + FeeType: pay.HalfFee, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskDenied}, PaymentDetails: []page.Payment{{Amount: 4100}}, }) diff --git a/internal/page/donor/how_to_email_or_post_evidence.go b/internal/page/donor/send_us_your_evidence_by_post.go similarity index 77% rename from internal/page/donor/how_to_email_or_post_evidence.go rename to internal/page/donor/send_us_your_evidence_by_post.go index 031f5e072b..17cfa159bb 100644 --- a/internal/page/donor/how_to_email_or_post_evidence.go +++ b/internal/page/donor/send_us_your_evidence_by_post.go @@ -8,14 +8,14 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) -type howToEmailOrPostEvidenceData struct { +type sendUsYourEvidenceByPostData struct { App page.AppData Errors validation.List } -func HowToEmailOrPostEvidence(tmpl template.Template, payer Payer) Handler { +func SendUsYourEvidenceByPost(tmpl template.Template, payer Payer) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, lpa *page.Lpa) error { - data := &howToEmailOrPostEvidenceData{ + data := &sendUsYourEvidenceByPostData{ App: appData, } diff --git a/internal/page/donor/how_to_email_or_post_evidence_test.go b/internal/page/donor/send_us_your_evidence_by_post_test.go similarity index 69% rename from internal/page/donor/how_to_email_or_post_evidence_test.go rename to internal/page/donor/send_us_your_evidence_by_post_test.go index 150660cb9c..0d46c83e60 100644 --- a/internal/page/donor/how_to_email_or_post_evidence_test.go +++ b/internal/page/donor/send_us_your_evidence_by_post_test.go @@ -11,39 +11,39 @@ import ( "github.com/stretchr/testify/mock" ) -func TestGetHowToEmailOrPostEvidence(t *testing.T) { +func TestGetSendUsYourEvidenceByPost(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/about-payment", nil) template := newMockTemplate(t) template. - On("Execute", w, &howToEmailOrPostEvidenceData{App: testAppData}). + On("Execute", w, &sendUsYourEvidenceByPostData{App: testAppData}). Return(nil) - err := HowToEmailOrPostEvidence(template.Execute, nil)(testAppData, w, r, &page.Lpa{}) + err := SendUsYourEvidenceByPost(template.Execute, nil)(testAppData, w, r, &page.Lpa{}) resp := w.Result() assert.Nil(t, err) assert.Equal(t, http.StatusOK, resp.StatusCode) } -func TestGetHowToEmailOrPostEvidenceWhenTemplateErrors(t *testing.T) { +func TestGetSendUsYourEvidenceByPostWhenTemplateErrors(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/about-payment", nil) template := newMockTemplate(t) template. - On("Execute", w, &howToEmailOrPostEvidenceData{App: testAppData}). + On("Execute", w, &sendUsYourEvidenceByPostData{App: testAppData}). Return(expectedError) - err := HowToEmailOrPostEvidence(template.Execute, nil)(testAppData, w, r, &page.Lpa{}) + err := SendUsYourEvidenceByPost(template.Execute, nil)(testAppData, w, r, &page.Lpa{}) resp := w.Result() assert.Equal(t, expectedError, err) assert.Equal(t, http.StatusOK, resp.StatusCode) } -func TestPostHowToEmailOrPostEvidence(t *testing.T) { +func TestPostSendUsYourEvidenceByPost(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodPost, "/about-payment", nil) @@ -54,11 +54,11 @@ func TestPostHowToEmailOrPostEvidence(t *testing.T) { On("Pay", testAppData, w, r, lpa). Return(nil) - err := HowToEmailOrPostEvidence(nil, payer)(testAppData, w, r, lpa) + err := SendUsYourEvidenceByPost(nil, payer)(testAppData, w, r, lpa) assert.Nil(t, err) } -func TestPostHowToEmailOrPostEvidenceWhenPayerErrors(t *testing.T) { +func TestPostSendUsYourEvidenceByPostWhenPayerErrors(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodPost, "/about-payment", nil) @@ -67,6 +67,6 @@ func TestPostHowToEmailOrPostEvidenceWhenPayerErrors(t *testing.T) { On("Pay", testAppData, w, r, mock.Anything). Return(expectedError) - err := HowToEmailOrPostEvidence(nil, payer)(testAppData, w, r, &page.Lpa{}) + err := SendUsYourEvidenceByPost(nil, payer)(testAppData, w, r, &page.Lpa{}) assert.Equal(t, expectedError, err) } diff --git a/internal/page/donor/upload_evidence.go b/internal/page/donor/upload_evidence.go index d48c16d053..390dadd048 100644 --- a/internal/page/donor/upload_evidence.go +++ b/internal/page/donor/upload_evidence.go @@ -12,6 +12,7 @@ import ( "github.com/gabriel-vasile/mimetype" "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -49,7 +50,7 @@ type uploadEvidenceData struct { App page.AppData Errors validation.List NumberOfAllowedFiles int - FeeType page.FeeType + FeeType pay.FeeType Documents page.Documents MimeTypes []string Deleted string diff --git a/internal/page/donor/upload_evidence_test.go b/internal/page/donor/upload_evidence_test.go index 3376f60ed4..ceabec6d36 100644 --- a/internal/page/donor/upload_evidence_test.go +++ b/internal/page/donor/upload_evidence_test.go @@ -13,6 +13,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + pay "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -32,13 +33,13 @@ func TestGetUploadEvidence(t *testing.T) { On("Execute", w, &uploadEvidenceData{ App: testAppData, NumberOfAllowedFiles: 5, - FeeType: page.FullFee, + FeeType: pay.FullFee, MimeTypes: acceptedMimeTypes(), Documents: page.Documents{{Scanned: false}}, }). Return(nil) - err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{FeeType: page.FullFee}) + err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{FeeType: pay.FullFee}) resp := w.Result() assert.Nil(t, err) @@ -49,7 +50,7 @@ func TestGetUploadEvidenceWhenTaskPending(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/", nil) - err := UploadEvidence(nil, nil, nil)(testAppData, w, r, &page.Lpa{ID: "lpa-id", FeeType: page.FullFee, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}}) + err := UploadEvidence(nil, nil, nil)(testAppData, w, r, &page.Lpa{ID: "lpa-id", FeeType: pay.FullFee, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}}) resp := w.Result() assert.Nil(t, err) @@ -114,7 +115,7 @@ func TestPostUploadEvidenceWithUploadActionAcceptedFileTypes(t *testing.T) { On("GetAll", r.Context()). Return(page.Documents{}, nil) documentStore. - On("Create", r.Context(), &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}, filename, mock.Anything). + On("Create", r.Context(), &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}, filename, mock.Anything). Return(page.Document{ PK: "LPA#lpa-id", SK: "#DOCUMENT#lpa-uid/evidence/a-uid", @@ -134,12 +135,12 @@ func TestPostUploadEvidenceWithUploadActionAcceptedFileTypes(t *testing.T) { }, NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), - FeeType: page.HalfFee, + FeeType: pay.HalfFee, StartScan: "1", }). Return(nil) - err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}) + err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}) assert.Nil(t, err) }) } @@ -149,7 +150,7 @@ func TestPostUploadEvidenceWhenTaskPending(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodPost, "/", nil) - err := UploadEvidence(nil, nil, nil)(testAppData, w, r, &page.Lpa{ID: "lpa-id", FeeType: page.FullFee, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}}) + err := UploadEvidence(nil, nil, nil)(testAppData, w, r, &page.Lpa{ID: "lpa-id", FeeType: pay.FullFee, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}}) resp := w.Result() assert.Nil(t, err) @@ -182,7 +183,7 @@ func TestPostUploadEvidenceWithUploadActionMultipleFiles(t *testing.T) { On("GetAll", r.Context()). Return(page.Documents{}, nil) documentStore. - On("Create", r.Context(), &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}, "dummy.pdf", mock.Anything). + On("Create", r.Context(), &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}, "dummy.pdf", mock.Anything). Return(page.Document{ PK: "LPA#lpa-id", SK: "#DOCUMENT#lpa-uid/evidence/a-uid", @@ -191,7 +192,7 @@ func TestPostUploadEvidenceWithUploadActionMultipleFiles(t *testing.T) { }, nil). Once() documentStore. - On("Create", r.Context(), &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}, "dummy.png", mock.Anything). + On("Create", r.Context(), &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}, "dummy.png", mock.Anything). Return(page.Document{ PK: "LPA#lpa-id", SK: "#DOCUMENT#lpa-uid/evidence/a-uid", @@ -220,12 +221,12 @@ func TestPostUploadEvidenceWithUploadActionMultipleFiles(t *testing.T) { }, NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), - FeeType: page.HalfFee, + FeeType: pay.HalfFee, StartScan: "1", }). Return(nil) - err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}) + err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}) assert.Nil(t, err) } @@ -255,7 +256,7 @@ func TestPostUploadEvidenceWithUploadActionFilenameSpecialCharactersAreEscaped(t On("GetAll", r.Context()). Return(page.Documents{}, nil) documentStore. - On("Create", r.Context(), &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}, "<img src=1 onerror=alert(document.domain)>’ brute.heic", mock.Anything). + On("Create", r.Context(), &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}, "<img src=1 onerror=alert(document.domain)>’ brute.heic", mock.Anything). Return(page.Document{ PK: "LPA#lpa-id", SK: "#DOCUMENT#lpa-uid/evidence/a-uid", @@ -277,12 +278,12 @@ func TestPostUploadEvidenceWithUploadActionFilenameSpecialCharactersAreEscaped(t }, NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), - FeeType: page.HalfFee, + FeeType: pay.HalfFee, StartScan: "1", }). Return(nil) - err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}) + err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}) assert.Nil(t, err) } @@ -309,10 +310,10 @@ func TestPostUploadEvidenceWithPayAction(t *testing.T) { payer := newMockPayer(t) payer. - On("Pay", testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}). + On("Pay", testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}). Return(nil) - err := UploadEvidence(nil, payer, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}) + err := UploadEvidence(nil, payer, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}) assert.Nil(t, err) } @@ -340,10 +341,10 @@ func TestPostUploadEvidenceWithPayActionWhenPayerError(t *testing.T) { payer := newMockPayer(t) payer. - On("Pay", testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}). + On("Pay", testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}). Return(expectedError) - err := UploadEvidence(nil, payer, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}) + err := UploadEvidence(nil, payer, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}) assert.Equal(t, expectedError, err) } @@ -396,13 +397,12 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFiles(t *testing.T) Documents: page.Documents{{Filename: "b", VirusDetected: false}}, NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), - FeeType: page.HalfFee, + FeeType: pay.HalfFee, Errors: validation.With("upload", validation.FilesInfectedError{Label: "upload", Filenames: []string{"a", "c", "d"}}), }). Return(nil) - err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}) - + err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}) assert.Nil(t, err) } @@ -436,12 +436,11 @@ func TestPostUploadEvidenceWithScanResultsActionWithoutInfectedFiles(t *testing. Documents: page.Documents{{Filename: "a", VirusDetected: false}}, NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), - FeeType: page.HalfFee, + FeeType: pay.HalfFee, }). Return(nil) - err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}) - + err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}) assert.Nil(t, err) } @@ -471,8 +470,7 @@ func TestPostUploadEvidenceWithPayActionWithInfectedFilesWhenDocumentStoreGetAll {Filename: "d", VirusDetected: true}, }, expectedError) - err := UploadEvidence(nil, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}) - + err := UploadEvidence(nil, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}) assert.Equal(t, expectedError, err) } @@ -510,8 +508,7 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFilesWhenDocumentSto }). Return(expectedError) - err := UploadEvidence(nil, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}) - + err := UploadEvidence(nil, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}) assert.Equal(t, expectedError, err) } @@ -556,8 +553,7 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFilesWhenDocumentSto }, expectedError). Once() - err := UploadEvidence(nil, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}) - + err := UploadEvidence(nil, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}) assert.Equal(t, expectedError, err) } @@ -609,12 +605,12 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFilesWhenTemplateErr Documents: page.Documents{{Filename: "b", VirusDetected: false}}, NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), - FeeType: page.HalfFee, + FeeType: pay.HalfFee, Errors: validation.With("upload", validation.FilesInfectedError{Label: "upload", Filenames: []string{"a", "c", "d"}}), }). Return(expectedError) - err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: page.HalfFee}) + err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", UID: "lpa-uid", FeeType: pay.HalfFee}) assert.Equal(t, expectedError, err) } @@ -644,12 +640,12 @@ func TestPostUploadEvidenceWhenBadCsrfField(t *testing.T) { NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), Errors: validation.With("upload", validation.CustomError{Label: "errorGenericUploadProblem"}), - FeeType: page.FullFee, + FeeType: pay.FullFee, Documents: page.Documents{}, }). Return(nil) - err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", FeeType: page.FullFee}) + err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", FeeType: pay.FullFee}) resp := w.Result() assert.Nil(t, err) @@ -684,12 +680,12 @@ func TestPostUploadEvidenceWhenBadActionField(t *testing.T) { NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), Errors: validation.With("upload", validation.CustomError{Label: "errorGenericUploadProblem"}), - FeeType: page.FullFee, + FeeType: pay.FullFee, Documents: page.Documents{}, }). Return(nil) - err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", FeeType: page.FullFee}) + err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", FeeType: pay.FullFee}) resp := w.Result() assert.Nil(t, err) @@ -732,12 +728,12 @@ func TestPostUploadEvidenceNumberOfFilesLimitPassed(t *testing.T) { NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), Errors: validation.With("upload", validation.CustomError{Label: "errorTooManyFiles"}), - FeeType: page.FullFee, + FeeType: pay.FullFee, Documents: page.Documents{}, }). Return(nil) - err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{UID: "lpa-uid", FeeType: page.FullFee}) + err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{UID: "lpa-uid", FeeType: pay.FullFee}) assert.Nil(t, err) } @@ -807,12 +803,12 @@ func TestPostUploadEvidenceWhenBadUpload(t *testing.T) { NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), Errors: validation.With("upload", tc.expectedError), - FeeType: page.FullFee, + FeeType: pay.FullFee, Documents: page.Documents{}, }). Return(nil) - err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", FeeType: page.FullFee}) + err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id", FeeType: pay.FullFee}) resp := w.Result() assert.Nil(t, err) @@ -857,7 +853,7 @@ func TestGetUploadEvidenceDeleteEvidence(t *testing.T) { App: testAppData, NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), - FeeType: page.FullFee, + FeeType: pay.FullFee, Documents: page.Documents{ {Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png"}, }, @@ -902,7 +898,7 @@ func TestGetUploadEvidenceDeleteEvidenceWhenUnexpectedFieldName(t *testing.T) { App: testAppData, NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), - FeeType: page.FullFee, + FeeType: pay.FullFee, Documents: page.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf"}, }, @@ -946,7 +942,6 @@ func TestGetUploadEvidenceDeleteEvidenceWhenDocumentStoreDeleteError(t *testing. Return(expectedError) err := UploadEvidence(nil, nil, documentStore)(testAppData, w, r, &page.Lpa{}) - assert.Equal(t, expectedError, err) } @@ -986,7 +981,7 @@ func TestGetUploadEvidenceDeleteEvidenceWhenTemplateError(t *testing.T) { App: testAppData, NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), - FeeType: page.FullFee, + FeeType: pay.FullFee, Documents: page.Documents{ {Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png"}, }, @@ -995,7 +990,6 @@ func TestGetUploadEvidenceDeleteEvidenceWhenTemplateError(t *testing.T) { Return(expectedError) err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{}) - assert.Equal(t, expectedError, err) } @@ -1032,7 +1026,7 @@ func TestPostUploadEvidenceWithCloseConnectionAction(t *testing.T) { App: testAppData, NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), - FeeType: page.HalfFee, + FeeType: pay.HalfFee, Documents: page.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf", Scanned: true}, }, @@ -1040,7 +1034,7 @@ func TestPostUploadEvidenceWithCloseConnectionAction(t *testing.T) { }). Return(nil) - err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{UID: "lpa-uid", FeeType: page.HalfFee}) + err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{UID: "lpa-uid", FeeType: pay.HalfFee}) resp := w.Result() @@ -1075,8 +1069,7 @@ func TestPostUploadEvidenceWithCloseConnectionActionWhenDocumentStoreDeleteError On("Delete", r.Context(), page.Document{Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png", Scanned: false}). Return(expectedError) - err := UploadEvidence(nil, nil, documentStore)(testAppData, w, r, &page.Lpa{UID: "lpa-uid", FeeType: page.HalfFee}) - + err := UploadEvidence(nil, nil, documentStore)(testAppData, w, r, &page.Lpa{UID: "lpa-uid", FeeType: pay.HalfFee}) resp := w.Result() assert.Equal(t, expectedError, err) @@ -1116,7 +1109,7 @@ func TestPostUploadEvidenceWithCloseConnectionActionWhenTemplateError(t *testing App: testAppData, NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), - FeeType: page.HalfFee, + FeeType: pay.HalfFee, Documents: page.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf", Scanned: true}, }, @@ -1124,8 +1117,7 @@ func TestPostUploadEvidenceWithCloseConnectionActionWhenTemplateError(t *testing }). Return(expectedError) - err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{UID: "lpa-uid", FeeType: page.HalfFee}) - + err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{UID: "lpa-uid", FeeType: pay.HalfFee}) resp := w.Result() assert.Equal(t, expectedError, err) @@ -1165,15 +1157,14 @@ func TestPostUploadEvidenceWithCancelUploadAction(t *testing.T) { App: testAppData, NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), - FeeType: page.HalfFee, + FeeType: pay.HalfFee, Documents: page.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf", Scanned: true}, }, }). Return(nil) - err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{UID: "lpa-uid", FeeType: page.HalfFee}) - + err := UploadEvidence(template.Execute, nil, documentStore)(testAppData, w, r, &page.Lpa{UID: "lpa-uid", FeeType: pay.HalfFee}) resp := w.Result() assert.Nil(t, err) diff --git a/internal/page/donor/which_fee_type_are_you_applying_for.go b/internal/page/donor/which_fee_type_are_you_applying_for.go index addc0ed7b5..d2fb7550d5 100644 --- a/internal/page/donor/which_fee_type_are_you_applying_for.go +++ b/internal/page/donor/which_fee_type_are_you_applying_for.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -12,7 +13,7 @@ type whichFeeTypeAreYouApplyingForData struct { App page.AppData Errors validation.List Form *whichFeeTypeAreYouApplyingForForm - Options page.FeeTypeOptions + Options pay.FeeTypeOptions } func WhichFeeTypeAreYouApplyingFor(tmpl template.Template, donorStore DonorStore) Handler { @@ -22,7 +23,7 @@ func WhichFeeTypeAreYouApplyingFor(tmpl template.Template, donorStore DonorStore Form: &whichFeeTypeAreYouApplyingForForm{ FeeType: lpa.FeeType, }, - Options: page.FeeTypeValues, + Options: pay.FeeTypeValues, } if r.Method == http.MethodPost { @@ -48,12 +49,12 @@ func WhichFeeTypeAreYouApplyingFor(tmpl template.Template, donorStore DonorStore } type whichFeeTypeAreYouApplyingForForm struct { - FeeType page.FeeType + FeeType pay.FeeType Error error } func readWhichFeeTypeAreYouApplyingForForm(r *http.Request) *whichFeeTypeAreYouApplyingForForm { - feeType, err := page.ParseFeeType(page.PostFormString(r, "fee-type")) + feeType, err := pay.ParseFeeType(page.PostFormString(r, "fee-type")) return &whichFeeTypeAreYouApplyingForForm{ FeeType: feeType, diff --git a/internal/page/donor/which_fee_type_are_you_applying_for_test.go b/internal/page/donor/which_fee_type_are_you_applying_for_test.go index 12d8250949..8ffaaf4bd2 100644 --- a/internal/page/donor/which_fee_type_are_you_applying_for_test.go +++ b/internal/page/donor/which_fee_type_are_you_applying_for_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + pay "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -22,7 +23,7 @@ func TestGetWhichFeeTypeAreYouApplyingFor(t *testing.T) { On("Execute", w, &whichFeeTypeAreYouApplyingForData{ App: testAppData, Form: &whichFeeTypeAreYouApplyingForForm{}, - Options: page.FeeTypeValues, + Options: pay.FeeTypeValues, }). Return(nil) @@ -41,12 +42,12 @@ func TestGetWhichFeeTypeAreYouApplyingForWithLpaData(t *testing.T) { template. On("Execute", w, &whichFeeTypeAreYouApplyingForData{ App: testAppData, - Form: &whichFeeTypeAreYouApplyingForForm{FeeType: page.HalfFee}, - Options: page.FeeTypeValues, + Form: &whichFeeTypeAreYouApplyingForForm{FeeType: pay.HalfFee}, + Options: pay.FeeTypeValues, }). Return(nil) - err := WhichFeeTypeAreYouApplyingFor(template.Execute, nil)(testAppData, w, r, &page.Lpa{FeeType: page.HalfFee}) + err := WhichFeeTypeAreYouApplyingFor(template.Execute, nil)(testAppData, w, r, &page.Lpa{FeeType: pay.HalfFee}) resp := w.Result() assert.Nil(t, err) @@ -62,7 +63,7 @@ func TestGetWhichFeeTypeAreYouApplyingForOnTemplateError(t *testing.T) { On("Execute", w, &whichFeeTypeAreYouApplyingForData{ App: testAppData, Form: &whichFeeTypeAreYouApplyingForForm{}, - Options: page.FeeTypeValues, + Options: pay.FeeTypeValues, }). Return(expectedError) @@ -74,11 +75,11 @@ func TestGetWhichFeeTypeAreYouApplyingForOnTemplateError(t *testing.T) { } func TestPostWhichFeeTypeAreYouApplyingFor(t *testing.T) { - testcases := map[page.FeeType]page.LpaPath{ - page.HalfFee: page.Paths.EvidenceRequired, - page.NoFee: page.Paths.EvidenceRequired, - page.HardshipFee: page.Paths.EvidenceRequired, - page.RepeatApplicationFee: page.Paths.PreviousApplicationNumber, + testcases := map[pay.FeeType]page.LpaPath{ + pay.HalfFee: page.Paths.EvidenceRequired, + pay.NoFee: page.Paths.EvidenceRequired, + pay.HardshipFee: page.Paths.EvidenceRequired, + pay.RepeatApplicationFee: page.Paths.PreviousApplicationNumber, } for feeType, redirect := range testcases { @@ -108,7 +109,7 @@ func TestPostWhichFeeTypeAreYouApplyingFor(t *testing.T) { func TestPostWhichFeeTypeAreYouApplyingForOnStoreError(t *testing.T) { form := url.Values{ - "fee-type": {page.HalfFee.String()}, + "fee-type": {pay.HalfFee.String()}, } w := httptest.NewRecorder() @@ -117,7 +118,7 @@ func TestPostWhichFeeTypeAreYouApplyingForOnStoreError(t *testing.T) { donorStore := newMockDonorStore(t) donorStore. - On("Put", r.Context(), &page.Lpa{ID: "lpa-id", FeeType: page.HalfFee}). + On("Put", r.Context(), &page.Lpa{ID: "lpa-id", FeeType: pay.HalfFee}). Return(expectedError) err := WhichFeeTypeAreYouApplyingFor(nil, donorStore)(testAppData, w, r, &page.Lpa{ID: "lpa-id"}) diff --git a/internal/page/fixtures/donor.go b/internal/page/fixtures/donor.go index 85379bd495..f8e274cd33 100644 --- a/internal/page/fixtures/donor.go +++ b/internal/page/fixtures/donor.go @@ -12,6 +12,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/random" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" @@ -197,7 +198,7 @@ func Donor( if progress >= slices.Index(progressValues, "payForTheLpa") { if feeType != "" && feeType != "FullFee" { - feeType, err := page.ParseFeeType(feeType) + feeType, err := pay.ParseFeeType(feeType) if err != nil { return err } @@ -220,9 +221,8 @@ func Donor( if err := documentStore.Put(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID}), document); err != nil { return err } - } else { - lpa.FeeType = page.FullFee + lpa.FeeType = pay.FullFee } lpa.PaymentDetails = append(lpa.PaymentDetails, page.Payment{ @@ -238,6 +238,7 @@ func Donor( return err } + lpa.EvidenceDelivery = pay.Upload lpa.Tasks.PayForLpa = taskState } } diff --git a/internal/page/paths.go b/internal/page/paths.go index 8629d4945d..fcbfe7209a 100644 --- a/internal/page/paths.go +++ b/internal/page/paths.go @@ -144,7 +144,6 @@ type AppPaths struct { HowShouldReplacementAttorneysMakeDecisions LpaPath HowShouldReplacementAttorneysStepIn LpaPath HowToConfirmYourIdentityAndSign LpaPath - HowToEmailOrPostEvidence LpaPath HowToSendEvidence LpaPath HowWouldCertificateProviderPreferToCarryOutTheirRole LpaPath HowWouldYouLikeToSendEvidence LpaPath @@ -168,6 +167,7 @@ type AppPaths struct { ResendCertificateProviderCode LpaPath ResendIndependentWitnessCode LpaPath Restrictions LpaPath + SendUsYourEvidenceByPost LpaPath SignTheLpaOnBehalf LpaPath SignYourLpa LpaPath TaskList LpaPath @@ -175,6 +175,7 @@ type AppPaths struct { UploadEvidenceSSE LpaPath UseExistingAddress LpaPath WhatACertificateProviderDoes LpaPath + WhatHappensNextPostEvidence LpaPath WhenCanTheLpaBeUsed LpaPath WhichFeeTypeAreYouApplyingFor LpaPath WithdrawThisLpa LpaPath @@ -279,7 +280,6 @@ var Paths = AppPaths{ HowShouldReplacementAttorneysMakeDecisions: "/how-should-replacement-attorneys-make-decisions", HowShouldReplacementAttorneysStepIn: "/how-should-replacement-attorneys-step-in", HowToConfirmYourIdentityAndSign: "/how-to-confirm-your-identity-and-sign", - HowToEmailOrPostEvidence: "/how-to-email-or-post-evidence", HowToSendEvidence: "/how-to-send-evidence", HowWouldCertificateProviderPreferToCarryOutTheirRole: "/how-would-certificate-provider-prefer-to-carry-out-their-role", HowWouldYouLikeToSendEvidence: "/how-would-you-like-to-send-evidence", @@ -308,6 +308,7 @@ var Paths = AppPaths{ ResendIndependentWitnessCode: "/resend-independent-witness-code", Restrictions: "/restrictions", Root: "/", + SendUsYourEvidenceByPost: "/send-us-your-evidence-by-post", SignOut: "/sign-out", SignTheLpaOnBehalf: "/sign-the-lpa-on-behalf", SignYourLpa: "/sign-your-lpa", @@ -317,6 +318,7 @@ var Paths = AppPaths{ UploadEvidenceSSE: "/upload-evidence-sse", UseExistingAddress: "/use-existing-address", WhatACertificateProviderDoes: "/what-a-certificate-provider-does", + WhatHappensNextPostEvidence: "/what-happens-next-post-evidence", WhenCanTheLpaBeUsed: "/when-can-the-lpa-be-used", WhichFeeTypeAreYouApplyingFor: "/which-fee-type-are-you-applying-for", WithdrawThisLpa: "/withdraw-this-lpa", diff --git a/internal/page/donor/enum_evidencedelivery.go b/internal/pay/enum_evidencedelivery.go similarity index 98% rename from internal/page/donor/enum_evidencedelivery.go rename to internal/pay/enum_evidencedelivery.go index f2a1ae267c..328e88cf47 100644 --- a/internal/page/donor/enum_evidencedelivery.go +++ b/internal/pay/enum_evidencedelivery.go @@ -1,5 +1,5 @@ // Code generated by "enumerator -type EvidenceDelivery -linecomment -empty"; DO NOT EDIT. -package donor +package pay import ( "fmt" diff --git a/internal/page/enum_feetype.go b/internal/pay/enum_feetype.go similarity index 99% rename from internal/page/enum_feetype.go rename to internal/pay/enum_feetype.go index 7a385a123b..eabc59a14d 100644 --- a/internal/page/enum_feetype.go +++ b/internal/pay/enum_feetype.go @@ -1,5 +1,5 @@ // Code generated by "enumerator -type FeeType"; DO NOT EDIT. -package page +package pay import ( "fmt" diff --git a/internal/page/enum_previousfee.go b/internal/pay/enum_previousfee.go similarity index 99% rename from internal/page/enum_previousfee.go rename to internal/pay/enum_previousfee.go index e880f20a69..a719781a48 100644 --- a/internal/page/enum_previousfee.go +++ b/internal/pay/enum_previousfee.go @@ -1,5 +1,5 @@ // Code generated by "enumerator -type PreviousFee -empty"; DO NOT EDIT. -package page +package pay import ( "fmt" diff --git a/internal/pay/evidence.go b/internal/pay/evidence.go new file mode 100644 index 0000000000..7a13db474a --- /dev/null +++ b/internal/pay/evidence.go @@ -0,0 +1,9 @@ +package pay + +//go:generate enumerator -type EvidenceDelivery -linecomment -empty +type EvidenceDelivery uint8 + +const ( + Upload EvidenceDelivery = iota + 1 // upload + Post // post +) diff --git a/internal/pay/fees.go b/internal/pay/fees.go new file mode 100644 index 0000000000..5e45bc297c --- /dev/null +++ b/internal/pay/fees.go @@ -0,0 +1,42 @@ +package pay + +//go:generate enumerator -type FeeType +type FeeType uint8 + +const ( + FullFee FeeType = iota + HalfFee + NoFee + HardshipFee + RepeatApplicationFee +) + +//go:generate enumerator -type PreviousFee -empty +type PreviousFee uint8 + +const ( + PreviousFeeFull PreviousFee = iota + 1 + PreviousFeeHalf + PreviousFeeExemption + PreviousFeeHardship +) + +func Cost(feeType FeeType, previousFee PreviousFee) int { + switch feeType { + case FullFee: + return 8200 + case HalfFee: + return 4100 + case RepeatApplicationFee: + switch previousFee { + case PreviousFeeFull: + return 4100 + case PreviousFeeHalf: + return 2050 + default: + return 0 + } + default: + return 0 + } +} diff --git a/internal/pay/fees_test.go b/internal/pay/fees_test.go new file mode 100644 index 0000000000..ca0ce60d0f --- /dev/null +++ b/internal/pay/fees_test.go @@ -0,0 +1,58 @@ +package pay + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestCost(t *testing.T) { + testCases := map[string]struct { + feeType FeeType + previousFee PreviousFee + expected int + }{ + "full": { + feeType: FullFee, + expected: 8200, + }, + "half": { + feeType: HalfFee, + expected: 4100, + }, + "no fee": { + feeType: NoFee, + expected: 0, + }, + "hardship": { + feeType: HardshipFee, + expected: 0, + }, + "repeat full": { + feeType: RepeatApplicationFee, + previousFee: PreviousFeeFull, + expected: 4100, + }, + "repeat half": { + feeType: RepeatApplicationFee, + previousFee: PreviousFeeHalf, + expected: 2050, + }, + "repeat exemption": { + feeType: RepeatApplicationFee, + previousFee: PreviousFeeExemption, + expected: 0, + }, + "repeat hardship": { + feeType: RepeatApplicationFee, + previousFee: PreviousFeeHardship, + expected: 0, + }, + } + + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + assert.Equal(t, tc.expected, Cost(tc.feeType, tc.previousFee)) + }) + } +} diff --git a/lang/cy.json b/lang/cy.json index 5410102beb..7d1a58fba4 100644 --- a/lang/cy.json +++ b/lang/cy.json @@ -927,5 +927,11 @@ "yourFilesAreUploading": "Welsh", "0OfNFilesUploaded": "Welsh {{ .TotalFilesCount }} welsh", "yourFilesAreUploadingContent": "Welsh", - "cancelUpload": "Welsh" + "cancelUpload": "Welsh", + "sendUsYourEvidenceByPost": "Welsh", + "sendUsYourEvidenceByPostContent": "
Welsh
", + "youMustIncludeYourReferenceNumberWarning": "Welsh", + "whatHappensNextPostEvidenceContent": "Welsh
", + "appealingTheDecision": "Welsh", + "appealingTheDecisionDetails": "Welsh
" } diff --git a/lang/en.json b/lang/en.json index bc07eb7f4d..d3bc9d9a88 100644 --- a/lang/en.json +++ b/lang/en.json @@ -864,12 +864,18 @@ "nothingHardship": "Nothing - I paid no fee because I got a hardship fee waiver", "howMuchYouPreviouslyPaid": "how much you previously paid", "evidenceSuccessfullyUploaded": "Evidence successfully uploaded", - "weWillReviewYourLpaApplicationAndSupportingEvidence": "We will review your LPA application and supporting evidence.
You can still sign your LPA while we’re reviewing your application. Your certificate provider must be there as a witness when you sign it.
However, we will not contact your certificate provider to provide their certificate until your {{.Application}} has been approved.
Once we have approved your payment, we will contact your certificate provider to provide their certificate.
We will contact you if we need more information or if your application is unsuccessful.
If your application is unsuccessful, you can appeal within 4 weeks of the decision by writing to the Head of Corporate Services.
If the original decision is upheld, it will be referred to the Public Guardian for confirmation.
We will review your LPA application and supporting evidence.
You can still sign your LPA while we’re reviewing your application. Your certificate provider must be there as a witness when you sign it.
However, we will not contact your certificate provider to provide their certificate until your {{.Application}} has been approved.
Once we have approved your payment, we will contact your certificate provider to provide their certificate.
We will contact you if we need more information or if your application is unsuccessful.
", "applicationNoFee": "application to pay no fee", "applicationHalfFee": "application to pay a half fee", "applicationHardshipFee": "hardship application", "yourFilesAreUploading": "Your files are uploading", "0OfNFilesUploaded": "0 of {{ .DocumentsToScanCount }} files uploaded", "yourFilesAreUploadingContent": "This may take a few minutes. Please do not close your browser window.", - "cancelUpload": "Cancel upload" + "cancelUpload": "Cancel upload", + "sendUsYourEvidenceByPost": "Send us your evidence by post", + "sendUsYourEvidenceByPostContent": "You can send your evidence to our postal address:
Office of the Public Guardian
PO Box 16185BirminghamB2 2WH
Your letter must include a cover letter with your reference number on it.
If you are making two LPAs at the same time, you do not need to send your evidence twice. You can send it once and include both LPA reference numbers on your cover letter.
", + "youMustIncludeYourReferenceNumberWarning": "You must include your reference number so we can link your evidence to your application. Not providing it could cause a delay and your LPA application could expire.", + "whatHappensNextPostEvidenceContent": "You should now send us your evidence by post. We will review it along with your LPA application.
You can still sign your LPA while we’re reviewing your application. Your certificate provider must be there as a witness when you sign it.
However, we will not contact your certificate provider to provide their certificate until your {{.Application}} has been approved.
Once we have approved your payment, we will contact your certificate provider to provide their certificate.
We will contact you if we need more information or if your application is unsuccessful.
", + "appealingTheDecision": "Appealing the decision", + "appealingTheDecisionDetails": "If your application is unsuccessful, you can appeal within 4 weeks of the decision by writing to the Head of Corporate Services.
If the original decision is upheld, it will be referred to the Public Guardian for confirmation.
" } diff --git a/web/template/evidence_successfully_uploaded.gohtml b/web/template/evidence_successfully_uploaded.gohtml index 3d73f9fb4b..a39bb913e4 100644 --- a/web/template/evidence_successfully_uploaded.gohtml +++ b/web/template/evidence_successfully_uploaded.gohtml @@ -10,7 +10,8 @@ {{ trFormatHtml .App "weWillReviewYourLpaApplicationAndSupportingEvidence" "Application" (printf "application%s" .Lpa.FeeType.String | tr .App) }} - + {{ template "details" (details . "appealingTheDecision" "appealingTheDecisionDetails" false) }} + diff --git a/web/template/payment_confirmation.gohtml b/web/template/payment_confirmation.gohtml index 3d6837b4d7..4169a5c889 100644 --- a/web/template/payment_confirmation.gohtml +++ b/web/template/payment_confirmation.gohtml @@ -16,10 +16,12 @@ {{ trHtml .App "paymentConfirmationContent" }} - {{ if .FeeType.IsHalfFee }} + {{ if or .FeeType.IsFullFee (and .FeeType.IsRepeatApplicationFee .PreviousFee.IsPreviousFeeFull) }} + {{ tr .App "continue" }} + {{ else if .EvidenceDelivery.IsUpload }} {{ tr .App "continue" }} {{ else }} - {{ tr .App "continue" }} + {{ tr .App "continue" }} {{ end }} diff --git a/web/template/how_to_email_or_post_evidence.gohtml b/web/template/send_us_your_evidence_by_post.gohtml similarity index 66% rename from web/template/how_to_email_or_post_evidence.gohtml rename to web/template/send_us_your_evidence_by_post.gohtml index 0c18e1ffe1..4b1a0e3666 100644 --- a/web/template/how_to_email_or_post_evidence.gohtml +++ b/web/template/send_us_your_evidence_by_post.gohtml @@ -1,14 +1,16 @@ {{ template "page" . }} -{{ define "pageTitle" }}{{ tr .App "howToEmailOrPostEvidence" }}{{ end }} +{{ define "pageTitle" }}{{ tr .App "sendUsYourEvidenceByPost" }}{{ end }} {{ define "main" }}