-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I have just added a new test to handle successful or error responses …
…from the Redsys payment gateway, Updated README
- Loading branch information
1 parent
dcf4949
commit 01764aa
Showing
4 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sermepa\Tpv; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Sermepa\Tpv\Tpv; | ||
|
||
class TpvResponseTest extends TestCase | ||
{ | ||
|
||
public function test_response_error_code() | ||
{ | ||
$response = [ | ||
'errorCode' => '123' | ||
]; | ||
|
||
$key = 'YOUR_KEY'; | ||
|
||
$redsys = $this->createMock(Tpv::class); | ||
$redsys->method('getMerchantParameters')->willReturn(['Ds_Response' => '00']); | ||
$redsys->method('check')->willReturn(true); | ||
|
||
try { | ||
|
||
if (array_key_exists('errorCode', $response)) { | ||
throw new \Exception("Error en la respuesta: " . $response['errorCode']); | ||
} else { | ||
$parameters = $redsys->getMerchantParameters($response['Ds_MerchantParameters']); | ||
$DsResponse = $parameters["Ds_Response"]; | ||
$DsResponse += 0; | ||
if ($redsys->check($key, $response) && $DsResponse <= 99) { | ||
print_r($parameters); | ||
} else { | ||
throw new \Exception("Error en la verificación de la respuesta."); | ||
} | ||
} | ||
} catch (\Exception $e) { | ||
$this->assertEquals("Error en la respuesta: 123", $e->getMessage()); | ||
} | ||
} | ||
|
||
public function test_successful_response() | ||
{ | ||
$response = [ | ||
'Ds_MerchantParameters' => 'encodedParams', | ||
'Ds_Signature' => 'signature' | ||
]; | ||
|
||
$key = 'YOUR_KEY'; | ||
|
||
$redsys = $this->createMock(Tpv::class); | ||
$redsys->method('getMerchantParameters')->willReturn([ | ||
'Ds_Response' => '00', | ||
'Ds_MerchantParameters' => 'param' | ||
]); | ||
|
||
$redsys->method('check')->willReturn(true); | ||
|
||
try { | ||
if (array_key_exists('errorCode', $response)) { | ||
throw new \Exception("Error en la respuesta: " . $response['errorCode']); | ||
} else { | ||
$parameters = $redsys->getMerchantParameters($response['Ds_MerchantParameters']); | ||
$DsResponse = $parameters["Ds_Response"]; | ||
$DsResponse += 0; | ||
if ($redsys->check($key, $response) && $DsResponse <= 99) { | ||
$this->assertTrue(true); // Success | ||
} else { | ||
throw new \Exception("Error en la verificación de la respuesta."); | ||
} | ||
} | ||
} catch (\Exception $e) { | ||
$this->fail("No se esperaba una excepción: " . $e->getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Sermepa\Tpv; | ||
|
||
|