Skip to content

Commit a3e7b39

Browse files
authored
Merge pull request #4086 from alphagov/PP-14842-add_new_endpoint
PP-14842 add new endpoint
2 parents 7b50998 + 21ace5b commit a3e7b39

5 files changed

Lines changed: 154 additions & 9 deletions

File tree

.secrets.baseline

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,21 @@
118118
"filename": "openapi/ledger_spec.yaml",
119119
"hashed_secret": "cbbaa15cf3814df641e9ee9cb279046f93f322eb",
120120
"is_verified": false,
121-
"line_number": 1245
121+
"line_number": 1282
122122
},
123123
{
124124
"type": "Hex High Entropy String",
125125
"filename": "openapi/ledger_spec.yaml",
126126
"hashed_secret": "9baeb3f7db14ddab5d172149762035c0c022d76d",
127127
"is_verified": false,
128-
"line_number": 1680
128+
"line_number": 1717
129129
},
130130
{
131131
"type": "Hex High Entropy String",
132132
"filename": "openapi/ledger_spec.yaml",
133133
"hashed_secret": "920734ed7628ef47739eed5571412e2c8271790f",
134134
"is_verified": false,
135-
"line_number": 1756
135+
"line_number": 1793
136136
}
137137
],
138138
"src/main/java/uk/gov/pay/ledger/event/model/Event.java": [
@@ -163,5 +163,5 @@
163163
}
164164
]
165165
},
166-
"generated_at": "2025-11-25T14:02:48Z"
166+
"generated_at": "2026-01-05T13:22:49Z"
167167
}

openapi/ledger_spec.yaml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,47 @@ paths:
838838
CSV (with Accept header="text/csv"). Refer to code for details
839839
tags:
840840
- Transactions
841-
/v1/transaction/gateway-transaction/{gatewayTransactionId}:
841+
/v1/transaction/gateway-transaction:
842842
get:
843843
operationId: findByGatewayTransactionId
844844
parameters:
845+
- description: Transaction ID from payment provider
846+
example: a14f0926-b44d-4160-8184-1b1f66e576ab
847+
in: query
848+
name: gateway_transaction_id
849+
required: true
850+
schema:
851+
type: string
852+
- example: sandbox
853+
in: query
854+
name: payment_provider
855+
required: true
856+
schema:
857+
type: string
858+
responses:
859+
"200":
860+
content:
861+
application/json; qs=1:
862+
schema:
863+
$ref: "#/components/schemas/TransactionView"
864+
description: OK
865+
"404":
866+
description: Not found
867+
"422":
868+
content:
869+
application/json; qs=1:
870+
schema:
871+
$ref: "#/components/schemas/ErrorResponse"
872+
description: If payment_provider and/or gateway_transaction_id query parameter
873+
is missing
874+
summary: Get transaction for a gateway transaction ID
875+
tags:
876+
- Transactions
877+
/v1/transaction/gateway-transaction/{gatewayTransactionId}:
878+
get:
879+
deprecated: true
880+
operationId: findByGatewayTransactionIdLegacy
881+
parameters:
845882
- description: Transaction ID from payment provider
846883
example: a14f0926-b44d-4160-8184-1b1f66e576ab
847884
in: path

src/main/java/uk/gov/pay/ledger/transaction/resource/TransactionResource.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,31 @@ public TransactionsForTransactionResponse getTransactionsForParentTransaction(
269269
@ApiResponse(responseCode = "404", description = "Not found")
270270
}
271271
)
272-
public TransactionView findByGatewayTransactionId(@Parameter(example = "a14f0926-b44d-4160-8184-1b1f66e576ab", description = "Transaction ID from payment provider")
272+
@Deprecated
273+
public TransactionView findByGatewayTransactionIdLegacy(@Parameter(example = "a14f0926-b44d-4160-8184-1b1f66e576ab", description = "Transaction ID from payment provider")
273274
@PathParam("gatewayTransactionId") String gatewayTransactionId,
274275
@Parameter(example = "sandbox", required = true) @QueryParam("payment_provider") @NotEmpty String paymentProvider
275276
) {
276277
return transactionService.findByGatewayTransactionId(gatewayTransactionId, paymentProvider)
277278
.orElseThrow(() -> new WebApplicationException(Response.Status.NOT_FOUND));
278279
}
280+
281+
@Path("/gateway-transaction")
282+
@GET
283+
@Timed
284+
@Operation(
285+
summary = "Get transaction for a gateway transaction ID",
286+
responses = {
287+
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = TransactionView.class))),
288+
@ApiResponse(responseCode = "422", description = "If payment_provider and/or gateway_transaction_id query parameter is missing", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
289+
@ApiResponse(responseCode = "404", description = "Not found")
290+
}
291+
)
292+
public TransactionView findByGatewayTransactionId(@Parameter(example = "a14f0926-b44d-4160-8184-1b1f66e576ab", description = "Transaction ID from payment provider", required = true)
293+
@QueryParam("gateway_transaction_id") @NotEmpty String gatewayTransactionId,
294+
@Parameter(example = "sandbox", required = true) @QueryParam("payment_provider") @NotEmpty String paymentProvider
295+
) {
296+
return transactionService.findByGatewayTransactionId(gatewayTransactionId, paymentProvider)
297+
.orElseThrow(() -> new WebApplicationException(Response.Status.NOT_FOUND));
298+
}
279299
}

src/test/java/uk/gov/pay/ledger/transaction/resource/TransactionResourceIT.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ public void returnedTransactionsShould_haveCorrectSourceAndLive() {
556556
}
557557

558558
@Test
559-
public void getByGatewayTransactionId_shouldReturnCorrectTransaction() {
559+
public void getByGatewayTransactionIdLegacy_shouldReturnCorrectTransaction() {
560560

561561
String gatewayTransactionIdParam = RandomStringUtils.randomAlphanumeric(20);
562562
String gatewayAccountId = RandomStringUtils.randomNumeric(5);
@@ -592,6 +592,43 @@ public void getByGatewayTransactionId_shouldReturnCorrectTransaction() {
592592
.body("payment_provider", is("sandbox"));
593593
}
594594

595+
@Test
596+
public void getByGatewayTransactionId_shouldReturnCorrectTransaction() {
597+
598+
String gatewayTransactionIdParam = RandomStringUtils.randomAlphanumeric(20);
599+
String gatewayAccountId = RandomStringUtils.randomNumeric(5);
600+
601+
TransactionFixture shouldExcludeThisTransaction = aTransactionFixture()
602+
.withGatewayAccountId(RandomStringUtils.randomNumeric(5))
603+
.withDefaultTransactionDetails()
604+
.insert(rule.getJdbi());
605+
TransactionFixture shouldExcludeThisTransactionToo = aTransactionFixture()
606+
.withGatewayAccountId(gatewayAccountId)
607+
.withGatewayTransactionId("random-gateway-transaction-id")
608+
.withPaymentProvider("random-provider")
609+
.withDefaultTransactionDetails()
610+
.insert(rule.getJdbi());
611+
TransactionFixture transaction = aTransactionFixture()
612+
.withGatewayAccountId(gatewayAccountId)
613+
.withGatewayTransactionId(gatewayTransactionIdParam)
614+
.withPaymentProvider("sandbox")
615+
.withDefaultTransactionDetails()
616+
.insert(rule.getJdbi());
617+
618+
given().port(port)
619+
.contentType(JSON)
620+
.accept(JSON)
621+
.get("/v1/transaction/gateway-transaction?gateway_transaction_id=" + gatewayTransactionIdParam +
622+
"&payment_provider=sandbox"
623+
)
624+
.then()
625+
.statusCode(Response.Status.OK.getStatusCode())
626+
.contentType(JSON)
627+
.body("gateway_account_id", is(transaction.getGatewayAccountId()))
628+
.body("gateway_transaction_id", is(transaction.getGatewayTransactionId()))
629+
.body("payment_provider", is("sandbox"));
630+
}
631+
595632
@Test
596633
public void shouldGetDisputeTransaction() {
597634
var createdDate = ZonedDateTime.parse("2022-06-08T11:22:48.822408Z");

src/test/java/uk/gov/pay/ledger/transaction/resource/TransactionResourceTest.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void findTransactionsForTransactionShouldReturn400IfGatewayAccountIdIsNot
131131
}
132132

133133
@Test
134-
public void findByGatewayTransactionId_ShouldReturn404IfTransactionNotFound() {
134+
public void findByGatewayTransactionIdLegacy_ShouldReturn404IfTransactionNotFound() {
135135
when(mockTransactionService.findByGatewayTransactionId(anyString(), anyString()))
136136
.thenReturn(Optional.empty());
137137

@@ -145,7 +145,22 @@ public void findByGatewayTransactionId_ShouldReturn404IfTransactionNotFound() {
145145
}
146146

147147
@Test
148-
public void findByGatewayTransactionId_ShouldReturn400IfPaymentProviderQueryParamIsEmpty() {
148+
public void findByGatewayTransactionId_ShouldReturn404IfTransactionNotFound() {
149+
when(mockTransactionService.findByGatewayTransactionId(anyString(), anyString()))
150+
.thenReturn(Optional.empty());
151+
152+
Response response = resources
153+
.target("/v1/transaction/gateway-transaction")
154+
.queryParam("gateway_transaction_id", "example-gateway-transaction-id")
155+
.queryParam("payment_provider", "sandbox")
156+
.request()
157+
.get();
158+
159+
assertThat(response.getStatus(), is(404));
160+
}
161+
162+
@Test
163+
public void findByGatewayTransactionIdLegacy_ShouldReturn400IfPaymentProviderQueryParamIsEmpty() {
149164
Response response = resources
150165
.target("/v1/transaction/gateway-transaction/exampleGatewayTransactionId")
151166
.queryParam("transaction_type", "PAYMENT")
@@ -160,6 +175,42 @@ public void findByGatewayTransactionId_ShouldReturn400IfPaymentProviderQueryPara
160175
assertThat(errors.get(0), is("query param payment_provider must not be empty"));
161176
}
162177

178+
@Test
179+
public void findByGatewayTransactionId_ShouldReturn400IfPaymentProviderQueryParamIsEmpty() {
180+
Response response = resources
181+
.target("/v1/transaction/gateway-transaction")
182+
.queryParam("gateway_transaction_id", "exampleGatewayTransactionId")
183+
.queryParam("transaction_type", "PAYMENT")
184+
.request()
185+
.get();
186+
187+
Map responseMessage = response.readEntity(new GenericType<HashMap>() {
188+
});
189+
List errors = (List) responseMessage.get("errors");
190+
191+
assertThat(response.getStatus(), is(400));
192+
assertThat(errors.get(0), is("query param payment_provider must not be empty"));
193+
}
194+
195+
@Test
196+
public void findByGatewayTransactionId_ShouldReturn400IfGatewayTransactionIdQueryParamIsEmpty() {
197+
when(mockTransactionService.findByGatewayTransactionId(anyString(), anyString()))
198+
.thenReturn(Optional.empty());
199+
200+
Response response = resources
201+
.target("/v1/transaction/gateway-transaction")
202+
.queryParam("payment_provider", "sandbox")
203+
.request()
204+
.get();
205+
206+
Map responseMessage = response.readEntity(new GenericType<HashMap>() {
207+
});
208+
List errors = (List) responseMessage.get("errors");
209+
210+
assertThat(response.getStatus(), is(400));
211+
assertThat(errors.get(0), is("query param gateway_transaction_id must not be empty"));
212+
}
213+
163214
@Test
164215
public void searchTransactionForCsvShouldReturn400IfGatewayAccountIdIsNotAvailable() {
165216
Response response = resources

0 commit comments

Comments
 (0)