Skip to content

Commit bc80f47

Browse files
authored
Merge pull request #7 from companieshouse/PCI-605-patch-payment-endpoint
added PATCH /basket/checkout endpoint
2 parents acccd85 + 6b867c6 commit bc80f47

File tree

6 files changed

+131
-3
lines changed

6 files changed

+131
-3
lines changed

src/main/java/uk/gov/companieshouse/orders/api/controller/BasketController.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.springframework.http.HttpStatus;
44
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.PatchMapping;
6+
import org.springframework.web.bind.annotation.PathVariable;
57
import org.springframework.web.bind.annotation.PostMapping;
68
import org.springframework.web.bind.annotation.RequestBody;
79
import org.springframework.web.bind.annotation.RequestHeader;
@@ -10,6 +12,7 @@
1012
import uk.gov.companieshouse.logging.LoggerFactory;
1113
import uk.gov.companieshouse.orders.api.dto.AddToBasketRequestDTO;
1214
import uk.gov.companieshouse.orders.api.dto.AddToBasketResponseDTO;
15+
import uk.gov.companieshouse.orders.api.dto.BasketPaymentRequestDTO;
1316
import uk.gov.companieshouse.orders.api.exception.ConflictException;
1417
import uk.gov.companieshouse.orders.api.mapper.BasketMapper;
1518
import uk.gov.companieshouse.orders.api.model.ApiError;
@@ -113,7 +116,15 @@ public ResponseEntity<?> checkoutBasket(@RequestBody(required = false) String js
113116
Checkout checkout = checkoutService.createCheckout(item, EricHeaderHelper.getIdentity(request));
114117
trace("Successfully created checkout with id "+checkout.getId(), requestId);
115118

116-
return ResponseEntity.status(HttpStatus.OK).body(null);
119+
return ResponseEntity.status(HttpStatus.OK).body(checkout);
120+
}
121+
122+
@PatchMapping("${uk.gov.companieshouse.orders.api.basket.payment}/{id}")
123+
public ResponseEntity<String> patchBasketPaymentDetails(final @RequestBody BasketPaymentRequestDTO basketPaymentRequestDTO,
124+
final @PathVariable String id,
125+
final @RequestHeader(REQUEST_ID_HEADER_NAME) String requestId) {
126+
trace("ENTERING patchBasketPaymentDetails(" + basketPaymentRequestDTO + ", " + id + ", " + requestId + ")", requestId);
127+
return ResponseEntity.ok("");
117128
}
118129

119130
/**
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package uk.gov.companieshouse.orders.api.dto;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
public class BasketPaymentRequestDTO {
6+
7+
@JsonProperty("paid_at")
8+
private String paidAt;
9+
10+
@JsonProperty("payment_reference")
11+
private String paymentReference;
12+
13+
@JsonProperty("status")
14+
private String status;
15+
16+
public String getPaidAt() {
17+
return paidAt;
18+
}
19+
20+
public void setPaidAt(String paidAt) {
21+
this.paidAt = paidAt;
22+
}
23+
24+
public String getPaymentReference() {
25+
return paymentReference;
26+
}
27+
28+
public void setPaymentReference(String paymentReference) {
29+
this.paymentReference = paymentReference;
30+
}
31+
32+
public String getStatus() {
33+
return status;
34+
}
35+
36+
public void setStatus(String status) {
37+
this.status = status;
38+
}
39+
}

src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ uk.gov.companieshouse.orders.api.health=/healthcheck
22
uk.gov.companieshouse.orders.api.basket=/basket
33
uk.gov.companieshouse.orders.api.basket.items=/basket/items
44
uk.gov.companieshouse.orders.api.basket.checkout=/basket/checkout
5+
uk.gov.companieshouse.orders.api.basket.payment=/basket/payment
56
spring.data.mongodb.uri=${MONGODB_URL}
67
spring.data.mongodb.field-naming-strategy=uk.gov.companieshouse.orders.api.model.NoIsSnakeCaseFieldNamingStrategy

src/test/java/uk/gov/companieshouse/orders/api/controller/BasketControllerIntegrationTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.springframework.http.MediaType;
1313
import org.springframework.test.web.servlet.MockMvc;
1414
import uk.gov.companieshouse.orders.api.dto.AddToBasketRequestDTO;
15+
import uk.gov.companieshouse.orders.api.dto.BasketPaymentRequestDTO;
1516
import uk.gov.companieshouse.orders.api.model.Basket;
1617
import uk.gov.companieshouse.orders.api.model.BasketData;
1718
import uk.gov.companieshouse.orders.api.model.BasketItem;
@@ -31,6 +32,7 @@
3132
import static org.mockito.ArgumentMatchers.any;
3233
import static org.mockito.Mockito.doAnswer;
3334
import static org.mockito.Mockito.when;
35+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
3436
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
3537
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
3638
import static uk.gov.companieshouse.orders.api.util.TestConstants.*;
@@ -236,4 +238,19 @@ public void checkoutBasketReturnsBadRequestIfBodyIsPresent() throws Exception {
236238
assertEquals(0, checkoutRepository.count());
237239
}
238240

241+
@Test
242+
@DisplayName("Patch basket payment details returns OK")
243+
public void patchBasketPaymentDetailsReturnsOK() throws Exception {
244+
BasketPaymentRequestDTO basketPaymentRequestDTO = new BasketPaymentRequestDTO();
245+
basketPaymentRequestDTO.setPaidAt("paid-at");
246+
basketPaymentRequestDTO.setPaymentReference("reference");
247+
basketPaymentRequestDTO.setStatus("status");
248+
249+
mockMvc.perform(patch("/basket/payment/1234")
250+
.header(REQUEST_ID_HEADER_NAME, TOKEN_REQUEST_ID_VALUE)
251+
.header(ERIC_IDENTITY_HEADER_NAME, ERIC_IDENTITY_VALUE)
252+
.contentType(MediaType.APPLICATION_JSON)
253+
.content(mapper.writeValueAsString(basketPaymentRequestDTO)))
254+
.andExpect(status().isOk());
255+
}
239256
}

src/test/postman/Orders_API.postman_collection.json

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,65 @@
9999
],
100100
"protocolProfileBehavior": {},
101101
"_postman_isSubFolder": true
102+
},
103+
{
104+
"name": "Update basket payment details",
105+
"item": [
106+
{
107+
"name": "Update basket payment details",
108+
"event": [
109+
{
110+
"listen": "prerequest",
111+
"script": {
112+
"id": "b7689c29-3b53-4386-a18c-419ccc5f5486",
113+
"exec": [
114+
""
115+
],
116+
"type": "text/javascript"
117+
}
118+
}
119+
],
120+
"request": {
121+
"method": "PATCH",
122+
"header": [
123+
{
124+
"key": "Content-Type",
125+
"name": "Content-Type",
126+
"value": "application/json",
127+
"type": "text"
128+
},
129+
{
130+
"key": "X-Request-ID",
131+
"value": "f058ebd6-02f7-4d3f-942e-904344e8cde5",
132+
"type": "text"
133+
}
134+
],
135+
"body": {
136+
"mode": "raw",
137+
"raw": "{\n \"paid_at\": \"2020-02-21T09:29:27.907\",\n \"payment_reference\": \"1234\",\n \"status\": \"paid\"\n}",
138+
"options": {
139+
"raw": {
140+
"language": "json"
141+
}
142+
}
143+
},
144+
"url": {
145+
"raw": "{{base_url}}/basket/payment/5e4ba64068f0760f8ff5487f",
146+
"host": [
147+
"{{base_url}}"
148+
],
149+
"path": [
150+
"basket",
151+
"payment",
152+
"5e4ba64068f0760f8ff5487f"
153+
]
154+
}
155+
},
156+
"response": []
157+
}
158+
],
159+
"protocolProfileBehavior": {},
160+
"_postman_isSubFolder": true
102161
}
103162
],
104163
"protocolProfileBehavior": {}
@@ -109,7 +168,7 @@
109168
"oauth2": [
110169
{
111170
"key": "accessToken",
112-
"value": "ypFJGPtGbQrsfJeu4CJnBt5uStpWPlZwW1QnMq6PAf2rWGvOAfTrgjxG0d_1wfeE9FZQY2Q7cH3-2-bal6lRkw",
171+
"value": "ik80a25WfxmX_FIolAiyOjUJbamxnNfz8Dfsza5Un5clMIYF1stVLVavr1siijkQQdr3NY_Ze2W7ydqG7bpWiQ",
113172
"type": "string"
114173
},
115174
{
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
uk.gov.companieshouse.orders.api.health=/healthcheck
22
uk.gov.companieshouse.orders.api.basket=/basket
33
uk.gov.companieshouse.orders.api.basket.items=/basket/items
4-
uk.gov.companieshouse.orders.api.basket.checkout=/basket/checkout
4+
uk.gov.companieshouse.orders.api.basket.checkout=/basket/checkout
5+
uk.gov.companieshouse.orders.api.basket.payment=/basket/payment

0 commit comments

Comments
 (0)