Skip to content

Commit

Permalink
Merge pull request #18 from mdevaud/feat/use-order-pay-total-amount
Browse files Browse the repository at this point in the history
feat: use Event TheliaEvents::ORDER_PAY_GET_TOTAL
  • Loading branch information
zawaze authored Jun 13, 2024
2 parents b83103b + f6711d6 commit 98ec896
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>2.0.8</version>
<version>2.1.0</version>
<authors>
<author>
<name>Vincent Lopes-Vicente</name>
Expand Down
4 changes: 2 additions & 2 deletions Event/PayPlugPaymentEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ class PayPlugPaymentEvent extends ActionEvent
*/
protected $notificationUrl;

public function buildFromOrder(Order $order)
public function buildFromOrder(Order $order, ?float $customTotalAmount = null)
{
$this->order = $order;

Expand All @@ -591,7 +591,7 @@ public function buildFromOrder(Order $order)

if (null !== $order) {
// Avoid php bad int cast https://www.php.net/manual/fr/function.intval.php#60793
$orderAmount = round($order->getTotalAmount(),2) * 100;
$orderAmount = round($customTotalAmount??$order->getTotalAmount(),2) * 100;
$this->setAmount(intval("$orderAmount"))
->setCurrency($order->getCurrency()->getCode());

Expand Down
8 changes: 5 additions & 3 deletions PayPlugModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ public function pay(Order $order)
$slice = 1;

$isMultiPayment = $this->getRequest()->getSession()->get(OrderFormListener::PAY_PLUG_MULTI_PAYMENT_FIELD_NAME, 0);
$orderTotalAmount = $this->getOrderPayTotalAmount($order);

if ($isMultiPayment) {
$orderTotalAmount = $order->getTotalAmount();
$minAmount = PayPlugModule::getConfigValue(PayPlugConfigValue::MULTI_PAYMENT_MINIMUM);
$maxAmount = PayPlugModule::getConfigValue(PayPlugConfigValue::MULTI_PAYMENT_MAXIMUM);

Expand All @@ -103,7 +104,8 @@ public function pay(Order $order)
$order,
PayPlugModule::getConfigValue(PayPlugConfigValue::DIFFERED_PAYMENT_ENABLED, false),
PayPlugModule::getConfigValue(PayPlugConfigValue::ONE_CLICK_PAYMENT_ENABLED, false),
$slice
$slice,
$orderTotalAmount
);

$forceRedirect = false;
Expand All @@ -125,7 +127,7 @@ public function pay(Order $order)
return new JsonResponse(['error' => $exception->getMessage()], 400);
}
Tlog::getInstance()->addError(
'Error PayPlugModule::pay() : ' . $exception->getMessage()
'Error PayPlugModule::pay() : ' . $exception->getMessage()
);
return new RedirectResponse(URL::getInstance()->absoluteUrl('error'));
}
Expand Down
5 changes: 3 additions & 2 deletions Service/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ public function sendOrderPayment(
Order $order,
bool $capture = false,
bool $allowSaveCard = false,
int $paymentSlice = 1
int $paymentSlice = 1,
float $totalOrder
) {
$paymentEvent = (new PayPlugPaymentEvent())
->buildFromOrder($order)
->buildFromOrder($order,$totalOrder)
->setCapture($capture)
->setAllowSaveCard($allowSaveCard);

Expand Down

0 comments on commit 98ec896

Please sign in to comment.