laravel-square icon indicating copy to clipboard operation
laravel-square copied to clipboard

Adds support for fulfillments

Open Mrkbingham opened this issue 9 months ago • 13 comments

Fulfillments

This merge request seeks to add support for fulfillments and creates models that are reflective of the Square data model. Orders can have Fulfillments, which themselves have Fulfillments Details of varying types (details on the model update below). This merge request adds the following:

  1. Fulfillment and Fulfillment Details models and migrations
  2. Fulfillment and Recipient builders
  3. SquareRequest builder calls to support updating of fulfillment details related to orders
  4. Tests that cover all the individually added models as well as scenarios for creating and adding orders that contain various Fulfillment Detail types.

Square API support

This adds support via the SquareRequestBuilder to update and modify data on square, and ensure it's synced properly with your application. Some notable assumptions are baked in here:

  1. Orders CANNOT have line-item fulfillment data
  2. This also means a single order CANNOT have multiple fulfillments. This is how the Square UI currently works, so this functionality is only available via the API. As it's currently an edge case - one that could likely be worked around by creating multiple orders, for now, this will be left out with no plans to add it in.

Model Updates

This creates a polymorphic relationship between orders via the Fulfillment model. Adding a fulfillment to an order requires both adding a Fulfillment model and a FulfillmentDetails model - which can be one of three types: DeliveryDetails, PickupDetails or ShipmentDetails. These relationships are handled through the trait HasFulfillments.

Recipient Addition

The recipients have been added as a distinct model. This distinction could be useful for adding future support for additional recipient type, for example Invoice Recipients.

Adds Order ID to Payment API request (fulfilling the requirements Square has for orders to show up on the Square Dashboard):

This PR contains a minor fix for adding in the order id to the payments API request, so the payment and order are connected within Square's System. This update exposed a few bugs that have now been addressed:

  1. The Tax calculations in Util::calculateTotalOrderCost/ByModel were not taking in to account discounts and inclusive taxes properly. This now makes sure that Additive taxes are calculated based off the Net Price (taking in to account Discounts and Inclusive Taxes). Added a private _calculateNetPrice method to support this.
  2. The Order Builder buildOrderCopyFromModel method was not properly creating taxes at the order level. Added Constants::DEDUCTIBLE_SCOPE_ORDER.

Mrkbingham avatar May 21 '24 14:05 Mrkbingham