Skip to content

Commit d6f097e

Browse files
committed
Merge branch 'changed_getJs' into develop
2 parents 23a0566 + a8d5837 commit d6f097e

File tree

3 files changed

+90
-15
lines changed

3 files changed

+90
-15
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

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

5+
## Version 1.4.6 (2023-10-28)
6+
7+
### Added
8+
- Test for method getPathJs
9+
10+
- I just added a second optional parameter, $version, was added to the getJsPath() method to allow users to specify the version of the Redsys JavaScript file they want to use. The default version is 2 for compatibility reasons, but users can specify 3 to get the latest Redsys JavaScript file.
11+
12+
### Changed
13+
- None
14+
### Fixed
15+
- None
16+
517
## Version 1.4.5 (2023-09-26)
618

719
### Added

src/Sermepa/Tpv/Tpv.php

+28-15
Original file line numberDiff line numberDiff line change
@@ -511,20 +511,33 @@ public function getEnvironment()
511511
}
512512

513513
/**
514-
* Return path Javascript to Insite
515-
*
516-
* @param string $env test or live
517-
* @return string string path javascript
518-
*/
519-
public static function getJsPath($environment = 'test'){
520-
if($environment == 'test'){
521-
return 'https://sis-t.redsys.es:25443/sis/NC/sandbox/redsysV2.js';
522-
}
523-
elseif($environment == 'live'){
524-
return 'https://sis.redsys.es/sis/NC/redsysV2.js';
525-
}else{
526-
throw new TpvException('Add test or live');
514+
* Returns the path to the Redsys JavaScript file for the specified environment and version.
515+
*
516+
* @param string $environment Environment: test or live.
517+
* @param string $version JavaScript file version: 2 or 3.
518+
* @return string JavaScript file path.
519+
*/
520+
public static function getJsPath($environment = 'test', $version = '2'){
521+
522+
// Stores the array of JavaScript file paths.
523+
static $jsPaths = [
524+
'test' => [
525+
'2' => 'https://sis-t.redsys.es:25443/sis/NC/sandbox/redsysV2.js',
526+
'3' => 'https://sis-t.redsys.es:25443/sis/NC/sandbox/redsysV3.js',
527+
],
528+
'live' => [
529+
'2' => 'https://sis.redsys.es/sis/NC/redsysV2.js',
530+
'3' => 'https://sis.redsys.es/sis/NC/redsysV3.js',
531+
],
532+
];
533+
534+
// Checks if the environment and version are valid.
535+
if (!isset($jsPaths[$environment][$version])) {
536+
throw new TpvException('Invalid environment or version');
527537
}
538+
539+
// Returns the JavaScript file path.
540+
return $jsPaths[$environment][$version];
528541
}
529542

530543
/**
@@ -607,10 +620,10 @@ public function setTradeName($tradename = '')
607620
/**
608621
* Payment type
609622
*
610-
* @param string $method
623+
* @param string $method
611624
* [
612625
* T o C = Sólo Tarjeta (mostrará sólo el formulario para datos de tarjeta)
613-
* R = Pago por Transferencia,
626+
* R = Pago por Transferencia,
614627
* D = Domiciliación
615628
* z = Bizum
616629
* p = PayPal

tests/TpvTest.php

+50
Original file line numberDiff line numberDiff line change
@@ -590,4 +590,54 @@ public function should_validate_a_method($method)
590590
$this->assertArrayHasKey('DS_MERCHANT_PAYMETHODS', $parameters);
591591
}
592592

593+
public function jsPathProvider()
594+
{
595+
return [
596+
['test', '2', 'https://sis-t.redsys.es:25443/sis/NC/sandbox/redsysV2.js'],
597+
['test', '3', 'https://sis-t.redsys.es:25443/sis/NC/sandbox/redsysV3.js'],
598+
['live', '2', 'https://sis.redsys.es/sis/NC/redsysV2.js'],
599+
['live', '3', 'https://sis.redsys.es/sis/NC/redsysV3.js'],
600+
];
601+
}
602+
603+
/**
604+
* @test
605+
* @dataProvider jsPathProvider
606+
*/
607+
public function should_return_the_correct_js_path($environment, $version, $expectedPath)
608+
{
609+
$redsys = new Tpv();
610+
$actualPath = $redsys->getJsPath($environment, $version);
611+
612+
$this->assertEquals($expectedPath, $actualPath);
613+
}
614+
615+
public function invalidEnvironmentVersionPathJs()
616+
{
617+
return [
618+
['test', '1'],
619+
['test', 'N'],
620+
['live', '12'],
621+
['live', '4'],
622+
['real', '2'],
623+
['testeo', '3'],
624+
['life', '2'],
625+
['', '1'],
626+
['real', '5'],
627+
['testing', '1'],
628+
];
629+
}
630+
631+
/**
632+
* @test
633+
* @dataProvider invalidEnvironmentVersionPathJs
634+
*/
635+
public function throw_when_set_environment_or_version_is_invalid($environment, $version)
636+
{
637+
$this->expectExceptionMessage("Invalid environment or version");
638+
$this->expectException(\Sermepa\Tpv\TpvException::class);
639+
$redsys = new Tpv();
640+
$redsys->getJsPath($environment, $version);
641+
}
642+
593643
}

0 commit comments

Comments
 (0)