Adjustments under one label only in Square dashboard

Created on 15 August 2021, almost 4 years ago
Updated 17 January 2023, over 2 years ago

Problem/Motivation

Various adjustments (tax, shipping for example) are being totalled under one heading titled "Adjustments" in Square.

Example of an order in Drupal Commerce (notice the tax and shipping costs):

Exampe of a transaction in Square (notice that tax and shipping costs fall under one general label titled "Adjustments"):

Steps to reproduce

Go through a typical checkout scenario using the Square payment gateway. Ensure that taxes are being applied to products and properly configured. Ensure that there is a shipping method available for users to select during checkout and a cost for shipping. Submit and pay for the order using the Commerce Square Connect payment gateway (which should be configured using a sandbox account).

Verify the transaction in the Square dashboard. Both adjustments will be combined as one.

Proposed resolution

Adjustments should be labelled as they are seen in Drupal. For example, taxes and shipping are clearly separate line items when viewing an order's details in Drupal, but when viewing the transaction in Square the two are combined under the label "Adjustments". This is specifically an issue when organizations need to calculate the amount of taxes that have been paid since the all amounts are combined.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs review

Version

1.5

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada joelseguin Ontario, Canada

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Needs work over 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States sah62 US

    Would something like this work to mark an order item each time is payment is processed?

    foreach ($payment->getOrder()->getItems() as $item) {
      $square_item_processed = $item->getData('square_item_processed', FALSE);
      if ($square_item_processed) continue;
      // Process the order item.
      ...
      $item->setData('square_item_processed', TRUE);
    }
    

    I've tried to test this idea. Nothing "bad" seems to happen when I process a first payment for a single item. If I edit the order and add an item, though, when I try to process the second payment the value of $square_item_processed is FALSE for both items in the order and the payment process fails because the amount of the order (2 items, plus tax, plus shipping) doesn't match the payment (1 new item plus tax). I'm clearly still missing something.

  • πŸ‡¨πŸ‡¦Canada trevorkjorlien

    Coming back to this after another year of tedious tax filing. Hoping to get the conversation flowing again and get some progress done on this!

    Taxes type: ADDITIVE or INCLUSIVE

    I think we can check what taxes are applied and if it should be marked as ADDITIVE or INCLUSIVE with this:

    // Check if this specific tax adjustment is inclusive or additive
    $tax_type = $adjustment->isIncluded() ? 'INCLUSIVE' : 'ADDITIVE';
    $line_item_adjustment->setType($tax_type);

    Taxes scope: LINE_ITEM or ORDER

    I think you would need to worry about this if your store includes tax-exempt products. If so, you need to have this set to LINE_ITEM, so that it calculates the tax in an order with taxed and non-taxed products.

    This isn't a use case for me, so I wouldn't know what to tap into to check for these values. Looks like the Commerce Tax Exemption module would allow something to hook into for that: https://www.drupal.org/project/commerce_tax_exemption β†’

    Shipping: SUBTOTAL_PHASE or TOTAL_PHASE

    This checks if taxes should be applied to shipping. If taxes should be applied, use SUBTOTAL_PHASE. If no taxes should be applied, use TOTAL_PHASE.

    In my case in Canada, we do apply taxes to shipping. I have a shipping tax creates in my Tax Types. Would the very existence of this imply using SUBTOTAL_PHASE? (and TOTAL_PHASE if it does not?)

    Something like:

     // Add applied taxes to the shipping charge
    $applied_taxes = [];
    foreach ($taxes as $tax) {
      $unique_id = $tax->getUid();
      $service_charge_applied_tax = new OrderLineItemAppliedTax($unique_id);
      $applied_taxes[] = $service_charge_applied_tax;
      $service_charge->setCalculationPhase('SUBTOTAL_PHASE');
      $service_charge->setTaxable(true);
    }

    Discounts: FIXED_AMOUNT or FIXED_PERCENTAGE

    We need to check if the discount is a fixed amount or percentage. Something like:

    // Check if it's a percentage or fixed amount discount
    $percentage = $adjustment->getPercentage();
    if ($percentage !== NULL) {
      $line_item_adjustment->setType('FIXED_PERCENTAGE');
    }
            
    else {
      $line_item_adjustment->setType('FIXED_AMOUNT');
    }

    Discounts: LINE_ITEM or ORDER

    We need to check if the discount is for a specific matching product (LINE_ITEM) or the order subtotal (ORDER).

    I'm more a front-end person than a back-end developer, but hopefully this can get us working on this issue again.

Production build 0.71.5 2024