-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2566ea5
commit 3c89855
Showing
9 changed files
with
338 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Paytrail\PaymentServiceGraphQl\Model; | ||
|
||
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface; | ||
|
||
/** | ||
* Get payment additional data for Payflow pro payment | ||
*/ | ||
class PaytrailAdditionalDataProvider implements AdditionalDataProviderInterface | ||
{ | ||
private const PATH_ADDITIONAL_DATA = 'paytrail'; | ||
|
||
/** | ||
* Returns additional data | ||
* | ||
* @param array $args | ||
* | ||
* @return array | ||
*/ | ||
public function getData(array $args): array | ||
{ | ||
return $args[self::PATH_ADDITIONAL_DATA] ?? []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
namespace Paytrail\PaymentServiceGraphQl\Model\Resolver; | ||
|
||
use Magento\Checkout\Model\Session; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\Payment\Gateway\Command\CommandManagerPoolInterface; | ||
use Magento\Sales\Model\Order; | ||
use Paytrail\PaymentService\Exceptions\CheckoutException; | ||
use Paytrail\PaymentService\Gateway\Config\Config; | ||
use Paytrail\PaymentService\Model\ProviderForm; | ||
use Paytrail\PaymentService\Model\Ui\DataProvider\PaymentProvidersData; | ||
use Paytrail\SDK\Response\PaymentResponse; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class PaymentDetails implements ResolverInterface | ||
{ | ||
public function __construct( | ||
private readonly Session $checkoutSession, | ||
private readonly LoggerInterface $logger, | ||
private readonly CommandManagerPoolInterface $commandManagerPool, | ||
private readonly PaymentProvidersData $paymentProvidersData, | ||
private readonly ProviderForm $providerForm | ||
) { | ||
} | ||
|
||
/** | ||
* @param Field $field | ||
* @param $context | ||
* @param ResolveInfo $info | ||
* @param array|null $value | ||
* @param array|null $args | ||
* | ||
* @return string[] | ||
*/ | ||
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null): array | ||
{ | ||
$result = [ | ||
'payment_url' => '', | ||
'error' => '', | ||
'payment_form_html' => '' | ||
]; | ||
|
||
try { | ||
$order = $this->checkoutSession->getLastRealOrder(); | ||
if ($order->getPayment()->getMethod() == Config::CODE) { | ||
$paytrailPayment = $this->getPaytrailPayment($order); | ||
$result['payment_url'] = $paytrailPayment->getHref(); | ||
$result['payment_form'] = $this->getForm($paytrailPayment, $order); | ||
} | ||
} catch (\Exception $e) { | ||
$this->logger->error($e->getMessage()); | ||
$result['error'] = $e->getMessage(); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @param Order $order | ||
* | ||
* @return PaymentResponse | ||
* @throws CheckoutException | ||
*/ | ||
private function getPaytrailPayment(Order $order): PaymentResponse | ||
{ | ||
$commandExecutor = $this->commandManagerPool->get('paytrail'); | ||
$response = $commandExecutor->executeByCode( | ||
'payment', | ||
null, | ||
[ | ||
'order' => $order, | ||
'payment_method' => $this->paymentProvidersData->getIdWithoutIncrement( | ||
$order->getPayment()->getAdditionalInformation()['provider'] ?? '' | ||
) | ||
] | ||
); | ||
|
||
if ($response['error']) { | ||
$this->errorMsg = ($response['error']); | ||
$this->processService->processError($response['error']); | ||
} | ||
|
||
return $response["data"]; | ||
} | ||
|
||
/** | ||
* @param PaymentResponse $response | ||
* @param Order $order | ||
* | ||
* @return array|null | ||
*/ | ||
private function getForm(PaymentResponse $response, Order $order): ?array | ||
{ | ||
$paymentMethodId = $this->paymentProvidersData->getIdWithoutIncrement( | ||
$order->getPayment()->getAdditionalInformation()['provider'] ?? '' | ||
); | ||
|
||
if (!$paymentMethodId) { | ||
return null; | ||
} | ||
|
||
return $this->providerForm->getFormParams($response, $paymentMethodId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Paytrail\PaymentServiceGraphQl\Model\Resolver; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\Quote\Api\CartRepositoryInterface; | ||
use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface; | ||
use Paytrail\PaymentService\Model\ConfigProvider; | ||
|
||
class PaytrailConfig implements ResolverInterface | ||
{ | ||
|
||
/** | ||
* @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId | ||
* @param CartRepositoryInterface $cartRepository | ||
*/ | ||
public function __construct( | ||
private readonly MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId, | ||
private readonly CartRepositoryInterface $cartRepository, | ||
private readonly \Paytrail\PaymentService\Model\Ui\ConfigProvider $configProvider | ||
) { | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) | ||
{ | ||
if (empty($args['cart_id'])) { | ||
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 | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Paytrail\PaymentServiceGraphQl\Observer; | ||
|
||
use Magento\Framework\Event\Observer; | ||
use Magento\Payment\Observer\AbstractDataAssignObserver; | ||
use Magento\Quote\Api\Data\PaymentInterface; | ||
|
||
/** | ||
* Set additional data for payflow link payment | ||
*/ | ||
class PaytrailSetAdditionalData extends AbstractDataAssignObserver | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
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'])) { | ||
$additionalData = $additionalData['additional_information']; | ||
} | ||
if (!is_array($additionalData)) { | ||
return; | ||
} | ||
|
||
$paymentModel = $this->readPaymentModelArgument($observer); | ||
$paymentModel->setAdditionalInformation($additionalData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,31 @@ | ||
# paytrail-for-adobe-commerce-graphql | ||
Paytrail for Adobe Commerce - GraphQL Module | ||
The README.md file content is generated automatically, see [Magento module README.md](https://github.com/magento/devdocs/wiki/Magento-module-README.md) for more information. | ||
|
||
# Paytrail_PaymentServiceGraphQl module | ||
|
||
|
||
|
||
## Installation details | ||
|
||
For information about a module installation in Magento 2, see [Enable or disable modules](https://devdocs.magento.com/guides/v2.4/install-gde/install/cli/install-cli-subcommands-enable.html). | ||
|
||
## Extensibility | ||
|
||
Extension developers can interact with the Paytrail_PaymentServiceGraphQl module. For more information about the Magento extension mechanism, see [Magento plug-ins](https://devdocs.magento.com/guides/v2.4/extension-dev-guide/plugins.html). | ||
|
||
[The Magento dependency injection mechanism](https://devdocs.magento.com/guides/v2.4/extension-dev-guide/depend-inj.html) enables you to override the functionality of the Paytrail_PaymentServiceGraphQl module. | ||
|
||
### Layouts | ||
|
||
The module introduces layout handles in the `view/adminhtml/layout` directory. | ||
|
||
For more information about a layout in Magento 2, see the [Layout documentation](https://devdocs.magento.com/guides/v2.4/frontend-dev-guide/layouts/layout-overview.html). | ||
|
||
### UI components | ||
|
||
You can extend product and category updates using the UI components located in the `view/adminhtml/ui_component` directory. | ||
|
||
For information about a UI component in Magento 2, see [Overview of UI components](https://devdocs.magento.com/guides/v2.4/ui_comp_guide/bk-ui_comps.html). | ||
|
||
## Additional information | ||
|
||
For information about significant changes in patch releases, see [Release information](https://devdocs.magento.com/guides/v2.4/release-notes/bk-release-notes.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
|
||
<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> | ||
</argument> | ||
</arguments> | ||
</type> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* 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"> | ||
<event name="payment_method_assign_data_paytrail"> | ||
<observer name="paytrail_data_assigner" instance="Paytrail\PaymentServiceGraphQl\Observer\PaytrailSetAdditionalData"/> | ||
</event> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters