Skip to content

Commit

Permalink
Merge branch 'add_source_to-transaction' of https://github.com/paymil…
Browse files Browse the repository at this point in the history
…l/paymill-php into develop
  • Loading branch information
Stefan Harenkamp committed Aug 12, 2014
2 parents 11e6348 + f0dec20 commit 33af57a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 19 deletions.
43 changes: 35 additions & 8 deletions lib/Paymill/Models/Request/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -62,6 +62,11 @@ class Transaction extends Base
*/
private $_feeCurrency;

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

/**
* Creates an instance of the transaction request model
*/
Expand Down Expand Up @@ -277,6 +282,25 @@ 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;
return $this;
}

/**
* 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
Expand Down Expand Up @@ -307,6 +331,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();
Expand Down
40 changes: 33 additions & 7 deletions lib/Paymill/Models/Response/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -94,7 +94,7 @@ public function setStatus($status)
}

/**
* @var string
* @var string
*/
private $_description;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -273,7 +273,7 @@ public function setInvoices($invoices)
}

/**
* @var \Paymill\Models\Response\Payment
* @var \Paymill\Models\Response\Payment
*/
private $_payment;

Expand Down Expand Up @@ -323,7 +323,7 @@ public function setClient($client)
}

/**
* @var \Paymill\Models\Response\Preauthorization
* @var \Paymill\Models\Response\Preauthorization
*/
private $_preauthorization = null;

Expand Down Expand Up @@ -361,6 +361,7 @@ public function getFees()
return $this->_fees;
}


/**
* Sets the Fees array for the transaction
* @param array $fees
Expand All @@ -371,4 +372,29 @@ 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;
return $this;
}

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

}
2 changes: 1 addition & 1 deletion lib/Paymill/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 10 additions & 3 deletions tests/unit/Paymill/Models/Request/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']);
Expand All @@ -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;
}
Expand All @@ -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'
Expand Down

0 comments on commit 33af57a

Please sign in to comment.