Skip to content

Commit

Permalink
#32835 fix after QA
Browse files Browse the repository at this point in the history
  • Loading branch information
Bohdan-Medv committed Apr 11, 2023
1 parent 3a62bfa commit bd5fc76
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.6.0
- Auto-cancel for payment status open (0) and redirected (46)

# 1.5.0
- Order item statuses

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mediaopt/worldline",
"description": "Worldline Online Payments",
"version": "1.5.0",
"version": "1.6.0",
"type": "shopware-platform-plugin",
"license": "proprietary",
"config": {
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Payment/PaymentFinalizeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function finalizeTransaction(Request $request, SalesChannelContext $sales
$this->transactionStateHandler
);

$paymentHandler->updatePaymentStatus($hostedCheckoutId);
$paymentHandler->updatePaymentStatus($hostedCheckoutId, true);

$finishUrl = $this->buildFinishUrl($request, $order, $salesChannelContext, $context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ public function enableButtons(Request $request, Context $context): JsonResponse
}
}

$lockButtons = false;
if (array_key_exists(Form::CUSTOM_FIELD_WORLDLINE_PAYMENT_TRANSACTION_IS_LOCKED, $customFields)) {
$lockButtons = $customFields[Form::CUSTOM_FIELD_WORLDLINE_PAYMENT_TRANSACTION_IS_LOCKED];
}

[$allowedActions, $allowedAmounts] = Payment::getAllowed($customFields);
} catch (\Exception $e) {
return $this->response(false, $e->getMessage());
Expand All @@ -211,7 +216,7 @@ public function enableButtons(Request $request, Context $context): JsonResponse
'allowedAmounts' => $allowedAmounts,
'log' => $log,
'worldlinePaymentStatus' => $itemsStatus,
'worldlineLockButtons' => false,
'worldlineLockButtons' => $lockButtons,
]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/MoptWorldline.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class MoptWorldline extends Plugin
{
const PLUGIN_NAME = 'MoptWorldline';
const PLUGIN_VERSION = '1.5.0';
const PLUGIN_VERSION = '1.6.0';

/**
* @param InstallContext $installContext
Expand Down
36 changes: 27 additions & 9 deletions src/Service/PaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ public function getOrderId(): string

/**
* @param string $hostedCheckoutId
* @param bool $isFinalize
* @return int
* @throws \Exception
*/
public function updatePaymentStatus(string $hostedCheckoutId): int
public function updatePaymentStatus(string $hostedCheckoutId, bool $isFinalize = false): int
{
$status = $this->updatePaymentTransactionStatus($hostedCheckoutId);
$status = $this->updatePaymentTransactionStatus($hostedCheckoutId, $isFinalize);
$this->updateOrderTransactionState($status, $hostedCheckoutId);

return $status;
Expand All @@ -95,10 +96,9 @@ public function updatePaymentStatus(string $hostedCheckoutId): int
*/
public function createPayment(int $worldlinePaymentMethodId): CreateHostedCheckoutResponse
{
$order = $this->order;
$orderObject = null;
if (in_array($worldlinePaymentMethodId, PaymentProducts::PAYMENT_PRODUCT_NEED_DETAILS)) {
$criteria = new Criteria([$order->getId()]);
$criteria = new Criteria([$this->order->getId()]);
$criteria->addAssociation('lineItems')
->addAssociation('deliveries.positions.orderLineItem')
->addAssociation('orderCustomer.customer')
Expand All @@ -111,7 +111,7 @@ public function createPayment(int $worldlinePaymentMethodId): CreateHostedChecko
$orderObject = $this->orderRepository->search($criteria, $this->context)->first();
}

$amountTotal = (int)round($order->getAmountTotal() * 100);
$amountTotal = (int)round($this->order->getAmountTotal() * 100);
$currencyISO = $this->getCurrencyISO();

$this->log(AdminTranslate::trans($this->translator->getLocale(), 'buildingOrder'));
Expand Down Expand Up @@ -146,8 +146,7 @@ public function createPayment(int $worldlinePaymentMethodId): CreateHostedChecko
*/
public function createHostedTokenizationPayment(array $iframeData): CreatePaymentResponse
{
$order = $this->order;
$amountTotal = (int)round($order->getAmountTotal() * 100);
$amountTotal = (int)round($this->order->getAmountTotal() * 100);
$currencyISO = $this->getCurrencyISO();

$this->log(AdminTranslate::trans($this->translator->getLocale(), 'buildingHostdTokenizationOrder'));
Expand Down Expand Up @@ -372,10 +371,11 @@ public function refundPayment(string $hostedCheckoutId, int $amount, array $item

/**
* @param string $hostedCheckoutId
* @param bool $isFinalize
* @return string
* @throws \Exception
*/
private function updatePaymentTransactionStatus(string $hostedCheckoutId): string
private function updatePaymentTransactionStatus(string $hostedCheckoutId, bool $isFinalize = false): string
{
$this->log('gettingPaymentDetails', 0, ['hostedCheckoutId' => $hostedCheckoutId]);
$paymentDetails = $this->adapter->getPaymentDetails($hostedCheckoutId);
Expand All @@ -389,7 +389,25 @@ private function updatePaymentTransactionStatus(string $hostedCheckoutId): strin

//Check log for any outer actions
$this->compareLog($paymentDetails);
$this->saveOrderCustomFields($status, $hostedCheckoutId);

//finalize for direct sales case
$autoCapture = $this->adapter->getPluginConfig(Form::AUTO_CAPTURE);
if ($isFinalize && $autoCapture == Form::AUTO_CAPTURE_IMMEDIATELY && in_array($status, Payment::STATUS_CAPTURED)) {
$amountTotal = (int)round($this->order->getAmountTotal() * 100);
$this->saveOrderCustomFields(
$status,
$hostedCheckoutId,
[
'toCaptureOrCancel' => 0,
'toRefund' => $amountTotal,
],
[],
$this->buildOrderItemStatus(true)
);
} else {
$this->saveOrderCustomFields($status, $hostedCheckoutId);
}

return $status;
}

Expand Down

0 comments on commit bd5fc76

Please sign in to comment.