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

add release channel config option #29

Merged
merged 1 commit into from
Sep 17, 2024
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
11 changes: 11 additions & 0 deletions Api/Config/System/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ interface ConnectionInterface extends DebugInterface
public const XML_PATH_SANDBOX_CLIENT_SECRET = 'payment/truelayer/sandbox_client_secret';
public const XML_PATH_SANDBOX_PRIVATE_KEY = 'payment/truelayer/sandbox_private_key';
public const XML_PATH_SANDBOX_KEY_ID = 'payment/truelayer/sandbox_key_id';
public const XML_PATH_SANDBOX_RELEASE_CHANNEL = 'payment/truelayer/sandbox_release_channel';
public const XML_PATH_PRODUCTION_CLIENT_ID = 'payment/truelayer/production_client_id';
public const XML_PATH_PRODUCTION_CLIENT_SECRET = 'payment/truelayer/production_client_secret';
public const XML_PATH_PRODUCTION_PRIVATE_KEY = 'payment/truelayer/production_private_key';
public const XML_PATH_PRODUCTION_KEY_ID = 'payment/truelayer/production_key_id';
public const XML_PATH_PRODUCTION_RELEASE_CHANNEL = 'payment/truelayer/production_release_channel';

/**
* Get Merchant Account Name
Expand Down Expand Up @@ -53,4 +55,13 @@ public function isSandbox(?int $storeId = null): bool;
* @return array
*/
public function getCredentials(?int $storeId = null, ?bool $forceSandbox = null): array;

/**
* Get associated array of credentials
*
* @param int|null $storeId
*
* @return array
*/
public function getReleaseChannel(?int $storeId = null): string;
}
34 changes: 34 additions & 0 deletions Model/Config/Source/ReleaseChannel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright © TrueLayer Ltd. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace TrueLayer\Connect\Model\Config\Source;

use Magento\Framework\Data\OptionSourceInterface;

/**
* ReleaseChannel Options Source model
*/
class ReleaseChannel implements OptionSourceInterface
{
public const GENERAL_AVAILABILITY = 'general_availability';
public const PUBLIC_BETA = 'public_beta';
public const PRIVATE_BETA = 'private_beta';

/**
* Returns mode option source array
*
* @return array
*/
public function toOptionArray(): array
{
return [
['value' => self::GENERAL_AVAILABILITY, 'label' => __('General Availability')],
['value' => self::PUBLIC_BETA, 'label' => __('Public Beta')],
['value' => self::PRIVATE_BETA, 'label' => __('Private Beta')]
];
}
}
11 changes: 11 additions & 0 deletions Model/Config/System/ConnectionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use TrueLayer\Connect\Api\Config\System\ConnectionInterface;
use TrueLayer\Connect\Model\Config\Source\Mode;
use TrueLayer\Connect\Model\Config\Source\ReleaseChannel;

/**
* Credentials provider class
Expand Down Expand Up @@ -46,6 +47,16 @@ public function getCredentials(?int $storeId = null, ?bool $forceSandbox = null)
];
}

/**
* @inheritDoc
*/
public function getReleaseChannel(?int $storeId = null): string
{
$isSandBox = $this->isSandbox($storeId);
$path = $isSandBox ? self::XML_PATH_SANDBOX_RELEASE_CHANNEL : self::XML_PATH_PRODUCTION_RELEASE_CHANNEL;
return $this->getStoreValue($path, $storeId) ?: ReleaseChannel::GENERAL_AVAILABILITY;
}

/**
* @param int|null $storeId
* @param bool $isSandBox
Expand Down
2 changes: 1 addition & 1 deletion Service/Order/PaymentCreationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private function createPaymentConfig(
"countries" => [
$order->getBillingAddress()->getCountryId()
],
"release_channel" => "general_availability",
"release_channel" => $this->configRepository->getReleaseChannel((int) $order->getStoreId()),
"customer_segments" => $this->configRepository->getBankingProviders(),
"excludes" => [
"provider_ids" => [
Expand Down
20 changes: 20 additions & 0 deletions etc/adminhtml/system/general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@
<field id="mode">sandbox</field>
</depends>
</field>
<field id="sandbox_release_channel" translate="label" type="select" sortOrder="35" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Release Channel</label>
<source_model>TrueLayer\Connect\Model\Config\Source\ReleaseChannel</source_model>
<config_path>payment/truelayer/sandbox_release_channel</config_path>
<tooltip><![CDATA[The lowest stability release stage of a provider that should be returned.<br>Note that many EUR providers are in Public Beta or Private Beta.]]></tooltip>
<depends>
<field id="active">1</field>
<field id="mode">sandbox</field>
</depends>
</field>
<field id="production_release_channel" translate="label" type="select" sortOrder="35" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Release Channel</label>
<source_model>TrueLayer\Connect\Model\Config\Source\ReleaseChannel</source_model>
<config_path>payment/truelayer/production_release_channel</config_path>
<tooltip><![CDATA[The lowest stability release stage of a provider that should be returned.<br>Note that many EUR providers are in Public Beta or Private Beta.]]></tooltip>
<depends>
<field id="active">1</field>
<field id="mode">production</field>
</depends>
</field>
<field id="check_credentials" translate="label" type="button" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="1">
<label/>
<frontend_model>TrueLayer\Connect\Block\Adminhtml\System\Config\Button\Credentials</frontend_model>
Expand Down
2 changes: 2 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
<payment_page_primary_color>#000000</payment_page_primary_color>
<payment_page_secondary_color>#e53935</payment_page_secondary_color>
<payment_page_tertiary_color>#32329f</payment_page_tertiary_color>
<sandbox_release_channel>general_availability</sandbox_release_channel>
<production_release_channel>general_availability</production_release_channel>
</truelayer>
</payment>
</default>
Expand Down
Loading