Skip to content

Commit

Permalink
Merge pull request #105 from tschelabaumann/checksum-action
Browse files Browse the repository at this point in the history
Checksum action
  • Loading branch information
christian-kolb committed Aug 24, 2015
2 parents 98b1136 + eb34569 commit 555bf66
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 2 deletions.
44 changes: 44 additions & 0 deletions lib/Paymill/Models/Request/Checksum.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,26 @@ class Checksum extends Base
const TYPE_PAYPAL = 'paypal';

/**
* Different checksum actions which will enable different validations for
* the input parameters.
*/
const ACTION_PAYMENT = 'payment';
const ACTION_TRANSACTION = 'transaction';

/**
* Checksum type
*
* @var string
*/
private $_checksumType = null;

/**
* Checksum action
*
* @var string
*/
private $_checksumAction = null;

/**
* @var string
*/
Expand Down Expand Up @@ -163,6 +179,30 @@ public function getChecksumType()
return $this->_checksumType;
}

/**
* Get checksum action
*
* @return string
*/
public function getChecksumAction()
{
return $this->_checksumAction;
}

/**
* Set checksum action
*
* @param string $checksumAction Checksum action
*
* @return $this
*/
public function setChecksumAction($checksumAction)
{
$this->_checksumAction = $checksumAction;

return $this;
}

/**
* Set currency
*
Expand Down Expand Up @@ -498,6 +538,10 @@ public function parameterize($method)
$parameterArray['checksum_type'] = $this->getChecksumType();
}

if($this->getChecksumAction()) {
$parameterArray['checksum_action'] = $this->getChecksumAction();
}

if($this->getAmount()) {
$parameterArray['amount'] = $this->getAmount();
}
Expand Down
31 changes: 30 additions & 1 deletion lib/Paymill/Models/Response/Checksum.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* If you send us a request with transaction data and the generated checksum, we can easily validate the data
* because we know your private key and the used hash algorithm.
* To make the checksum computation as easy as possible we provide this endpoint for you.
* @tutorial https://paymill.com/de-de/dokumentation/referenz/api-referenz/#document-checksum
* @tutorial https://developers.paymill.com/API/#checksums
*/
class Checksum extends Base
{
Expand All @@ -28,6 +28,13 @@ class Checksum extends Base
*/
private $_type;

/**
* Action
*
* @var string
*/
private $_action;

/**
* Data
*
Expand Down Expand Up @@ -78,6 +85,28 @@ public function getType()
public function setType($type)
{
$this->_type = $type;
}

/**
* Get action
*
* @return string
*/
public function getAction()
{
return $this->_action;
}

/**
* Set action
*
* @param string $action action
*
* @return $this
*/
public function setAction($action)
{
$this->_action = $action;

return $this;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Paymill/Services/ResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ResponseHandler
11000 => "Retry later",

20000 => "General success response.",
20100 => "",
20100 => "Funds held by acquirer.",
20101 => "Funds held by acquirer because merchant is new.",
20200 => "Transaction reversed.",
20201 => "Reversed due to chargeback.",
Expand All @@ -47,6 +47,7 @@ class ResponseHandler

40000 => "General problem with data.",
40001 => "General problem with payment data.",
40002 => "Invalid checksum.",
40100 => "Problem with credit card data.",
40101 => "Problem with cvv.",
40102 => "Card expired or not yet valid.",
Expand Down Expand Up @@ -405,6 +406,7 @@ private function _createChecksum($response)
$model->setChecksum($response['checksum']);
$model->setData($response['data']);
$model->setType($response['type']);
$model->setAction($response['action']);
$model->setAppId($response['app_id']);
$model->setCreatedAt($response['created_at']);
$model->setUpdatedAt($response['updated_at']);
Expand Down
1 change: 1 addition & 0 deletions tests/integration/ChecksumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected function setUp()

$this->_model = new Checksum();
$this->_model->setChecksumType(Checksum::TYPE_PAYPAL);
$this->_model->setChecksumAction(Checksum::ACTION_TRANSACTION);
$this->_model->setAmount('200');
$this->_model->setCurrency('EUR');
$this->_model->setDescription('Dummy description');
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/Paymill/Models/Request/ChecksumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function setGetTest()
{
$sample = array(
'checksum_type' => Checksum::TYPE_PAYPAL,
'checksum_action' => Checksum::ACTION_TRANSACTION,
'amount' => '200',
'currency' => 'EUR',
'description' => 'foo bar',
Expand Down Expand Up @@ -92,6 +93,7 @@ public function setGetTest()

$this->_model
->setChecksumType($sample['checksum_type'])
->setChecksumAction($sample['checksum_action'])
->setAmount($sample['amount'])
->setCurrency($sample['currency'])
->setDescription($sample['description'])
Expand All @@ -105,6 +107,7 @@ public function setGetTest()
;

$this->assertEquals($this->_model->getChecksumType(), $sample['checksum_type']);
$this->assertEquals($this->_model->getChecksumAction(), $sample['checksum_action']);
$this->assertEquals($this->_model->getAmount(), $sample['amount']);
$this->assertEquals($this->_model->getCurrency(), $sample['currency']);
$this->assertEquals($this->_model->getDescription(), $sample['description']);
Expand Down Expand Up @@ -152,6 +155,7 @@ public function parameterizeTestCreate(Checksum $model)
{
$parameterArray = array();
$parameterArray['checksum_type'] = Checksum::TYPE_PAYPAL;
$parameterArray['checksum_action'] = Checksum::ACTION_TRANSACTION;
$parameterArray['amount'] = '200';
$parameterArray['currency'] = 'EUR';
$parameterArray['description'] = 'foo bar';
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/Paymill/Models/Response/ChecksumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Paymill\Test\Unit\Models\Response;

use Paymill\Models\Request\Checksum;
use Paymill\Models\Response as Response;
use PHPUnit_Framework_TestCase;

Expand Down Expand Up @@ -43,6 +44,7 @@ public function setGetTest()
{
$this->_model->setData('test=foo&foo[bar1]=test1&foo[bar2]=test2');
$this->_model->setType('creditcard');
$this->_model->setAction(Checksum::ACTION_TRANSACTION);
$this->_model->setChecksum('foo-checksum');
$this->_model->setAppId('app_123');
$this->_model->setId('chk_123');
Expand All @@ -58,6 +60,7 @@ public function setGetTest()
)
));
$this->assertEquals($this->_model->getType(), 'creditcard');
$this->assertEquals($this->_model->getAction(), Checksum::ACTION_TRANSACTION);
$this->assertEquals($this->_model->getChecksum(), 'foo-checksum');
$this->assertEquals($this->_model->getAppId(), 'app_123');
$this->assertEquals($this->_model->getId(), 'chk_123');
Expand Down

0 comments on commit 555bf66

Please sign in to comment.