diff --git a/assets/penalty_details.yml b/assets/penalty_details.yml index 2e37f91..b20b5af 100644 --- a/assets/penalty_details.yml +++ b/assets/penalty_details.yml @@ -4,6 +4,7 @@ details: LP: Description: "Late Filing Penalty" DescriptionId: "late-filing-penalty" + ClassOfPayment: "penalty" ResourceKind: "late-filing-penalty#late-filing-penalty" ProductType: "late-filing-penalty" EmailReceivedAppId: "penalty-payment-api.penalty_payment_received_email" @@ -11,6 +12,7 @@ details: C1: Description: "Sanctions Penalty Payment" DescriptionId: "penalty-sanctions" + ClassOfPayment: "data-maintenance" ResourceKind: "penalty#sanctions" ProductType: "penalty-sanctions" EmailReceivedAppId: "penalty-payment-api.penalty_payment_received_email" diff --git a/config/config.go b/config/config.go index 3fbf3cb..c958142 100644 --- a/config/config.go +++ b/config/config.go @@ -42,6 +42,7 @@ type PenaltyDetailsMap struct { type PenaltyDetails struct { Description string `yaml:"Description"` DescriptionId string `yaml:"DescriptionId"` + ClassOfPayment string `yaml:"ClassOfPayment"` ResourceKind string `yaml:"ResourceKind"` ProductType string `yaml:"ProductType"` EmailReceivedAppId string `yaml:"EmailReceivedAppId"` diff --git a/spec/schema.json b/spec/schema.json index 15afbfd..717a950 100644 --- a/spec/schema.json +++ b/spec/schema.json @@ -608,7 +608,8 @@ "items": { "type": "string", "enum": [ - "penalty" + "penalty", + "data-maintenance" ] } }, diff --git a/transformers/payable_resource.go b/transformers/payable_resource.go index bc38153..bd89d98 100644 --- a/transformers/payable_resource.go +++ b/transformers/payable_resource.go @@ -112,7 +112,7 @@ func PayableResourceToPaymentDetails(payable *models.PayableResource, cost := models.Cost{ Amount: fmt.Sprintf("%g", tx.Amount), AvailablePaymentMethods: []string{"credit-card"}, - ClassOfPayment: []string{"penalty"}, + ClassOfPayment: []string{penaltyDetailsMap.Details[companyCode].ClassOfPayment}, Description: penaltyDetailsMap.Details[companyCode].Description, DescriptionIdentifier: penaltyDetailsMap.Details[companyCode].DescriptionId, Kind: "cost#cost", diff --git a/transformers/payable_resource_test.go b/transformers/payable_resource_test.go index bccb3c0..9f66af5 100644 --- a/transformers/payable_resource_test.go +++ b/transformers/payable_resource_test.go @@ -195,3 +195,73 @@ func TestUnitPayableResourceToPaymentDetails(t *testing.T) { So(response.Items[0].ProductType, ShouldEqual, "late-filing-penalty") }) } + +func TestUnitPayableResourceToPaymentDetailsConfirmationStatement(t *testing.T) { + Convey("field mappings are correct from payable resource to payment details", t, func() { + t := time.Now().Truncate(time.Millisecond) + payable := &models.PayableResource{ + CompanyNumber: "12345678", + Reference: "1234", + Etag: "qwertyetag1234", + CreatedAt: &t, + CreatedBy: models.CreatedBy{ + ID: "uz3r_1d", + Email: "test@user.com", + Forename: "some", + Surname: "body", + }, + Links: models.PayableResourceLinks{ + Self: "/foo", + Payment: "/foo/pay", + }, + Payment: models.Payment{ + Amount: "100", + Status: "pending", + Reference: "payref", + PaidAt: &t, + }, + Transactions: []models.TransactionItem{ + { + Amount: 100, + Type: "penalty", + MadeUpDate: "2019-01-01", + }, + }, + } + + penaltyDetailsMap, err := config.LoadPenaltyDetails("../assets/penalty_details.yml") + if err != nil { + log.Fatal(err) + } + + response := PayableResourceToPaymentDetails(payable, penaltyDetailsMap, utils.Sanctions) + + _, filename, _, _ := runtime.Caller(0) + fmt.Printf("Current test filename: %s\n", filename) + + dir, err := os.Getwd() + if err != nil { + log.Fatal(err) + } + fmt.Println("Dir: " + dir) + + So(response, ShouldNotBeNil) + So(response.Description, ShouldEqual, "Sanctions Penalty Payment") + So(response.Kind, ShouldEqual, "payment-details#payment-details") + So(response.PaidAt, ShouldEqual, payable.Payment.PaidAt) + So(response.PaymentReference, ShouldEqual, payable.Payment.Reference) + So(response.Links.Self, ShouldEqual, payable.Links.Payment) + So(response.Links.Resource, ShouldEqual, payable.Links.Self) + So(response.Status, ShouldEqual, payable.Payment.Status) + So(response.CompanyNumber, ShouldEqual, payable.CompanyNumber) + So(len(response.Items), ShouldEqual, 1) + So(response.Items[0].Amount, ShouldEqual, fmt.Sprintf("%g", payable.Transactions[0].Amount)) + So(response.Items[0].AvailablePaymentMethods, ShouldResemble, []string{"credit-card"}) + So(response.Items[0].ClassOfPayment, ShouldResemble, []string{"data-maintenance"}) + So(response.Items[0].Description, ShouldEqual, "Sanctions Penalty Payment") + So(response.Items[0].DescriptionIdentifier, ShouldEqual, "penalty-sanctions") + So(response.Items[0].Kind, ShouldEqual, "cost#cost") + So(response.Items[0].ResourceKind, ShouldEqual, "penalty#sanctions") + So(response.Items[0].ProductType, ShouldEqual, "penalty-sanctions") + }) +}