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

Commit

Permalink
Release 2.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Oct 12, 2023
1 parent 80f0d1d commit 4f2fab0
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 43 deletions.
135 changes: 105 additions & 30 deletions Model/Resolver/RestoreQuote.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
namespace PostFinanceCheckout\Payment\Model\Resolver;

use Magento\Authorization\Model\UserContextInterface;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\CustomerGraphQl\Model\Customer\GetCustomer;
use Magento\Framework\Event\ManagerInterface;
Expand Down Expand Up @@ -79,7 +80,16 @@ class RestoreQuote implements ResolverInterface
*/
private $logger;


/**
* @param Session $customerSession
* @param CheckoutSession $checkoutSession
* @param GetCustomer $getCustomer
* @param CartRepositoryInterface $cartRepository
* @param OrderRepositoryInterface $orderRepository
* @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteIdService
* @param ManagerInterface $eventManager
* @param LoggerInterface $logger
*/
public function __construct(Session $customerSession, CheckoutSession $checkoutSession,GetCustomer $getCustomer,
CartRepositoryInterface $cartRepository, OrderRepositoryInterface $orderRepository,
MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteIdService, ManagerInterface $eventManager, LoggerInterface $logger) {
Expand All @@ -93,43 +103,39 @@ public function __construct(Session $customerSession, CheckoutSession $checkoutS
$this->logger = $logger;
}

/**
* @inheritDoc
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
$customerId = null;
try {
$cartIdMasked = $args['input']['cart_id'];

//only perform validations if the user is anonymous.
if ($this->checkoutSession->getQuote()->getCustomerId() || !$this->customerSession->getCustomer()->getId()) {
/** @var ContextInterface $context */
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
if ($context->getUserType() === UserContextInterface::USER_TYPE_GUEST) {
return $this->restoreGuestQuote($cartIdMasked);
}

$customer = $this->getCustomer->execute($context);
$customerId = $customer->getId();

if (!empty($this->customerSession) && $customerId !== $this->customerSession->getCustomer()->getId()) {
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
if ($context->getUserType() !== UserContextInterface::USER_TYPE_GUEST) {
/** @var ContextInterface $context $customerId */
$customerId = $this->getCustomerIdFromContext($context);
return $this->restoreCustomerQuote($cartIdMasked, $customerId);
}
}

try {
$cartIdMasked = $args['input']['cart_id'];
return $this->restoreQuote($cartIdMasked, $customerId);
return ['result' => 'There is no cart available'];
} catch (NoSuchEntityException|\Exception $e) {
$this->logger->critical($e);
throw new GraphQlNoSuchEntityException(__($e->getMessage()));
}
}

/**
* Restores a client's quote from a cart id
* Restores a customer's quote from a cart id
*
* @param string $cartIdMasked
* @param string $customerId
* @return array
* @throws LocalizedException
*/
private function restoreQuote(string $cartIdMasked, string $customerId)
private function restoreCustomerQuote(string $cartIdMasked, string $customerId)
{
try {
// Convert the masked ID to the real quote ID
Expand All @@ -144,19 +150,31 @@ private function restoreQuote(string $cartIdMasked, string $customerId)
$this->guardQuoteBelongsToCurrentCustomer($order, $customerId);
$this->guardQuoteIsStillActive($quote);

//restore a customer's quote
$quote->setIsActive(1)->setReservedOrderId(null);
return $this->restoreQuote($cartIdMasked, $quote, $order);
} catch (NoSuchEntityException|\Exception $e) {
return ['result' => 'KO. ' . $e->getMessage()];
}
}

$this->cartRepository->save($quote);
$this->checkoutSession->replaceQuote($quote)->unsLastRealOrderId();
/**
* Restores a guest's quote from a cart id
*
* @param string $cartIdMasked
* @return array
* @throws LocalizedException
*/
private function restoreGuestQuote(string $cartIdMasked)
{
try {
// Convert the masked ID to the real quote ID
$quoteId = $this->maskedQuoteIdToQuoteIdService->execute($cartIdMasked);

$this->eventManager->dispatch('restore_quote', ['order' => $order, 'quote' => $quote]);
$this->logger->debug("RESTORE-QUOTE-MUTATION::restoreQuote - Quote with id $cartIdMasked was restored");
// Get the quote using the actual ID
/** @var Quote $quote */
$quote = $this->cartRepository->get($quoteId);
$order = $this->getOrderByQuote($quote);

return [
'result' => 'OK',
'cart_id' => $cartIdMasked
];
return $this->restoreQuote($cartIdMasked, $quote, $order);
} catch (NoSuchEntityException|\Exception $e) {
return ['result' => 'KO. ' . $e->getMessage()];
}
Expand All @@ -174,7 +192,7 @@ public function getOrderByQuote(Quote $quote)
$orderId = $quote->getReservedOrderId();

if (empty($orderId)) {
throw new \Exception(__('The quote does not have an associated order'));
throw new \Exception(__('The cart does not have an associated order'));
}

return $this->orderRepository->getOrderById($orderId);
Expand Down Expand Up @@ -212,4 +230,61 @@ private function guardQuoteIsStillActive(Quote $quote)
throw new \Exception(__('The quote is still active.'));
}
}

/**
* Gets the customer id from the user context
* @param ContextInterface $context
* @param int|null $customerId
* @return int|null
* @throws GraphQlAuthorizationException
* @throws GraphQlNoSuchEntityException
* @throws LocalizedException
* @throws NoSuchEntityException
* @throws \Magento\Framework\GraphQl\Exception\GraphQlAuthenticationException
* @throws \Magento\Framework\GraphQl\Exception\GraphQlInputException
*/
public function getCustomerIdFromContext(ContextInterface $context): mixed
{
$customerId = null;
if ($context->getUserType() === UserContextInterface::USER_TYPE_GUEST) {
return $customerId;
}

//only perform validations if the user is anonymous.
if ($this->checkoutSession->getQuote()->getCustomerId() || !$this->customerSession->getCustomer()->getId()) {
/** @var ContextInterface $context */
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
}

$customer = $this->getCustomer->execute($context);
$customerId = $customer->getId();

if (!empty($this->customerSession) && $customerId !== $this->customerSession->getCustomer()->getId()) {
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
}
}
return $customerId;
}

/**
* Restore a customer or guest's quote
* @param Quote $quote
* @param OrderInterface|null $order
* @return array<mixed>
*/
public function restoreQuote(string $cartIdMasked, Quote $quote, OrderInterface $order = null)
{
$quote->setIsActive(1)->setReservedOrderId(null);

$this->cartRepository->save($quote);
$this->checkoutSession->replaceQuote($quote)->unsLastRealOrderId();
$this->eventManager->dispatch('restore_quote', ['order' => $order, 'quote' => $quote]);
$this->logger->debug("RESTORE-QUOTE-MUTATION::restoreQuote - Quote with id $cartIdMasked was restored");

return [
'result' => 'OK',
'cart_id' => $cartIdMasked
];
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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/2.1.5/docs/en/documentation.html)
* [Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.6/docs/en/documentation.html)

## Support

Expand All @@ -28,4 +28,4 @@ We do provide special integrations for the following one step checkouts:

## License

Please see the [license file](https://github.com/pfpayments/magento-2.2/blob/2.1.5/LICENSE) for more information.
Please see the [license file](https://github.com/pfpayments/magento-2.2/blob/2.1.6/LICENSE) for more information.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"type" : "magento2-module",
"version" : "2.1.5",
"version" : "2.1.6",
"require" : {
"php": "7.0.2|7.0.4|~7.0.6|~7.1.0|~7.2.0|~8.0|~8.1",
"magento/framework" : "^101.0.2",
Expand Down
2 changes: 1 addition & 1 deletion docs/en/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h2>Documentation</h2> </div>
</a>
</li>
<li>
<a href="https://github.com/pfpayments/magento-2.2/releases/tag/2.1.5/">
<a href="https://github.com/pfpayments/magento-2.2/releases/tag/2.1.6/">
Source
</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
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/2.1.5/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/2.1.6/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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<default>
<postfinancecheckout_payment>
<information>
<version>2.1.5</version>
<version>2.1.6</version>
<sdk_version>3.2.0</sdk_version>
</information>
<general>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
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="2.1.5">
<module name="PostFinanceCheckout_Payment" setup_version="2.1.6">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down
2 changes: 1 addition & 1 deletion i18n/de_DE.csv
Original file line number Diff line number Diff line change
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/2.1.5/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/2.1.5/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/2.1.6/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/2.1.6/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
Original file line number Diff line number Diff line change
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/2.1.5/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/2.1.5/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/2.1.6/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/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a>."
"Inactive","Inactive"
"Information","Information"
"Invoice","Invoice"
Expand Down
2 changes: 1 addition & 1 deletion i18n/fr_CH.csv
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"Gift Wrap","Papier cadeau"
"Hold Delivery","Suspendre la livraison"
"ID required","Pièce d'identité requise"
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Si vous avez besoin d'aide pour configurer l'extension wallee, consultez la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentation</a> an."
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Si vous avez besoin d'aide pour configurer l'extension wallee, consultez la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a> an."
"Inactive","Inactif"
"Information","Information"
"Invoice","Facture"
Expand Down
2 changes: 1 addition & 1 deletion i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"Gift Wrap","Papier cadeau"
"Hold Delivery","Suspendre la livraison"
"ID required","Pièce d'identité requise"
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Si vous avez besoin d'aide pour configurer l'extension wallee, consultez la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentation</a> an."
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Si vous avez besoin d'aide pour configurer l'extension wallee, consultez la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a> an."
"Inactive","Inactif"
"Information","Information"
"Invoice","Facture"
Expand Down
2 changes: 1 addition & 1 deletion i18n/it_CH.csv
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"Gift Wrap","Confezione regalo"
"Hold Delivery","Sospendi la consegna"
"ID required","ID richiesto"
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Se hai bisogno di aiuto per configurare l'estensione wallee, consulta la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentazione</a> an."
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Se hai bisogno di aiuto per configurare l'estensione wallee, consulta la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentazione</a> an."
"Inactive","Inattivo"
"Information","Informazione"
"Invoice","Fattura"
Expand Down
2 changes: 1 addition & 1 deletion i18n/it_IT.csv
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"Gift Wrap","Confezione regalo"
"Hold Delivery","Sospendi la consegna"
"ID required","ID richiesto"
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Se hai bisogno di aiuto per configurare l'estensione wallee, consulta la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.5/docs/en/documentation.html"" target=""_blank"">documentazione</a> an."
"If you need help setting up the wallee extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Se hai bisogno di aiuto per configurare l'estensione wallee, consulta la <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.2/2.1.6/docs/en/documentation.html"" target=""_blank"">documentazione</a> an."
"Inactive","Inattivo"
"Information","Informazione"
"Invoice","Fattura"
Expand Down

0 comments on commit 4f2fab0

Please sign in to comment.