Skip to content

Commit edf4942

Browse files
committed
Merge pull request #118 from cyrrill/paypal-checksum
Reusable Payments and Client Id for PayPal Checksums. Thanks @cyrrill
2 parents 28b7de8 + f283e6f commit edf4942

File tree

2 files changed

+118
-2
lines changed

2 files changed

+118
-2
lines changed

lib/Paymill/Models/Request/Checksum.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,27 @@ class Checksum extends Base
121121
*/
122122
private $_handling_amount;
123123

124+
/**
125+
* Client identifier
126+
*
127+
* @var string $_client
128+
*/
129+
private $_client;
130+
131+
/**
132+
* Reusable payment
133+
*
134+
* @var bool $_requireReusablePayment
135+
*/
136+
private $_requireReusablePayment;
137+
138+
/**
139+
* Reusable payment description
140+
*
141+
* @var string $_reusablePaymentDescription
142+
*/
143+
private $_reusablePaymentDescription;
144+
124145
/**
125146
* Creates an instance of the checksum request model
126147
*/
@@ -129,6 +150,30 @@ function __construct()
129150
$this->_serviceResource = 'checksums/';
130151
}
131152

153+
/**
154+
* Sets the identifier of the Client for the transaction
155+
*
156+
* @param string $clientId Client identifier
157+
*
158+
* @return $this
159+
*/
160+
public function setClient($client)
161+
{
162+
$this->_client = $client;
163+
164+
return $this;
165+
}
166+
167+
/**
168+
* Returns the identifier of the Client associated with the checksum. If no client is available null will be returned
169+
*
170+
* @return string
171+
*/
172+
public function getClient()
173+
{
174+
return $this->_client;
175+
}
176+
132177
/**
133178
* Set amount
134179
*
@@ -515,6 +560,54 @@ public function setHandlingAmount($handling_amount)
515560
return $this;
516561
}
517562

563+
/**
564+
* Get require reusable payment
565+
*
566+
* @return bool
567+
*/
568+
public function getRequireReusablePayment()
569+
{
570+
return $this->_requireReusablePayment;
571+
}
572+
573+
/**
574+
* Set require reusable payment
575+
*
576+
* @param bool $requireReusablePayment Reusable payment
577+
*
578+
* @return $this
579+
*/
580+
public function setRequireReusablePayment($requireReusablePayment)
581+
{
582+
$this->_requireReusablePayment = $requireReusablePayment;
583+
584+
return $this;
585+
}
586+
587+
/**
588+
* Get reusable payment description
589+
*
590+
* @return string
591+
*/
592+
public function getReusablePaymentDescription()
593+
{
594+
return $this->_reusablePaymentDescription;
595+
}
596+
597+
/**
598+
* Set reusable payment description
599+
*
600+
* @param string $reusablePaymentDescription Reusable payment description
601+
*
602+
* @return $this
603+
*/
604+
public function setReusablePaymentDescription($reusablePaymentDescription)
605+
{
606+
$this->_reusablePaymentDescription = $reusablePaymentDescription;
607+
608+
return $this;
609+
}
610+
518611
/**
519612
* Returns an array of parameters customized for the given method name
520613
*
@@ -582,6 +675,18 @@ public function parameterize($method)
582675
$parameterArray['handling_amount'] = $this->getHandlingAmount();
583676
}
584677

678+
if($this->getRequireReusablePayment()) {
679+
$parameterArray['require_reusable_payment'] = $this->getRequireReusablePayment();
680+
}
681+
682+
if($this->getReusablePaymentDescription()) {
683+
$parameterArray['reusable_payment_description'] = $this->getReusablePaymentDescription();
684+
}
685+
686+
if($this->getClient()) {
687+
$parameterArray['client'] = $this->getClient();
688+
}
689+
585690
// Unite params:
586691

587692
if($this->getAppId()) {

tests/unit/Paymill/Models/Request/ChecksumTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ protected function tearDown()
4242
public function setGetTest()
4343
{
4444
$sample = array(
45+
'client' => 'client_88a388d9dd48f86c3136',
4546
'checksum_type' => Checksum::TYPE_PAYPAL,
4647
'checksum_action' => Checksum::ACTION_TRANSACTION,
4748
'amount' => '200',
@@ -88,10 +89,13 @@ public function setGetTest()
8889
)
8990
),
9091
'shipping_amount' => '50',
91-
'handling_amount' => '50'
92+
'handling_amount' => '50',
93+
'require_reusable_payment' => true,
94+
'reusable_payment_description' => 'Paymill Paypal test'
9295
);
9396

9497
$this->_model
98+
->setClient($sample['client'])
9599
->setChecksumType($sample['checksum_type'])
96100
->setChecksumAction($sample['checksum_action'])
97101
->setAmount($sample['amount'])
@@ -104,8 +108,11 @@ public function setGetTest()
104108
->setItems($sample['items'])
105109
->setShippingAmount($sample['shipping_amount'])
106110
->setHandlingAmount($sample['handling_amount'])
111+
->setRequireReusablePayment($sample['require_reusable_payment'])
112+
->setReusablePaymentDescription($sample['reusable_payment_description'])
107113
;
108114

115+
$this->assertEquals($this->_model->getClient(), $sample['client']);
109116
$this->assertEquals($this->_model->getChecksumType(), $sample['checksum_type']);
110117
$this->assertEquals($this->_model->getChecksumAction(), $sample['checksum_action']);
111118
$this->assertEquals($this->_model->getAmount(), $sample['amount']);
@@ -118,7 +125,8 @@ public function setGetTest()
118125
$this->assertEquals($this->_model->getItems(), $sample['items']);
119126
$this->assertEquals($this->_model->getShippingAmount(), $sample['shipping_amount']);
120127
$this->assertEquals($this->_model->getHandlingAmount(), $sample['handling_amount']);
121-
128+
$this->assertEquals($this->_model->getRequireReusablePayment(), $sample['require_reusable_payment']);
129+
$this->assertEquals($this->_model->getReusablePaymentDescription(), $sample['reusable_payment_description']);
122130
return $this->_model;
123131
}
124132

@@ -154,6 +162,7 @@ public function parameterizeTestGetOne(Checksum $model)
154162
public function parameterizeTestCreate(Checksum $model)
155163
{
156164
$parameterArray = array();
165+
$parameterArray['client'] = 'client_88a388d9dd48f86c3136';
157166
$parameterArray['checksum_type'] = Checksum::TYPE_PAYPAL;
158167
$parameterArray['checksum_action'] = Checksum::ACTION_TRANSACTION;
159168
$parameterArray['amount'] = '200';
@@ -201,6 +210,8 @@ public function parameterizeTestCreate(Checksum $model)
201210
);
202211
$parameterArray['shipping_amount'] = '50';
203212
$parameterArray['handling_amount'] = '50';
213+
$parameterArray['require_reusable_payment'] = true;
214+
$parameterArray['reusable_payment_description'] = 'Paymill Paypal test';
204215

205216
$creationArray = $model->parameterize("create");
206217

0 commit comments

Comments
 (0)