Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIPRES-329: Use Mollie mapped status for initial subscription order #827

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Utility/NumberUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static function divide(
return (float) $result->toPrecision($precision, $roundingMode);
}

public static function isEqual($a, $b)
public static function isEqual(float $a, float $b): bool
{
$firstNumber = self::getNumber($a);
$secondNumber = self::getNumber($b);
Expand Down
8 changes: 4 additions & 4 deletions src/Utility/OrderStatusUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public static function transformPaymentStatusToRefunded($transaction)
$remainingAmount = $payment->getAmountRemaining();
}
}
$amountRefunded = $transaction->amountRefunded->value;
$amountPayed = $transaction->amountCaptured->value;
$isPartiallyRefunded = NumberUtility::isLowerThan($amountRefunded, $amountPayed);
$isFullyRefunded = NumberUtility::isEqual($amountRefunded, $amountPayed);
$amountRefunded = (float) $transaction->amountRefunded->value;
$amountPaid = (float) $transaction->amountCaptured->value;
$isPartiallyRefunded = NumberUtility::isLowerThan($amountRefunded, $amountPaid);
$isFullyRefunded = NumberUtility::isEqual($amountRefunded, $amountPaid);

if ($isPartiallyRefunded) {
if ($isVoucher && NumberUtility::isEqual(0, $remainingAmount)) {
Expand Down
29 changes: 20 additions & 9 deletions subscription/Handler/RecurringOrderHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Mollie\Subscription\Repository\RecurringOrderRepositoryInterface;
use Mollie\Subscription\Repository\RecurringOrdersProductRepositoryInterface;
use Mollie\Subscription\Utility\ClockInterface;
use Mollie\Utility\NumberUtility;
use Mollie\Utility\SecureKeyUtility;
use MolRecurringOrder;
use MolRecurringOrdersProduct;
Expand Down Expand Up @@ -245,11 +246,14 @@ private function createSubscription(Payment $transaction, MolRecurringOrder $rec

$methodName = $paymentMethod->method_name ?: Config::$methods[$transaction->method];

$subscriptionPaidTotal = (float) $subscription->amount->value;
$cartTotal = (float) $newCart->getOrderTotal(true, Cart::BOTH);

try {
$this->mollie->validateOrder(
(int) $newCart->id,
(int) $this->configuration->get(Config::MOLLIE_STATUS_AWAITING),
(float) $subscription->amount->value,
(int) Config::getStatuses()[$transaction->status],
$subscriptionPaidTotal,
sprintf('subscription/%s', $methodName),
null,
['transaction_id' => $transaction->id],
Expand All @@ -258,23 +262,30 @@ private function createSubscription(Payment $transaction, MolRecurringOrder $rec
$newCart->secure_key
);
} catch (\Throwable $exception) {
if (!NumberUtility::isEqual($cartTotal, $subscriptionPaidTotal)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could check it prior and not inside the catch

$this->logger->error('Order failed. Paid price is not equal to the order\'s total', [
'Paid price' => $subscriptionPaidTotal,
'Order price' => $cartTotal,
]);
}

$specificPrice->delete();

throw $exception;
}

if (!NumberUtility::isEqual($cartTotal, $subscriptionPaidTotal)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, seems like it should be just prior to validateOrder

$this->logger->info('Paid price is not equal to the order\'s total', [
'Paid price' => $subscriptionPaidTotal,
'Order price' => $cartTotal,
]);
}

$specificPrice->delete();

$orderId = (int) Order::getIdByCartId((int) $newCart->id);
$order = new Order($orderId);

if ((float) $order->total_paid_tax_incl !== (float) $subscription->amount->value) {
$this->logger->error('Paid price is not equal to the order\'s total', [
'Paid price' => (float) $subscription->amount->value,
'Order price' => (float) $order->total_paid_tax_incl,
]);
}

$this->mollieOrderCreationService->createMolliePayment($transaction, (int) $newCart->id, $order->reference, (int) $orderId, PaymentStatus::STATUS_PAID);

$this->orderStatusService->setOrderStatus($orderId, (int) Config::getStatuses()[$transaction->status]);
Expand Down
Loading