Skip to content

Commit

Permalink
Merge pull request #2 from Solteq/master
Browse files Browse the repository at this point in the history
merge changes from fork repo
  • Loading branch information
loueranta-paytrail authored Jan 10, 2024
2 parents 933c224 + af88b64 commit c456e67
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 19 deletions.
23 changes: 21 additions & 2 deletions Model/Resolver/PaymentDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace Paytrail\PaymentServiceGraphQl\Model\Resolver;

use Magento\Checkout\Model\Session;
use Magento\Framework\Exception\NotFoundException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Payment\Gateway\Command\CommandException;
use Magento\Payment\Gateway\Command\CommandManagerPoolInterface;
use Magento\Sales\Model\Order;
use Paytrail\PaymentService\Exceptions\CheckoutException;
Expand All @@ -17,6 +20,15 @@

class PaymentDetails implements ResolverInterface
{
/**
* Class constructor.
*
* @param Session $checkoutSession
* @param LoggerInterface $logger
* @param CommandManagerPoolInterface $commandManagerPool
* @param PaymentProvidersData $paymentProvidersData
* @param ProviderForm $providerForm
*/
public function __construct(
private readonly Session $checkoutSession,
private readonly LoggerInterface $logger,
Expand All @@ -27,8 +39,10 @@ public function __construct(
}

/**
* Resolve function.
*
* @param Field $field
* @param $context
* @param ContextInterface $context
* @param ResolveInfo $info
* @param array|null $value
* @param array|null $args
Expand Down Expand Up @@ -59,10 +73,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
}

/**
* Get Paytrail payment.
*
* @param Order $order
*
* @return PaymentResponse
* @throws CheckoutException
* @throws NotFoundException
* @throws CommandException
*/
private function getPaytrailPayment(Order $order): PaymentResponse
{
Expand All @@ -87,6 +104,8 @@ private function getPaytrailPayment(Order $order): PaymentResponse
}

/**
* Get form parameters for selected provider.
*
* @param PaymentResponse $response
* @param Order $order
*
Expand Down
5 changes: 1 addition & 4 deletions Model/Resolver/PaytrailConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ class PaytrailConfig implements ResolverInterface

/**
* @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId
* @param CartRepositoryInterface $cartRepository
* @param \Paytrail\PaymentService\Model\Ui\ConfigProvider $configProvider
*/
public function __construct(
private readonly MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId,
private readonly CartRepositoryInterface $cartRepository,
private readonly \Paytrail\PaymentService\Model\Ui\ConfigProvider $configProvider
) {
}
Expand All @@ -33,12 +32,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
}

$cartId = $this->maskedQuoteIdToQuoteId->execute($args['cart_id']);
$config = $this->configProvider->getConfig();

$methodGroups = $config['payment']['paytrail']['method_groups'];


return [
'groups' => $methodGroups
];
Expand Down
23 changes: 20 additions & 3 deletions Model/Resolver/RestoreQuote.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Quote\Api\CartRepositoryInterface;
Expand All @@ -27,7 +28,6 @@

class RestoreQuote implements ResolverInterface
{

/**
* RestoreQuote constructor.
*
Expand All @@ -41,11 +41,22 @@ public function __construct(
}

/**
* @inheritdoc
* Resolve masked cart id to quote id
*
* @param Field $field
* @param ContextInterface $context
* @param ResolveInfo $info
* @param array|null $value
* @param array|null $args
*
* @return string
* @throws GraphQlAuthorizationException
* @throws GraphQlInputException
* @throws GraphQlNoSuchEntityException
*/
public function resolve(
Field $field,
$context,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
Expand All @@ -66,6 +77,8 @@ public function resolve(
}

/**
* Get cart for user
*
* @param string $cartHash
* @param int|null $customerId
* @param int $storeId
Expand Down Expand Up @@ -113,7 +126,11 @@ private function getQuoteByHash(string $cartHash, ?int $customerId, int $storeId
}

/**
* Restore Quote
*
* @param CartInterface $cart
*
* @return void
*/
private function restoreQuote(CartInterface $cart): void
{
Expand Down
5 changes: 4 additions & 1 deletion Observer/PaytrailSetAdditionalData.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ public function execute(Observer $observer): void
$dataObject = $this->readDataArgument($observer);

$additionalData = $dataObject->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
if (isset($additionalData['additional_information']) and isset($additionalData['additional_information']['provider'])) {
if (isset($additionalData['additional_information'])
&& isset($additionalData['additional_information']['provider'])
) {
$additionalData = $additionalData['additional_information'];
}

if (!is_array($additionalData)) {
return;
}
Expand Down
27 changes: 21 additions & 6 deletions Plugin/GetFrontendUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,34 @@
use Magento\Quote\Model\QuoteIdMaskFactory;
use Magento\Sales\Model\Order;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Support\Model\Report\Group\Modules\Modules;
use Paytrail\PaymentService\Controller\Receipt\Index;

class GetFrontendUrl
{
/**
* @param QuoteIdMaskFactory $idMaskFactory
* @param Modules $modules
* @param ScopeConfigInterface $config
* @param StoreManagerInterface $storeManager
*/
public function __construct(
private readonly QuoteIdMaskFactory $idMaskFactory,
private readonly \Magento\Support\Model\Report\Group\Modules\Modules $modules,
private readonly ScopeConfigInterface $config,
private readonly QuoteIdMaskFactory $idMaskFactory,
private readonly Modules $modules,
private readonly ScopeConfigInterface $config,
private readonly StoreManagerInterface $storeManager
) {
}

/**
* Get success url based on pwa configuration.
*
* @param Index $subject
* @param string $result
* @param Order $order
*
* @return string
* @throws NoSuchEntityException
*/
public function afterGetSuccessUrl(Index $subject, string $result, Order $order): string
{
Expand All @@ -38,14 +48,15 @@ public function afterGetSuccessUrl(Index $subject, string $result, Order $order)
}

$maskedId = $this->getMaskedId($order);
$result = trim($frontendBaseUrl, '/') . '/checkout/success/' . $order->getIncrementId(
) . '/maskedId/' . $maskedId;
$result = trim($frontendBaseUrl, '/') . '/checkout/success/' . $order->getIncrementId()
. '/maskedId/' . $maskedId;

return $result;
}


/**
* Get cart url based on pwa configuration.
*
* @param Index $subject
* @param string $result
* @param Order $order
Expand All @@ -72,6 +83,8 @@ public function afterGetCartUrl(Index $subject, string $result, Order $order): s
}

/**
* Get quote masked id.
*
* @param Order $order
*
* @return string
Expand All @@ -84,6 +97,8 @@ private function getMaskedId(Order $order): string
}

/**
* Get base url for pwa frontend
*
* @return string
*/
private function getBaseUrl(): string
Expand Down
5 changes: 5 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@
type="Paytrail\PaymentServiceGraphQl\Plugin\GetFrontendUrl"
sortOrder="100"/>
</type>
<type name="Paytrail\PaymentServiceGraphQl\Model\Resolver\PaymentDetails">
<arguments>
<argument name="checkoutSession" xsi:type="object">Magento\Checkout\Model\Session\Proxy</argument>
</arguments>
</type>
</config>
4 changes: 3 additions & 1 deletion etc/graphql/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<type name="Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool">
<arguments>
<argument name="dataProviders" xsi:type="array">
<item name="paytrail" xsi:type="object">Paytrail\PaymentServiceGraphQl\Model\PaytrailAdditionalDataProvider</item>
<item name="paytrail" xsi:type="object">
Paytrail\PaymentServiceGraphQl\Model\PaytrailAdditionalDataProvider
</item>
</argument>
</arguments>
</type>
Expand Down
6 changes: 4 additions & 2 deletions etc/graphql/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="payment_method_assign_data_paytrail">
<observer name="paytrail_data_assigner" instance="Paytrail\PaymentServiceGraphQl\Observer\PaytrailSetAdditionalData"/>
<observer name="paytrail_data_assigner"
instance="Paytrail\PaymentServiceGraphQl\Observer\PaytrailSetAdditionalData"/>
</event>
</config>

0 comments on commit c456e67

Please sign in to comment.