NikolaGavric94 / laravel-square

Square integration with Laravel/Lumen >=5.5
MIT License
31 stars 23 forks source link

Adds support for fulfillments #88

Open Mrkbingham opened 3 months ago

Mrkbingham commented 3 months ago

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 commented 3 months ago

Also when you get a chance @NikolaGavric94, I'm not able to run StyleCI for this repo, so granting access there would be greatly appreciated so I can clean up any syntax issues: image

NikolaGavric94 commented 2 months ago

Hey Mark,

I will take a detailed look at this over the upcoming weekend and will get it sorted by next Tuesday, thank you for your effort and willingness to help :)

NikolaGavric94 commented 2 months ago

Would you be able to add the wiki page changes with the examples, notes and limitations of using fulfillments with this package in this PR?

Mrkbingham commented 2 months ago

Would you be able to add the wiki page changes with the examples, notes and limitations of using fulfillments with this package in this PR?

Definitely! I'm heading out for vacation this week, so will get to this when I return, but will be sure to add a wiki page with examples using the existing ones as a reference point.

Mrkbingham commented 1 month ago

@NikolaGavric94 After a bit of a long hiatus from looking at this, I've resumed work again! I've added quite a few more tests along with negative testing coverage. Happy to add anything more that you think is missing. I still need to add the Wiki pages, but outside of that I think everything should be ready here (other than the one open thread left above re: mail.yml)

Mrkbingham commented 1 month ago

Okay, I've added the wiki page here: https://github.com/NikolaGavric94/laravel-square/wiki/Examples-with-Fulfillments-(coming-soon)

NikolaGavric94 commented 3 weeks ago

I will check the changes this upcoming weekend and we will see where we are at, thanks for all your hard work & effort @Mrkbingham

NikolaGavric94 commented 2 weeks ago

Would you be able to just attach the picture of passing tests here and I'll merge it. Need to get on fixing actions when PRs are made from forks

Mrkbingham commented 2 weeks ago

FYI @NikolaGavric94 I did make this new MR that contains part of the changes included in here. I really should have done this sooner, but in order to more easily digest some of the changes, I figured this might be helpful if we ever need to go back and do any debugging:

https://github.com/NikolaGavric94/laravel-square/pull/95

Mrkbingham commented 2 weeks ago

Okay, in addition to branching out a subset of this MR - I've also created a "master" branch in my repo called "nikolag_master" that was just synced from the current state of master of this main repo. I've created MRs in my own repo against that branch, and have linked here to this successful pipeline run: https://github.com/Mrkbingham/laravel-square/pull/25/checks

There were a few syntax issues, but those are now resolved too!