Sending support information for a delivery service (Java)

In this use case, the user contacts the delivery support against an active or completed delivery. As a response, the user is provided the phone number or email to the customer support or sometimes redirected to a chat window.

Support

Code snippets

BPP receives protocol support

/*
Example Request JSON:
{
    "context": {
        "domain": "delivery",
        "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-06-23T08:22:44.059Z"
    },
    "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 = supportDelivery(orderSupport);

        //invoke on_support api
        return invokeOnSupport(onSupportRequest, headers);
    }
}

BPP generates response

/*
Example Response JSON:
{
    "context": {
        "domain": "delivery",
        "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-06-23T08:24:26.519Z"
    },
    "message": {
        "phone": "+919898989898",
        "email": "[email protected]",
        "uri": "http://support.bpp.com?order_id=order_id"
    }
}
*/
    public OnSupportRequest supportDelivery(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);
        }
    }