- Status changed to Needs work
over 2 years ago 2:53pm 18 January 2023 - πΊπΈ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.