Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIL-1362 Update SubmitUktr to use header for pillar2Id #40

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 34 additions & 125 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [Get Obligation \- Get Obligation Test Data](#get-obligation---get-obligation-test-data)
* [Post Liability](#post-liability)
* [Below Threshold Notification](#below-threshold-notification)
* [UK Tax Return Submission](#submit-uk-tax-return)


# pillar2-stubs
Expand Down Expand Up @@ -201,7 +202,6 @@ HTTP 503 Request Could not be processed Error
}
}
}

```

> Response status: 503
Expand Down Expand Up @@ -346,6 +346,39 @@ HTTP 404 Record Not Found Error

---

## Submit UK Tax Return

```
POST /RESTAdapter/PLR/UKTaxReturn
```

Submit a UK Tax Return request. This endpoint requires an `X-Pillar2-Id` header.

### Request Headers:
- `X-Pillar2-Id`: The Pillar 2 identifier (Required)
- `Content-Type`: application/json
- `Authorization`: Bearer token

### Response Scenarios:

| PLR Reference | Response Status | Description |
|--------------|-----------------|-------------|
| XTC01234123412 | 201 Created | Successful submission |
| XEPLR1066196400 | 400 Bad Request | Invalid JSON message content |
| XEPLR1066196401 | 401 Unauthorized | Authentication failed |
| XEPLR1066196403 | 403 Forbidden | User not authorized |
| XEPLR1066196404 | 404 Not Found | Resource not found |
| XEPLR1066196415 | 415 Unsupported Media Type | Invalid content type |
| XEPLR1066196422 | 422 Unprocessable Entity | Request validation failed |
| XEPLR1066196500 | 500 Internal Server Error | Internal server error |
| Any other ID | 201 Created | Successful submission |

Additionally:
- Missing X-Pillar2-Id header will return 400 Bad Request
- Invalid JSON payload will return 400 Bad Request with validation details

---

```
GET /pillar2/subscription/:plrReference
```
Expand Down Expand Up @@ -638,130 +671,6 @@ For now this API has not been developed by ETMP therefore we are making assumpti
| XEPLR4040000000 | NOT_FOUND Error Response |
| Any valid ID | Will return a response with Open status |


## Post Liability

Liability Detail Submission

This endpoint allows submission of liability details based on a provided idNumber (PLR Reference Number). There are two main types of submissions supported:
• Liability Submission: A detailed submission of liability amounts.
• Nil Return Submission: A minimal submission indicating no liability for the period.

Request Types and Expected Payloads

Liability Submission

A valid liability submission includes details about the total liabilities and entities liable for the tax period. Here’s the expected structure for a successful liability submission:
```
{
"accountingPeriodFrom": "2024-08-14",
"accountingPeriodTo": "2024-12-14",
"qualifyingGroup": true,
"obligationDTT": true,
"obligationMTT": true,
"electionUKGAAP": true,
"liabilities": {
"totalLiability": 10000.99,
"totalLiabilityDTT": 5000.99,
"totalLiabilityIIR": 4000,
"totalLiabilityUTPR": 10000.99,
"liableEntities": [
{
"ukChargeableEntityName": "Newco PLC",
"idType": "CRN",
"idValue": "12345678",
"amountOwedDTT": 5000,
"electedDTT": true,
"amountOwedIIR": 3400,
"amountOwedUTPR": 6000.5,
"electedUTPR": true
}
]
}
}
```

Nil Return Submission

A Nil Return submission is used when there is no liability for the specified period. The returnType field in liabilities should be set to "NIL_RETURN":
```
{
"accountingPeriodFrom": "2024-08-14",
"accountingPeriodTo": "2024-09-14",
"qualifyingGroup": true,
"obligationDTT": true,
"obligationMTT": true,
"electionUKGAAP": true,
"liabilities": {
"returnType": "NIL_RETURN"
}
}
```

Response Codes and Conditions

| Status | Description |
|-----------------|-------------------------------------------------------------------------------------------|
| 201 CREATED | Success response for a valid liability or Nil Return submission when idNumber is correct. |
| 400 BAD_REQUEST | Submission did not pass validation (e.g., invalid JSON format or required fields missing). |
| 400 BAD_REQUEST | Non-JSON data received, expecting a valid JSON object. |
| 404 NOT_FOUND | No liabilities found for the provided idNumber (PLR Reference Number is incorrect). |

Examples of Invalid Requests

Invalid JSON

A request with invalid JSON syntax will return a 400 BAD_REQUEST response:

```json
{
"accountingPeriod": "2024-08-1",
"accountingPeriod": "2024-12-14"
}
```

Non-JSON Body

If a non-JSON body is submitted, a 400 BAD_REQUEST response will be returned:

```
This is not a JSON body
```
Details of Expected Fields

• idNumber (PLR Reference Number): Only the idNumber “XTC01234123412” will result in a successful 201 CREATED response.
• Valid idNumber: Returns 201 CREATED with the liability success details for valid liability submissions.
• Invalid idNumber: Returns 404 NOT_FOUND, indicating no matching liability data for other idNumbers.
• Liability Fields: In a liability submission, totalLiability, totalLiabilityDTT, totalLiabilityIIR, and totalLiabilityUTPR are expected fields. Additionally, liableEntities should be a non-empty array.
• Nil Return Field: In a Nil Return submission, liabilities.returnType should be "NIL_RETURN", indicating no liability.

Response Examples

Successful Liability Submission Response

If the idNumber is valid and the payload is correct, a 201 CREATED response will be returned with liability details:
```
{
"success": {
"processingDate": "2024-08-14T09:26:17Z",
"formBundleNumber": "119000004320",
"chargeReference": "XTC01234123412"
}
}
```

Successful Nil Return Response

If the idNumber is valid and the payload indicates a Nil Return, a 201 CREATED response will be returned with the Nil Return details:
```
{
"success": {
"processingDate": "2024-08-14T09:26:17Z",
"message": "Nil return received and processed successfully"
}
}
```

## Below Threshold Notification

This endpoint allows submission of a below threshold notification, which defines an organisation as earning below the threshold
Expand Down
91 changes: 0 additions & 91 deletions app/uk/gov/hmrc/pillar2stubs/controllers/LiabilityController.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.pillar2stubs.controllers

import play.api.Logging
import play.api.libs.json.Json
import play.api.mvc.{Action, ControllerComponents}
import uk.gov.hmrc.pillar2stubs.controllers.actions.AuthActionFilter
import uk.gov.hmrc.pillar2stubs.utils.ResourceHelper.resourceAsString
import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController

import javax.inject.{Inject, Singleton}
import scala.concurrent.Future
import java.time.ZonedDateTime
import java.time.ZoneOffset
import play.api.mvc.Result
import uk.gov.hmrc.pillar2stubs.models.UKTRSubmissionRequest

@Singleton
class UkTaxReturnController @Inject() (
cc: ControllerComponents,
authFilter: AuthActionFilter
) extends BackendController(cc)
with Logging {

def submitUktr: Action[UKTRSubmissionRequest] = (Action(parse.json[UKTRSubmissionRequest]) andThen authFilter).async { implicit request =>
request.headers.get("X-Pillar2-Id") match {
case None =>
logger.warn("No PLR Reference provided in headers")
returnErrorResponse("uktaxreturn/MissingPLRResponse.json", 400)

case Some(plrReference) => handleSubmission(plrReference)
}
}

private def handleSubmission(plrReference: String): Future[Result] =
plrReference match {
case "XTC01234123412" => returnSuccessResponse("uktaxreturn/SuccessResponse.json")
case "XEPLR1066196400" => returnErrorResponse("uktaxreturn/InvalidRequestResponse.json", 400)
case "XEPLR1066196401" => Future.successful(Unauthorized)
case "XEPLR1066196403" => Future.successful(Forbidden)
case "XEPLR1066196404" => Future.successful(NotFound)
case "XEPLR1066196415" => Future.successful(UnsupportedMediaType)
case "XEPLR1066196422" => returnErrorResponse("uktaxreturn/UnprocessableEntityResponse.json", 422)
case "XEPLR1066196500" => returnErrorResponse("uktaxreturn/InternalServerErrorResponse.json", 500)
case _ =>
returnSuccessResponse("uktaxreturn/SuccessResponse.json")
}

private def returnSuccessResponse(filename: String): Future[Result] = {
val response = resourceAsString(s"/resources/$filename")
.map(replaceDate(_, getCurrentTimestamp))
.map(Json.parse)
.getOrElse(Json.obj("error" -> "Response not found"))

logger.info(s"Returning success response for $filename")
Future.successful(Created(response).as("application/json"))
}

private def returnErrorResponse(filename: String, status: Int): Future[Result] = {
val response = resourceAsString(s"/resources/$filename")
.map(replaceDate(_, getCurrentTimestamp))
.map(Json.parse)
.getOrElse(Json.obj("error" -> "Error response not found"))

Future.successful(Status(status)(response))
}

private def getCurrentTimestamp: String =
ZonedDateTime.now(ZoneOffset.UTC).toString

private def replaceDate(response: String, newDate: String): String =
response.replace("2022-01-31T09:26:17Z", newDate)
}
4 changes: 1 addition & 3 deletions app/uk/gov/hmrc/pillar2stubs/models/LiableEntity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ case class LiableEntity(
idType: String,
idValue: String,
amountOwedDTT: BigDecimal,
electedDTT: Boolean,
amountOwedIIR: BigDecimal,
amountOwedUTPR: BigDecimal,
electedUTPR: Boolean
amountOwedUTPR: BigDecimal
)

object LiableEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import scala.util.Try
case class UKTRSubmissionRequest(
accountingPeriodFrom: String,
accountingPeriodTo: String,
qualifyingGroup: Boolean,
obligationDTT: Boolean,
obligationMTT: Boolean,
electionUKGAAP: Boolean,
liabilities: Liability
Expand All @@ -47,8 +45,6 @@ object UKTRSubmissionRequest {
implicit val reads: Reads[UKTRSubmissionRequest] = (
(JsPath \ "accountingPeriodFrom").read[String] and
(JsPath \ "accountingPeriodTo").read[String] and
(JsPath \ "qualifyingGroup").read[Boolean] and
(JsPath \ "obligationDTT").read[Boolean] and
(JsPath \ "obligationMTT").read[Boolean] and
(JsPath \ "electionUKGAAP").read[Boolean] and
(JsPath \ "liabilities").read[Liability]
Expand Down
Loading