-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathOrderTotalCollector.php
More file actions
78 lines (65 loc) · 2.42 KB
/
Copy pathOrderTotalCollector.php
File metadata and controls
78 lines (65 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* Mollie https://www.mollie.nl
*
* @author Mollie B.V. <info@mollie.nl>
* @copyright Mollie B.V.
* @license https://github.com/mollie/PrestaShop/blob/master/LICENSE.md
*
* @see https://github.com/mollie/PrestaShop
* @codingStandardsIgnoreStart
*/
namespace Mollie\Collector\ApplePayDirect;
use Cart;
use Mollie\Config\Config;
use Mollie\DTO\ApplePay\Carrier\Carrier as AppleCarrier;
use Mollie\Service\OrderPaymentFeeService;
if (!defined('_PS_VERSION_')) {
exit;
}
class OrderTotalCollector
{
/** @var OrderPaymentFeeService */
private $orderPaymentFeeService;
public function __construct(OrderPaymentFeeService $orderPaymentFeeService)
{
$this->orderPaymentFeeService = $orderPaymentFeeService;
}
/**
* @param AppleCarrier[] $applePayCarriers
*
* @return array|array
*
* @throws \Exception
*/
public function getOrderTotals($applePayCarriers, Cart $cart)
{
$originalDeliveryOption = $cart->delivery_option;
// Apple Pay addresses are soft-deleted, which fails Customer::customerHasAddress inside
// getPackageShippingCost, so explicit-carrier totals price shipping against the
// default-country zone; pricing through the cart's delivery option resolves the real zone
$totals = array_map(function (AppleCarrier $carrier) use ($cart) {
// raw assignment on purpose: Cart::setDeliveryOption() fires CartRule::autoRemoveFromCart(),
// which deletes vouchers from the shopper's real cart while this loop is only quoting
$cart->delivery_option = json_encode([
$cart->id_address_delivery => $carrier->getCarrierId() . ',',
]);
$orderTotal = (float) number_format(
$cart->getOrderTotal(true, Cart::BOTH),
2,
'.',
''
);
$paymentFeeData = $this->orderPaymentFeeService->getPaymentFee($orderTotal, Config::APPLEPAY);
$paymentFee = $paymentFeeData->getPaymentFeeTaxIncl();
return [
'type' => 'final',
'label' => $carrier->getName(),
'amount' => number_format($orderTotal + $paymentFee, 2, '.', ''),
'amountWithoutFee' => $orderTotal,
];
}, $applePayCarriers);
$cart->delivery_option = $originalDeliveryOption;
return $totals;
}
}