Skip to content

Commit

Permalink
Sentry fixes (#835)
Browse files Browse the repository at this point in the history
* Sentry fixes

* allow php-http discovery
  • Loading branch information
mandan2 authored Oct 24, 2023
1 parent b2b3339 commit 97b0eff
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
"platform": {
"php": "7.2"
},
"prepend-autoloader": false
"prepend-autoloader": false,
"allow-plugins": {
"php-http/discovery": true
}
},
"type": "prestashop-module",
"author": "PrestaShop"
Expand Down
33 changes: 26 additions & 7 deletions mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public function hookDisplayBackOfficeHeader()
*/
public function hookDisplayAdminOrder($params)
{
/** @var \Mollie\Repository\PaymentMethodRepository $paymentMethodRepo */
/** @var PaymentMethodRepositoryInterface $paymentMethodRepo */
$paymentMethodRepo = $this->getService(PaymentMethodRepositoryInterface::class);

/** @var \Mollie\Service\ShipmentServiceInterface $shipmentService */
Expand Down Expand Up @@ -568,8 +568,8 @@ public function hookPaymentOptions($params)
*/
public function hookDisplayOrderConfirmation()
{
/** @var \Mollie\Repository\PaymentMethodRepository $paymentMethodRepo */
$paymentMethodRepo = $this->getService(\Mollie\Repository\PaymentMethodRepository::class);
/** @var PaymentMethodRepositoryInterface $paymentMethodRepo */
$paymentMethodRepo = $this->getService(PaymentMethodRepositoryInterface::class);
$payment = $paymentMethodRepo->getPaymentBy('cart_id', (string) Tools::getValue('id_cart'));
if (!$payment) {
return '';
Expand Down Expand Up @@ -634,6 +634,10 @@ public function hookActionOrderStatusUpdate(array $params): void
return;
}

if ($order->module !== $this->name) {
return;
}

if (!$this->getApiClient()) {
return;
}
Expand Down Expand Up @@ -771,6 +775,12 @@ public function hookDisplayPDFInvoice($params): string
return '';
}

$order = $params['object']->getOrder();

if ($order->module !== $this->name) {
return '';
}

$localeRepo = $this->get('prestashop.core.localization.locale.repository');

if (!$localeRepo) {
Expand All @@ -786,7 +796,7 @@ public function hookDisplayPDFInvoice($params): string
$invoiceTemplateBuilder = $this->getService(\Mollie\Builder\InvoicePdfTemplateBuilder::class);

$templateParams = $invoiceTemplateBuilder
->setOrder($params['object']->getOrder())
->setOrder($order)
->setLocale($locale)
->buildParams();

Expand Down Expand Up @@ -930,8 +940,8 @@ public function hookActionValidateOrder($params)

$newPayment = $apiClient->payments->create($paymentData->jsonSerialize());

/** @var \Mollie\Repository\PaymentMethodRepository $paymentMethodRepository */
$paymentMethodRepository = $this->getService(\Mollie\Repository\PaymentMethodRepository::class);
/** @var PaymentMethodRepositoryInterface $paymentMethodRepository */
$paymentMethodRepository = $this->getService(PaymentMethodRepositoryInterface::class);
$paymentMethodRepository->addOpenStatusPayment(
$cartId,
$orderPayment,
Expand All @@ -958,15 +968,24 @@ public function hookActionObjectOrderPaymentAddAfter($params)
$paymentMethodRepo = $this->getService(PaymentMethodRepositoryInterface::class);

$orders = Order::getByReference($orderPayment->order_reference);

/** @var Order $order */
$order = $orders->getFirst();

if (!Validate::isLoadedObject($order)) {
return;
}

if ($order->module !== $this->name) {
return;
}

$mollieOrder = $paymentMethodRepo->getPaymentBy('cart_id', $order->id_cart);

if (!$mollieOrder) {
return;
}

$orderPayment->payment_method = Config::$methods[$mollieOrder['method']];
$orderPayment->update();
}
Expand Down Expand Up @@ -1037,7 +1056,7 @@ public static function resendOrderPaymentLink($orderId)
{
/** @var Mollie $module */
$module = Module::getInstanceByName('mollie');
/** @var \Mollie\Repository\PaymentMethodRepository $molliePaymentRepo */
/** @var PaymentMethodRepositoryInterface $molliePaymentRepo */
$molliePaymentRepo = $module->getService(PaymentMethodRepositoryInterface::class);
$molPayment = $molliePaymentRepo->getPaymentBy('cart_id', (string) Cart::getCartIdByOrderId($orderId));
if (\Mollie\Utility\MollieStatusUtility::isPaymentFinished($molPayment['bank_status'])) {
Expand Down
8 changes: 4 additions & 4 deletions src/Provider/PaymentFeeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct(
public function getPaymentFee(MolPaymentMethod $paymentMethod, float $totalCartPriceTaxIncl): PaymentFeeData
{
// TODO handle exception on all calls.
$surchargeFixedPriceTaxExcl = $paymentMethod->surcharge_fixed_amount_tax_excl;
$surchargeFixedPriceTaxExcl = (float) $paymentMethod->surcharge_fixed_amount_tax_excl;
$surchargePercentage = (float) $paymentMethod->surcharge_percentage;
$surchargeLimit = (float) $paymentMethod->surcharge_limit;

Expand All @@ -86,9 +86,9 @@ public function getPaymentFee(MolPaymentMethod $paymentMethod, float $totalCartP
}

$taxCalculator = $this->taxProvider->getTaxCalculator(
$paymentMethod->tax_rules_group_id,
$address->id_country,
$address->id_state
(int) $paymentMethod->tax_rules_group_id,
(int) $address->id_country,
(int) $address->id_state
);

$paymentFeeCalculator = new PaymentFeeCalculator($taxCalculator, $this->context);
Expand Down
10 changes: 5 additions & 5 deletions src/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ private function getMethodsObjForConfig($apiMethods)

if (!empty($paymentMethod->surcharge_fixed_amount_tax_excl)) {
$apiMethod['surcharge_fixed_amount_tax_incl'] = $this->getSurchargeFixedAmountTaxInclPrice(
$paymentMethod->surcharge_fixed_amount_tax_excl,
$paymentMethod->tax_rules_group_id,
(float) $paymentMethod->surcharge_fixed_amount_tax_excl,
(int) $paymentMethod->tax_rules_group_id,
$this->context->getCountryId()
);

$paymentMethod->surcharge_fixed_amount_tax_excl = NumberUtility::toPrecision(
$paymentMethod->surcharge_fixed_amount_tax_excl,
(float) $paymentMethod->surcharge_fixed_amount_tax_excl,
NumberUtility::FLOAT_PRECISION
);

Expand Down Expand Up @@ -443,12 +443,12 @@ private function toPrecisionForDecimalNumbers(MolPaymentMethod $paymentMethod):
);

$paymentMethod->min_amount = NumberUtility::toPrecision(
$paymentMethod->min_amount,
(float) $paymentMethod->min_amount,
NumberUtility::FLOAT_PRECISION
);

$paymentMethod->max_amount = NumberUtility::toPrecision(
$paymentMethod->max_amount,
(float) $paymentMethod->max_amount,
NumberUtility::FLOAT_PRECISION
);

Expand Down

0 comments on commit 97b0eff

Please sign in to comment.