Skip to content

Commit

Permalink
Merge pull request #124 from enricohofmann/PR-183
Browse files Browse the repository at this point in the history
Add Source also 2 Preauthorizations
  • Loading branch information
mschindler83 committed Mar 1, 2016
2 parents 1110880 + ae2675f commit 919d9e2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
35 changes: 34 additions & 1 deletion lib/Paymill/Models/Request/Preauthorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class Preauthorization extends Base
*/
private $_token;

/**
* Source
*
* @var $_source
*/
private $_source;

/**
* @var string
*/
Expand Down Expand Up @@ -128,6 +135,30 @@ public function setToken($token)
return $this;
}

/**
* Sets the name of origin of the call creating the transaction.
*
* @param string $source Source
*
* @return $this
*/
public function setSource($source)
{
$this->_source = $source;

return $this;
}

/**
* Gets the name of origin of the call creating the transaction.
*
* @return string
*/
public function getSource()
{
return $this->_source;
}

/**
* Returns the description
* @return string
Expand Down Expand Up @@ -189,7 +220,9 @@ public function parameterize($method)
if (!is_null($this->getClient())) {
$parameterArray['client'] = $this->getClient();
}

if(!is_null($this->getSource())) {
$parameterArray['source'] = $this->getSource();
}
break;
case 'getOne':
$parameterArray['count'] = 1;
Expand Down
7 changes: 5 additions & 2 deletions lib/Paymill/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,11 @@ private function _request(Base $model, $method)
$parameter = $model->parameterize($method);
$serviceResource = $model->getServiceResource() . $model->getId();

if(is_a($model, '\Paymill\Models\Request\Transaction') && $method === "create") {
$source = !array_key_exists('source',$parameter) ?
if ((is_a($model, '\Paymill\Models\Request\Transaction')
|| is_a($model, '\Paymill\Models\Request\Preauthorization'))
&& $method === "create"
) {
$source = !array_key_exists('source', $parameter) ?
"PhpLib" . $this->getVersion() :
"PhpLib" . $this->getVersion() . "_" . $parameter['source'];
$parameter['source'] = $source;
Expand Down
16 changes: 10 additions & 6 deletions tests/unit/Paymill/Models/Request/PreauthorizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,21 @@ protected function tearDown()
public function setGetTest()
{
$sample = array(
'token' => '098f6bcd4621d373cade4e832627b4f6',
'payment' => 'pay_d43cf0ee969d9847512b',
'amount' => '4200',
'currency' => 'EUR',
'token' => '098f6bcd4621d373cade4e832627b4f6',
'payment' => 'pay_d43cf0ee969d9847512b',
'amount' => '4200',
'currency' => 'EUR',
'description' => 'Test Description',
'client' => 'client_4624bcfbac1f4862642f'
'source' => 'Test Source',
'client' => 'client_4624bcfbac1f4862642f',
);

$this->_preauthorization
->setPayment($sample['payment'])
->setToken($sample['token'])
->setAmount($sample['amount'])
->setCurrency($sample['currency'])
->setSource(($sample['source']))
->setDescription($sample['description'])
->setClient($sample['client']);

Expand All @@ -64,6 +66,7 @@ public function setGetTest()
$this->assertEquals($this->_preauthorization->getCurrency(), $sample['currency']);
$this->assertEquals($this->_preauthorization->getDescription(), $sample['description']);
$this->assertEquals($this->_preauthorization->getClient(), $sample['client']);
$this->assertEquals($this->_preauthorization->getSource(), $sample['source']);

return $this->_preauthorization;
}
Expand All @@ -86,7 +89,8 @@ public function parameterizeTest($preauthorization)
'amount' => '4200',
'currency' => 'EUR',
'description' => 'Test Description',
'client' => 'client_4624bcfbac1f4862642f'
'client' => 'client_4624bcfbac1f4862642f',
'source' => 'Test Source'
)
);
$this->assertEquals($getOneArray, array(
Expand Down

0 comments on commit 919d9e2

Please sign in to comment.