diff --git a/lib/Paymill/Models/Request/Preauthorization.php b/lib/Paymill/Models/Request/Preauthorization.php index 437186d..aa7fc46 100644 --- a/lib/Paymill/Models/Request/Preauthorization.php +++ b/lib/Paymill/Models/Request/Preauthorization.php @@ -30,6 +30,13 @@ class Preauthorization extends Base */ private $_token; + /** + * Source + * + * @var $_source + */ + private $_source; + /** * @var string */ @@ -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 @@ -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; diff --git a/lib/Paymill/Request.php b/lib/Paymill/Request.php index c49d697..b7f4b99 100644 --- a/lib/Paymill/Request.php +++ b/lib/Paymill/Request.php @@ -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; diff --git a/tests/unit/Paymill/Models/Request/PreauthorizationTest.php b/tests/unit/Paymill/Models/Request/PreauthorizationTest.php index 8104a94..9065d68 100644 --- a/tests/unit/Paymill/Models/Request/PreauthorizationTest.php +++ b/tests/unit/Paymill/Models/Request/PreauthorizationTest.php @@ -42,12 +42,13 @@ 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 @@ -55,6 +56,7 @@ public function setGetTest() ->setToken($sample['token']) ->setAmount($sample['amount']) ->setCurrency($sample['currency']) + ->setSource(($sample['source'])) ->setDescription($sample['description']) ->setClient($sample['client']); @@ -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; } @@ -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(