Procard
Overview
The provided routes define a /procard API group for managing procard applications. They include endpoints for health checks, retrieving draft applications, checking active applications, saving drafts, submitting applications, and matching principles. Each route is associated with methods in the ProcardApplicationController to handle specific functionality. This structure facilitates organized management of procard-related operations in the application.
Get Draft Application
- Route:
GET ../procard/application/draft - Controller:
ProcardApplicationController - Method:
show - Request:
ProcardDraftApplicationRequest - Description: Endpoint to retrieve the draft application for a customer.
The show method in the ProcardApplicationController fetches the draft application associated with the authenticated user. It calls the getDraftApplicationForCustomer method from the application service, passing the user's ID and the application types for Procard and Procard Zero.
Upon successfully retrieving the draft application, the method returns an ApplicationResource, which formats the application data appropriately for the response.
Check for Active Application
- Route:
GET ../procard/application/is-active - Controller:
ProcardApplicationController - Method:
hasActiveApplication - Request:
ProcardHasActiveApplicationRequest - Description: Endpoint to check if the user has an active Procard application.
The hasActiveApplication method in the ProcardApplicationController checks whether the authenticated user has an active application of type Procard. It utilizes the hasActiveApplication method on the user model, passing the application type for Procard.
The method returns a JSON response indicating whether an active application exists, with a status of 200 OK.
Save Procard Application
- Route:
PUT ../procard/application/save - Controller:
ProcardApplicationController - Method:
save - Request:
ProcardSaveApplicationRequest - Description: Endpoint to save progress on a Procard application.
The save method in the ProcardApplicationController handles saving the progress of a Procard application. It retrieves the requested data from the incoming request and adds the authenticated user's ID to the data array. Next, it determines the application type using the getApplicationType method. Before saving the application, it checks for any existing active applications for the user using the checkForActiveApplication method.
Finally, the method calls the saveProgress method from the application service to save the application data and returns an ApplicationResource containing the saved application.
Submit Procard Application
- Route:
POST ../procard/application - Controller:
ProcardApplicationController - Method:
submit - Request:
ProcardSubmitApplicationRequest - Description: Endpoint to submit a Procard application.
The submit method in the ProcardApplicationController is responsible for handling the submission of a Procard application. It validates the incoming request data and determines the application type.
The application status is set to APPROVED if the application type is PROCARD_ZERO, otherwise it is set to PENDING. The method then attempts to retrieve any existing draft application for the user. If a draft exists, it updates the draft with the new data; if not, it creates a new application.
After logging the submission details, if the application type is PROCARD_ZERO, the method also creates a Procard Zero account for the customer.
Finally, it returns an ApplicationResource containing the submitted application.
Match Company Principle
- Route:
POST ../procard/match-principle - Controller:
ProcardApplicationController - Method:
matchPrinciple - Request:
MatchPrincipleRequest - Description: Endpoint to match a company's principle based on provided DUNS and name.
The matchPrinciple method in the ProcardApplicationController is responsible for matching a company's principle using the provided DUNS number and name.
Upon receiving a request, the method attempts to build a dataset of principles associated with the given DUNS number. If successful, it checks if the specified company name matches any principles in the dataset.
In case of a successful match, the matched principle data is returned; otherwise, it returns false. If there’s an error during the request to the external service or in processing, appropriate error messages are logged and returned in the response.