Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BP-1375 Retrieve extra information for payment method #1

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions Model/AdditionalDataProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/**
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* It is available through the world-wide-web at this URL:
* https://tldrlegal.com/license/mit-license
* If you are unable to obtain it through the world-wide-web, please send an email
* to support@buckaroo.nl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact support@buckaroo.nl for more information.
*
* @copyright Copyright (c) Buckaroo B.V.
* @license https://tldrlegal.com/license/mit-license
*/

namespace Buckaroo\Magento2Graphql\Model;

use Buckaroo\Magento2Graphql\Plugin\AdditionalDataProviderPool;
use Buckaroo\Magento2Graphql\Model\Payment\Method\ConfigFactory;
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface;

class AdditionalDataProvider implements AdditionalDataProviderInterface
{
const PAYMENT_FROM = 'buckaroo_payment_from';
/**
*
* @var Buckaroo\Magento2Graphql\Model\Payment\Method\ConfigFactory
*/
protected $fieldListFactory;

public function __construct(ConfigFactory $fieldListFactory)
{
$this->fieldListFactory = $fieldListFactory;
}
/**
* Return Additional Data,
* set a flag so we know the payment originated from graphql
*
* @param array $args
* @return array
*/
public function getData(array $args): array
{
$args[self::PAYMENT_FROM] = 'graphQl';

if (isset($args[AdditionalDataProviderPool::PROVIDER_KEY][$args['code']])) {

$additionalArgs = $args[AdditionalDataProviderPool::PROVIDER_KEY][$args['code']];
unset($args[AdditionalDataProviderPool::PROVIDER_KEY]);

return array_merge($args, $additionalArgs);
}

return $args;
}
}
76 changes: 76 additions & 0 deletions Model/MainConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* It is available through the world-wide-web at this URL:
* https://tldrlegal.com/license/mit-license
* If you are unable to obtain it through the world-wide-web, please send an email
* to support@buckaroo.nl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact support@buckaroo.nl for more information.
*
* @copyright Copyright (c) Buckaroo B.V.
* @license https://tldrlegal.com/license/mit-license
*/

namespace Buckaroo\Magento2Graphql\Model;

use Magento\Store\Model\StoreManagerInterface;
use \Magento\Framework\App\Config\ScopeConfigInterface;

class MainConfig
{

const XPATH_ENABLE_GRAPHQL = 'buckaroo_magento2/graphql/enable_graphql';
const XPATH_BASE_URL = 'buckaroo_magento2/graphql/base_url';
const XPATH_PAYMENT_PROCESSED_REDIRECT = 'buckaroo_magento2/graphql/payment_processed_redirect';

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;

/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;

public function __construct(
ScopeConfigInterface $scopeConfig,
StoreManagerInterface $storeManager
) {
$this->scopeConfig = $scopeConfig;
$this->storeManager = $storeManager;
}

public function isGraphQlEnabled()
{
return $this->getValue(self::XPATH_ENABLE_GRAPHQL) == 1;
}
public function getBaseUrl()
{
$baseUrl = $this->getValue(self::XPATH_BASE_URL);
if (is_string($baseUrl) && filter_var($baseUrl, FILTER_VALIDATE_URL)) {
return rtrim($baseUrl, "/");
}
}
public function getPaymentProcessedPath()
{
return ltrim($this->getValue(self::XPATH_PAYMENT_PROCESSED_REDIRECT), "/");
}

protected function getValue($xpath)
{
return $this->scopeConfig->getValue(
$xpath,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$this->storeManager->getStore()
);
}
}
45 changes: 45 additions & 0 deletions Model/Payment/Method/AbstractConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* It is available through the world-wide-web at this URL:
* https://tldrlegal.com/license/mit-license
* If you are unable to obtain it through the world-wide-web, please send an email
* to support@buckaroo.nl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact support@buckaroo.nl for more information.
*
* @copyright Copyright (c) Buckaroo B.V.
* @license https://tldrlegal.com/license/mit-license
*/

namespace Buckaroo\Magento2Graphql\Model\Payment\Method;

use Buckaroo\Magento2\Model\ConfigProvider\Method\ConfigProviderInterface;

abstract class AbstractConfig
{
/**
*
* @var Buckaroo\Magento2\Model\ConfigProvider\Method\ConfigProviderInterface
*/
protected $configProvider;

public function __construct(ConfigProviderInterface $configProvider) {
$this->configProvider = $configProvider;
}
/**
* Get payment method configuration
*
* @return array
*/
public function getConfig()
{
return [];
}
}
48 changes: 48 additions & 0 deletions Model/Payment/Method/Config/Afterpay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* It is available through the world-wide-web at this URL:
* https://tldrlegal.com/license/mit-license
* If you are unable to obtain it through the world-wide-web, please send an email
* to support@buckaroo.nl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact support@buckaroo.nl for more information.
*
* @copyright Copyright (c) Buckaroo B.V.
* @license https://tldrlegal.com/license/mit-license
*/

namespace Buckaroo\Magento2Graphql\Model\Payment\Method\Config;

use Buckaroo\Magento2Graphql\Model\Payment\Method\AbstractConfig;

class Afterpay extends AbstractConfig
{
/**
*
* @var Buckaroo\Magento2\Model\ConfigProvider\Method\Afterpay
*/
protected $configProvider;
/**
* @inheritDoc
*/
public function getConfig()
{
return [
[
"key"=>"businessMethod",
"value" => $this->configProvider->getBusiness()
],
[
"key"=>"paymentMethod",
"value" => $this->configProvider->getPaymentMethod()
]
];
}
}
43 changes: 43 additions & 0 deletions Model/Payment/Method/Config/Afterpay2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* It is available through the world-wide-web at this URL:
* https://tldrlegal.com/license/mit-license
* If you are unable to obtain it through the world-wide-web, please send an email
* to support@buckaroo.nl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact support@buckaroo.nl for more information.
*
* @copyright Copyright (c) Buckaroo B.V.
* @license https://tldrlegal.com/license/mit-license
*/

namespace Buckaroo\Magento2Graphql\Model\Payment\Method\Config;

use Buckaroo\Magento2Graphql\Model\Payment\Method\AbstractConfig;

class Afterpay2 extends AbstractConfig
{
/**
* @inheritDoc
*/
public function getConfig()
{
return [
[
"key"=>"businessMethod",
"value" => $this->configProvider->getBusiness()
],
[
"key"=>"paymentMethod",
"value" => $this->configProvider->getPaymentMethod()
]
];
}
}
85 changes: 85 additions & 0 deletions Model/Payment/Method/Config/Applepay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

/**
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* It is available through the world-wide-web at this URL:
* https://tldrlegal.com/license/mit-license
* If you are unable to obtain it through the world-wide-web, please send an email
* to support@buckaroo.nl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact support@buckaroo.nl for more information.
*
* @copyright Copyright (c) Buckaroo B.V.
* @license https://tldrlegal.com/license/mit-license
*/

namespace Buckaroo\Magento2Graphql\Model\Payment\Method\Config;

use Buckaroo\Magento2Graphql\Model\Payment\Method\AbstractConfig;

class Applepay extends AbstractConfig
{
/**
* @inheritDoc
*/
public function getConfig()
{
return [
[
"key" => "storeName",
"value" => $this->getConfigValue('storeName')
],
[
"key" => "currency",
"value" => $this->getConfigValue('currency')
],
[
"key" => "cultureCode",
"value" => $this->getConfigValue('cultureCode')
],
[
"key" => "country",
"value" => $this->getConfigValue('country')
],
[
"key" => "guid",
"value" => $this->getConfigValue('guid')
],
[
"key" => "buttonStyle",
"value" => $this->getConfigValue('buttonStyle')
],
[
"key" => "dontAskBillingInfoInCheckout",
"value" => $this->getConfigValue('dontAskBillingInfoInCheckout')
],
[
"key" => "availableButtons",
"value" => $this->getAvailableButtons()
]

];
}
protected function getConfigValue($key)
{
return $this->configProvider->getConfig()['payment']['buckaroo']['applepay'][$key];
}
/**
* Get list of available buttons
*
* @return void
*/
protected function getAvailableButtons()
{
$availableButtons = $this->getConfigValue('availableButtons');
if (count($availableButtons)) {
return implode(",", $availableButtons);
}
}
}
Loading