From 75de6975f24c9059d8da5d446f0b95545faff3e8 Mon Sep 17 00:00:00 2001 From: tschela Date: Tue, 9 Jun 2015 14:10:25 +0200 Subject: [PATCH 1/4] Update checksum models --- README.md | 13 +- lib/Paymill/API/Curl.php | 4 +- lib/Paymill/Models/Request/Checksum.php | 336 +++++++++++- lib/Paymill/Models/Request/Subscription.php | 5 +- lib/Paymill/Models/Request/Transaction.php | 308 +++++++++-- lib/Paymill/Models/Response/Checksum.php | 85 ++- lib/Paymill/Models/Response/Transaction.php | 501 +++++++++++++----- lib/Paymill/Request.php | 44 +- lib/Paymill/Services/ResponseHandler.php | 51 +- samples/checksums/create.php | 54 ++ samples/checksums/get_by_id.php | 4 + samples/checksums/list.php | 3 + samples/refunds/get_refund_details.php | 2 +- tests/integration/ChecksumTest.php | 18 +- .../Paymill/Models/Request/ChecksumTest.php | 148 +++++- .../Models/Request/TransactionTest.php | 127 +++-- .../Paymill/Models/Response/ChecksumTest.php | 25 +- .../Paymill/Services/ResponseHandlerTest.php | 41 +- 18 files changed, 1460 insertions(+), 309 deletions(-) create mode 100644 samples/checksums/create.php create mode 100644 samples/checksums/get_by_id.php create mode 100644 samples/checksums/list.php diff --git a/README.md b/README.md index aa4104c..f755036 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,20 @@ VERSIONING This wrapper is using the api v2.1 launched in June 2014. If you wish to use the old api v2.0 please use the wrapper in branch v2: https://github.com/paymill/paymill-php/tree/v2. -How to test ------------ +How to test cards and errors +---------------------------- There are different credit card numbers, frontend and backend error codes, which can be used for testing. For more information, please read our testing reference. https://www.paymill.com/en-gb/documentation-3/reference/testing/ +How to run unit and integration tests +------------------------------------- +Just run: + +``` +ant test +``` + + Getting started with PAYMILL ---------------------------- diff --git a/lib/Paymill/API/Curl.php b/lib/Paymill/API/Curl.php index dce7ca8..9004dab 100644 --- a/lib/Paymill/API/Curl.php +++ b/lib/Paymill/API/Curl.php @@ -105,13 +105,15 @@ public function requestApi($action = '', $params = array(), $method = 'POST') return $responseBody; } - return array( + $result = array( 'header' => array( 'status' => $responseInfo['http_code'], 'reason' => null, ), 'body' => $responseBody ); + + return $result; } /** diff --git a/lib/Paymill/Models/Request/Checksum.php b/lib/Paymill/Models/Request/Checksum.php index 24ed97b..00e0cfd 100755 --- a/lib/Paymill/Models/Request/Checksum.php +++ b/lib/Paymill/Models/Request/Checksum.php @@ -14,6 +14,12 @@ */ class Checksum extends Base { + /** + * Different checksum types which will enable different validations for + * the input parameters. + */ + const TYPE_PAYPAL = 'paypal'; + /** * @var string */ @@ -34,6 +40,16 @@ class Checksum extends Base */ private $_description = null; + /** + * @var string + */ + private $_returnUrl = null; + + /** + * @var string + */ + private $_cancelUrl = null; + /** * @var null|string */ @@ -54,27 +70,67 @@ class Checksum extends Base */ private $_feePayment = null; + /** + * Shipping address + * + * @var array $_shippingAddress + */ + private $_shippingAddress; + + /** + * Billing address + * + * @var array $_billingAddress + */ + private $_billingAddress; + + /** + * Items + * + * @var array $_items + */ + private $_items; + + /** + * Shipping amount + * + * @var int $_shipping_amount + */ + private $_shipping_amount; + + /** + * Handling amount + * + * @var int $_handling_amount + */ + private $_handling_amount; + /** * Creates an instance of the checksum request model */ function __construct() { - $this->_serviceResource = 'checksum/'; + $this->_serviceResource = 'checksums/'; } /** - * @param string $amount + * Set amount * - * @return \Paymill\Models\Request\Checksum + * @param string $amount Amount in s the smallest unit (e.g. Cent) + * + * @return $this */ public function setAmount($amount) { $this->_amount = $amount; + return $this; } /** - * @return string + * Get amount + * + * @return string Amount in s the smallest unit (e.g. Cent) */ public function getAmount() { @@ -82,17 +138,22 @@ public function getAmount() } /** + * Set checksum type + * * @param string $checksumType * - * @return \Paymill\Models\Request\Checksum + * @return $this */ public function setChecksumType($checksumType) { $this->_checksumType = $checksumType; + return $this; } /** + * Get checksum type + * * @return string * * @return $this @@ -103,18 +164,23 @@ public function getChecksumType() } /** - * @param array $currency + * Set currency * - * @return \Paymill\Models\Request\Checksum + * @param string $currency (alpha 3) + * + * @return $this */ public function setCurrency($currency) { $this->_currency = $currency; + return $this; } /** - * @return array + * Get currency + * + * @return string (alpha 3) */ public function getCurrency() { @@ -122,18 +188,23 @@ public function getCurrency() } /** - * @param array $description + * Set description * - * @return \Paymill\Models\Request\Checksum + * @param string $description + * + * @return $this */ public function setDescription($description) { $this->_description = $description; + return $this; } /** - * @return array + * Get description + * + * @return string */ public function getDescription() { @@ -141,6 +212,56 @@ public function getDescription() } /** + * Get return url + * + * @return string + */ + public function getReturnUrl() + { + return $this->_returnUrl; + } + + /** + * Set return url + * + * @param string $returnUrl return url + * + * @return $this + */ + public function setReturnUrl($returnUrl) + { + $this->_returnUrl = $returnUrl; + + return $this; + } + + /** + * Get cancel url + * + * @return string + */ + public function getCancelUrl() + { + return $this->_cancelUrl; + } + + /** + * Set cancel url + * + * @param string $cancelUrl cancel url + * + * @return $this + */ + public function setCancelUrl($cancelUrl) + { + $this->_cancelUrl = $cancelUrl; + + return $this; + } + + /** + * Set app ID + * * @param null|string $appId * * @return \Paymill\Models\Request\Checksum @@ -148,10 +269,13 @@ public function getDescription() public function setAppId($appId) { $this->_appId = $appId; + return $this; } /** + * Get app Id + * * @return null|string */ public function getAppId() @@ -160,17 +284,22 @@ public function getAppId() } /** + * Set fee amount + * * @param null|string $feeAmount * - * @return \Paymill\Models\Request\Checksum + * @return $this */ public function setFeeAmount($feeAmount) { $this->_feeAmount = $feeAmount; + return $this; } /** + * Get fee amount + * * @return null|string */ public function getFeeAmount() @@ -179,17 +308,22 @@ public function getFeeAmount() } /** + * Set fee currency + * * @param null|string $feeCurrency * - * @return \Paymill\Models\Request\Checksum + * @return $this */ public function setFeeCurrency($feeCurrency) { $this->_feeCurrency = $feeCurrency; + return $this; } /** + * Get fee currency + * * @return null|string */ public function getFeeCurrency() @@ -198,17 +332,22 @@ public function getFeeCurrency() } /** + * Set fee payment + * * @param null|string $feePayment * - * @return \Paymill\Models\Request\Checksum + * @return $this */ public function setFeePayment($feePayment) { $this->_feePayment = $feePayment; + return $this; } /** + * get fee payment + * * @return null|string */ public function getFeePayment() @@ -216,6 +355,126 @@ public function getFeePayment() return $this->_feePayment; } + /** + * Get shipping address + * + * @return array + */ + public function getShippingAddress() + { + return $this->_shippingAddress; + } + + /** + * Set shipping address + * + * @param array $shippingAddress Shipping address + * + * @return $this + */ + public function setShippingAddress(array $shippingAddress) + { + $this->_shippingAddress = $shippingAddress; + + return $this; + } + + /** + * Get billing address + * + * @return array + */ + public function getBillingAddress() + { + return $this->_billingAddress; + } + + /** + * Set billing address + * + * @param array $billingAddress Billing address + * + * @return $this + */ + public function setBillingAddress(array $billingAddress) + { + $this->_billingAddress = $billingAddress; + + return $this; + } + + /** + * Get items + * + * @return array + */ + public function getItems() + { + return $this->_items; + } + + /** + * Set items + * + * @param array $items Items + * + * @return $this + */ + public function setItems(array $items) + { + $this->_items = $items; + + return $this; + } + + /** + * Get shipping amount + * + * @return int + */ + public function getShippingAmount() + { + return $this->_shipping_amount; + } + + /** + * Set shipping_amount + * + * @param int $shipping_amount Shipping amount + * + * @return $this + */ + public function setShippingAmount($shipping_amount) + { + $this->_shipping_amount = $shipping_amount; + + return $this; + } + + /** + * Get handling amount + * + * @return int + */ + public function getHandlingAmount() + { + return $this->_handling_amount; + } + + /** + * Set handling amount + * + * @param int $handling_amount Handling amount + * + * @return $this + */ + public function setHandlingAmount($handling_amount) + { + $this->_handling_amount = $handling_amount; + + return $this; + } + /** * Returns an array of parameters customized for the given method name * @@ -228,38 +487,73 @@ public function parameterize($method) $parameterArray = array(); switch ($method) { case 'getOne': + $parameterArray['count'] = 1; + $parameterArray['offset'] = 0; + break; + case 'getAll': + $parameterArray = $this->getFilter(); + break; + case 'create': if($this->getChecksumType()) { $parameterArray['checksum_type'] = $this->getChecksumType(); } if($this->getAmount()) { - $parameterArray['amount'] = $this->getAmount(); + $parameterArray['amount'] = $this->getAmount(); } if($this->getCurrency()) { - $parameterArray['currency'] = $this->getCurrency(); + $parameterArray['currency'] = $this->getCurrency(); } if($this->getDescription()){ - $parameterArray['description'] = $this->getDescription(); + $parameterArray['description'] = $this->getDescription(); + } + + if($this->getReturnUrl()){ + $parameterArray['return_url'] = $this->getReturnUrl(); + } + + if($this->getCancelUrl()){ + $parameterArray['cancel_url'] = $this->getCancelUrl(); + } + + if($this->getShippingAddress()) { + $parameterArray['shipping_address'] = $this->getShippingAddress(); + } + + if($this->getBillingAddress()) { + $parameterArray['billing_address'] = $this->getBillingAddress(); + } + + if($this->getItems()) { + $parameterArray['items'] = $this->getItems(); + } + + if($this->getShippingAmount()) { + $parameterArray['shipping_amount'] = $this->getShippingAmount(); + } + + if($this->getHandlingAmount()) { + $parameterArray['handling_amount'] = $this->getHandlingAmount(); } // Unite params: if($this->getAppId()) { - $parameterArray['app_id'] = $this->getAppId(); + $parameterArray['app_id'] = $this->getAppId(); } if($this->getFeeAmount()) { - $parameterArray['fee_amount'] = $this->getFeeAmount(); + $parameterArray['fee_amount'] = $this->getFeeAmount(); } if($this->getFeeCurrency()) { - $parameterArray['fee_currency'] = $this->getFeeCurrency(); + $parameterArray['fee_currency'] = $this->getFeeCurrency(); } if($this->getFeePayment()) { - $parameterArray['fee_payment'] = $this->getFeePayment(); + $parameterArray['fee_payment'] = $this->getFeePayment(); } break; diff --git a/lib/Paymill/Models/Request/Subscription.php b/lib/Paymill/Models/Request/Subscription.php index cdcccb1..de1b50f 100755 --- a/lib/Paymill/Models/Request/Subscription.php +++ b/lib/Paymill/Models/Request/Subscription.php @@ -414,12 +414,15 @@ public function getMandateReference() /** * Set mandate reference + * * @param string $mandateReference - * @return \Paymill\Models\Request\Subscription + * + * @return $this */ public function setMandateReference($mandateReference) { $this->_mandateReference = $mandateReference; + return $this; } diff --git a/lib/Paymill/Models/Request/Transaction.php b/lib/Paymill/Models/Request/Transaction.php index b99e3c4..26645a7 100755 --- a/lib/Paymill/Models/Request/Transaction.php +++ b/lib/Paymill/Models/Request/Transaction.php @@ -4,6 +4,7 @@ /** * 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 @@ -13,60 +14,117 @@ class Transaction extends Base { /** + * Amount + * * @var string */ private $_amount; /** + * Description + * * @var string */ private $_description; /** + * Currency + * * @var string */ private $_currency; /** + * Payment + * * @var string */ private $_payment; /** + * Client + * * @var string */ private $_client = null; /** + * Preauthorization + * * @var string */ private $_preauthorization; /** + * Token + * * @var string */ private $_token; /** + * Fee amount + * * @var string */ private $_feeAmount; /** + * Fee payment + * * @var string */ private $_feePayment; /** + * Fee currency + * * @var string */ private $_feeCurrency; /** + * Source + * * @var $_source */ private $_source; + /** + * Shipping address + * + * @var array $_shippingAddress + */ + private $_shippingAddress; + + /** + * Billing address + * + * @var array $_billingAddress + */ + private $_billingAddress; + + /** + * Items + * + * @var array $_items + */ + private $_items; + + /** + * Shipping amount + * + * @var int $_shipping_amount + */ + private $_shipping_amount; + + /** + * Handling amount + * + * @var int $_handling_amount + */ + private $_handling_amount; + /** * @var string */ @@ -82,6 +140,7 @@ function __construct() /** * Returns the 'real' amount + * * @return string */ public function getAmount() @@ -91,18 +150,22 @@ public function getAmount() /** * Sets the 'real' amount for the transaction. - * The number musst be in the smallest currency unit and will be saved as a string - * @param string $amount - * @return \Paymill\Models\Request\Transaction + * The number must be in the smallest currency unit and will be saved as a string + * + * @param string $amount Amount + * + * @return $this */ public function setAmount($amount) { $this->_amount = $amount; + return $this; } /** * Returns the transaction description + * * @return string */ public function getDescription() @@ -112,8 +175,10 @@ public function getDescription() /** * Sets the transaction description - * @param string $description - * @return \Paymill\Models\Request\Transaction + * + * @param string $description Description + * + * @return $this */ public function setDescription($description) { @@ -123,6 +188,7 @@ public function setDescription($description) /** * Returns the currency + * * @return string */ public function getCurrency() @@ -132,17 +198,21 @@ public function getCurrency() /** * Sets the currency - * @param string $currency - * @return \Paymill\Models\Request\Transaction + * + * @param string $currency Currency + * + * @return $this */ public function setCurrency($currency) { $this->_currency = $currency; + return $this; } /** * Returns the identifier of the payment associated with the transaction + * * @return string */ public function getPayment() @@ -151,18 +221,22 @@ public function getPayment() } /** - * Sets the identifier of the Payment for the transcation - * @param string $payment - * @return \Paymill\Models\Request\Transaction + * Sets the identifier of the Payment for the transaction + * + * @param string $payment Payment + * + * @return $this */ public function setPayment($payment) { $this->_payment = $payment; + return $this; } /** * Returns the identifier of the Client associated with the transaction. If no client is available null will be returned + * * @return string|null */ public function getClient() @@ -172,17 +246,21 @@ public function getClient() /** * Sets the identifier of the Client for the transaction - * @param string $client - * @return \Paymill\Models\Request\Transaction + * + * @param string $client Client + * + * @return $this */ public function setClient($client) { $this->_client = $client; + return $this; } /** * Returns the identifier of the Preauthorization associated with the transaction. If no preAuth is available null will be returned + * * @return string|null */ public function getPreauthorization() @@ -192,18 +270,22 @@ public function getPreauthorization() /** * Sets the identifier of the Preauthorization for the transaction - * @param string $preauthorization - * @return \Paymill\Models\Request\Transaction + * + * @param string $preauthorization Preauthorization + * + * @return $this */ public function setPreauthorization($preauthorization) { $this->_preauthorization = $preauthorization; + return $this; } /** * Returns the FeeAmount * Fee included in the transaction amount (set by a connected app). Mandatory if feePayment is set + * * @return integer */ public function getFeeAmount() @@ -213,17 +295,21 @@ public function getFeeAmount() /** * Sets the Fee included in the transaction amount (set by a connected app). - * @param integer $feeAmount - * @return \Paymill\Models\Request\Transaction + * + * @param integer $feeAmount Fee amount + * + * @return $this */ public function setFeeAmount($feeAmount) { $this->_feeAmount = $feeAmount; + return $this; } /** - * Returns the identifier of the payment from which the fee will be charged (creditcard-object or directdebit-object). + * Returns the identifier of the payment from which the fee will be charged (creditcard-object or direct debit-object). + * * @return string */ public function getFeePayment() @@ -232,30 +318,37 @@ public function getFeePayment() } /** - * Sets the identifier of the payment from which the fee will be charged (creditcard-object or directdebit-object). - * @param string $feePayment - * @return \Paymill\Models\Request\Transaction + * Sets the identifier of the payment from which the fee will be charged (creditcard-object or direct debit-object). + * + * @param string $feePayment Fee payment + * + * @return $this */ public function setFeePayment($feePayment) { $this->_feePayment = $feePayment; + return $this; } /** * Set the currency which should be used for collecting the given fee + * * @param string $feeCurrency (e.g. EUR, USD ...) - * @return \Paymill\Models\Response\Transaction + * + * @return $this */ public function setFeeCurrency($feeCurrency) { $this->_feeCurrency = $feeCurrency; + return $this; } /** * returns the set fee currency which is used for the fee collection + * * @return string */ public function getFeeCurrency() @@ -268,6 +361,7 @@ public function getFeeCurrency() /** * Returns the token generated through our JavaScript-Bridge. * When this parameter is used, none of the following should be used: payment, preauthorization. + * * @return string */ public function getToken() @@ -278,34 +372,162 @@ public function getToken() /** * Sets the token generated through our JavaScript-Bridge. * When this parameter is used, none of the following should be used: payment, preauthorization. - * @param string $token - * @return \Paymill\Models\Request\Transaction + * + * @param string $token Token + * + * @return $this */ public function setToken($token) { $this->_token = $token; + return $this; } /** - * Sets the name of origin of the call creating the transaction - * @param mixed $source + * Sets the name of origin of the call creating the transaction. + * + * @param string $source Source + * + * @return $this */ public function setSource($source) { $this->_source = $source; + return $this; } /** - * Gets the name of origin of the call creating the transaction - * @return mixed + * Gets the name of origin of the call creating the transaction. + * + * @return string */ public function getSource() { return $this->_source; } + /** + * Get shipping address + * + * @return array + */ + public function getShippingAddress() + { + return $this->_shippingAddress; + } + + /** + * Set shipping address + * + * @param array $shippingAddress Shipping address + * + * @return $this + */ + public function setShippingAddress(array $shippingAddress) + { + $this->_shippingAddress = $shippingAddress; + + return $this; + } + + /** + * Get billing address + * + * @return array + */ + public function getBillingAddress() + { + return $this->_billingAddress; + } + + /** + * Set billing address + * + * @param array $billingAddress Billing address + * + * @return $this + */ + public function setBillingAddress(array $billingAddress) + { + $this->_billingAddress = $billingAddress; + + return $this; + } + + /** + * Get items + * + * @return array + */ + public function getItems() + { + return $this->_items; + } + + /** + * Set items + * + * @param array $items Items + * + * @return $this + */ + public function setItems(array $items) + { + $this->_items = $items; + + return $this; + } + + /** + * Get shipping amount + * + * @return int + */ + public function getShippingAmount() + { + return $this->_shipping_amount; + } + + /** + * Set shipping_amount + * + * @param int $shipping_amount Shipping amount + * + * @return $this + */ + public function setShippingAmount($shipping_amount) + { + $this->_shipping_amount = $shipping_amount; + + return $this; + } + + /** + * Get handling amount + * + * @return int + */ + public function getHandlingAmount() + { + return $this->_handling_amount; + } + + /** + * Set handling amount + * + * @param int $handling_amount Handling amount + * + * @return $this + */ + public function setHandlingAmount($handling_amount) + { + $this->_handling_amount = $handling_amount; + + return $this; + } + /** * Returns mandate reference * @return string @@ -317,18 +539,23 @@ public function getMandateReference() /** * Set mandate reference + * * @param string $mandateReference - * @return \Paymill\Models\Request\Subscription + * + * @return $this */ public function setMandateReference($mandateReference) { $this->_mandateReference = $mandateReference; + return $this; } /** - * Returns an array of parameters customized for the argumented methodname - * @param string $method + * Returns an array of parameters customized for the given method name. + * + * @param string $method Method + * * @return array */ public function parameterize($method) @@ -359,9 +586,30 @@ public function parameterize($method) if(!is_null($this->getSource())) { $parameterArray['source'] = $this->getSource(); } + if(!is_null($this->getShippingAddress())) { + $parameterArray['shipping_address'] = $this->getShippingAddress(); + } + if(!is_null($this->getBillingAddress())) { + $parameterArray['billing_address'] = $this->getBillingAddress(); + } + if(!is_null($this->getItems())) { + $parameterArray['items'] = $this->getItems(); + } + if(!is_null($this->getShippingAmount())) { + $parameterArray['shipping_amount'] = $this->getShippingAmount(); + } + if(!is_null($this->getHandlingAmount())) { + $parameterArray['handling_amount'] = $this->getHandlingAmount(); + } if (!is_null($this->getMandateReference())) { $parameterArray['mandate_reference'] = $this->getMandateReference(); } + if(!is_null($this->getShippingAddress())) { + $parameterArray['shipping_address'] = $this->getShippingAddress(); + } + if(!is_null($this->getBillingAddress())) { + $parameterArray['billing_address'] = $this->getBillingAddress(); + } break; case 'update': $parameterArray['description'] = $this->getDescription(); diff --git a/lib/Paymill/Models/Response/Checksum.php b/lib/Paymill/Models/Response/Checksum.php index 55efafb..3c38a49 100755 --- a/lib/Paymill/Models/Response/Checksum.php +++ b/lib/Paymill/Models/Response/Checksum.php @@ -12,16 +12,32 @@ * 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 */ -class Checksum +class Checksum extends Base { /** + * Checksum + * * @var string */ - private $_checksum = null; - private $_livemode = false; + private $_checksum; + + /** + * Type + * + * @var string + */ + private $_type; + + /** + * Data + * + * @var string + */ + private $_data; /** * Returns the checksum + * * @return string */ public function getChecksum() @@ -31,32 +47,75 @@ public function getChecksum() /** * Sets the checksum + * * @param string $val - * @return \Paymill\Models\Response\Checksum + * @return $this */ public function setChecksum($val) { $this->_checksum = $val; + + return $this; + } + + /** + * Get type + * + * @return string + */ + public function getType() + { + return $this->_type; + } + + /** + * Set type + * + * @param string $type type + * + * @return $this + */ + public function setType($type) + { + $this->_type = $type; + return $this; } /** - * Returns the livemode flag of the checksum - * @return boolean + * Get data + * + * @return string */ - public function getLivemode() + public function getData() { - return $this->_livemode; + return $this->_data; } /** - * Sets the livemode flag of the checksum - * @param boolean $livemode - * @return \Paymill\Models\Response\Checksum + * Set data + * + * @param string $data data + * + * @return $this */ - public function setLivemode($livemode) + public function setData($data) { - $this->_livemode = $livemode; + $this->_data = $data; + return $this; } + + /** + * Returns url encoded checksum data as array + * + * @return array + */ + public function getDataAsArray() + { + $checksumData = null; + parse_str($this->getData(), $checksumData); + + return $checksumData; + } } diff --git a/lib/Paymill/Models/Response/Transaction.php b/lib/Paymill/Models/Response/Transaction.php index c790a2c..8e20600 100755 --- a/lib/Paymill/Models/Response/Transaction.php +++ b/lib/Paymill/Models/Response/Transaction.php @@ -12,15 +12,151 @@ */ class Transaction extends Base { - /** * 'real' amount + * * @var string */ private $_amount; /** - * Returns the 'real' amount + * origin amount + * + * @var integer + */ + private $_originAmount; + + /** + * Status + * Possible status values (open, closed, failed, preauth, pending, refunded, partially_refunded, chargeback) + * + * @var string + */ + private $_status; + + /** + * Description + * + * @var string + */ + private $_description; + + /** + * Live mode + * + * @var boolean + */ + private $_livemode; + + /** + * Currency + * + * @var string + */ + private $_currency; + + /** + * Refunds + * + * @var array + */ + private $_refunds = null; + + /** + * Response code for transaction feedback. 20000 marks a successful transaction + * @tutorial https://paymill.com/de-de/dokumentation/referenz/api-referenz/#document-statuscodes + * + * @var integer + */ + private $_responseCode; + + /** + * Unique identifier of this transaction provided to the acquirer for the statements. + * + * @var string + */ + private $_shortId; + + /** + * PAYMILL invoice where the transaction fees are charged or null. + * + * @var array + */ + private $_invoices = null; + + /** + * Payment + * + * @var Payment + */ + private $_payment; + + /** + * Client + * + * @var Client + */ + private $_client = null; + + /** + * Preauthorization + * + * @var Preauthorization + */ + private $_preauthorization = null; + + /** + * Fees + * + * @var array + */ + private $_fees; + + /** + * Source + * + * @var $_source + */ + private $_source; + + /** + * Shipping address + * + * @var array|null $_shippingAddress + */ + private $_shippingAddress; + + /** + * Billing address + * + * @var array|null $_billingAddress + */ + private $_billingAddress; + + /** + * Items + * + * @var array $_items + */ + private $_items; + + /** + * Shipping amount + * + * @var int $_shipping_amount + */ + private $_shipping_amount; + + /** + * Handling amount + * + * @var int $_handling_amount + */ + private $_handling_amount; + + /** + * Returns the 'real' amount. + * * @return string */ public function getAmount() @@ -30,22 +166,19 @@ public function getAmount() /** * Sets the 'real' amount for the transaction. - * The number musst be in the smallest currency unit and will be saved as a string - * @param string $amount - * @return \Paymill\Models\Response\Transaction + * The number must be in the smallest currency unit and will be saved as a string. + * + * @param string $amount Amount + * + * @return $this */ public function setAmount($amount) { $this->_amount = $amount; + return $this; } - /** - * origin amount - * @var integer - */ - private $_originAmount; - /** * @var string */ @@ -53,6 +186,7 @@ public function setAmount($amount) /** * Returns the origin amount for the transaction. + * * @return integer */ public function getOriginAmount() @@ -62,24 +196,22 @@ public function getOriginAmount() /** * Sets the origin amount for the transaction. - * The number musst be in the smallest currency unit and will be saved as a string - * @param integer $originAmount - * @return \Paymill\Models\Response\Transaction + * The number must be in the smallest currency unit and will be saved as a string. + * + * @param integer $originAmount Origin amount + * + * @return $this */ public function setOriginAmount($originAmount) { $this->_originAmount = $originAmount; + return $this; } - /** - * Possible status values (open, closed, failed, preauth, pending, refunded, partially_refunded, chargeback) - * @var string - */ - private $_status; - /** * Returns the transaction status + * * @return string */ public function getStatus() @@ -88,23 +220,22 @@ public function getStatus() } /** - * Sets the transaction status - * @param string $status - * @return \Paymill\Models\Response\Transaction + * Sets the transaction status. + * + * @param string $status Status + * + * @return $this */ public function setStatus($status) { $this->_status = $status; + return $this; } /** - * @var string - */ - private $_description; - - /** - * Returns the transaction description + * Returns the transaction description. + * * @return string */ public function getDescription() @@ -113,23 +244,22 @@ public function getDescription() } /** - * Sets the transaction description - * @param string $description - * @return \Paymill\Models\Response\Transaction + * Sets the transaction description. + * + * @param string $description Description + * + * @return $this */ public function setDescription($description) { $this->_description = $description; + return $this; } /** - * @var boolean - */ - private $_livemode; - - /** - * Returns the livemode flag of the transaction + * Returns the livemode flag of the transaction. + * * @return boolean */ public function getLivemode() @@ -138,23 +268,22 @@ public function getLivemode() } /** - * Sets the livemode flag of the transaction - * @param boolean $livemode - * @return \Paymill\Models\Response\Transaction + * Sets the livemode flag of the transaction. + * + * @param boolean $livemode Live mode + * + * @return $this */ public function setLivemode($livemode) { $this->_livemode = $livemode; + return $this; } /** - * @var array - */ - private $_refunds = null; - - /** - * Returns the refunds stored in the transaction + * Returns the refunds stored in the transaction. + * * @return array|null */ public function getRefunds() @@ -163,23 +292,22 @@ public function getRefunds() } /** - * Sets the refunds stored in the transaction - * @param array $refunds - * @return \Paymill\Models\Response\Transaction + * Sets the refunds stored in the transaction. + * + * @param array $refunds Refunds + * + * @return $this */ public function setRefunds($refunds) { $this->_refunds = $refunds; + return $this; } /** - * @var string - */ - private $_currency; - - /** - * Returns the currency + * Returns the currency. + * * @return string */ public function getCurrency() @@ -188,25 +316,22 @@ public function getCurrency() } /** - * Sets the currency - * @param string $currency - * @return \Paymill\Models\Response\Transaction + * Sets the currency. + * + * @param string $currency Currency + * + * @return $this */ public function setCurrency($currency) { $this->_currency = $currency; + return $this; } - /** - * Response code for transaction feedback. 20000 marks a successful transaction - * @tutorial https://paymill.com/de-de/dokumentation/referenz/api-referenz/#document-statuscodes - * @var integer - */ - private $_responseCode; - /** * Returns the response code (20000 marks a successful transaction) + * * @return integer */ public function getResponseCode() @@ -216,23 +341,21 @@ public function getResponseCode() /** * Sets the response code of the transaction - * @param integer $responseCode - * @return \Paymill\Models\Response\Transaction + * + * @param integer $responseCode Response code + * + * @return $this */ public function setResponseCode($responseCode) { $this->_responseCode = $responseCode; + return $this; } - /** - * Unique identifier of this transaction provided to the acquirer for the statements. - * @var string - */ - private $_shortId; - /** * Returns the short id of the transaction + * * @return string */ public function getShortId() @@ -241,24 +364,22 @@ public function getShortId() } /** - * Sets the transaction short id + * Sets the transaction short id. + * * @param string $shortId - * @return \Paymill\Models\Response\Transaction + * + * @return $this */ public function setShortId($shortId) { $this->_shortId = $shortId; + return $this; } /** - * PAYMILL invoice where the transaction fees are charged or null. - * @var array - */ - private $_invoices = null; - - /** - * Returns an array of invoices stored in the transaction + * Returns an array of invoices stored in the transaction. + * * @return array|null */ public function getInvoices() @@ -267,24 +388,23 @@ public function getInvoices() } /** - * Stores an array of invoices in the transaction - * @param array $invoices - * @return \Paymill\Models\Response\Transaction + * Stores an array of invoices in the transaction. + * + * @param array $invoices Invoices + * + * @return $this */ public function setInvoices($invoices) { $this->_invoices = $invoices; + return $this; } /** - * @var \Paymill\Models\Response\Payment - */ - private $_payment; - - /** - * Returns the payment associated with the transaction - * @return \Paymill\Models\Response\Payment + * Returns the payment associated with the transaction. + * + * @return Payment */ public function getPayment() { @@ -292,24 +412,23 @@ public function getPayment() } /** - * Sets the Payment for the transcation - * @param \Paymill\Models\Response\Payment $payment - * @return \Paymill\Models\Response\Transaction + * Sets the Payment for the transaction. + * + * @param Payment $payment Payment + * + * @return $this */ public function setPayment($payment) { $this->_payment = $payment; + return $this; } /** - * @var \Paymill\Models\Response\Client - */ - private $_client = null; - - /** - * Returns the Client associated with the transaction. If no client is available null will be returned - * @return \Paymill\Models\Response\Client|null + * Returns the Client associated with the transaction. If no client is available null will be returned. + * + * @return Client|null */ public function getClient() { @@ -318,23 +437,22 @@ public function getClient() /** * Sets the Client for the transaction - * @param \Paymill\Models\Response\Client $client - * @return \Paymill\Models\Response\Transaction + * + * @param Client $client Client + * + * @return $this */ public function setClient($client) { $this->_client = $client; + return $this; } /** - * @var \Paymill\Models\Response\Preauthorization - */ - private $_preauthorization = null; - - /** - * Returns the Preauthorization associated with the transaction. If no preAuth is available null will be returned - * @return \Paymill\Models\Response\Preauthorization|null + * Returns the Preauthorization associated with the transaction. If no preAuth is available null will be returned. + * + * @return Preauthorization|null */ public function getPreauthorization() { @@ -342,21 +460,19 @@ public function getPreauthorization() } /** - * Sets the Preauthorization for the transaction - * @param \Paymill\Models\Response\Preauthorization $preauthorization - * @return \Paymill\Models\Response\Transaction + * Sets the Preauthorization for the transaction. + * + * @param Preauthorization $preauthorization Preauthorization + * + * @return $this */ public function setPreauthorization($preauthorization) { $this->_preauthorization = $preauthorization; + return $this; } - /** - * @var array - */ - private $_fees; - /** * Returns the fee array stored in the transaction * @return array @@ -369,39 +485,162 @@ public function getFees() /** * Sets the Fees array for the transaction - * @param array $fees - * @return \Paymill\Models\Response\Transaction + * + * @param array $fees Fees + * + * @return $this */ 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 + * Sets the name of origin of the call creating the transaction. + * + * @param string $source Source + * + * @return $this */ public function setSource($source) { $this->_source = $source; + return $this; } /** * Gets the name of origin of the call creating the transaction - * @return mixed + * + * @return string */ public function getSource() { return $this->_source; } + /** + * Get shipping address + * + * @return array|null + */ + public function getShippingAddress() + { + return $this->_shippingAddress; + } + + /** + * Set shipping address + * + * @param array|null $shippingAddress Shipping address + * + * @return $this + */ + public function setShippingAddress($shippingAddress) + { + $this->_shippingAddress = $shippingAddress; + + return $this; + } + + /** + * Get billing address + * + * @return array|null + */ + public function getBillingAddress() + { + return $this->_billingAddress; + } + + /** + * Set billing address + * + * @param array|null $billingAddress Billing address + * + * @return $this + */ + public function setBillingAddress($billingAddress) + { + $this->_billingAddress = $billingAddress; + + return $this; + } + + /** + * Get items + * + * @return array + */ + public function getItems() + { + return $this->_items; + } + + /** + * Set items + * + * @param array $items Items + * + * @return $this + */ + public function setItems($items) + { + $this->_items = $items; + + return $this; + } + + /** + * Get shipping amount + * + * @return int + */ + public function getShippingAmount() + { + return $this->_shipping_amount; + } + + /** + * Set shipping amount + * + * @param int $shipping_amount Shipping amount + * + * @return $this + */ + public function setShippingAmount($shipping_amount) + { + $this->_shipping_amount = $shipping_amount; + + return $this; + } + + /** + * Get handling amount + * + * @return int + */ + public function getHandlingAmount() + { + return $this->_handling_amount; + } + + /** + * Set handling amount + * + * @param int $handling_amount Handling amount + * + * @return $this + */ + public function setHandlingAmount($handling_amount) + { + $this->_handling_amount = $handling_amount; + + return $this; + } + /** Set mandate reference mandate_reference * @param string $mandateReference */ @@ -418,4 +657,4 @@ public function getMandateReference() { return $this->_mandateReference; } -} \ No newline at end of file +} diff --git a/lib/Paymill/Request.php b/lib/Paymill/Request.php index 0000384..8bf7c84 100644 --- a/lib/Paymill/Request.php +++ b/lib/Paymill/Request.php @@ -216,14 +216,19 @@ private function _request(Base $model, $method) if(!is_a($this->_connectionClass, '\Paymill\API\CommunicationAbstract')){ throw new PaymillException(null,'The connection class is missing!'); } + $convertedResponse = null; - $httpMethod = $this->_getHTTPMethod($method); + $httpMethod = $this->_getHTTPMethod($method); $parameter = $model->parameterize($method); $serviceResource = $model->getServiceResource() . $model->getId(); - if(is_a($model, "\Paymill\Models\Request\Transaction") && $method === "create"){ - $source = !array_key_exists('source',$parameter) ? "PhpLib" . $this->getVersion(): "PhpLib" . $this->getVersion() . "_" . $parameter['source']; + + if(is_a($model, '\Paymill\Models\Request\Transaction') && $method === "create") { + $source = !array_key_exists('source',$parameter) ? + "PhpLib" . $this->getVersion() : + "PhpLib" . $this->getVersion() . "_" . $parameter['source']; $parameter['source'] = $source; } + try { $this->_lastRequest = $parameter; $response = $this->_connectionClass->requestApi( @@ -231,24 +236,33 @@ private function _request(Base $model, $method) ); $this->_lastResponse = $response; $responseHandler = new ResponseHandler(); - if($method === "getAllAsModel" && $responseHandler->validateResponse($response) && $this->_util->isNumericArray($response['body']['data'])){ - foreach($response['body']['data'] as $object){ - $convertedResponse[] = $responseHandler->convertResponse($object, $model->getServiceResource()); - } - }elseif($method === "getAll" && $responseHandler->validateResponse($response)){ + if($method === "getAllAsModel" + && $responseHandler->validateResponse($response) + && $this->_util->isNumericArray($response['body']['data']) + ) { + foreach($response['body']['data'] as $object){ + $convertedResponse[] = $responseHandler->convertResponse($object, $model->getServiceResource()); + } + } elseif($method === "getAll" && $responseHandler->validateResponse($response)) { $convertedResponse = $response['body']['data']; - }elseif($responseHandler->validateResponse($response)){ - $convertedResponse = $responseHandler->convertResponse($response['body']['data'], $model->getServiceResource()); - }else{ - $convertedResponse = $responseHandler->convertErrorToModel($response, $model->getServiceResource()); - } - } catch (\Exception $e) { + } elseif($responseHandler->validateResponse($response)) { + $convertedResponse = $responseHandler->convertResponse( + $response['body']['data'], $model->getServiceResource() + ); + } else { + $convertedResponse = $responseHandler->convertErrorToModel($response, $model->getServiceResource()); + } + } catch (Exception $e) { $errorModel = new Error(); $convertedResponse = $errorModel->setErrorMessage($e->getMessage()); } + if (is_a($convertedResponse, '\Paymill\Models\Response\Error')) { throw new PaymillException( - $convertedResponse->getResponseCode(), $convertedResponse->getErrorMessage(), $convertedResponse->getHttpStatusCode(), $convertedResponse->getRawObject() + $convertedResponse->getResponseCode(), + $convertedResponse->getErrorMessage(), + $convertedResponse->getHttpStatusCode(), + $convertedResponse->getRawObject() ); } diff --git a/lib/Paymill/Services/ResponseHandler.php b/lib/Paymill/Services/ResponseHandler.php index acc8703..d77730e 100644 --- a/lib/Paymill/Services/ResponseHandler.php +++ b/lib/Paymill/Services/ResponseHandler.php @@ -3,6 +3,7 @@ namespace Paymill\Services; use Paymill\Models\Response as Models; +use Paymill\Models\Response\Checksum; use Paymill\Models\Response\Error; /** @@ -107,6 +108,9 @@ private function _convertResponseToModel($response, $resourceName) case 'fraud': $model = $this->_createFraud($response); break; + case 'checksum': + $model = $this->_createChecksum($response); + break; } return $model; @@ -329,6 +333,26 @@ private function _createFraud($response) return $model; } + /** + * Creates and fills a checksum model + * + * @param array $response + * @return Checksum + */ + private function _createChecksum($response) + { + $model = new Checksum(); + $model->setId($response['id']); + $model->setChecksum($response['checksum']); + $model->setData($response['data']); + $model->setType($response['type']); + $model->setAppId($response['app_id']); + $model->setCreatedAt($response['created_at']); + $model->setUpdatedAt($response['updated_at']); + + return $model; + } + /** * Handles the multidimensional param arrays during model creation * @param array $response @@ -376,7 +400,7 @@ public function convertErrorToModel($response, $resourceName = null) $errorModel->setRawObject($this->convertResponse($response['body']['data'], $resourceName)); } catch (\Exception $e) { } } - + if (isset($response['body'])) { if (is_array($response['body'])) { if (isset($response['body']['error'])) { @@ -396,25 +420,24 @@ public function convertErrorToModel($response, $resourceName = null) } /** - * Validates the data responsed by the API + * Validates the data responded by the API + * Just checks the header status is successful. * - * Only Refund, Transaction and Preauthorization return an response_code * @param array $response - * @return boolean + * + * @return boolean True if valid */ public function validateResponse($response) { $returnValue = false; - if ($response['header']['status'] == 200) { - if (isset($response['body']['data']['response_code'])) { - $returnValue = false; - if ($response['body']['data']['response_code'] == 20000) { - $returnValue = true; - } - } else { - $returnValue = true; - } + if (isset($response['header']) + && isset($response['header']['status']) + && $response['header']['status'] >= 200 + && $response['header']['status'] < 300 + ) { + $returnValue = true; } + return $returnValue; } @@ -436,7 +459,7 @@ private function getErrorMessageFromArray($errorArray) */ public function arrayToObject($array) { - return is_array($array) ? (object) array_map(array($this, 'arrayToObject'), $array) : $array; + return is_array($array) ? (object) array_map([$this, 'arrayToObject'], $array) : $array; } } diff --git a/samples/checksums/create.php b/samples/checksums/create.php new file mode 100644 index 0000000..65fccfe --- /dev/null +++ b/samples/checksums/create.php @@ -0,0 +1,54 @@ +$checksum = new Paymill\Models\Request\Checksum(); +$checksum + ->setChecksumType(\Paymill\Models\Request\Checksum::TYPE_PAYPAL) // Checksum type + ->setAmount(4200) // e.g. "4200" for 42.00 EUR + ->setCurrency('EUR') // Alpha-3 country code + ->setDescription('My transaction description') // Optional + ->setShippingAddress([ // Optional - Shipping address + 'name' => 'John Doe', + 'street_address' => 'Example street 1', + 'street_address_addition' => '45 floor', // Optional + 'postal_code' => '12345', // Optional + 'city' => 'Munich', + 'state' => 'Bavaria', // Optional + 'country' => 'DE', // Alpha-2 country code + 'phone' => '0123 456789' // Optional + ]) + ->setBillingAddress([ // Optional - Billing address + 'name' => 'John Doe', + 'street_address' => 'Example street 1', + 'street_address_addition' => '45 floor', // Optional + 'postal_code' => '12345', // Optional + 'city' => 'Munich', + 'state' => 'Bavaria', // Optional + 'country' => 'DE', // Alpha-2 country code + 'phone' => '0123 456789' // Optional + ]) + ->setItems([ // Optional - Shopping cart items + [ + 'name' => 'Product orange', // Optional + 'description' => 'An orange product', // Optional + 'item_number' => 'PROD1OR', // Optional + 'url' => 'http://www.example.com/orange-product', // Optional + 'amount' => 50, // Price of a single product in cent, e.g. "50" for 0,50 € + 'quantity' => 2 + ], + [ + 'name' => 'Product blue', // Optional + 'description' => 'A blue product', // Optional + 'item_number' => 'PROD3BL', // Optional + 'url' => 'http://www.example.com/blue-product', // Optional + 'amount' => 70, // Price of a single product in cent, e.g. "50" for 0,50 € + 'quantity' => 1 + ] + ]) + ->setShippingAmount(300) // Optional - Shipping costs in cent, e.g. "50" for 0,50 € + ->setHandlingAmount(250) // Optional - Other handling costs in cent, e.g. "50" for 0,50 € + ->setReturnUrl('http://www.example.com/checkout/success') // Required for e.g. PayPal - Valid return URL + ->setCancelUrl('http://www.example.com/checkout/canceled') // Required for e.g. PayPal - Valid cancel URL + ->setFeeAmount(420) // Optional - Unite fees in cent, e.g. "50" for 0,50 € + ->setFeeCurrency('EUR') // Optional - Unite fee currency + ->setFeePayment('pay_3af44644dd6d25c820a8') // Optional - Unite payment ID +; + +$response = $request->create($checksum); diff --git a/samples/checksums/get_by_id.php b/samples/checksums/get_by_id.php new file mode 100644 index 0000000..a6dbd87 --- /dev/null +++ b/samples/checksums/get_by_id.php @@ -0,0 +1,4 @@ +$checksum = new Paymill\Models\Request\Checksum(); +$checksum->setId('chk_9db8a1793e084a896da4289bf050'); + +$response = $request->getOne($checksum); diff --git a/samples/checksums/list.php b/samples/checksums/list.php new file mode 100644 index 0000000..45c7927 --- /dev/null +++ b/samples/checksums/list.php @@ -0,0 +1,3 @@ +$checksums = new Paymill\Models\Request\Checksum(); + +$response = $request->getAll($checksums); diff --git a/samples/refunds/get_refund_details.php b/samples/refunds/get_refund_details.php index f8ac807..be9b354 100644 --- a/samples/refunds/get_refund_details.php +++ b/samples/refunds/get_refund_details.php @@ -1,4 +1,4 @@ $refund = new Paymill\Models\Request\Refund(); -$refund->setId('refund_87bc404a95d5ce616049'); +$refund->setId('refund_773ab6f9cd03428953c9'); $response = $request->getOne($refund); diff --git a/tests/integration/ChecksumTest.php b/tests/integration/ChecksumTest.php index 297ebeb..b37ff12 100644 --- a/tests/integration/ChecksumTest.php +++ b/tests/integration/ChecksumTest.php @@ -4,6 +4,7 @@ use Paymill\API\Curl; use Paymill\Models as Models; +use Paymill\Models\Request\Checksum; use Paymill\Request; use PHPUnit_Framework_TestCase; @@ -13,12 +14,12 @@ class ChecksumTest extends PHPUnit_Framework_TestCase { /** - * @var \Paymill\Services\Request + * @var Request */ private $_service; /** - * @var \Paymill\Models\Request\Checksum + * @var Checksum */ private $_model; @@ -29,14 +30,14 @@ protected function setUp() { $this->_service = new Request(); $this->_service->setConnectionClass( - new Curl(API_TEST_KEY, API_HOST, array(CURLOPT_SSL_VERIFYPEER => SSL_VERIFY_PEER)) + new Curl(API_TEST_KEY, API_HOST, [CURLOPT_SSL_VERIFYPEER => SSL_VERIFY_PEER]) ); - $this->_model = new Models\Request\Checksum(); - $this->_model->setChecksumType('postfinance_card'); + $this->_model = new Checksum(); + $this->_model->setChecksumType(Checksum::TYPE_PAYPAL); $this->_model->setAmount('200'); - $this->_model->setCurrency('CHF'); - $this->_model->setDescription('dummy description'); + $this->_model->setCurrency('EUR'); + $this->_model->setDescription('Dummy description'); parent::setUp(); } @@ -59,6 +60,7 @@ public function createChecksum() { $result = $this->_service->getOne($this->_model); $this->assertInstanceOf('Paymill\Models\Response\Checksum', $result, var_export($result, true)); - return $result; + + return $result; } } diff --git a/tests/unit/Paymill/Models/Request/ChecksumTest.php b/tests/unit/Paymill/Models/Request/ChecksumTest.php index 928b214..2745153 100755 --- a/tests/unit/Paymill/Models/Request/ChecksumTest.php +++ b/tests/unit/Paymill/Models/Request/ChecksumTest.php @@ -2,7 +2,8 @@ namespace Paymill\Test\Unit\Models\Request; -use Paymill\Models\Request as Request; +use Paymill\Models\Request; +use Paymill\Models\Request\Checksum; use PHPUnit_Framework_TestCase; /** @@ -12,7 +13,7 @@ class ChecksumTest extends PHPUnit_Framework_TestCase { /** - * @var Request\Checksum + * @var Checksum */ private $_model; @@ -22,7 +23,7 @@ class ChecksumTest extends PHPUnit_Framework_TestCase protected function setUp() { parent::setUp(); - $this->_model = new Request\Checksum(); + $this->_model = new Checksum(); } /** @@ -34,7 +35,6 @@ protected function tearDown() parent::tearDown(); } - //Testmethods /** * Tests the getters and setters of the model * @test @@ -42,42 +42,164 @@ protected function tearDown() public function setGetTest() { $sample = array( - 'checksum_type' => 'postfinance_card', + 'checksum_type' => Checksum::TYPE_PAYPAL, 'amount' => '200', - 'currency' => 'CHF', - 'description' => 'foo bar' + 'currency' => 'EUR', + 'description' => 'foo bar', + 'return_url' => 'https://www.example.com', + 'cancel_url' => 'https://www.example.com', + 'shipping_address' => array( + 'name' => 'Noch ein test', + 'street_address' => 'Unit street', + 'street_address_additional' => 'uff', + 'city' => 'Test city', + 'postal_code' => 'BLABLA', + 'state' => 'BAVARIA', + 'country' => 'DE', + 'phone' => '0892353453' + ), + 'billing_address' => array( + 'name' => 'Noch ein test', + 'street_address' => 'Unit street', + 'street_address_additional' => 'uff', + 'city' => 'Test city', + 'postal_code' => 'BLABLA', + 'state' => 'BAVARIA', + 'country' => 'DE', + 'phone' => '0892353453' + ), + 'items' => array( + array( + 'name' => 'Foo', + 'description' => 'Bar', + 'item_number' => 'PROD1', + 'url' => 'http://www.foo.de', + 'amount' => '200', + 'quantity' => 1 + ), + array( + 'name' => 'Foo', + 'description' => 'bock auf testing', + 'item_number' => 'PROD2', + 'url' => 'http://www.bar.de', + 'amount' => '200', + 'quantity' => 1 + ) + ), + 'shipping_amount' => '50', + 'handling_amount' => '50' ); $this->_model ->setChecksumType($sample['checksum_type']) ->setAmount($sample['amount']) ->setCurrency($sample['currency']) - ->setDescription($sample['description']); + ->setDescription($sample['description']) + ->setReturnUrl($sample['return_url']) + ->setCancelUrl($sample['cancel_url']) + ->setShippingAddress($sample['shipping_address']) + ->setBillingAddress($sample['billing_address']) + ->setItems($sample['items']) + ->setShippingAmount($sample['shipping_amount']) + ->setHandlingAmount($sample['handling_amount']) + ; $this->assertEquals($this->_model->getChecksumType(), $sample['checksum_type']); $this->assertEquals($this->_model->getAmount(), $sample['amount']); $this->assertEquals($this->_model->getCurrency(), $sample['currency']); $this->assertEquals($this->_model->getDescription(), $sample['description']); + $this->assertEquals($this->_model->getReturnUrl(), $sample['return_url']); + $this->assertEquals($this->_model->getCancelUrl(), $sample['cancel_url']); + $this->assertEquals($this->_model->getShippingAddress(), $sample['shipping_address']); + $this->assertEquals($this->_model->getBillingAddress(), $sample['billing_address']); + $this->assertEquals($this->_model->getItems(), $sample['items']); + $this->assertEquals($this->_model->getShippingAmount(), $sample['shipping_amount']); + $this->assertEquals($this->_model->getHandlingAmount(), $sample['handling_amount']); return $this->_model; } /** * Test the Parameterize function of the model + * + * @param Checksum $model + * * @test * @depends setGetTest */ - public function parameterizeTest(Request\Checksum $model) + public function parameterizeTestGetOne(Checksum $model) + { + $model->setId('chk_123'); + $parameterArray = array( + 'count' => 1, + 'offset' => 0 + ); + + $creationArray = $model->parameterize("getOne"); + + $this->assertEquals($creationArray, $parameterArray); + } + + /** + * Test the Parameterize function of the model + * + * @param Checksum $model + * + * @test + * @depends setGetTest + */ + public function parameterizeTestCreate(Checksum $model) { $parameterArray = array(); - $parameterArray['checksum_type'] = 'postfinance_card'; + $parameterArray['checksum_type'] = Checksum::TYPE_PAYPAL; $parameterArray['amount'] = '200'; - $parameterArray['currency'] = 'CHF'; + $parameterArray['currency'] = 'EUR'; $parameterArray['description'] = 'foo bar'; + $parameterArray['return_url'] = 'https://www.example.com'; + $parameterArray['cancel_url'] = 'https://www.example.com'; + $parameterArray['shipping_address'] = array( + 'name' => 'Noch ein test', + 'street_address' => 'Unit street', + 'street_address_additional' => 'uff', + 'city' => 'Test city', + 'postal_code' => 'BLABLA', + 'state' => 'BAVARIA', + 'country' => 'DE', + 'phone' => '0892353453' + ); + $parameterArray['billing_address'] = array( + 'name' => 'Noch ein test', + 'street_address' => 'Unit street', + 'street_address_additional' => 'uff', + 'city' => 'Test city', + 'postal_code' => 'BLABLA', + 'state' => 'BAVARIA', + 'country' => 'DE', + 'phone' => '0892353453' + ); + $parameterArray['items'] = array( + array( + 'name' => 'Foo', + 'description' => 'Bar', + 'item_number' => 'PROD1', + 'url' => 'http://www.foo.de', + 'amount' => '200', + 'quantity' => 1 + ), + array( + 'name' => 'Foo', + 'description' => 'bock auf testing', + 'item_number' => 'PROD2', + 'url' => 'http://www.bar.de', + 'amount' => '200', + 'quantity' => 1 + ) + ); + $parameterArray['shipping_amount'] = '50'; + $parameterArray['handling_amount'] = '50'; - $creationArray = $model->parameterize("getOne"); + $creationArray = $model->parameterize("create"); $this->assertEquals($creationArray, $parameterArray); } - } diff --git a/tests/unit/Paymill/Models/Request/TransactionTest.php b/tests/unit/Paymill/Models/Request/TransactionTest.php index aa1209a..7ff26ef 100755 --- a/tests/unit/Paymill/Models/Request/TransactionTest.php +++ b/tests/unit/Paymill/Models/Request/TransactionTest.php @@ -3,6 +3,7 @@ namespace Paymill\Test\Unit\Models\Request; use Paymill\Models\Request as Request; +use Paymill\Models\Request\Transaction; use PHPUnit_Framework_TestCase; /** @@ -10,9 +11,8 @@ */ class TransactionTest extends PHPUnit_Framework_TestCase { - /** - * @var Request\Transaction + * @var Transaction */ private $_transaction; @@ -22,7 +22,7 @@ class TransactionTest extends PHPUnit_Framework_TestCase protected function setUp() { parent::setUp(); - $this->_transaction = new Request\Transaction(); + $this->_transaction = new Transaction(); } /** @@ -34,27 +34,13 @@ protected function tearDown() parent::tearDown(); } - //Testmethods /** * Tests the getters and setters of the model * @test */ public function setGetTest() { - $sample = array( - 'amount' => '4200', // e.g. "4200" for 42.00 EUR - 'currency' => 'EUR', // ISO 4217 - 'payment' => 'pay_2f82a672574647cd911d', - 'token' => '098f6bcd4621d373cade4e832627b4f6', - 'client' => 'client_c781b1d2f7f0f664b4d9', - 'preauthorization' => 'preauth_ec54f67e52e92051bd65', - 'fee_amount' => '420', // e.g. "420" for 4.20 EUR - 'fee_payment' => 'pay_098f6bcd4621d373cade4e832627b4f6', - 'fee_currency' => 'EUR', - 'description' => 'Test Transaction', - 'source' => 'merchantcenter', - 'mandate_reference' =>'DE1234TEST' - ); + $sample = $this->getSampleData(); $this->_transaction ->setAmount($sample['amount']) @@ -68,10 +54,10 @@ public function setGetTest() ->setFeeCurrency($sample['fee_currency']) ->setDescription($sample['description']) ->setSource($sample['source']) + ->setShippingAddress($sample['shipping_address']) + ->setBillingAddress($sample['billing_address']) ->setMandateReference($sample['mandate_reference']); - - $this->assertEquals($this->_transaction->getAmount(), $sample['amount']); $this->assertEquals($this->_transaction->getCurrency(), $sample['currency']); $this->assertEquals($this->_transaction->getPayment(), $sample['payment']); @@ -83,46 +69,103 @@ public function setGetTest() $this->assertEquals($this->_transaction->getFeeCurrency(), $sample['fee_currency']); $this->assertEquals($this->_transaction->getDescription(), $sample['description']); $this->assertEquals($this->_transaction->getSource(), $sample['source']); + $this->assertEquals($this->_transaction->getShippingAddress(), $sample['shipping_address']); + $this->assertEquals($this->_transaction->getBillingAddress(), $sample['billing_address']); $this->assertEquals($this->_transaction->getMandateReference(), $sample['mandate_reference']); - return $this->_transaction; } /** * Test the Parameterize function of the model + * + * @param Transaction $transaction + * * @test * @depends setGetTest */ - public function parameterizeTest($transaction) + public function parameterizeTest(Transaction $transaction) { + $sample = $this->getSampleData(); $testId = "transaction_88a388d9dd48f86c3136"; $transaction->setId($testId); $creationArray = $transaction->parameterize("create"); - $updateArray = $transaction->parameterize("update"); - $getOneArray = $transaction->parameterize("getOne"); - - $this->assertEquals($creationArray, array( - 'amount' => '4200', // e.g. "4200" for 42.00 EUR - 'currency' => 'EUR', // ISO 4217 - 'client' => 'client_c781b1d2f7f0f664b4d9', - 'preauthorization' => 'preauth_ec54f67e52e92051bd65', - 'fee_amount' => '420', // e.g. "420" for 4.20 EUR - 'fee_payment' => 'pay_098f6bcd4621d373cade4e832627b4f6', - 'fee_currency' => 'EUR', - 'description' => 'Test Transaction', - 'source' => 'merchantcenter', - 'mandate_reference' => 'DE1234TEST' - )); - $this->assertEquals($updateArray, array( + $updateArray = $transaction->parameterize("update"); + $getOneArray = $transaction->parameterize("getOne"); + + $this->assertEquals([ + 'amount' => $sample['amount'], // e.g. "4200" for 42.00 EUR + 'currency' => $sample['currency'], // ISO 4217 + 'client' => $sample['client'], + 'preauthorization' => $sample['preauthorization'], + 'fee_amount' => $sample['fee_amount'], // e.g. "420" for 4.20 EUR + 'fee_payment' => $sample['fee_payment'], + 'fee_currency' => $sample['fee_currency'], + 'description' => $sample['description'], + 'source' => $sample['source'], + 'mandate_reference' => $sample['mandate_reference'], + 'shipping_address' => $sample['shipping_address'], + 'billing_address' => $sample['billing_address'] + ], $creationArray); + + $this->assertEquals([ 'description' => 'Test Transaction' - )); - $this->assertEquals($getOneArray, array( + ], $updateArray); + + $this->assertEquals([ 'count' => 1, 'offset' => 0 - ) + ], $getOneArray ); } -} \ No newline at end of file + /** + * Returns array of sample data + * + * @return array + */ + private function getSampleData() + { + $shippingAddress = array( + 'name' => 'Sam Shippy', + 'street_address' => 'St. Cajetanstr. 43', + 'street_address_addition' => '5. OG', + 'postal_code' => '814669', + 'city' => 'München', + 'state' => 'Bayern', + 'country' => 'DE', + 'phone' => '+49 89 189 045 300' + ); + + $billingAddress = array( + 'name' => 'Biff Billy', + 'street_address' => 'St. Cajetanstr. 43', + 'street_address_addition' => '5. OG', + 'postal_code' => '814669', + 'city' => 'München', + 'state' => 'Bayern', + 'country' => 'DE', + 'phone' => '+49 89 189 045 300' + ); + + $sample = array( + 'amount' => '4200', // e.g. "4200" for 42.00 EUR + 'currency' => 'EUR', // ISO 4217 + 'payment' => 'pay_2f82a672574647cd911d', + 'token' => '098f6bcd4621d373cade4e832627b4f6', + 'client' => 'client_c781b1d2f7f0f664b4d9', + 'preauthorization' => 'preauth_ec54f67e52e92051bd65', + 'fee_amount' => '420', // e.g. "420" for 4.20 EUR + 'fee_payment' => 'pay_098f6bcd4621d373cade4e832627b4f6', + 'fee_currency' => 'EUR', + 'description' => 'Test Transaction', + 'source' => 'merchantcenter', + 'mandate_reference' =>'DE1234TEST', + 'shipping_address' => $shippingAddress, + 'billing_address' => $billingAddress + ); + + return $sample; + } +} diff --git a/tests/unit/Paymill/Models/Response/ChecksumTest.php b/tests/unit/Paymill/Models/Response/ChecksumTest.php index d9afe21..65e6f14 100755 --- a/tests/unit/Paymill/Models/Response/ChecksumTest.php +++ b/tests/unit/Paymill/Models/Response/ChecksumTest.php @@ -35,17 +35,34 @@ protected function tearDown() parent::tearDown(); } - //Testmethods /** * Tests the getters and setters of the model * @test */ public function setGetTest() { - $this->_model->setLivemode('live')->setChecksum('foobar'); + $this->_model->setData('test=foo&foo[bar1]=test1&foo[bar2]=test2'); + $this->_model->setType('creditcard'); + $this->_model->setChecksum('foo-checksum'); + $this->_model->setAppId('app_123'); + $this->_model->setId('chk_123'); + $this->_model->setCreatedAt(23423142314); + $this->_model->setUpdatedAt(23423142314); - $this->assertEquals($this->_model->getLivemode(), 'live'); - $this->assertEquals($this->_model->getChecksum(), 'foobar'); + $this->assertEquals($this->_model->getData(), 'test=foo&foo[bar1]=test1&foo[bar2]=test2'); + $this->assertEquals($this->_model->getDataAsArray(), array( + 'test' => 'foo', + 'foo' => array( + 'bar1' => 'test1', + 'bar2' => 'test2' + ) + )); + $this->assertEquals($this->_model->getType(), 'creditcard'); + $this->assertEquals($this->_model->getChecksum(), 'foo-checksum'); + $this->assertEquals($this->_model->getAppId(), 'app_123'); + $this->assertEquals($this->_model->getId(), 'chk_123'); + $this->assertEquals($this->_model->getCreatedAt(), 23423142314); + $this->assertEquals($this->_model->getUpdatedAt(), 23423142314); } } diff --git a/tests/unit/Paymill/Services/ResponseHandlerTest.php b/tests/unit/Paymill/Services/ResponseHandlerTest.php index 770b146..30e1ab0 100644 --- a/tests/unit/Paymill/Services/ResponseHandlerTest.php +++ b/tests/unit/Paymill/Services/ResponseHandlerTest.php @@ -80,7 +80,7 @@ protected function tearDown() * Tests the convertResponseModel method with the client model as outcome * @test */ - public function clientTest() + public function testClientTest() { $response = array( "id" => "client_88a388d9dd48f86c3136", @@ -113,7 +113,7 @@ public function clientTest() * Tests the convertResponseModel method with the client model as outcome using a client with multiple payment objects * @test */ - public function clientMultiPaymentTest() + public function testClientMultiPaymentTest() { $response = array( 'id' => "client_018dcaf0d8d03dde3ff6", @@ -163,7 +163,7 @@ public function clientMultiPaymentTest() * Tests the convertResponseModel method with the payment model as outcome * @test */ - public function paymentCCTest() + public function testPaymentCCTest() { $response= array( "id" => "pay_3af44644dd6d25c820a8", @@ -187,7 +187,7 @@ public function paymentCCTest() * Tests the convertResponseModel method with the payment model as outcome * @test */ - public function paymentSEPATest() + public function testPaymentSEPA() { $response = array( "id" => "pay_3af44644dd6d25c820a8", @@ -212,7 +212,7 @@ public function paymentSEPATest() * Tests the convertResponseModel method with the transaction model as outcome * @test */ - public function transactionTest() + public function testTransaction() { $response = array( "id" => "tran_54645bcb98ba7acfe204", @@ -276,7 +276,7 @@ public function transactionTest() * Tests the convertResponseModel method with the preauthorization model as outcome * @test */ - public function preauthorizationTest() + public function testPreauthorization() { $response = array( "id" => "tran_54645bcb98ba7acfe204", @@ -387,7 +387,7 @@ public function preauthorizationTest() * Tests the convertResponseModel method with the refund model as outcome * @test */ - public function refundTest() + public function testRefund() { $response = array( "id" => "refund_87bc404a95d5ce616049", @@ -462,7 +462,7 @@ public function refundTest() * Tests the convertResponseModel method with the offer model as outcome * @test */ - public function offerTest() + public function testOfferTest() { $response = array( "id" => "offer_40237e20a7d5a231d99b", @@ -487,7 +487,7 @@ public function offerTest() * Tests the convertResponseModel method with the subscription model as outcome * @test */ - public function subscriptionTest() + public function testSubscriptionTest() { $response = array( 'id' => 'sub_012db05186ccfe22d86c', @@ -564,7 +564,7 @@ public function subscriptionTest() * Tests the convertResponseModel method with the url version of the Webhook model as outcome * @test */ - public function urlWebhookTest() + public function testUrlWebhookTest() { $response = array( "id" => "hook_40237e20a7d5a231d99b", @@ -588,7 +588,7 @@ public function urlWebhookTest() * Tests the convertResponseModel method with the email version of the Webhook model as outcome * @test */ - public function emailWebhookTest() + public function testEmailWebhook() { $response = array( "id" => "hook_40237e20a7d5a231d99b", @@ -609,6 +609,22 @@ public function emailWebhookTest() $this->assertInstanceOf("\Paymill\Models\Response\Webhook", $subject, var_export($subject, true)); } + public function testValidateResponseIssetFalse() + { + $this->assertFalse($this->_responseHandler->validateResponse(array())); + } + + public function testValidateResponseStatusFalse() + { + $this->assertFalse($this->_responseHandler->validateResponse(array('header' => array('status' => 404)))); + } + + public function testValidateResponseStatusTrue() + { + $this->assertTrue($this->_responseHandler->validateResponse(array('header' => array('status' => 200)))); + } + + /** * Tests the handling of ResponseCodes * @test @@ -657,5 +673,4 @@ public function ProveConversionToArray(){ $this->assertInstanceOf('stdClass', $responseObject); $this->assertEquals($response['body']['data']['id'], $responseObject->data->id); } - -} \ No newline at end of file +} From 670665081293808c5c448a3d959451813c699b82 Mon Sep 17 00:00:00 2001 From: tschela Date: Tue, 9 Jun 2015 14:10:25 +0200 Subject: [PATCH 2/4] Update checksum models --- lib/Paymill/Services/ResponseHandler.php | 79 ++++++++++++++++--- samples/checksums/create.php | 20 ++--- .../Models/Request/TransactionTest.php | 8 +- 3 files changed, 83 insertions(+), 24 deletions(-) diff --git a/lib/Paymill/Services/ResponseHandler.php b/lib/Paymill/Services/ResponseHandler.php index d77730e..00b5c01 100644 --- a/lib/Paymill/Services/ResponseHandler.php +++ b/lib/Paymill/Services/ResponseHandler.php @@ -11,11 +11,40 @@ */ class ResponseHandler { - + /** + * Possible response codes + * + * @var array + */ private $_errorCodes = array( 10001 => "General undefined response.", 10002 => "Still waiting on something.", + 11000 => "Retry later", + 20000 => "General success response.", + 20100 => "", + 20101 => "Funds held by acquirer because merchant is new.", + 20200 => "Transaction reversed.", + 20201 => "Reversed due to chargeback.", + 20202 => "Reversed due to money-back guarantee.", + 20203 => "Reversed due to complaint by buyer.", + 20204 => "Payment has been refunded.", + 20300 => "Reversal has been canceled.", + + 30000 => "Transaction still in progress.", + 30100 => "Transaction has been accepted.", + 31000 => "Transaction pending.", + 31100 => "Pending due to address.", + 31101 => "Pending due to uncleared eCheck.", + 31102 => "Pending due to risk review.", + 31103 => "Pending due regulatory review.", + 31104 => "Pending due to unregistered/unconfirmed receiver.", + 31200 => "Pending due to unverified account, verify acquirer account.", + 31201 => "Pending due to uncaptured funds, capture funds first.", + 31202 => "Pending due to international account, accept manually.", + 31203 => "Pending due to currency conflict, accept manually.", + 31204 => "Pending due to fraud filters.", + 40000 => "General problem with data.", 40001 => "General problem with payment data.", 40100 => "Problem with credit card data.", @@ -34,8 +63,17 @@ class ResponseHandler 40401 => "Amount too low or zero.", 40402 => "Usage field too long.", 40403 => "Currency not allowed.", + 40410 => "Invalid shopping cart data.", + 40420 => "Invalid address data.", + 40500 => "Permission error.", + 40510 => "Rate limit.", + 50000 => "General problem with backend.", 50001 => "Country blacklisted.", + 50002 => "IP-Address blacklisted", + 50003 => "Anonymous IP proxy used", + 50004 => "Live mode not allowed.", + 50005 => "Insufficient permissions (paymill accesskey).", 50100 => "Technical error with credit card.", 50101 => "Error limit exceeded.", 50102 => "Card declined by authorization system.", @@ -46,10 +84,31 @@ class ResponseHandler 50201 => "Card blacklisted.", 50300 => "Technical error with 3D secure.", 50400 => "Decline because of risk issues.", + 50401 => "Checksum invalid.", + 50402 => "Bank account number invalid (format check).", + 50403 => "Technical risk error.", + 50404 => "Unknown risk error.", + 50405 => "Invalid bank code.", + 50406 => "Open chargeback.", + 50407 => "Historic chargeback.", + 50408 => "Institution/Government bank account (NCA).", + 50409 => "Fraud case.", + 50410 => "Personal Account Protection (PAP).", + 50420 => "Rejected due to fraud settings.", + 50430 => "Rejected due to risk settings.", + 50440 => "Merchant account restriction.", 50500 => "General timeout.", 50501 => "Timeout on side of the acquirer.", 50502 => "Risk management transaction timeout.", 50600 => "Duplicate transaction.", + 50700 => "Transaction canceled by user.", + 50710 => "Failed due to funding source.", + 50711 => "Cannot pay with PayPal.", + 50720 => "Declined by acquirer.", + 50730 => "Transaction denied by merchant.", + 50800 => "capture preauthorization failed.", + 50810 => "Authorization has been voided.", + 50820 => "Authorization period expired." ); /** @@ -117,7 +176,7 @@ private function _convertResponseToModel($response, $resourceName) } /** - * Creates and fills a clientmodel + * Creates and fills a client model * * @param array $response * @return \Paymill\Models\Response\Client @@ -137,7 +196,7 @@ private function _createClient($response) } /** - * Creates and fills a paymentmodel + * Creates and fills a payment model * * @param array $response * @return \Paymill\Models\Response\Payment @@ -169,7 +228,7 @@ private function _createPayment($response) } /** - * Creates and fills a transactionmodel + * Creates and fills a transaction model * * @param array $response * @return \Paymill\Models\Response\Transaction @@ -199,7 +258,7 @@ private function _createTransaction($response) } /** - * Creates and fills a preauthorizationmodel + * Creates and fills a preauthorization model * * @param array $response * @return \Paymill\Models\Response\Preauthorization @@ -223,7 +282,7 @@ private function _createPreauthorization($response) } /** - * Creates and fills a refundmodel + * Creates and fills a refund model * * @param array $response * @return \Paymill\Models\Response\Refund @@ -246,7 +305,7 @@ private function _createRefund($response) } /** - * Creates and fills a offermodel + * Creates and fills a offer model * * @param array $response * @return \Paymill\Models\Response\Offer @@ -268,7 +327,7 @@ private function _createOffer($response) } /** - * Creates and fills a subscriptionmodel + * Creates and fills a subscription model * * @param array $response * @return \Paymill\Models\Response\Subscription @@ -297,7 +356,7 @@ private function _createSubscription($response) } /** - * Creates and fills a webhookmodel + * Creates and fills a webhook model * * @param array $response * @return \Paymill\Models\Response\Webhook @@ -317,7 +376,7 @@ private function _createWebhook($response) } /** - * Creates and fills a fraudmodel + * Creates and fills a fraud model * * @param array $response * @return \Paymill\Models\Response\Fraud diff --git a/samples/checksums/create.php b/samples/checksums/create.php index 65fccfe..b9e6266 100644 --- a/samples/checksums/create.php +++ b/samples/checksums/create.php @@ -4,7 +4,7 @@ ->setAmount(4200) // e.g. "4200" for 42.00 EUR ->setCurrency('EUR') // Alpha-3 country code ->setDescription('My transaction description') // Optional - ->setShippingAddress([ // Optional - Shipping address + ->setShippingAddress(array( // Optional - Shipping address 'name' => 'John Doe', 'street_address' => 'Example street 1', 'street_address_addition' => '45 floor', // Optional @@ -13,8 +13,8 @@ 'state' => 'Bavaria', // Optional 'country' => 'DE', // Alpha-2 country code 'phone' => '0123 456789' // Optional - ]) - ->setBillingAddress([ // Optional - Billing address + )) + ->setBillingAddress(array( // Optional - Billing address 'name' => 'John Doe', 'street_address' => 'Example street 1', 'street_address_addition' => '45 floor', // Optional @@ -23,25 +23,25 @@ 'state' => 'Bavaria', // Optional 'country' => 'DE', // Alpha-2 country code 'phone' => '0123 456789' // Optional - ]) - ->setItems([ // Optional - Shopping cart items - [ + )) + ->setItems(array( // Optional - Shopping cart items + array( 'name' => 'Product orange', // Optional 'description' => 'An orange product', // Optional 'item_number' => 'PROD1OR', // Optional 'url' => 'http://www.example.com/orange-product', // Optional 'amount' => 50, // Price of a single product in cent, e.g. "50" for 0,50 € 'quantity' => 2 - ], - [ + ), + array( 'name' => 'Product blue', // Optional 'description' => 'A blue product', // Optional 'item_number' => 'PROD3BL', // Optional 'url' => 'http://www.example.com/blue-product', // Optional 'amount' => 70, // Price of a single product in cent, e.g. "50" for 0,50 € 'quantity' => 1 - ] - ]) + ) + )) ->setShippingAmount(300) // Optional - Shipping costs in cent, e.g. "50" for 0,50 € ->setHandlingAmount(250) // Optional - Other handling costs in cent, e.g. "50" for 0,50 € ->setReturnUrl('http://www.example.com/checkout/success') // Required for e.g. PayPal - Valid return URL diff --git a/tests/unit/Paymill/Models/Request/TransactionTest.php b/tests/unit/Paymill/Models/Request/TransactionTest.php index 7ff26ef..2ace4b3 100755 --- a/tests/unit/Paymill/Models/Request/TransactionTest.php +++ b/tests/unit/Paymill/Models/Request/TransactionTest.php @@ -109,14 +109,14 @@ public function parameterizeTest(Transaction $transaction) 'billing_address' => $sample['billing_address'] ], $creationArray); - $this->assertEquals([ + $this->assertEquals(array( 'description' => 'Test Transaction' - ], $updateArray); + ), $updateArray); - $this->assertEquals([ + $this->assertEquals(array( 'count' => 1, 'offset' => 0 - ], $getOneArray + ), $getOneArray ); } From a6586392af945a0f40df20504a1fd41f8f6f74f4 Mon Sep 17 00:00:00 2001 From: tschela Date: Tue, 9 Jun 2015 14:10:25 +0200 Subject: [PATCH 3/4] Update checksum models --- lib/Paymill/Services/ResponseHandler.php | 2 +- tests/integration/ChecksumTest.php | 2 +- tests/unit/Paymill/Models/Request/TransactionTest.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Paymill/Services/ResponseHandler.php b/lib/Paymill/Services/ResponseHandler.php index 00b5c01..b1b00de 100644 --- a/lib/Paymill/Services/ResponseHandler.php +++ b/lib/Paymill/Services/ResponseHandler.php @@ -518,7 +518,7 @@ private function getErrorMessageFromArray($errorArray) */ public function arrayToObject($array) { - return is_array($array) ? (object) array_map([$this, 'arrayToObject'], $array) : $array; + return is_array($array) ? (object) array_map(array($this, 'arrayToObject'), $array) : $array; } } diff --git a/tests/integration/ChecksumTest.php b/tests/integration/ChecksumTest.php index b37ff12..0ad8c0b 100644 --- a/tests/integration/ChecksumTest.php +++ b/tests/integration/ChecksumTest.php @@ -30,7 +30,7 @@ protected function setUp() { $this->_service = new Request(); $this->_service->setConnectionClass( - new Curl(API_TEST_KEY, API_HOST, [CURLOPT_SSL_VERIFYPEER => SSL_VERIFY_PEER]) + new Curl(API_TEST_KEY, API_HOST, array(CURLOPT_SSL_VERIFYPEER => SSL_VERIFY_PEER)) ); $this->_model = new Checksum(); diff --git a/tests/unit/Paymill/Models/Request/TransactionTest.php b/tests/unit/Paymill/Models/Request/TransactionTest.php index 2ace4b3..8a4d5f2 100755 --- a/tests/unit/Paymill/Models/Request/TransactionTest.php +++ b/tests/unit/Paymill/Models/Request/TransactionTest.php @@ -94,7 +94,7 @@ public function parameterizeTest(Transaction $transaction) $updateArray = $transaction->parameterize("update"); $getOneArray = $transaction->parameterize("getOne"); - $this->assertEquals([ + $this->assertEquals(array( 'amount' => $sample['amount'], // e.g. "4200" for 42.00 EUR 'currency' => $sample['currency'], // ISO 4217 'client' => $sample['client'], @@ -107,7 +107,7 @@ public function parameterizeTest(Transaction $transaction) 'mandate_reference' => $sample['mandate_reference'], 'shipping_address' => $sample['shipping_address'], 'billing_address' => $sample['billing_address'] - ], $creationArray); + ), $creationArray); $this->assertEquals(array( 'description' => 'Test Transaction' From fd06d05e31cc245f1ea0feede5d2852f16f32ed4 Mon Sep 17 00:00:00 2001 From: Christian Kolb Date: Mon, 15 Jun 2015 09:23:42 +0200 Subject: [PATCH 4/4] Update Changelog and version --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index f755036..da2f7f8 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,13 @@ Changelog - bugfix: [#92](https://github.com/paymill/paymill-php/pull/92) remove typecheck for http response code +#### 4.0.0 + +- Added shipping and billing address +- Added shopping cart (items) +- Added PayPal functionality +- Possible [BC break in ResponseHandler.php](https://github.com/paymill/paymill-php/pull/102#discussion_r32232137) + Documentation -------------