Routes

Trolley

Overview

The provided routes define a /trolleys API group for managing trolleys in the application. They include endpoints for health checks, retrieving, updating, and deleting trolleys, as well as managing trolley lines, applying promo codes, sharing trolleys by email, and handling delivery methods. Additional functionalities cover pickup points, order totals, and converting guest trolleys to customer trolleys. Each route is linked to specific controller methods that facilitate organized handling of trolley-related operations.


Get Trolley Details

  • Route: GET ../trolleys/{trolleyId}
  • Controller: TrolleyController
  • Method: get
  • Request: ViewTrolleyRequest
  • Description: Endpoint to retrieve the Trolley associated with a specific trolleyId.

The get method in the TrolleyController retrieves the Trolley for a specified trolleyId. It first fetches the trolley using the validated request data. If successful, it logs a debug message indicating that the trolley was fetched, including the trolley ID and the associated customer ID. Finally, it returns a TrolleyResource, which formats the trolley data appropriately for the response.

Request Parameters for :

  • Header :- X-Toolstation-Customer-ID:- Token

Response:-

Status: 201 Created


"data": {
"id": "e46fb955-XXXXXXXXXXX",
"customer_id": null,
"session_id": "5621cCXXXXXXGYTDXX9",
"status": 1,
"name": null,
"created_at": "2024-07-22T09:15:00+02:00",
"updated_at": "2024-07-22T09:15:00+02:00",
"lines": [
{
"id": 12873XXX,
"product_code": "95214XX",
"quantity": 1,
"channel": 1,
"product_channel": 0,
"delivery_method_code": null,
"created_at": "2024-07-24T15:29:35+02:00",
"updated_at": "2024-07-24T16:12:21+02:00"
},
{
"id": 12873XX,
"product_code": "77855XX",
"quantity": 3,
"channel": 1,
"product_channel": 4,
"delivery_method_code": null,
"created_at": "2024-07-24T16:25:17+02:00",
"updated_at": "2024-07-24T16:39:13+02:00"
},
{
"id": 1287XX,
"product_code": "6690XX0",
"quantity": 1,
"channel": 1,
"product_channel": 4,
"delivery_method_code": null,
"created_at": "2024-07-24T16:25:41+02:00",
"updated_at": "2024-07-24T16:27:09+02:00"
}
],
"attributes": [],
"applied_promo_codes": [],
"session_token": "XXX",
"order_id": null,
"ordered_at": null
}
  

Update Trolley Details

  • Route: PATCH ../trolleys/{trolleyId}
  • Controller: TrolleyController
  • Method: update
  • Request: UpdateTrolleyRequest
  • Description: Endpoint to update the Trolley associated with a specific trolleyId.

The update method in the TrolleyController handles the updating of a trolley identified by its trolleyId. It fetches the trolley, logs relevant information, and updates its status using the trolleyService. If successful, it returns a 204 No Content response. In case of errors, it logs the exception details and returns a 422 Unprocessable Entity response. The UpdateTrolleyRequest class ensures authorization and validates the incoming request data.


Delete Trolley

  • Route: DELETE ../trolleys/{trolleyId}
  • Controller: TrolleyController
  • Method: destroy
  • Request: DeleteTrolleyRequest
  • Description: Endpoint to delete a Trolley associated with a specific trolleyId.

The destroy method in the TrolleyController deletes a trolley identified by its trolleyId. It fetches the trolley and logs relevant information before calling the trolleyService to perform the deletion. Upon success, it returns a 204 No Content response. The DeleteTrolleyRequest class ensures the user is authorized to delete the trolley. No additional validation rules are required for the deletion request.


Create New Trolley Line

  • Route: POST ../trolleys/{trolleyId}/lines
  • Controller: TrolleyController
  • Method: createNewTrolleyLine
  • Request: CreateTrolleyLineRequest
  • Description: Endpoint to add a new line item to a trolley associated with a specific trolleyId.

The createNewTrolleyLine method in the TrolleyController adds a new line item to the trolley identified by its trolleyId. It validates the request using the CreateTrolleyLineRequest, ensuring the user is authorized to update the trolley and that the product code and quantity adhere to specific validation rules. The method checks for the existence of the product, the minimum and maximum quantity constraints, and the correct delivery channel before adding the line. If validation passes, the trolley line is created successfully.

Request Parameters for :

  • Header :- X-Toolstation-Customer-ID:- Token

Body :-

  • product_code: Product Code (String, required).
  • quantity: Quantity Number
  • channel: channel Id

Response:-

Status: 403 Forbidden

{
403 Forbidden
}
  

Apply Promo-code to Trolley

  • Route: POST ../trolleys/{trolleyId}/promo-codes
  • Controller: TrolleyController
  • Method: applyNewPromoCode
  • Request: ApplyPromoCodeRequest
  • Description: Endpoint to apply a Promo-Code to a trolley associated with a specific trolleyId and customerId.

The applyNewPromoCode method in the TrolleyController is responsible for applying a new promo code to the trolley identified by its trolleyId. It first logs the request details, including the promo code being applied. The method checks for duplicate requests by verifying if the promo code has already been applied to the trolley. If a duplicate request is detected, it responds with a 409 Conflict status.


Share Trolley by Email

  • Route: POST ../trolleys/{trolleyId}/share-by-email
  • Controller: ShareTrolleyByEmailController
  • Method: __invoke
  • Request: ShareTrolleyByEmailRequest
  • Description: Endpoint to share a trolley via email to a specified recipient associated with a specific trolleyId.

The __invoke method in the ShareTrolleyByEmailController allows a user to share a trolley identified by its trolleyId with a specified email address. It logs the recipient's email address and attempts to retrieve the trolley using the trolleyService. If successful, it checks the user's authorization to view the trolley and logs the successful retrieval and If the trolley is found, the method proceeds to share the trolley by email using the shareTrolleyService. If the trolley is not found, it catches the TrolleyNotFoundException, logs the incident, and returns a 404 Not Found response. Upon successful sharing, the method returns a 204 No Content response, indicating that the request was processed without any content returned.

Request Parameters for :

  • Header :- X-Toolstation-Customer-ID:- Token

Response:-

Status: 204 No Content


Get Delivery Methods

  • Route: GET ../trolleys/{trolleyId}/delivery-methods
  • Controller: DeliveryMethodsController
  • Method: __invoke
  • Request: DeliveryMethodsRequest
  • Description: Endpoint to retrieve available delivery methods for a trolley associated with a specific trolleyId.

The __invoke method in the DeliveryMethodsController retrieves the available delivery methods for the trolley identified by its trolleyId. It attempts to fetch the trolley using the trolleyService, and if not found, it aborts the request with a 404 Not Found response. The method then collects the channels of the trolley lines and checks if collection or delivery options are available. If the trolley includes collection channels, it validates that a collection_address_id is provided in the request. Similarly, if delivery channels are present, it validates that a delivery_address_id is included. Before returning the delivery methods, the method checks if the requesting user is authorized to view the trolley. Finally, it returns a collection of delivery methods using the DeliveryMethodsResource, providing the user with the available options for their trolley.


Check Discounts

  • Route: POST ../trolleys/{trolleyId}/check-discounts
  • Controller: TrolleyDiscountController
  • Method: __invoke
  • Request: TrolleyDiscountRequest
  • Description: Endpoint to check available discounts for a trolley associated with a specific trolleyId.

The __invoke method in the TrolleyDiscountController checks for available discounts on the trolley identified by its trolleyId. It first attempts to retrieve the trolley using the trolleyService, and if not found, it logs the incident and returns a 404 Not Found response. The method then authorizes the request to ensure the user has permission to view the trolley. If discount data is provided in the request, it processes this data to retrieve relevant discounts. If no discount data is provided, it defaults to fetching discounts based on the trolley and other parameters such as branch ID and discount token.

Request Parameters for :

  • Header :- X-Toolstation-Customer-ID:- Token

Response:-

Status: 500Internal Server Error

"error": {
      "code": "500.99",
      "message": "Internal Server Error",
      "info": "https://developers.example.com",
      "data": null
  }
  

Get Order Totals

  • Route: POST ../trolleys/{trolleyId}/order-totals
  • Controller: TrolleyTotalsController
  • Method: __invoke
  • Request: TrolleyTotalsRequest
  • Description: Endpoint to calculate and retrieve the order totals for a trolley associated with a specific trolleyId.

The __invoke method in the TrolleyTotalsController calculates the order totals for the trolley identified by its trolleyId. It starts by logging relevant request details, such as branch ID, discount token, and any ignored promotions. The method then attempts to retrieve the trolley using the trolleyService, and if the trolley is not found, it logs the incident and returns a 404 Not Found response, After confirming that the user is authorized to view the trolley, the method fetches any applicable discounts using the trolleyDiscountHelpers. Finally, it builds and returns the order totals in a JSON format, containing the calculated totals based on the trolley and associated discounts.

The getTrolleyDiscounts method is used to construct the necessary data for fetching discounts, utilizing various parameters such as branch ID and discount tokens to ensure accurate discount calculations.


Recalculate Delivery Methods

  • Route: POST ../trolleys/{trolleyId}/recalculate-delivery-methods
  • Controller: TrolleyController
  • Method: recalculateDeliveryMethods
  • Request: RecalculateTrolleyDeliveryMethodsRequest
  • Description: Endpoint to recalculate delivery methods for trolley items associated with a specific trolleyId.

The recalculateDeliveryMethods method in the TrolleyController updates the delivery methods for each line item in the trolley identified by its trolleyId. It iterates over the trolley lines and checks if the channel for each line is set to COLLECTION. If so, it updates the delivery method for that line item using a default delivery code specific to the region.

After processing all relevant line items, the method retrieves the updated trolley using the trolleyService and returns it as a TrolleyResource. This response reflects the recalculated delivery methods for the trolley.


Check Trolley Validity for Pickup Points

  • Route: GET ../trolleys/{trolleyId}/delivery/pickup-points/valid
  • Controller: PickUpPointController
  • Method: isTrolleyValidForPickUpPoints
  • Request: Request
  • Description: Endpoint to check if a trolley is valid for pickup points associated with a specific trolleyId.

The isTrolleyValidForPickUpPoints method in the PickUpPointController verifies the validity of a trolley for pickup points identified by its trolleyId. It first attempts to retrieve the trolley using the trolleyService, logging an error and returning a 404 Not Found response if the trolley is not found.

After confirming that the user is authorized to view the trolley, the method checks the trolley's validity for pickup points using the pickUpPointService. It then returns a JSON response indicating whether the trolley is valid for pickup points, encapsulated within a data structure.


Get Pickup Point Locations

  • Route: GET ../trolleys/{trolleyId}/delivery/pickup-points/locations
  • Controller: PickUpPointController
  • Method: getPickUpPointLocations
  • Request: Request
  • Description: Endpoint to retrieve available pickup point locations for a trolley associated with a specific trolleyId.

The getPickUpPointLocations method in the PickUpPointController fetches the pickup point locations for the trolley identified by its trolleyId. It starts by attempting to retrieve the trolley using the trolleyService, and if not found, logs the incident and returns a 404 Not Found response.

After confirming the user's authorization to view the trolley, the method collects the delivery codes associated with the trolley. It then gathers the customer’s primary address and prepares the search criteria for pickup points, allowing for optional parameters such as aRoad, city, postcode, and radius.

Using the unique delivery codes, the method calls the pickUpPointService to fetch the pickup point locations based on the specified search criteria. Finally, it returns the locations as a collection of PickUpPointLocationResource, providing the user with the relevant pickup point information.


Store Pickup Point Address

  • Route: POST ../trolleys/{trolleyId}/delivery/pickup-points
  • Controller: PickUpPointController
  • Method: store
  • Request: StorePickUpPointAddressRequest
  • Description: Endpoint to store a pickup point address associated with a specific trolleyId.

The store method in the PickUpPointController handles the storage of a pickup point address for the trolley identified by its trolleyId. It begins by extracting the request data and then retrieves the customer’s existing addresses using the customerAddressService. It filters these addresses to find a match based on the provided address components, If no matching address is found, a new address is created using the customerAddressService, setting its type to PICKUP and populating it with the provided data. If an existing address is found, it reuses that address.

Next, the method updates the trolley attributes using the trolleyService to set the delivery address, mark the trolley as using a pickup point, and store the pickup point data in JSON format. Finally, it returns a 201 Created response containing the ID of the address that was either created or retrieved, indicating successful storage of the pickup point address.


Update Trolley Line Quantity

  • Route: PUT ../trolleys/lines/{trolleyLineId}/quantity
  • Controller: TrolleyController
  • Method: updateLineQuantity
  • Request: UpdateTrolleyLineQuantityRequest
  • Description: Endpoint to update the quantity of a specific trolley line item associated with a trolley.

The updateLineQuantity method in the TrolleyController updates the quantity of a trolley line item identified by its trolleyLineId. It begins by retrieving the trolley using the trolley method from the request, then logs the update attempt, including the trolley ID, line item ID, quantity, and customer ID.

The method proceeds to call the updateLineItemQuantity method of the trolleyService, passing the trolley line ID and the new quantity. After successfully updating the quantity, it logs an informational message that includes the trolley ID, line item ID, and the updated quantity.

Finally, it returns a TrolleyResource containing the updated trolley information, allowing the user to see the current state of the trolley after the update.


Update Trolley Line Channel

  • Route: PUT ../trolleys/lines/{trolleyLineId}/channel
  • Controller: TrolleyController
  • Method: updateLineChannel
  • Request: UpdateTrolleyLineChannelRequest
  • Description: Endpoint to update the delivery channel of a specific trolley line item associated with a trolley.

The updateLineChannel method in the TrolleyController updates the delivery channel of a trolley line item identified by its trolleyLineId. It retrieves the channel from the request and the trolley using the trolley method and that locates the specific trolley line from the trolley's lines collection, then calls the updateLineItemChannel method of the trolleyService to update the channel for the specified line item.

An informational log entry is created to record the update, including the trolley ID, line item ID, product code, customer ID, and the new channel. Finally, it returns a TrolleyResource containing the updated trolley information, reflecting the current state after the channel update.


Update Trolley Line Delivery Method

  • Route: PUT ../trolleys/lines/{trolleyLineId}/delivery-method
  • Controller: TrolleyController
  • Method: updateLineDeliveryMethod
  • Request: UpdateTrolleyLineDeliveryMethodRequest
  • Description: Endpoint to update the delivery method of a specific trolley line item associated with a trolley.

The updateLineDeliveryMethod method in the TrolleyController updates the delivery method of a trolley line item identified by its trolleyLineId. It first retrieves the delivery method code from the request and then calls the updateLineItemDeliveryMethod method of the trolleyService to perform the update.

The method locates the specific trolley line from the trolley's lines collection and creates a debug log entry to track the request details. After successfully updating the delivery method, an informational log entry is generated, capturing relevant details like the trolley ID, line item ID, product code, customer ID, and the new delivery method code and then it finally returns a TrolleyResource containing the updated trolley information, reflecting the current state after the delivery method update.


Patch Trolley Line

  • Route: PATCH ../trolleys/lines/{trolleyLineId}
  • Controller: TrolleyController
  • Method: patchTrolleyLine
  • Request: PatchTrolleyLineRequest
  • Description: Endpoint to update various attributes of a specific trolley line item associated with a trolley.

The patchTrolleyLine method in the TrolleyController handles the partial update of a trolley line item identified by its trolleyLineId. It retrieves the trolley associated with the request and logs the initial details, including the trolley ID, line item ID, customer ID, and the request data. Using the patchLineItem method from the trolleyService, it applies the validated request data to update the trolley line. After the operation, an informational log entry is created to document the successful patch, including relevant details like the updated trolley ID, line item ID, and customer ID.

Finally, the method returns a TrolleyResource containing the updated trolley, reflecting the changes made to the trolley line item.


Delete Trolley Line

  • Route: DELETE ../trolleys/lines/{trolleyLineId}
  • Controller: TrolleyController
  • Method: deleteTrolleyLine
  • Request: DeleteTrolleyLineRequest
  • Description: Endpoint to delete a specific trolley line item associated with a trolley.

The deleteTrolleyLine method in the TrolleyController is responsible for removing a trolley line item identified by its trolleyLineId. It first retrieves the trolley associated with the request and logs the relevant details, including the trolley ID, customer ID, and line item ID the the method calls the deleteTrolleyLine function of the trolleyService to perform the deletion. After successfully removing the line item, it logs an informational message indicating that the trolley line item has been deleted.

Finally, the method returns a TrolleyResource representing the updated trolley, which now excludes the deleted line item.


Remove Promo Code

  • Route: DELETE ../trolleys/promo-codes/{appliedPromoCodeId}
  • Controller: TrolleyController
  • Method: removePromoCode
  • Request: RemovePromoCodeRequest
  • Description: Endpoint to remove a specific promo code from a trolley.

The removePromoCode method in the TrolleyController allows the removal of a specific promo code identified by appliedPromoCodeId. It first validates the request using RemovePromoCodeRequest. If successful, it calls the trolley service to remove the promo code from the trolley, including soft-deleted codes if specified.

Upon successful removal, it logs a debug message indicating that the promo code was removed, including the trolley ID, the associated customer ID, and the applied promo code ID. Finally, it returns a TrolleyResource, which formats the updated trolley data appropriately for the response.


Remove All Promo Codes

  • Route: DELETE ../trolleys/{trolleyId}/promo-codes
  • Controller: TrolleyController
  • Method: removeAllPromoCodes
  • Request: RemovePromoCodeRequest
  • Description: Endpoint to remove all promo codes from a specified trolley.

The removeAllPromoCodes method in the TrolleyController removes all promo codes associated with the trolley identified by trolleyId. It first validates the request using RemovePromoCodeRequest. If successful, it calls the trolley service to remove all promo codes from the specified trolley.

Upon successful removal, it logs a debug message indicating that all promo codes have been removed, including the trolley ID and the associated customer ID. Finally, it returns a TrolleyResource, which formats the updated trolley data appropriately for the response.


Convert Guest Trolley to Customer

  • Route: PATCH ../trolleys/{trolleyId}/convert-to-customer
  • Controller: TrolleyController
  • Method: convertGuestTrolleyToCustomer
  • Request: ConvertGuestTrolleyToCustomerRequest
  • Description: Endpoint to convert a guest trolley to a customer trolley.

The convertGuestTrolleyToCustomer method in the TrolleyController allows the conversion of a guest trolley identified by trolleyId to a customer trolley. It first fetches the trolley using the trolley service and validates the request using ConvertGuestTrolleyToCustomerRequest. After validation, the method performs authorization to ensure the logged-in user is allowed to convert the trolley. It checks that the customer ID provided in the request matches the logged-in user’s ID; if not, it aborts the request with a 403 Forbidden response.

If the authorization passes, it calls the trolley service to convert the guest trolley to the specified customer. Upon successful conversion, it logs a debug message indicating the action taken, including the trolley ID and the associated customer ID. Finally, it returns a TrolleyResource, which formats the updated trolley data appropriately for the response.


Create New Trolley Attribute

  • Route: POST ../trolleys/{trolleyId}/attributes
  • Controller: TrolleyAttributeController
  • Method: createNewTrolleyAttribute
  • Request: CreateTrolleyAttributeRequest
  • Description: Endpoint to add a new attribute to a specified trolley.

The createNewTrolleyAttribute method in the TrolleyAttributeController allows the addition of a new attribute to a trolley identified by trolleyId. It first validates the incoming request data using the CreateTrolleyAttributeRequest. The request is authorized by checking if the logged-in user has permission to update the specified trolley. If authorized, it calls the trolley service to add the attribute to the trolley using the validated request data.

After successful addition, it returns a TrolleyResource, which formats the updated trolley data appropriately for the response.

Request Parameters

  • trolleyId: The ID of the trolley to which the attribute will be added.
  • attribute_id: The ID of the attribute to be added (must be unique for the specified trolley and not soft-deleted).
  • value: The value associated with the attribute.

Update Trolley Attribute

  • Route: PATCH ../trolleys/{trolleyId}/attributes/{attributeId}
  • Controller: TrolleyAttributeController
  • Method: patchTrolleyAttribute
  • Request: PatchTrolleyAttributeRequest
  • Description: Endpoint to update the value of a specified attribute for a trolley.

The patchTrolleyAttribute method in the TrolleyAttributeController allows the update of an existing attribute value for a trolley identified by trolleyId and attributeId. It first validates the incoming request data using PatchTrolleyAttributeRequest.The request is authorized by checking if the logged-in user has permission to update the specified trolley. If authorized, it calls the trolley service to update the attribute value on the trolley using the validated request data. Upon successful update, it returns a TrolleyResource, which formats the updated trolley data appropriately for the response.

Request Parameters

  • trolleyId: The ID of the trolley containing the attribute to be updated.
  • attributeId: The ID of the attribute to be updated.
  • value: The new value for the specified attribute (must be valid based on the attribute's rules).

Delete Trolley Attribute

  • Route: DELETE ../trolleys/{trolleyId}/attributes/{attributeId}
  • Controller: TrolleyAttributeController
  • Method: deleteTrolleyAttribute
  • Request: RemoveTrolleyAttributeRequest
  • Description: Endpoint to remove a specified attribute from a trolley.

The deleteTrolleyAttribute method in the TrolleyAttributeController allows the removal of a specified attribute from a trolley identified by trolleyId and attributeId. It first validates the incoming request using RemoveTrolleyAttributeRequest. The request is authorized by checking if the logged-in user has permission to update the specified trolley. If authorized, it calls the trolley service to delete the attribute from the trolley. Upon successful deletion, it returns a TrolleyResource, which formats the updated trolley data appropriately for the response.

Request Parameters

  • trolleyId: The ID of the trolley from which the attribute will be removed.
  • attributeId: The ID of the attribute to be removed.

Get La Poste Checkout Data

  • Route: GET ../trolleys/{trolleyId}/checkout/laposte
  • Controller: LaPosteAddressController
  • Method: index
  • Request: ViewTrolleyRequest
  • Description: Endpoint to retrieve checkout data for La Poste shipping.

The index method in the LaPosteAddressController retrieves the necessary checkout data for the La Poste shipping service based on the trolley identified by trolleyId. It first checks if the La Poste carrier API is enabled; if not, it aborts the request with a 404 Not Found response. The method then gathers general fields, customer details, and address information for the user associated with the trolley. It processes this information and constructs an array containing the data required by La Poste, including delivery charges and a unique signature for the request. Finally, the method returns a JSON response containing the La Poste data.

Request Parameters

  • trolleyId: The ID of the trolley for which checkout data is requested.

Store La Poste Checkout Address

  • Route: POST ../trolleys/{trolleyId}/checkout/laposte
  • Controller: LaPosteAddressController
  • Method: store
  • Request: AddLaPosteAddressRequest
  • Description: Endpoint to store a new address for La Poste shipping during checkout.

The store method in the LaPosteAddressController handles the creation or updating of a customer's address for La Poste shipping based on the trolley identified by trolleyId. It first checks if the La Poste carrier API is enabled; if not, it aborts the request with a 404 Not Found response.The method retrieves the request data and checks if an address with the provided details already exists in the customer's address book. If no matching address is found, it creates a new customer address using the provided data. If a match is found, it uses the existing address.

After obtaining the address, the method updates the trolley's attributes by adding or updating the delivery address and La Poste pickup data. Finally, it returns a JSON response containing the ID of the stored address and a 201 Created status.

Request Parameters

  • trolleyId: The ID of the trolley for which the address is being stored.
  • Request Body: The request body must contain the address fields:
    • line_1: The first line of the address.
    • line_2: The second line of the address.
    • line_3: The third line of the address (if applicable).
    • postcode: The postcode of the address.
    • town: The town or city of the address.

Store PostNL Checkout Address

  • Route: POST ../trolleys/{trolleyId}/checkout/postnl
  • Controller: PostNLAddressController
  • Method: store
  • Request: AddPostNLAddressRequest
  • Description: Endpoint to store a new address for PostNL shipping during checkout.

The store method in the PostNLAddressController handles the creation or updating of a customer's address for PostNL shipping based on the trolley identified by trolleyId.

The method retrieves the request data and checks if an address with the provided details already exists in the customer's address book. If no matching address is found, it creates a new customer address using the provided data. If a match is found, it uses the existing address.

After obtaining the address, the method updates the trolley's attributes by adding or updating the delivery address and PostNL pickup data. Finally, it returns a JSON response containing the ID of the stored address and a 201 Created status.

Request Parameters

  • trolleyId: The ID of the trolley for which the address is being stored.
  • Request Body: The request body must contain the address fields:
    • line_1: The first line of the address.
    • line_2: The second line of the address.
    • line_3: The third line of the address (if applicable).
    • postcode: The postcode of the address.
    • town: The town or city of the address.

Braintree Checkout

  • Route: POST ../trolleys/checkout/braintree
  • Controller: BraintreePaymentController
  • Method: checkout
  • Request: BraintreeCheckoutTrolleyRequest
  • Description: Endpoint to handle Braintree payment processing during checkout.

The checkout method in the BraintreePaymentController processes a Braintree payment for the trolley during the checkout phase. It begins by logging the received payment request, including the payment ID and the trolley ID.

The method retrieves the trolley and associated customer, ensuring the user is authorized to update the customer's information. It reloads the customer's addresses to account for any new changes that might not be reflected in the cache. Next, it checks for an existing payment ID and updates or adds the payment ID as a trolley attribute. The validated request data, including user information (determined by whether the request comes from a mobile app or a web user), is also added to the trolley as an attribute.

The trolley ID is then stored in the order cache associated with the payment ID to facilitate later retrieval. Finally, the method returns a JSON response containing the payment ID and trolley ID with a 201 Created status.

Request Parameters

  • Request Body: The request body must contain the following:
    • payment_id: The ID of the payment processed by Braintree.

Copyright © 2026