Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
Release 1.0.61
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Schurter committed Oct 2, 2019
1 parent 43dcdea commit dc84181
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 15 deletions.
40 changes: 35 additions & 5 deletions Model/Service/Order/TransactionService.php
Expand Up @@ -20,6 +20,7 @@
use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Address;
use Magento\Sales\Model\Order\Invoice;
Expand Down Expand Up @@ -87,6 +88,12 @@ class TransactionService extends AbstractTransactionService
*/
private $quoteRepository;

/**
*
* @var OrderRepositoryInterface
*/
private $orderRepository;

/**
*
* @var LineItemService
Expand Down Expand Up @@ -119,6 +126,7 @@ class TransactionService extends AbstractTransactionService
* @param ManagerInterface $eventManager
* @param CustomerRegistry $customerRegistry
* @param CartRepositoryInterface $quoteRepository
* @param OrderRepositoryInterface $orderRepository
* @param PaymentMethodConfigurationManagementInterface $paymentMethodConfigurationManagement
* @param ApiClient $apiClient
* @param CookieManagerInterface $cookieManager
Expand All @@ -129,17 +137,18 @@ class TransactionService extends AbstractTransactionService
*/
public function __construct(ResourceConnection $resource, Helper $helper, ScopeConfigInterface $scopeConfig,
ManagerInterface $eventManager, CustomerRegistry $customerRegistry, CartRepositoryInterface $quoteRepository,
TimezoneInterface $timezone, PaymentMethodConfigurationManagementInterface $paymentMethodConfigurationManagement,
ApiClient $apiClient, CookieManagerInterface $cookieManager, LoggerInterface $logger,
LineItemService $lineItemService, LineItemHelper $lineItemHelper,
TransactionInfoRepositoryInterface $transactionInfoRepository)
OrderRepositoryInterface $orderRepository, TimezoneInterface $timezone,
PaymentMethodConfigurationManagementInterface $paymentMethodConfigurationManagement, ApiClient $apiClient,
CookieManagerInterface $cookieManager, LoggerInterface $logger, LineItemService $lineItemService,
LineItemHelper $lineItemHelper, TransactionInfoRepositoryInterface $transactionInfoRepository)
{
parent::__construct($resource, $helper, $scopeConfig, $customerRegistry, $quoteRepository, $timezone,
$paymentMethodConfigurationManagement, $apiClient, $cookieManager);
$this->helper = $helper;
$this->scopeConfig = $scopeConfig;
$this->eventManager = $eventManager;
$this->quoteRepository = $quoteRepository;
$this->orderRepository = $orderRepository;
$this->logger = $logger;
$this->lineItemService = $lineItemService;
$this->lineItemHelper = $lineItemHelper;
Expand All @@ -163,6 +172,9 @@ public function confirmTransaction(Transaction $transaction, Order $order, Invoi
{
if ($transaction->getState() == TransactionState::CONFIRMED) {
return $transaction;
} elseif ($transaction->getState() != TransactionState::PENDING) {
$this->cancelOrder($order, $invoice);
throw new LocalizedException(\__('postfinancecheckout_checkout_failure'));
}

$spaceId = $order->getPostfinancecheckoutSpaceId();
Expand All @@ -175,7 +187,8 @@ public function confirmTransaction(Transaction $transaction, Order $order, Invoi
return $transaction;
} elseif (! ($transaction instanceof Transaction) ||
$transaction->getState() != TransactionState::PENDING) {
throw new LocalizedException(\__('The order failed because the payment timed out.'));
$this->cancelOrder($order, $invoice);
throw new LocalizedException(\__('postfinancecheckout_checkout_failure'));
}
}

Expand All @@ -195,6 +208,23 @@ public function confirmTransaction(Transaction $transaction, Order $order, Invoi
throw new VersioningException();
}

/**
* Cancels the given order and invoice linked to the transaction.
*
* @param Order $order
* @param Invoice $invoice
*/
private function cancelOrder(Order $order, Invoice $invoice)
{
if ($invoice) {
$order->setPostfinancecheckoutInvoiceAllowManipulation(true);
$invoice->cancel();
$order->addRelatedObject($invoice);
}
$order->registerCancellation(null, false);
$this->orderRepository->save($order);
}

/**
* Assembles the transaction data from the given order and invoice.
*
Expand Down
4 changes: 3 additions & 1 deletion Observer/SubmitQuote.php
Expand Up @@ -13,6 +13,7 @@
use Magento\Framework\DB\TransactionFactory as DBTransactionFactory;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;
Expand Down Expand Up @@ -106,7 +107,7 @@ public function execute(Observer $observer)
if (! empty($transactionId)) {
if (! $this->checkTransactionInfo($order)) {
$this->cancelOrder($order);
return;
throw new LocalizedException(\__('postfinancecheckout_checkout_failure'));
}

$transaction = $this->transactionService->getTransaction($order->getPostfinancecheckoutSpaceId(),
Expand Down Expand Up @@ -211,4 +212,5 @@ private function getInvoiceForTransaction(Order $order)
}
}
}

}
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -10,8 +10,8 @@ This repository contains the Magento 2.2 extension that enables to process payme

## Documentation

* [Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/1.0.60/docs/en/documentation.html)
* [Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/1.0.61/docs/en/documentation.html)

## License

Please see the [license file](https://github.com/pfpayments/magento-2.2/blob/1.0.60/LICENSE) for more information.
Please see the [license file](https://github.com/pfpayments/magento-2.2/blob/1.0.61/LICENSE) for more information.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -18,7 +18,7 @@
}
],
"type" : "magento2-module",
"version" : "1.0.60",
"version" : "1.0.61",
"require" : {
"php": "7.0.2|7.0.4|~7.0.6|~7.1.0",
"magento/framework" : "^101.0.2",
Expand Down
2 changes: 1 addition & 1 deletion docs/en/documentation.html
Expand Up @@ -21,7 +21,7 @@ <h2>Documentation</h2> </div>
</a>
</li>
<li>
<a href="https://github.com/pfpayments/magento-2.2/releases/tag/1.0.60/">
<a href="https://github.com/pfpayments/magento-2.2/releases/tag/1.0.61/">
Source
</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/system.xml
Expand Up @@ -18,7 +18,7 @@
<resource>PostFinanceCheckout_Payment::config</resource>
<group id="information" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Information</label>
<comment><![CDATA[If you need help setting up the PostFinance Checkout extension, check out the <a href="https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/1.0.60/docs/en/documentation.html" target="_blank">documentation</a>.]]></comment>
<comment><![CDATA[If you need help setting up the PostFinance Checkout extension, check out the <a href="https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/1.0.61/docs/en/documentation.html" target="_blank">documentation</a>.]]></comment>
<field id="version" translate="label" type="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Module Version</label>
</field>
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Expand Up @@ -14,7 +14,7 @@
<default>
<postfinancecheckout_payment>
<information>
<version>1.0.60</version>
<version>1.0.61</version>
<sdk_version>1.1.16</sdk_version>
</information>
<general>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Expand Up @@ -11,7 +11,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="PostFinanceCheckout_Payment" setup_version="1.0.60">
<module name="PostFinanceCheckout_Payment" setup_version="1.0.61">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down
2 changes: 1 addition & 1 deletion i18n/de_DE.csv
Expand Up @@ -50,7 +50,7 @@
"Gift Wrap","Geschenkverpackung"
"Hold Delivery","Lieferung halten"
"ID required","ID erforderlich"
"If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/1.0.60/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Falls Sie Hilfe benötigen beim Einrichten der PostFinance Checkout-Erweiterung, sehen Sie sich die <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/1.0.60/docs/en/documentation.html"" target=""_blank"">Dokumentation</a> an."
"If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/1.0.61/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Falls Sie Hilfe benötigen beim Einrichten der PostFinance Checkout-Erweiterung, sehen Sie sich die <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/1.0.61/docs/en/documentation.html"" target=""_blank"">Dokumentation</a> an."
"Inactive","Inaktiv"
"Information","Informationen"
"Invoice","Rechnung"
Expand Down
2 changes: 1 addition & 1 deletion i18n/en_US.csv
Expand Up @@ -50,7 +50,7 @@
"Gift Wrap","Gift Wrap"
"Hold Delivery","Hold Delivery"
"ID required","ID required"
"If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/1.0.60/docs/en/documentation.html"" target=""_blank"">documentation</a>.","If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/1.0.60/docs/en/documentation.html"" target=""_blank"">documentation</a>."
"If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/1.0.61/docs/en/documentation.html"" target=""_blank"">documentation</a>.","If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/1.0.61/docs/en/documentation.html"" target=""_blank"">documentation</a>."
"Inactive","Inactive"
"Information","Information"
"Invoice","Invoice"
Expand Down
Expand Up @@ -14,6 +14,7 @@ define([
'Magento_Checkout/js/model/payment/method-list',
'mage/url',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/payment/additional-validators',
'PostFinanceCheckout_Payment/js/model/checkout-handler'
], function(
$,
Expand All @@ -22,6 +23,7 @@ define([
methodList,
urlBuilder,
quote,
additionalValidators,
checkoutHandler
){
'use strict';
Expand Down Expand Up @@ -130,6 +132,42 @@ define([
}
},

placeOrder: function (data, event) {
var self = this;

if (event) {
event.preventDefault();
}

if (this.validate() && additionalValidators.validate()) {
this.isPlaceOrderActionAllowed(false);

this.getPlaceOrderDeferredObject()
.fail(
function (response) {
var error = null;
try {
error = JSON.parse(response.responseText);
} catch (exception) {
}
if (typeof error == 'object' && error.message == 'postfinancecheckout_checkout_failure') {
window.location.replace(urlBuilder.build("postfinancecheckout_payment/checkout/failure"));
} else {
self.isPlaceOrderActionAllowed(true);
}
}
).done(
function () {
self.afterPlaceOrder();
}
);

return true;
}

return false;
},

afterPlaceOrder: function(){
if (this.handler) {
this.handler.submit();
Expand Down

0 comments on commit dc84181

Please sign in to comment.