Skip to content

Commit d6a0cb1

Browse files
authored
Merge pull request #64 from two-inc/brtkwr-two/cet-714-add-net_amount-and-tax_amount-to-magento-order-intent
CET-714/fix: Add net_amount and tax_amount to Magento order intent
2 parents df2df93 + 5e63c04 commit d6a0cb1

File tree

4 files changed

+24
-31
lines changed

4 files changed

+24
-31
lines changed

Model/Two.php

-4
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,12 @@ public function authorize(InfoInterface $payment, $amount)
207207

208208
$additionalInformation = $payment->getAdditionalInformation();
209209

210-
$invoiceEmails = $additionalInformation['invoiceEmails'] ?? null;
211-
212210
$payload = $this->compositeOrder->execute(
213211
$order,
214212
$orderReference,
215213
$additionalInformation
216214
);
217215

218-
219-
220216
// Create order
221217
$response = $this->apiAdapter->execute('/v1/order', $payload);
222218
$error = $this->getErrorFromResponse($response);

Model/Ui/ConfigProvider.php

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public function getConfig(): array
7373
$orderIntentConfig = [
7474
'extensionPlatformName' => $this->configRepository->getExtensionPlatformName(),
7575
'extensionDBVersion' => $this->configRepository->getExtensionDBVersion(),
76-
'invoiceType' => 'FUNDED_INVOICE',
7776
'weightUnit' => $this->configRepository->getWeightUnit(),
7877
'merchant' => $merchant,
7978
];

Service/Order/ComposeOrder.php

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public function execute(Order $order, string $orderReference, array $additionalD
7777
$payload['invoice_details'] = $invoiceDetails;
7878
}
7979

80-
8180
return $payload;
8281
}
8382
}

view/frontend/web/js/view/payment/method-renderer/two_payment.js

+24-25
Original file line numberDiff line numberDiff line change
@@ -326,27 +326,6 @@ define([
326326
getEmail: function () {
327327
return quote.guestEmail ? quote.guestEmail : window.checkoutConfig.customerData.email;
328328
},
329-
calculateTaxSubtotals: function (lineItems) {
330-
const taxSubtotals = {};
331-
332-
lineItems.forEach((item) => {
333-
const taxRate = parseFloat(item.tax_rate);
334-
const taxAmount = parseFloat(item.tax_amount);
335-
const taxableAmount = parseFloat(item.net_amount);
336-
337-
if (!taxSubtotals[taxRate]) {
338-
taxSubtotals[taxRate] = {
339-
tax_amount: 0,
340-
taxable_amount: 0,
341-
tax_rate: taxRate
342-
};
343-
}
344-
taxSubtotals[taxRate].tax_amount += taxAmount;
345-
taxSubtotals[taxRate].taxable_amount += taxableAmount;
346-
});
347-
348-
return Object.values(taxSubtotals);
349-
},
350329
placeOrderIntent: function () {
351330
let totals = quote.getTotals()(),
352331
billingAddress = quote.billingAddress(),
@@ -368,13 +347,33 @@ define([
368347
type: item['is_virtual'] === '0' ? 'PHYSICAL' : 'DIGITAL'
369348
});
370349
});
350+
lineItems.push({
351+
name: 'Shipping',
352+
description: 'Shipping fee',
353+
gross_amount: parseFloat(totals['shipping_incl_tax']).toFixed(2),
354+
net_amount: parseFloat(totals['shipping_amount']).toFixed(2),
355+
quantity: 1,
356+
unit_price: parseFloat(totals['shipping_amount']).toFixed(2),
357+
tax_amount: parseFloat(totals['shipping_tax_amount']).toFixed(2),
358+
tax_rate: (
359+
parseFloat(totals['shipping_tax_amount']) /
360+
parseFloat(totals['shipping_amount'])
361+
).toFixed(6),
362+
tax_class_name: '',
363+
quantity_unit: 'unit',
364+
type: 'SHIPPING_FEE'
365+
});
371366

367+
const gross_amount = parseFloat(totals['grand_total']);
368+
const tax_amount =
369+
parseFloat(totals['tax_amount']) + parseFloat(totals['shipping_tax_amount']);
370+
const net_amount = gross_amount - tax_amount;
372371
const orderIntentRequestBody = {
373-
gross_amount: parseFloat(totals['grand_total']).toFixed(2),
374-
invoice_type: config.orderIntentConfig.invoiceType,
375-
currency: totals['base_currency_code'],
372+
gross_amount: gross_amount.toFixed(2),
373+
net_amount: net_amount.toFixed(2),
374+
tax_amount: tax_amount.toFixed(2),
375+
currency: totals['quote_currency_code'],
376376
line_items: lineItems,
377-
tax_subtotals: this.calculateTaxSubtotals(lineItems),
378377
buyer: {
379378
company: {
380379
organization_number: this.companyId(),

0 commit comments

Comments
 (0)