From ba8566371d74b98eddb1a4a58f7bf70936f7baa9 Mon Sep 17 00:00:00 2001 From: "enrico.hofmann" Date: Fri, 26 Feb 2016 11:54:18 +0100 Subject: [PATCH] Add reason parapeter to library --- lib/Paymill/Models/Request/Refund.php | 49 +++++++++++++++++++ lib/Paymill/Models/Response/Refund.php | 32 +++++++++++- .../Paymill/Models/Request/RefundTest.php | 3 +- 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/lib/Paymill/Models/Request/Refund.php b/lib/Paymill/Models/Request/Refund.php index df6957e..0597a0e 100644 --- a/lib/Paymill/Models/Request/Refund.php +++ b/lib/Paymill/Models/Request/Refund.php @@ -9,6 +9,11 @@ */ class Refund extends Base { + + CONST REASON_KEY_REQUESTED_BY_CUSTOMER = 'requested_by_customer'; + CONST REASON_KEY_DUPLICATE = 'duplicate'; + CONST REASON_KEY_FRAUDULENT = 'fraudulent'; + /** * @var string */ @@ -19,6 +24,11 @@ class Refund extends Base */ private $_description; + /** + * @var string + */ + private $_reason; + /** * Creates an instance of the refund request model */ @@ -29,6 +39,7 @@ function __construct() /** * Returns the amount + * * @return string */ public function getAmount() @@ -39,6 +50,7 @@ public function getAmount() /** * Sets the amount * @param string $amount + * * @return \Paymill\Models\Request\Refund */ public function setAmount($amount) @@ -49,6 +61,7 @@ public function setAmount($amount) /** * Returns the description + * * @return string */ public function getDescription() @@ -59,6 +72,7 @@ public function getDescription() /** * Sets the description * @param string $description + * * @return \Paymill\Models\Request\Refund */ public function setDescription($description) @@ -67,9 +81,41 @@ public function setDescription($description) return $this; } + /** + * Returns the reason + * @return string + */ + public function getReason() + { + return $this->_reason; + } + + /** + * Sets the reason possible Reasons are + * - Refund::REASON_KEY_REQUESTED_BY_CUSTOMER (requested_by_customer) + * - Refund::REASON_KEY_DUPLICATE (duplicate) + * - Refund::REASON_KEY_FRAUDULENT (fraudulent) + * + * @param string $reason + * + * @return \Paymill\Models\Request\Refund + */ + public function setReason($reason) + { + if (in_array( + $reason, + array(self::REASON_KEY_FRAUDULENT, self::REASON_KEY_REQUESTED_BY_CUSTOMER, self::REASON_KEY_DUPLICATE) + )) { + $this->_reason = $reason; + } + + return $this; + } + /** * Returns an array of parameters customized for the argumented methodname * @param string $method + * * @return array */ public function parameterize($method) @@ -79,6 +125,9 @@ public function parameterize($method) case 'create': $parameterArray['amount'] = $this->getAmount(); $parameterArray['description'] = $this->getDescription(); + if (!empty($this->_reason)) { + $parameterArray['reason'] = $this->_reason; + } break; case 'getOne': $parameterArray['count'] = 1; diff --git a/lib/Paymill/Models/Response/Refund.php b/lib/Paymill/Models/Response/Refund.php index 31fcb0c..7377e02 100644 --- a/lib/Paymill/Models/Response/Refund.php +++ b/lib/Paymill/Models/Response/Refund.php @@ -27,6 +27,7 @@ public function getTransaction() /** * Sets the transaction model * @param \Paymill\Models\Response\Transaction $transaction + * * @return \Paymill\Models\Response\Refund */ public function setTransaction($transaction) @@ -53,6 +54,7 @@ public function getAmount() /** * Sets the amount * @param integer $amount + * * @return \Paymill\Models\Response\Refund */ public function setAmount($amount) @@ -79,6 +81,7 @@ public function getStatus() /** * Sets the Status of the refund * @param string $status + * * @return \Paymill\Models\Response\Refund */ public function setStatus($status) @@ -105,6 +108,7 @@ public function getDescription() /** * Sets the description of this refund * @param string $description + * * @return \Paymill\Models\Response\Refund */ public function setDescription($description) @@ -112,7 +116,33 @@ public function setDescription($description) $this->_description = $description; return $this; } - + + /** + * @var string + */ + private $_reason; + + /** + * Sets the reason + * @return string + */ + public function getReason() + { + return $this->_reason; + } + + /** + * @param string $reason + * + * @return \Paymill\Models\Response\Refund + */ + public function setReason($reason) + { + $this->_reason = $reason; + + return $this; + } + /** * Whether this refund happend in test- or in livemode. * @var boolean diff --git a/tests/unit/Paymill/Models/Request/RefundTest.php b/tests/unit/Paymill/Models/Request/RefundTest.php index c2c9c02..e3b6439 100644 --- a/tests/unit/Paymill/Models/Request/RefundTest.php +++ b/tests/unit/Paymill/Models/Request/RefundTest.php @@ -43,7 +43,8 @@ public function setGetTest() { $sample = array( 'amount' => '4200', // e.g. "4200" for 42.00 EUR - 'description' => 'Sample Description' + 'description' => 'Sample Description', + 'reason' => 'requested_by_customer' ); $this->_refund->setAmount($sample['amount'])