Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ssheduardo committed Aug 7, 2023
2 parents 70676af + cba1838 commit d347683
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

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

## Version 1.4.4 (2023-08-07)

### Added
- Merge pull request from diegomarty.
- Changed value by default in setMethod: T to C.
- Added validation for this parameters: 'T', 'C', 'R', 'D', 'z', 'p', 'N'
- Added new test for setMethod
### Fixed
- Nothing
-
## Version 1.4.3 (2023-02-16)

### Added
Expand Down
17 changes: 14 additions & 3 deletions src/Sermepa/Tpv/Tpv.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,18 +607,29 @@ public function setTradeName($tradename = '')
/**
* Payment type
*
* @param string $method [T o C = Sólo Tarjeta (mostrará sólo el formulario para datos de tarjeta)
* R = Pago por Transferencia, D = Domiciliación]
* @param string $method
* [
* T o C = Sólo Tarjeta (mostrará sólo el formulario para datos de tarjeta)
* R = Pago por Transferencia,
* D = Domiciliación
* z = Bizum
* p = PayPal
* N = Masterpass
* ]
*
* @return $this
* @throws Exception
*/
public function setMethod($method = 'T')
public function setMethod($method = 'C')
{
if ($this->isEmpty($method)) {
throw new TpvException('Add pay method');
}

if (!in_array($method, ['T', 'C', 'R', 'D', 'z', 'p', 'N'])) {
throw new TpvException('Pay method is not valid');
}

$this->_setParameters['DS_MERCHANT_PAYMETHODS'] = trim($method);

return $this;
Expand Down
49 changes: 49 additions & 0 deletions tests/TpvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,4 +541,53 @@ public function set_new_parameters()

}

public function invalidSetMethod()
{
return [
['V'],
['A'],
['X'],
['AA'],
['Np'],
];
}

/**
* @test
* @dataProvider invalidSetMethod
*/
public function throw_when_set_method_is_invalid($method)
{
$this->expectExceptionMessage("Pay method is not valid");
$this->expectException(\Sermepa\Tpv\TpvException::class);
$redsys = new Tpv();
$redsys->setMethod($method);
}

public function methodsProvider()
{
return [
['T'],
['C'],
['R'],
['D'],
['z'],
['p'],
['N']
];
}

/**
*
* @test
* @dataProvider methodsProvider
*/
public function should_validate_a_method($method)
{
$redsys = new Tpv();
$redsys->setMethod($method);
$parameters = $redsys->getParameters();
$this->assertArrayHasKey('DS_MERCHANT_PAYMETHODS', $parameters);
}

}

0 comments on commit d347683

Please sign in to comment.