Skip to content

Commit

Permalink
Merge pull request #52 from companieshouse/feature/SAN-272-Payment-Token
Browse files Browse the repository at this point in the history
SAN-272 Update class_of_payment "data-maintenance" for payment in CS
  • Loading branch information
klai-ch authored Feb 19, 2025
2 parents a8bb2ef + 975fc45 commit 9d5f41c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 2 deletions.
2 changes: 2 additions & 0 deletions assets/penalty_details.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ 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"
EmailMsgType: "penalty_payment_received_email"
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"
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
3 changes: 2 additions & 1 deletion spec/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@
"items": {
"type": "string",
"enum": [
"penalty"
"penalty",
"data-maintenance"
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion transformers/payable_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
70 changes: 70 additions & 0 deletions transformers/payable_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
}

0 comments on commit 9d5f41c

Please sign in to comment.