Skip to content

Commit 25cc13b

Browse files
authored
Merge pull request #58 from two-inc/brtkwr-two/cet-533-magento-remove-merchant_short_name-input-from-admin-settings
CET-533/fix: Magento: Remove merchant_short_name input from admin settings
2 parents efbf943 + 58c2511 commit 25cc13b

File tree

13 files changed

+66
-94
lines changed

13 files changed

+66
-94
lines changed

Api/Config/RepositoryInterface.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ interface RepositoryInterface
2222
public const XML_PATH_ENABLED = 'payment/two_payment/active';
2323
public const XML_PATH_TITLE = 'payment/two_payment/title';
2424
public const XML_PATH_MODE = 'payment/two_payment/mode';
25-
public const XML_PATH_MERCHANT_SHORT_NAME = 'payment/two_payment/merchant_short_name';
2625
public const XML_PATH_API_KEY = 'payment/two_payment/api_key';
2726
public const XML_PATH_DAYS_ON_INVOICE = 'payment/two_payment/days_on_invoice';
2827
public const XML_PATH_FULFILL_TRIGGER = 'payment/two_payment/fulfill_trigger';
@@ -59,15 +58,6 @@ public function isActive(?int $storeId = null): bool;
5958
*/
6059
public function getMode(?int $storeId = null): string;
6160

62-
/**
63-
* Get merchant short name
64-
*
65-
* @param int|null $storeId
66-
*
67-
* @return string
68-
*/
69-
public function getMerchantShortName(?int $storeId = null): string;
70-
7161
/**
7262
* Get API key
7363
*

Block/Adminhtml/System/Config/Field/ApiKeyCheck.php

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020
class ApiKeyCheck extends Field
2121
{
22-
2322
/**
2423
* @var string
2524
*/
@@ -28,24 +27,25 @@ class ApiKeyCheck extends Field
2827
/**
2928
* @var ConfigRepository
3029
*/
31-
private $_configRepository;
30+
private $configRepository;
3231

3332
/**
3433
* @var Two
3534
*/
36-
private $_two;
35+
private $two;
3736

3837
/**
3938
* @var Adapter
4039
*/
41-
private $_adapter;
40+
private $adapter;
4241

4342
/**
4443
* Version constructor.
4544
*
46-
* @param Context $context
47-
* @param Adapter $adapter
4845
* @param ConfigRepository $configRepository
46+
* @param Adapter $adapter
47+
* @param Two $two
48+
* @param Context $context
4949
* @param array $data
5050
*/
5151
public function __construct(
@@ -55,9 +55,9 @@ public function __construct(
5555
Context $context,
5656
array $data = []
5757
) {
58-
$this->_configRepository = $configRepository;
59-
$this->_adapter = $adapter;
60-
$this->_two = $two;
58+
$this->configRepository = $configRepository;
59+
$this->adapter = $adapter;
60+
$this->two = $two;
6161
parent::__construct($context, $data);
6262
}
6363

@@ -68,34 +68,27 @@ public function __construct(
6868
*/
6969
public function getApiKeyStatus(): array
7070
{
71-
$short_name = $this->_configRepository->getMerchantShortName();
72-
if ($short_name && $this->_configRepository->getApiKey()) {
73-
$result = $this->_adapter->execute('/v1/merchant/' . $short_name, [], 'GET');
74-
$error = $this->_two->getErrorFromResponse($result);
75-
if ($error) {
76-
return [
77-
'message' => __('Credentials are invalid'),
78-
'status' => 'error',
79-
'error' => $error
80-
];
81-
} else {
82-
if ($result['short_name'] != $short_name) {
83-
return [
84-
'message' => __('Username should be set to %1', $result['short_name']),
85-
'status' => 'warning',
86-
];
87-
}
88-
return [
89-
'message' => __('Credentials are valid'),
90-
'status' => 'success'
91-
];
92-
}
93-
} else {
71+
if (!$this->configRepository->getApiKey()) {
9472
return [
95-
'message' => __('Credentials are missing'),
73+
'message' => __('API key is missing'),
9674
'status' => 'warning'
9775
];
9876
}
77+
78+
$result = $this->adapter->execute('/v1/merchant/verify_api_key', [], 'GET');
79+
$error = $this->two->getErrorFromResponse($result);
80+
if ($error) {
81+
return [
82+
'message' => __('API key is not valid'),
83+
'status' => 'error',
84+
'error' => $error
85+
];
86+
} else {
87+
return [
88+
'message' => __('API key is valid'),
89+
'status' => 'success'
90+
];
91+
}
9992
}
10093

10194
/**

Model/Config/Repository.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,6 @@ private function isSetFlag(string $path, ?int $storeId = null, ?string $scope =
7979
return $this->scopeConfig->isSetFlag($path, $scope, $storeId);
8080
}
8181

82-
/**
83-
* @inheritDoc
84-
*/
85-
public function getMerchantShortName(?int $storeId = null): string
86-
{
87-
return (string)$this->getConfig(self::XML_PATH_MERCHANT_SHORT_NAME, $storeId);
88-
}
89-
9082
/**
9183
* Retrieve config value
9284
*

Model/Ui/ConfigProvider.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Magento\Framework\View\Asset\Repository as AssetRepository;
1212
use Two\Gateway\Api\Config\RepositoryInterface as ConfigRepository;
1313
use Two\Gateway\Service\UrlCookie;
14+
use Two\Gateway\Service\Api\Adapter;
15+
use Two\Gateway\Model\Two;
1416

1517
/**
1618
* Ui Config Provider
@@ -22,6 +24,16 @@ class ConfigProvider implements ConfigProviderInterface
2224
*/
2325
private $configRepository;
2426

27+
/**
28+
* @var Two
29+
*/
30+
private $two;
31+
32+
/**
33+
* @var Adapter
34+
*/
35+
private $adapter;
36+
2537
/**
2638
* @var AssetRepository
2739
*/
@@ -31,13 +43,19 @@ class ConfigProvider implements ConfigProviderInterface
3143
* ConfigProvider constructor.
3244
*
3345
* @param ConfigRepository $configRepository
46+
* @param Adapter $adapter
47+
* @param Two $two
3448
* @param AssetRepository $assetRepository
3549
*/
3650
public function __construct(
3751
ConfigRepository $configRepository,
52+
Adapter $adapter,
53+
Two $two,
3854
AssetRepository $assetRepository
3955
) {
4056
$this->configRepository = $configRepository;
57+
$this->adapter = $adapter;
58+
$this->two = $two;
4159
$this->assetRepository = $assetRepository;
4260
}
4361

@@ -48,12 +66,16 @@ public function __construct(
4866
*/
4967
public function getConfig(): array
5068
{
69+
$merchant = null;
70+
if ($this->configRepository->getApiKey()) {
71+
$merchant = $this->adapter->execute('/v1/merchant/verify_api_key', [], 'GET');
72+
}
5173
$orderIntentConfig = [
5274
'extensionPlatformName' => $this->configRepository->getExtensionPlatformName(),
5375
'extensionDBVersion' => $this->configRepository->getExtensionDBVersion(),
5476
'invoiceType' => 'FUNDED_INVOICE',
55-
'merchantShortName' => $this->configRepository->getMerchantShortName(),
5677
'weightUnit' => $this->configRepository->getWeightUnit(),
78+
'merchant' => $merchant,
5779
];
5880

5981
$provider = $this->configRepository::PROVIDER;

bumpver.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.bumpver]
2-
current_version = "1.7.2"
2+
current_version = "1.7.3"
33
version_pattern = "MAJOR.MINOR.PATCH[-TAGNUM]"
44
commit_message = "chore: Bump version {old_version} -> {new_version}"
55
commit = true

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "two-inc/magento2",
33
"description": "Two B2B BNPL payments extension",
44
"type": "magento2-module",
5-
"version": "1.7.2",
5+
"version": "1.7.3",
66
"license": [
77
"OSL-3.0",
88
"AFL-3.0"

etc/adminhtml/system.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@
4040
</depends>
4141
<config_path>payment/two_payment/mode</config_path>
4242
</field>
43-
<field id="merchant_short_name" translate="label" type="text" sortOrder="40" showInDefault="1"
44-
showInWebsite="1" showInStore="1">
45-
<label>Username</label>
46-
<comment>Username for your merchant account</comment>
47-
<depends>
48-
<field id="active">1</field>
49-
</depends>
50-
<config_path>payment/two_payment/merchant_short_name</config_path>
51-
</field>
5243
<field id="api_key" translate="label" type="obscure" sortOrder="50" showInDefault="1" showInWebsite="1"
5344
showInStore="1">
5445
<label>API key</label>
@@ -62,7 +53,6 @@
6253
</field>
6354
<field id="api_key_check" translate="label" type="button" sortOrder="55" showInDefault="1"
6455
showInWebsite="1" showInStore="1">
65-
<label>Credentials</label>
6656
<frontend_model>Two\Gateway\Block\Adminhtml\System\Config\Field\ApiKeyCheck</frontend_model>
6757
</field>
6858
<field id="debug" translate="label" type="select" sortOrder="60" showInDefault="1" showInWebsite="1"

etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<payment>
1212
<two_payment>
1313
<active>1</active>
14-
<version>1.7.2</version>
14+
<version>1.7.3</version>
1515
<title>Business invoice - 30 days</title>
1616
<mode>sandbox</mode>
1717
<invoice_type>FUNDED_INVOICE</invoice_type>

i18n/en_US.csv

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"%1 requires whole order to be shipped before it can be fulfilled.","%1 requires whole order to be shipped before it can be fulfilled."
99
"* Required Fields","* Required Fields"
1010
"API key","API key"
11+
"API key is missing","API key is missing"
12+
"API key is not valid","API key is not valid"
13+
"API key is valid","API key is valid"
1114
"Add PO number field","Add PO number field"
1215
"Add department field","Add department field"
1316
"Add order note field","Add order note field"
@@ -29,15 +32,10 @@ Branding,Branding
2932
"Could not initiate refund with %1","Could not initiate refund with %1"
3033
"Could not update %1 order status to cancelled. Please contact support with order ID %2. Error: %3","Could not update %1 order status to cancelled. Please contact support with order ID %2. Error: %3"
3134
"Country is not valid.","Country is not valid."
32-
Credentials,Credentials
33-
"Credentials are invalid","Credentials are invalid"
34-
"Credentials are missing","Credentials are missing"
35-
"Credentials are valid","Credentials are valid"
3635
"Credit Note","Credit Note"
3736
"Debug mode","Debug mode"
3837
Department,Department
3938
"Developed by Magmodules.","Developed by Magmodules."
40-
"Display info link","Display info link"
4139
Download,Download
4240
"Download as .txt file","Download as .txt file"
4341
"Email Address is not valid.","Email Address is not valid."
@@ -96,8 +94,6 @@ Title,Title
9694
"Two is a payment solution for B2B purchases online, allowing you to buy from your favourite merchants and suppliers on trade credit. Using Two, you can access flexible trade credit instantly to make purchasing simple.","Two is a payment solution for B2B purchases online, allowing you to buy from your favourite merchants and suppliers on trade credit. Using Two, you can access flexible trade credit instantly to make purchasing simple."
9795
"Unable to find the requested %1 order","Unable to find the requested %1 order"
9896
"Unable to retrieve payment information for your invoice purchase with %1. The cart will be restored.","Unable to retrieve payment information for your invoice purchase with %1. The cart will be restored."
99-
Username,Username
100-
"Username should be set to %1","Username should be set to %1"
10197
Version,Version
10298
"You must first accept the payment terms.","You must first accept the payment terms."
10399
"You will be redirected to %1 when you place order.","You will be redirected to %1 when you place order."

i18n/nb_NO.csv

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"%1 requires whole order to be shipped before it can be fulfilled.","%1 krever at hele bestillingen sendes før den kan oppfylles."
99
"* Required Fields","* Obligatoriske felter"
1010
"API key",API-nøkkel
11+
"API key is missing","API-nøkkel mangler"
12+
"API key is not valid","API-nøkkel er ikke gyldig"
13+
"API key is valid","API-nøkkel er gyldig"
1114
"Add PO number field","Legg til PO-nummerfelt"
1215
"Add department field","Legg til felt for avdeling"
1316
"Add order note field","Legg til bestillingsnotatfelt"
@@ -29,15 +32,10 @@ Branding,Merkevarebygging
2932
"Could not initiate refund with %1","Kunne ikke starte refusjon med %1"
3033
"Could not update %1 order status to cancelled. Please contact support with order ID %2. Error: %3","Kunne ikke oppdatere %1 ordrestatus til kansellert. Ta kontakt med brukerstøtten med ordre-ID %2. Feil: %3"
3134
"Country is not valid.","Land er ikke gyldig."
32-
Credentials,Legitimasjon
33-
"Credentials are invalid","Legitimasjonen er ugyldig"
34-
"Credentials are missing","Legitimasjon mangler"
35-
"Credentials are valid","Legitimasjonen er gyldig"
3635
"Credit Note",Kreditnota
3736
"Debug mode",Feilsøkingsmodus
3837
Department,Avdeling
3938
"Developed by Magmodules.","Utviklet av Magmodules."
40-
"Display info link","Vis infolink"
4139
Download,"Last ned"
4240
"Download as .txt file","Last ned som .txt-fil"
4341
"Email Address is not valid.","E-postadresse er ikke gyldig."
@@ -96,8 +94,6 @@ Title,Tittel
9694
"Two is a payment solution for B2B purchases online, allowing you to buy from your favourite merchants and suppliers on trade credit. Using Two, you can access flexible trade credit instantly to make purchasing simple.","Two er en betalingsløsning for B2B-kjøp på nettet, som lar deg kjøpe fra dine favorittforhandlere og leverandører på handelskreditt. Med Two kan du få tilgang til fleksibel handelskreditt umiddelbart for å gjøre innkjøp enkelt."
9795
"Unable to find the requested %1 order","Kan ikke finne den forespurte bestillingen %1"
9896
"Unable to retrieve payment information for your invoice purchase with %1. The cart will be restored.","Kan ikke hente betalingsinformasjon for fakturakjøpet med %1. Vognen vil bli restaurert."
99-
Username,Brukernavn
100-
"Username should be set to %1","Brukernavn skal settes til %1"
10197
Version,Versjon
10298
"You must first accept the payment terms.","Du må først godta betalingsvilkårene."
10399
"You will be redirected to %1 when you place order.","Du vil bli omdirigert til %1 når du legger inn bestilling."

i18n/nl_NL.csv

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"%1 requires whole order to be shipped before it can be fulfilled.","%1 vereist dat de gehele bestelling wordt verzonden voordat deze kan worden uitgevoerd."
99
"* Required Fields","* Verplichte velden"
1010
"API key",API-sleutel
11+
"API key is missing","API-sleutel ontbreekt"
12+
"API key is not valid","API-sleutel is niet geldig"
13+
"API key is valid","API-sleutel is geldig"
1114
"Add PO number field","PO-nummer veld toevoegen"
1215
"Add department field","Afdelingsveld toevoegen"
1316
"Add order note field","Bestelnotitie veld toevoegen"
@@ -29,15 +32,10 @@ Branding,Merknaam
2932
"Could not initiate refund with %1","Kon geen terugbetaling starten met %1"
3033
"Could not update %1 order status to cancelled. Please contact support with order ID %2. Error: %3","Kon %1 orderstatus niet updaten naar geannuleerd. Neem contact op met support met bestelnummer %2. Fout: %3"
3134
"Country is not valid.","Land is niet geldig."
32-
Credentials,Inloggegevens
33-
"Credentials are invalid","Inloggegevens zijn ongeldig"
34-
"Credentials are missing","Inloggegevens ontbreken"
35-
"Credentials are valid","Inloggegevens zijn geldig"
3635
"Credit Note",Creditnota
3736
"Debug mode",Debug-modus
3837
Department,Afdeling
3938
"Developed by Magmodules.","Ontwikkeld door Magmodules."
40-
"Display info link","Infolink weergeven"
4139
Download,Download
4240
"Download as .txt file","Downloaden als .txt-bestand"
4341
"Email Address is not valid.","E-mailadres is niet geldig."
@@ -96,8 +94,6 @@ Title,Titel
9694
"Two is a payment solution for B2B purchases online, allowing you to buy from your favourite merchants and suppliers on trade credit. Using Two, you can access flexible trade credit instantly to make purchasing simple.","Two is een betalingsoplossing voor online B2B-aankopen, waarmee u op handelskrediet kunt kopen bij uw favoriete handelaren en leveranciers. Met Two heeft u direct toegang tot flexibel handelskrediet om het aankopen eenvoudig te maken."
9795
"Unable to find the requested %1 order","Kan de gevraagde %1 bestelling niet vinden"
9896
"Unable to retrieve payment information for your invoice purchase with %1. The cart will be restored.","Betalingsgegevens voor uw aankoop op factuur met %1 kunnen niet worden opgehaald. De winkelwagen wordt hersteld."
99-
Username,Gebruikersnaam
100-
"Username should be set to %1","Gebruikersnaam moet ingesteld worden op %1"
10197
Version,Versie
10298
"You must first accept the payment terms.","U moet eerst de betaalvoorwaarden accepteren."
10399
"You will be redirected to %1 when you place order.","U wordt doorgestuurd naar %1 wanneer u een bestelling plaatst."

i18n/sv_SE.csv

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"%1 requires whole order to be shipped before it can be fulfilled.","%1 kräver att hela beställningen skickas innan den kan uppfyllas."
99
"* Required Fields","* Obligatoriska fält"
1010
"API key",API-nyckel
11+
"API key is missing","API-nyckel saknas"
12+
"API key is not valid","API-nyckeln är inte giltig"
13+
"API key is valid","API-nyckeln är giltig"
1114
"Add PO number field","Lägg till PO-nummerfält"
1215
"Add department field","Lägg till fält för avdelning"
1316
"Add order note field","Lägg till orderanteckningsfält"
@@ -29,15 +32,10 @@ Branding,Branding
2932
"Could not initiate refund with %1","Kunde inte initiera återbetalning med %1"
3033
"Could not update %1 order status to cancelled. Please contact support with order ID %2. Error: %3","Kunde inte uppdatera %1 orderstatus till annullerad. Kontakta supporten med beställnings-ID %2. Fel: %3"
3134
"Country is not valid.","Land är inte giltigt."
32-
Credentials,Autentiseringsuppgifter
33-
"Credentials are invalid","Autentiseringsuppgifterna är ogiltiga"
34-
"Credentials are missing","Autentiseringsuppgifterna saknas"
35-
"Credentials are valid","Autentiseringsuppgifterna är giltiga"
3635
"Credit Note",Kreditnota
3736
"Debug mode",Felsökningsläge
3837
Department,Avdelning
3938
"Developed by Magmodules.","Utvecklad av Magmodules."
40-
"Display info link","Visa infolänk"
4139
Download,"Ladda ner"
4240
"Download as .txt file","Ladda ner som .txt-fil"
4341
"Email Address is not valid.","E-postadress är inte giltig."
@@ -96,8 +94,6 @@ Title,Titel
9694
"Two is a payment solution for B2B purchases online, allowing you to buy from your favourite merchants and suppliers on trade credit. Using Two, you can access flexible trade credit instantly to make purchasing simple.","Two är en betalningslösning för B2B-köp online, som låter dig köpa från dina favorithandlare och leverantörer på handelskredit. Med Two får du omedelbar tillgång till flexibel handelskredit för att göra inköp enkelt."
9795
"Unable to find the requested %1 order","Det gick inte att hitta den begärda beställningen %1"
9896
"Unable to retrieve payment information for your invoice purchase with %1. The cart will be restored.","Det gick inte att hämta betalningsinformation för ditt fakturaköp med %1. Vagnen kommer att återställas."
99-
Username,Användarnamn
100-
"Username should be set to %1","Användarnamn ska ställas in till %1"
10197
Version,Version
10298
"You must first accept the payment terms.","Du måste först acceptera betalningsvillkoren."
10399
"You will be redirected to %1 when you place order.","Du kommer att omdirigeras till %1 när du beställer."

0 commit comments

Comments
 (0)