diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f4de261a..179a7874 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,8 +17,8 @@ repos: - -l language: system files: '\.(php)$' - - repo: git@github.com:two-inc/git-hooks - rev: 24.07.26 + - repo: https://github.com/two-inc/git-hooks + rev: 24.11.29 hooks: - id: commit-msg stages: [commit-msg] diff --git a/Controller/Payment/Confirm.php b/Controller/Payment/Confirm.php index 28539035..fad44955 100755 --- a/Controller/Payment/Confirm.php +++ b/Controller/Payment/Confirm.php @@ -23,9 +23,6 @@ */ class Confirm extends Action { - public const STATE_CONFIRMED = 'CONFIRMED'; - public const STATE_VERIFIED = 'VERIFIED'; - /** * @var ConfigRepository */ @@ -76,10 +73,10 @@ public function execute() try { $order = $this->orderService->getOrderByReference(); $twoOrder = $this->orderService->getTwoOrderFromApi($order); - if (isset($twoOrder['state']) && - (($twoOrder['state'] == self::STATE_VERIFIED) || ($twoOrder['state'] == self::STATE_CONFIRMED)) - ) { - $this->orderService->confirmOrder($order); + if (isset($twoOrder['state']) && $twoOrder['state'] != 'UNVERIFIED') { + if (in_array($twoOrder['state'], ['VERIFIED', 'CONFIRMED'])) { + $this->orderService->confirmOrder($order); + } $this->orderSender->send($order); if ($order->getCustomerId()) { if ($order->getBillingAddress()->getCustomerAddressId()) { @@ -97,20 +94,27 @@ public function execute() $customerAddress = $customerAddressCollection[0] ?? null; } if ($customerAddress && $customerAddress->getId()) { - $this->saveAddressMetadata( + $this->copyMetadataToAddress( $twoOrder, $customerAddress ); + $this->addressRepository->save($customerAddress); } } else { - $this->saveAddressMetadata( + // Save metadata to shipping address + $shippingAddress = $order->getShippingAddress(); + $this->copyMetadataToAddress( $twoOrder, - $order->getShippingAddress() + $shippingAddress ); - $this->saveAddressMetadata( + $shippingAddress->save(); + // Save metadata to billing address + $billingAddress = $order->getBillingAddress(); + $this->copyMetadataToAddress( $twoOrder, - $order->getBillingAddress() + $billingAddress ); + $billingAddress->save(); } $this->orderService->processOrder($order, $twoOrder['id']); return $this->getResponse()->setRedirect($this->_url->getUrl('checkout/onepage/success')); @@ -145,7 +149,7 @@ public function execute() * * @throws Exception */ - public function saveAddressMetadata(array $twoOrder, $address) + public function copyMetadataToAddress(array $twoOrder, $address) { if (isset($twoOrder['buyer']['company']['organization_number'])) { $address->setData('company_id', $twoOrder['buyer']['company']['organization_number']); @@ -159,6 +163,5 @@ public function saveAddressMetadata(array $twoOrder, $address) if (isset($twoOrder['buyer_project'])) { $address->setData('project', $twoOrder['buyer_project']); } - $address->save(); } } diff --git a/Service/Payment/OrderService.php b/Service/Payment/OrderService.php index 836a495a..2a432c88 100755 --- a/Service/Payment/OrderService.php +++ b/Service/Payment/OrderService.php @@ -301,25 +301,27 @@ public function processOrder(Order $order, string $transactionId) $order->setState(Order::STATE_PROCESSING); $order->setStatus(Order::STATE_PROCESSING); $invoice = $this->invoiceService->prepareInvoice($order); - $invoice->setRequestedCaptureCase(Invoice::CAPTURE_ONLINE); - $invoice->register(); - $this->addOrderComment( - $order, - sprintf( - '%s order payment has been verified', - $this->configRepository::PROVIDER - ) - ); - $transactionSave = $this->transaction - ->addObject( - $payment - )->addObject( - $invoice - )->addObject( - $invoice->getOrder() + if ($invoice->getGrandTotal() > 0) { + $invoice->setRequestedCaptureCase(Invoice::CAPTURE_ONLINE); + $invoice->register(); + $this->addOrderComment( + $order, + sprintf( + '%s order payment has been verified', + $this->configRepository::PROVIDER + ) ); - $transactionSave->save(); - $this->addAuthorizationTransaction($order, $transactionId); + $transactionSave = $this->transaction + ->addObject( + $payment + )->addObject( + $invoice + )->addObject( + $invoice->getOrder() + ); + $transactionSave->save(); + $this->addAuthorizationTransaction($order, $transactionId); + } } return $this; } diff --git a/view/frontend/web/js/view/payment/method-renderer/two_payment.js b/view/frontend/web/js/view/payment/method-renderer/two_payment.js index 6165d190..e2f09413 100755 --- a/view/frontend/web/js/view/payment/method-renderer/two_payment.js +++ b/view/frontend/web/js/view/payment/method-renderer/two_payment.js @@ -178,11 +178,6 @@ define([ }, fillCustomerData: function () { const self = this; - quote.shippingAddress.subscribe((address) => self.updateShippingAddress(address)); - this.updateShippingAddress(quote.shippingAddress()); - - quote.billingAddress.subscribe((address) => self.updateBillingAddress(address)); - this.updateBillingAddress(quote.billingAddress()); customerData .get('companyData') @@ -198,6 +193,12 @@ define([ .get('countryCode') .subscribe((countryCode) => self.fillCountryCode(countryCode)); this.fillCountryCode(customerData.get('countryCode')()); + + quote.shippingAddress.subscribe((address) => self.updateShippingAddress(address)); + this.updateShippingAddress(quote.shippingAddress()); + + quote.billingAddress.subscribe((address) => self.updateBillingAddress(address)); + this.updateBillingAddress(quote.billingAddress()); }, afterPlaceOrder: function () { const url = $.mage.cookies.get(config.redirectUrlCookieCode);