Sending support information for a pharmacy regarding an order (Java)
In this use case, the user wants to contact the customer support due to an issue with the order. Here the pharmacy returns the customer support info of the pharmacy
Code snippets
BPP receives protocol support
/*
Example Request JSON:
{
"context": {
"domain": "nic2004:52311",
"country": "IND",
"city": "std:080",
"action": "support",
"core_version": "0.9.2",
"bap_id": "https://mock_bap.com/",
"bap_uri": "https://mock_bap.com/beckn/",
"transaction_id": "1239890342",
"message_id": "123793824",
"timestamp": "2021-03-23T10:00:40.065Z"
},
"message": {
"ref_id": "order_1"
}
}
*/
// BPP Support Endpoint
@PostMapping("/bpp/support")
public ResponseEntity support(
@RequestHeader HttpHeaders headers,
@RequestBody SupportRequest request) {
var response = bppApplicationService.support(request, headers);
return ResponseEntity.ok(response);
}
BPP processes the support
public Response support(SupportRequest request, HttpHeaders headers) {
var onSupportRequest = new OnSupportRequest();
// Validate the headers
var isHeadersValid = validateHeaders(headers);
// Construct and return error
if (!isHeadersValid) return null;
// support contact for the given order
var orderSupport = request.getMessage().getRefId();
// Execute business logic here
// Generate the response
onSupportRequest = orderSupport(orderSupport);
//invoke on_support api
return invokeOnSupport(onSupportRequest, headers);
}
}
BPP generates response
/*
Example Response JSON:
{
"context": {
"domain": "nic2004:52311",
"country": "IND",
"city": "std:080",
"action": "on_support",
"core_version": "0.9.2",
"bap_id": "https://mock_bap.com/",
"bap_uri": "https://mock_bap.com/beckn/",
"transaction_id": "1239890342",
"message_id": "123793824",
"timestamp": "2021-03-23T10:00:40.065Z"
},
"message": {
"phone": "+919898989898",
"email": "[email protected]",
"uri": "http://support.bpp.com?order_id=1"
}
}
*/
public OnSupportRequest orderSupport(SupportContact support) {
var supportResult = SupportResponseBuilder.builder.result(support).build();
// Convert response into protocol object similar to example above
return supportResult;
}
BPP calls protocol on_support
public Response invokeOnSupport(OnSupportRequest supportResponse, HttpHeaders headers) {
if(supportResponse.getError() == null) {
// Call BAP on_support api with the order response
// Call to look up function which returns the the public key and BAP Endpoint to be called
var url = lookUp(headers);
// Call BAP on_support with the support contact details
var response = apiClient.post(url[0] + Context.ActionEnum.on_support,
constructResponseHeaders(),
supportResponse,
OnSupportRequest.class);
return Response.of("ACK", null);
} else {
return Response.of("NACK", null);
}
}