From 77e31f7c05e71841429160d2b32b9beea276d3cb Mon Sep 17 00:00:00 2001 From: "moritz.deissner" Date: Tue, 12 Aug 2014 14:05:15 +0200 Subject: [PATCH 1/4] add parameter source to transaction --- lib/Paymill/Models/Request/Transaction.php | 42 +++++++++++++++---- lib/Paymill/Models/Response/Transaction.php | 39 +++++++++++++---- .../Models/Request/TransactionTest.php | 13 ++++-- 3 files changed, 76 insertions(+), 18 deletions(-) diff --git a/lib/Paymill/Models/Request/Transaction.php b/lib/Paymill/Models/Request/Transaction.php index 3afde5e..5ce8935 100755 --- a/lib/Paymill/Models/Request/Transaction.php +++ b/lib/Paymill/Models/Request/Transaction.php @@ -16,42 +16,42 @@ class Transaction extends Base * @var string */ private $_amount; - + /** * @var string */ private $_description; - + /** * @var string */ private $_currency; - + /** * @var string */ private $_payment; - + /** * @var string */ private $_client = null; - + /** * @var string */ private $_preauthorization; - + /** * @var string */ private $_token; - + /** * @var string */ private $_feeAmount; - + /** * @var string */ @@ -62,6 +62,11 @@ class Transaction extends Base */ private $_feeCurrency; + /** + * @var $_source + */ + private $_source; + /** * Creates an instance of the transaction request model */ @@ -277,6 +282,24 @@ public function setToken($token) return $this; } + /** + * Sets the name of origin of the call creating the transaction + * @param mixed $source + */ + public function setSource($source) + { + $this->_source = $source; + } + + /** + * Gets the name of origin of the call creating the transaction + * @return mixed + */ + public function getSource() + { + return $this->_source; + } + /** * Returns an array of parameters customized for the argumented methodname * @param string $method @@ -307,6 +330,9 @@ public function parameterize($method) if (!is_null($this->getFeeCurrency())) { $parameterArray['fee_currency'] = $this->getFeeCurrency(); } + if(!is_null($this->getSource())) { + $parameterArray['source'] = $this->getSource(); + } break; case 'update': $parameterArray['description'] = $this->getDescription(); diff --git a/lib/Paymill/Models/Response/Transaction.php b/lib/Paymill/Models/Response/Transaction.php index eab7848..6ea1e74 100755 --- a/lib/Paymill/Models/Response/Transaction.php +++ b/lib/Paymill/Models/Response/Transaction.php @@ -4,9 +4,9 @@ /** * Transaction Model - * A transaction is the charging of a credit card or a direct debit. - * In this case you need a new transaction object with either a valid token, payment, client + payment or - * preauthorization. Every transaction has a unique identifier which will be generated by Paymill to identify every + * A transaction is the charging of a credit card or a direct debit. + * In this case you need a new transaction object with either a valid token, payment, client + payment or + * preauthorization. Every transaction has a unique identifier which will be generated by Paymill to identify every * transaction. You can issue/create, list and display transactions in detail. Refunds can be done in an extra entity. * @tutorial https://paymill.com/de-de/dokumentation/referenz/api-referenz/#document-transactions */ @@ -94,7 +94,7 @@ public function setStatus($status) } /** - * @var string + * @var string */ private $_description; @@ -222,7 +222,7 @@ public function setResponseCode($responseCode) /** * Unique identifier of this transaction provided to the acquirer for the statements. - * @var string + * @var string */ private $_shortId; @@ -273,7 +273,7 @@ public function setInvoices($invoices) } /** - * @var \Paymill\Models\Response\Payment + * @var \Paymill\Models\Response\Payment */ private $_payment; @@ -323,7 +323,7 @@ public function setClient($client) } /** - * @var \Paymill\Models\Response\Preauthorization + * @var \Paymill\Models\Response\Preauthorization */ private $_preauthorization = null; @@ -361,6 +361,7 @@ public function getFees() return $this->_fees; } + /** * Sets the Fees array for the transaction * @param array $fees @@ -371,4 +372,28 @@ public function setFees($fees) $this->_fees = $fees; return $this; } + + /** + * @var $_source + */ + private $_source; + + /** + * Sets the name of origin of the call creating the transaction + * @param mixed $source + */ + public function setSource($source) + { + $this->_source = $source; + } + + /** + * Gets the name of origin of the call creating the transaction + * @return mixed + */ + public function getSource() + { + return $this->_source; + } + } \ No newline at end of file diff --git a/tests/unit/Paymill/Models/Request/TransactionTest.php b/tests/unit/Paymill/Models/Request/TransactionTest.php index f7562e8..a3c9d5a 100755 --- a/tests/unit/Paymill/Models/Request/TransactionTest.php +++ b/tests/unit/Paymill/Models/Request/TransactionTest.php @@ -51,7 +51,8 @@ public function setGetTest() 'fee_amount' => '420', // e.g. "420" for 4.20 EUR 'fee_payment' => 'pay_098f6bcd4621d373cade4e832627b4f6', 'fee_currency' => 'EUR', - 'description' => 'Test Transaction' + 'description' => 'Test Transaction', + 'source' => 'merchantcenter' ); $this->_transaction @@ -64,7 +65,10 @@ public function setGetTest() ->setFeeAmount($sample['fee_amount']) ->setFeePayment($sample['fee_payment']) ->setFeeCurrency($sample['fee_currency']) - ->setDescription($sample['description']); + ->setDescription($sample['description']) + ->setSource($sample['source']); + + $this->assertEquals($this->_transaction->getAmount(), $sample['amount']); $this->assertEquals($this->_transaction->getCurrency(), $sample['currency']); @@ -76,6 +80,8 @@ public function setGetTest() $this->assertEquals($this->_transaction->getFeePayment(), $sample['fee_payment']); $this->assertEquals($this->_transaction->getFeeCurrency(), $sample['fee_currency']); $this->assertEquals($this->_transaction->getDescription(), $sample['description']); + $this->assertEquals($this->_transaction->getSource(), $sample['source']); + return $this->_transaction; } @@ -102,7 +108,8 @@ public function parameterizeTest($transaction) 'fee_amount' => '420', // e.g. "420" for 4.20 EUR 'fee_payment' => 'pay_098f6bcd4621d373cade4e832627b4f6', 'fee_currency' => 'EUR', - 'description' => 'Test Transaction' + 'description' => 'Test Transaction', + 'source' => 'merchantcenter' )); $this->assertEquals($updateArray, array( 'description' => 'Test Transaction' From a39a07e5e7bb5dc87c02721d037ce3da57106217 Mon Sep 17 00:00:00 2001 From: "moritz.deissner" Date: Tue, 12 Aug 2014 15:00:40 +0200 Subject: [PATCH 2/4] add parameter source to transaction --- lib/Paymill/Models/Request/Transaction.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Paymill/Models/Request/Transaction.php b/lib/Paymill/Models/Request/Transaction.php index 5ce8935..37b191f 100755 --- a/lib/Paymill/Models/Request/Transaction.php +++ b/lib/Paymill/Models/Request/Transaction.php @@ -289,6 +289,7 @@ public function setToken($token) public function setSource($source) { $this->_source = $source; + return $this; } /** From f7d5bef636813e1625ae180e4a1a9134e3b9e023 Mon Sep 17 00:00:00 2001 From: "moritz.deissner" Date: Tue, 12 Aug 2014 15:02:20 +0200 Subject: [PATCH 3/4] add parameter source to transaction --- lib/Paymill/Models/Response/Transaction.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Paymill/Models/Response/Transaction.php b/lib/Paymill/Models/Response/Transaction.php index 6ea1e74..7f0861c 100755 --- a/lib/Paymill/Models/Response/Transaction.php +++ b/lib/Paymill/Models/Response/Transaction.php @@ -385,6 +385,7 @@ public function setFees($fees) public function setSource($source) { $this->_source = $source; + return $this; } /** From f0dec20b851a300571baf0bcca176da81443d6d1 Mon Sep 17 00:00:00 2001 From: "moritz.deissner" Date: Tue, 12 Aug 2014 15:30:16 +0200 Subject: [PATCH 4/4] add parameter source to transaction --- lib/Paymill/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Paymill/Request.php b/lib/Paymill/Request.php index 3d2c973..8d0e9af 100644 --- a/lib/Paymill/Request.php +++ b/lib/Paymill/Request.php @@ -221,7 +221,7 @@ 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 = empty($this->_source) ? "PhpLib" . $this->getVersion(): "PhpLib" . $this->getVersion() . "_" . $this->getSource(); + $source = is_null($parameter['source']) ? "PhpLib" . $this->getVersion(): "PhpLib" . $this->getVersion() . "_" . $parameter['source']; $parameter['source'] = $source; } try {