Skip to content

Commit

Permalink
Added getFormValues method to return form inputs as array
Browse files Browse the repository at this point in the history
  • Loading branch information
eusonlito committed Nov 21, 2019
1 parent 6307d0d commit e537464
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Redsys/Tpv/Tpv.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,27 @@ public function setFormHiddens(array $options)
}

public function getFormHiddens()
{
$hiddens = '';

foreach ($this->getFormValues() as $key => $value) {
$hiddens .= $this->getInputHidden($key, $value);
}

return $hiddens;
}

public function getFormValues()
{
if (empty($this->values)) {
throw new Exception('Form fields must be initialized previously');
}

return $this->getInputHidden('SignatureVersion', $this->options['SignatureVersion'])
.$this->getInputHidden('MerchantParameters', $this->getMerchantParametersEncoded())
.$this->getInputHidden('Signature', $this->getValuesSignature());
return array(
'SignatureVersion' => $this->options['SignatureVersion'],
'MerchantParameters' => $this->getMerchantParametersEncoded(),
'Signature' => $this->getValuesSignature()
);
}

public function getInputHidden($name, $value)
Expand Down
4 changes: 4 additions & 0 deletions tests/Redsys/Tpv/TpvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public function testFormFields($tpv)
'MerchantURL' => 'http://example.com',
]);

$values = $tpv->getFormValues();

$this->assertTrue(count($values) === count(array_filter($values)));

$fields = $tpv->getFormHiddens();

$this->assertContains('<input', $fields);
Expand Down

0 comments on commit e537464

Please sign in to comment.