Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ssheduardo committed Oct 27, 2023
2 parents b2d3172 + d6f097e commit 538e8a5
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 15 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

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

## Version 1.4.6 (2023-10-28)

### Added
- Test for method getPathJs

- 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.

### Changed
- None
### Fixed
- None

## Version 1.4.5 (2023-09-26)

### Added
Expand Down
43 changes: 28 additions & 15 deletions src/Sermepa/Tpv/Tpv.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,20 +511,33 @@ public function getEnvironment()
}

/**
* Return path Javascript to Insite
*
* @param string $env test or live
* @return string string path javascript
*/
public static function getJsPath($environment = 'test'){
if($environment == 'test'){
return 'https://sis-t.redsys.es:25443/sis/NC/sandbox/redsysV2.js';
}
elseif($environment == 'live'){
return 'https://sis.redsys.es/sis/NC/redsysV2.js';
}else{
throw new TpvException('Add test or live');
* Returns the path to the Redsys JavaScript file for the specified environment and version.
*
* @param string $environment Environment: test or live.
* @param string $version JavaScript file version: 2 or 3.
* @return string JavaScript file path.
*/
public static function getJsPath($environment = 'test', $version = '2'){

// Stores the array of JavaScript file paths.
static $jsPaths = [
'test' => [
'2' => 'https://sis-t.redsys.es:25443/sis/NC/sandbox/redsysV2.js',
'3' => 'https://sis-t.redsys.es:25443/sis/NC/sandbox/redsysV3.js',
],
'live' => [
'2' => 'https://sis.redsys.es/sis/NC/redsysV2.js',
'3' => 'https://sis.redsys.es/sis/NC/redsysV3.js',
],
];

// Checks if the environment and version are valid.
if (!isset($jsPaths[$environment][$version])) {
throw new TpvException('Invalid environment or version');
}

// Returns the JavaScript file path.
return $jsPaths[$environment][$version];
}

/**
Expand Down Expand Up @@ -607,10 +620,10 @@ public function setTradeName($tradename = '')
/**
* Payment type
*
* @param string $method
* @param string $method
* [
* T o C = Sólo Tarjeta (mostrará sólo el formulario para datos de tarjeta)
* R = Pago por Transferencia,
* R = Pago por Transferencia,
* D = Domiciliación
* z = Bizum
* p = PayPal
Expand Down
50 changes: 50 additions & 0 deletions tests/TpvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,4 +590,54 @@ public function should_validate_a_method($method)
$this->assertArrayHasKey('DS_MERCHANT_PAYMETHODS', $parameters);
}

public function jsPathProvider()
{
return [
['test', '2', 'https://sis-t.redsys.es:25443/sis/NC/sandbox/redsysV2.js'],
['test', '3', 'https://sis-t.redsys.es:25443/sis/NC/sandbox/redsysV3.js'],
['live', '2', 'https://sis.redsys.es/sis/NC/redsysV2.js'],
['live', '3', 'https://sis.redsys.es/sis/NC/redsysV3.js'],
];
}

/**
* @test
* @dataProvider jsPathProvider
*/
public function should_return_the_correct_js_path($environment, $version, $expectedPath)
{
$redsys = new Tpv();
$actualPath = $redsys->getJsPath($environment, $version);

$this->assertEquals($expectedPath, $actualPath);
}

public function invalidEnvironmentVersionPathJs()
{
return [
['test', '1'],
['test', 'N'],
['live', '12'],
['live', '4'],
['real', '2'],
['testeo', '3'],
['life', '2'],
['', '1'],
['real', '5'],
['testing', '1'],
];
}

/**
* @test
* @dataProvider invalidEnvironmentVersionPathJs
*/
public function throw_when_set_environment_or_version_is_invalid($environment, $version)
{
$this->expectExceptionMessage("Invalid environment or version");
$this->expectException(\Sermepa\Tpv\TpvException::class);
$redsys = new Tpv();
$redsys->getJsPath($environment, $version);
}

}

0 comments on commit 538e8a5

Please sign in to comment.