Skip to content

Commit 34d8da6

Browse files
committed
I have just fixed an error in the setMerchantCofIni method. It always returns the value 'S'
1 parent 6ea40eb commit 34d8da6

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
All Notable changes to `Redsys` will be documented in this file
44

5+
## Version 1.4.9 (2025-01-11)
6+
### Added
7+
- None
8+
9+
### Changed
10+
- None
11+
12+
### Fixed
13+
- I have just fixed an error in the setMerchantCofIni method. It always returns the value 'S'.
14+
15+
516
## Version 1.4.8 (2024-03-05)
617
### Added
718
- Implementation of the `xpay` method within the `setMethod` functionality to support GooglePay and ApplePay.

src/Sermepa/Tpv/Tpv.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -943,12 +943,19 @@ public function getMerchantSignature()
943943
* “S”: It is first COF transaction (store credentials)
944944
* “N”: It is not the first COF transaction
945945
*
946+
* @param $value
947+
*
946948
* @return $this
947949
* @throws Exception
948950
*/
949-
public function setMerchantCofIni($isFirstTransaction)
951+
public function setMerchantCofIni($value)
950952
{
951-
$this->_setParameters['DS_MERCHANT_COF_INI'] = $isFirstTransaction ? 'S' : 'N';
953+
$validOptions = ['S', 'N'];
954+
$value = strtoupper($value);
955+
if (!in_array($value, $validOptions, true)) {
956+
throw new TpvException('Set Merchant COF INI valid options');
957+
}
958+
$this->_setParameters['DS_MERCHANT_COF_INI'] = $value;
952959

953960
return $this;
954961
}

tests/TpvTest.php

+46
Original file line numberDiff line numberDiff line change
@@ -630,4 +630,50 @@ public function throw_when_set_environment_or_version_is_invalid($environment, $
630630
$redsys = new Tpv();
631631
$redsys->getJsPath($environment, $version);
632632
}
633+
634+
public function cofIniProvider()
635+
{
636+
return [
637+
['S'],
638+
['N'],
639+
];
640+
}
641+
642+
/**
643+
*
644+
* @dataProvider cofIniProvider
645+
*/
646+
public function test_should_validate_a_merchant_cof_ini($cofIni)
647+
{
648+
$redsys = new Tpv();
649+
$redsys->setMerchantCofIni($cofIni);
650+
$parameters = $redsys->getParameters();
651+
$this->assertArrayHasKey('DS_MERCHANT_COF_INI', $parameters);
652+
$this->assertContains($parameters['DS_MERCHANT_COF_INI'], [$cofIni]);
653+
654+
}
655+
656+
public function invalidSetMerchantCofIni()
657+
{
658+
return [
659+
[''],
660+
['B'],
661+
['-1'],
662+
['G'],
663+
[0],
664+
['Del']
665+
];
666+
}
667+
668+
/**
669+
* @test
670+
* @dataProvider invalidSetMerchantCofIni
671+
*/
672+
public function throw_when_set_method_merchnant_cof_ini_is_invalid($cofIni)
673+
{
674+
$this->expectExceptionMessage("Set Merchant COF INI valid options");
675+
$this->expectException(\Sermepa\Tpv\TpvException::class);
676+
$redsys = new Tpv();
677+
$redsys->setMerchantCofIni($cofIni);
678+
}
633679
}

0 commit comments

Comments
 (0)