Skip to content

Commit e2d51d2

Browse files
dgjlindsayclaude
andcommitted
ABN-298/fix: surcharge display — net amounts, payment method guard, sort order
Surcharge line and chips now show net (excl. tax); surcharge tax flows into Magento's native Tax line via setTaxAmount. Total Collector skips when a non-Two payment method is selected (clears session too). Summary sort order set to 39 (between shipping at 30 and tax at 40). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 22efeba commit e2d51d2

File tree

6 files changed

+24
-16
lines changed

6 files changed

+24
-16
lines changed

Model/Total/Surcharge.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ public function collect(
7979
return $this;
8080
}
8181

82+
$paymentMethod = $quote->getPayment()->getMethod();
83+
if ($paymentMethod && $paymentMethod !== 'two_payment') {
84+
$this->logRepository->addDebugLog('TotalCollector: skipped (payment method: ' . $paymentMethod . ')', []);
85+
$this->clearSessionSurcharge();
86+
return $this;
87+
}
88+
8289
$storeId = (int)$quote->getStoreId();
8390
$surchargeType = $this->configRepository->getSurchargeType($storeId);
8491

@@ -142,8 +149,8 @@ public function collect(
142149
$total->setTaxAmount((float)$total->getTaxAmount() + $taxAmount);
143150
$total->setBaseTaxAmount((float)$total->getBaseTaxAmount() + $taxAmount);
144151

145-
// Store on total object for fetch() in the same request
146-
$total->setData('two_surcharge_gross', $grossAmount);
152+
// Store net on total object for fetch() — tax flows via setTaxAmount above
153+
$total->setData('two_surcharge_net', $netAmount);
147154
$total->setData('two_surcharge_description', $result['description']);
148155

149156
// Store in session for ComposeOrder and cross-request persistence
@@ -168,13 +175,14 @@ public function collect(
168175
*/
169176
public function fetch(Quote $quote, Total $total): array
170177
{
171-
// Prefer the total object (same request as collect), fall back to session
172-
$amount = (float)$total->getData('two_surcharge_gross')
173-
?: (float)$this->checkoutSession->getTwoSurchargeGross();
178+
// Prefer the total object (same request as collect), fall back to session.
179+
// Returns net amount — surcharge tax is included in the Tax line via setTaxAmount.
180+
$amount = (float)$total->getData('two_surcharge_net')
181+
?: (float)$this->checkoutSession->getTwoSurchargeAmount();
174182

175183
$this->logRepository->addDebugLog('TotalCollector fetch()', [
176-
'totalGross' => (float)$total->getData('two_surcharge_gross'),
177-
'sessionGross' => (float)$this->checkoutSession->getTwoSurchargeGross(),
184+
'totalNet' => (float)$total->getData('two_surcharge_net'),
185+
'sessionNet' => (float)$this->checkoutSession->getTwoSurchargeAmount(),
178186
'amount' => $amount,
179187
]);
180188

Model/Ui/ConfigProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private function getTermSurcharges(): array
195195
);
196196
$net = $result['amount'];
197197
$tax = round($net * ($result['tax_rate'] / 100), 2);
198-
$surcharges[$days] = $net + $tax;
198+
$surcharges[$days] = $net;
199199
} catch (\Exception $e) {
200200
$surcharges[$days] = 0.0;
201201
}

Model/Webapi/TermSelection.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function selectTerm(string $cartId, int $termDays): array
9494
}
9595

9696
/**
97-
* Compute gross surcharges for all available terms.
97+
* Compute net surcharges for all available terms.
9898
*/
9999
private function computeAllTermSurcharges(float $baseAmount, $quote): array
100100
{
@@ -122,11 +122,9 @@ private function computeAllTermSurcharges(float $baseAmount, $quote): array
122122
$currency,
123123
$storeId
124124
);
125-
$net = $result['amount'];
126-
$tax = round($net * ($result['tax_rate'] / 100), 2);
127-
$surcharges[] = ['days' => $days, 'gross' => $net + $tax];
125+
$surcharges[] = ['days' => $days, 'net' => (float)$result['amount']];
128126
} catch (\Exception $e) {
129-
$surcharges[] = ['days' => $days, 'gross' => 0.0];
127+
$surcharges[] = ['days' => $days, 'net' => 0.0];
130128
}
131129
}
132130

view/frontend/layout/checkout_index_index.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<item name="children" xsi:type="array">
7070
<item name="two-surcharge" xsi:type="array">
7171
<item name="component" xsi:type="string">Two_Gateway/js/view/checkout/summary/surcharge</item>
72-
<item name="sortOrder" xsi:type="string">65</item>
72+
<item name="sortOrder" xsi:type="string">39</item>
7373
<item name="config" xsi:type="array">
7474
<item name="title" xsi:type="string">Payment terms fee</item>
7575
</item>

view/frontend/web/js/model/surcharge.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ define([
9797
if (data && data.term_surcharges) {
9898
var updated = {};
9999
data.term_surcharges.forEach(function (item) {
100-
updated[item.days] = item.gross;
100+
updated[item.days] = item.net;
101101
});
102102
termSurcharges(updated);
103103
}

view/frontend/web/js/view/checkout/summary/surcharge.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ define([
1919

2020
isDisplayed: function () {
2121
var segment = totals.getSegment('two_surcharge');
22-
return segment && parseFloat(segment.value) > 0;
22+
var method = quote.paymentMethod();
23+
return segment && parseFloat(segment.value) > 0
24+
&& method && method.method === 'two_payment';
2325
},
2426

2527
getValue: function () {

0 commit comments

Comments
 (0)