diff --git a/README.md b/README.md index af87abb..df8ac22 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,12 @@ PAYMILL-PHP [![Latest Stable Version](https://poser.pugx.org/paymill/paymill/v/stable.png)](https://packagist.org/packages/paymill/paymill) [![Total Downloads](https://poser.pugx.org/paymill/paymill/downloads.png)](https://packagist.org/packages/paymill/paymill) +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 ----------- There are different credit card numbers, frontend and backend error codes, which can be used for testing. diff --git a/composer.json b/composer.json index 705a6cd..ff73064 100644 --- a/composer.json +++ b/composer.json @@ -1,4 +1,5 @@ { + "name": "paymill/paymill", "type": "library", "description": "Paymill PHPLib", @@ -16,4 +17,6 @@ "Paymill": "lib/" } } + } + diff --git a/composer.phar b/composer.phar new file mode 100755 index 0000000..2cff306 Binary files /dev/null and b/composer.phar differ diff --git a/lib/Paymill/API/Curl.php b/lib/Paymill/API/Curl.php index ddc69c2..b3bbb94 100644 --- a/lib/Paymill/API/Curl.php +++ b/lib/Paymill/API/Curl.php @@ -41,7 +41,7 @@ class Curl extends CommunicationAbstract * Extra cURL options. The array is keyed by the name of the cURL * options. */ - public function __construct($apiKey, $apiEndpoint = 'https://api.paymill.com/v2/', array $extracURL = array()) + public function __construct($apiKey, $apiEndpoint = 'https://api.paymill.com/v2.1/', array $extracURL = array()) { $this->_apiKey = $apiKey; $this->_apiUrl = $apiEndpoint; @@ -68,7 +68,7 @@ public function requestApi($action = '', $params = array(), $method = 'POST') CURLOPT_CUSTOMREQUEST => $method, CURLOPT_USERAGENT => 'Paymill-php/0.0.2', CURLOPT_SSL_VERIFYPEER => true, - CURLOPT_CAINFO => realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'paymill.crt', + CURLOPT_CAINFO => realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'paymill.crt' ); // Add extra options to cURL if defined. @@ -88,7 +88,6 @@ public function requestApi($action = '', $params = array(), $method = 'POST') if ($this->_apiKey) { $curlOpts[CURLOPT_USERPWD] = $this->_apiKey . ':'; } - $curl = curl_init(); curl_setopt_array($curl, $curlOpts); $responseBody = $this->_curlExec($curl); @@ -101,6 +100,10 @@ public function requestApi($action = '', $params = array(), $method = 'POST') if ('application/json' === $responseInfo['content_type']) { $responseBody = json_decode($responseBody, true); + } elseif('text/csv' === $responseInfo['content_type'] + && !isset($responseBody['error']) + ) { + return $responseBody; } return array( diff --git a/lib/Paymill/Models/Request/Base.php b/lib/Paymill/Models/Request/Base.php index 5e3b16a..575c05c 100644 --- a/lib/Paymill/Models/Request/Base.php +++ b/lib/Paymill/Models/Request/Base.php @@ -57,6 +57,9 @@ public function setId($id) */ public function getFilter() { + if (is_null($this->_filter)) { + return array(); + } return $this->_filter; } diff --git a/lib/Paymill/Models/Request/Fraud.php b/lib/Paymill/Models/Request/Fraud.php new file mode 100644 index 0000000..5859c46 --- /dev/null +++ b/lib/Paymill/Models/Request/Fraud.php @@ -0,0 +1,72 @@ +_serviceResource = 'Frauds/'; + } + + /** + * Returns the identifier + * @return string||null + */ + public function getIdentifier() + { + return $this->_identifier; + } + + /** + * Sets the identifier + * @param string $identifier + * @return \Paymill\Models\Request\Fraud + */ + public function setIdentifier($identifier) + { + $this->_identifier = $identifier; + return $this; + } + + /** + * Returns an array of parameters customized for the argumented methodname + * @param string $method + * @return array + */ + public function parameterize($method) + { + $parameterArray = array(); + switch ($method) { + case 'create': + $parameterArray['Identifier'] = $this->getIdentifier(); + break; + case 'update': + $parameterArray['Identifier'] = $this->getIdentifier(); + break; + case 'delete': + break; + case 'getOne': + $parameterArray['count'] = 1; + $parameterArray['offset'] = 0; + break; + case 'getAll': + $parameterArray = $this->getFilter(); + break; + } + + return $parameterArray; + } +} diff --git a/lib/Paymill/Models/Request/Offer.php b/lib/Paymill/Models/Request/Offer.php index d4d647e..722e2e8 100644 --- a/lib/Paymill/Models/Request/Offer.php +++ b/lib/Paymill/Models/Request/Offer.php @@ -22,17 +22,27 @@ class Offer extends Base * @var string */ private $_currency; - + /** * @var string */ private $_interval; - + /** * @var integer */ private $_trialPeriodDays; + /** + * @var boolean + */ + private $_removeWithSubscriptions; + + /** + * @var boolean + */ + private $_updateSubscriptions; + /** * Creates an instance of the offer request model */ @@ -144,6 +154,48 @@ public function setCurrency($currency) } /** + * Returns true if connected subscriptions should also be removed + * @return bool + */ + public function getRemoveWithSubscriptions() + { + return $this->_removeWithSubscriptions; + } + + /** + * Set if connected subscriptions should also be removed + * @param $removeWithSubscriptions bool + * + * @return $this \Paymill\Models\Request\Offer + */ + public function setRemoveWithSubscriptions($removeWithSubscriptions) + { + $this->_removeWithSubscriptions = $removeWithSubscriptions; + return $this; + } + + /** + * Returns true if connected subscriptions should also be updated + * @return bool + */ + public function getUpdateSubscriptions() + { + return $this->_updateSubscriptions; + } + + /** + * Set if connected subscriptions should also be updated + * @param $updateSubscriptions bool + * + * @return $this \Paymill\Models\Request\Offer + */ + public function setUpdateSubscriptions($updateSubscriptions) + { + $this->_updateSubscriptions = $updateSubscriptions; + return $this; + } + + /** * Returns an array of parameters customized for the argumented methodname * @param string $method * @return array @@ -160,16 +212,26 @@ public function parameterize($method) $parameterArray['trial_period_days'] = $this->getTrialPeriodDays(); break; case 'update': + if (!is_null($this->getUpdateSubscriptions())) { + $parameterArray['update_subscriptions'] = $this->getUpdateSubscriptions(); + } $parameterArray['name'] = $this->getName(); + $parameterArray['amount'] = $this->getAmount(); + $parameterArray['currency'] = $this->getCurrency(); + $parameterArray['interval'] = $this->getInterval(); + $parameterArray['trial_period_days'] = $this->getTrialPeriodDays(); break; case 'getOne': $parameterArray['count'] = 1; $parameterArray['offset'] = 0; break; case 'getAll': - $parameterArray = $this->getFilter(); + $parameterArray = $this->getFilter(); break; case 'delete': + if (!is_null($this->getRemoveWithSubscriptions())) { + $parameterArray['remove_with_subscriptions'] = $this->getRemoveWithSubscriptions(); + } break; } diff --git a/lib/Paymill/Models/Request/Subscription.php b/lib/Paymill/Models/Request/Subscription.php index 6a0fb58..ac0787f 100644 --- a/lib/Paymill/Models/Request/Subscription.php +++ b/lib/Paymill/Models/Request/Subscription.php @@ -15,28 +15,79 @@ class Subscription extends Base /** * @var string */ - private $_offer; - + private $_name; + /** - * @var boolean + * @var int + */ + private $_amount; + + /** + * @var string + */ + private $_currency; + + /** + * @var string */ - private $_cancelAtPeriodEnd; - + private $_interval; + + /** + * @var string + */ + private $_offer; + /** * @var string */ private $_payment; - + + /** + * @var string + */ + private $_token; + /** * @var string */ private $_client; - + /** * @var integer */ private $_startAt; + /** + * @var string + */ + private $_periodOfValidity; + + /** + * @var boolean + */ + private $_pause; + + /** + * @var int timestamp + */ + private $_trialEnd; + + /** + * @var int + */ + private $_amountChangeType; + + /** + * @var int + */ + private $_offerChangeType; + + /** + * @var + */ + private $_remove; + + /** * Creates an instance of the subscription request model */ @@ -45,43 +96,104 @@ public function __construct() $this->_serviceResource = 'Subscriptions/'; } + /** - * Returns the identifier of the offer the subscription is based on + * Returns name of subscription * @return string */ - public function getOffer() + public function getName() { - return $this->_offer; + return $this->_name; } /** - * Sets the identifier of the offer the subscription is based on - * @param string $offer + * Sets name of the subscription + * @param $name string * @return \Paymill\Models\Request\Subscription */ - public function setOffer($offer) + public function setName($name) { - $this->_offer = $offer; + $this->_name = $name; return $this; } /** - * Returns the flag determining whether to cancel this subscription immediately or at the end of the current period - * @return boolean + * Returns the amount as an integer + * @return integer */ - public function getCancelAtPeriodEnd() + public function getAmount() + { + return $this->_amount; + } + + /** + * Sets the amount. + * Every interval the specified amount will be charged. Only integer values are allowed (e.g. 42.00 = 4200) + * @param integer $amount + * @return \Paymill\Models\Request\Subscription + */ + public function setAmount($amount) + { + $this->_amount = $amount; + return $this; + } + + /** + * Returns the interval defining how often the client should be charged. + * @return string + */ + public function getInterval() + { + return $this->_interval; + } + + /** + * Sets the interval defining how often the client should be charged. + * Additionally a special day of the week can be appended (unless daily interval) + * @example Format: number DAY || number WEEK | MONTH | YEAR [, MONDAY | TUESDAY | ... | SUNDAY] Example: 3 WEEK, MONDAY + * @param string $interval + * @return \Paymill\Models\Request\Subscription + */ + public function setInterval($interval) + { + $this->_interval = $interval; + return $this; + } + + /** + * Returns the currency + * @return string + */ + public function getCurrency() + { + return $this->_currency; + } + + /** + * Sets the currency + * @param string $currency + * @return \Paymill\Models\Request\Subscription + */ + public function setCurrency($currency) + { + $this->_currency = $currency; + return $this; + } + + + public function getOffer() { - return $this->_cancelAtPeriodEnd; + return $this->_offer; } /** - * Sets a flag determining whether to cancel this subscription immediately or at the end of the current period - * @param boolean $cancelAtPeriodEnd + * Sets the identifier of the offer the subscription is based on + * @param string $offer * @return \Paymill\Models\Request\Subscription */ - public function setCancelAtPeriodEnd($cancelAtPeriodEnd) + public function setOffer($offer) { - $this->_cancelAtPeriodEnd = $cancelAtPeriodEnd; + $this->_offer = $offer; return $this; } @@ -145,6 +257,148 @@ public function setStartAt($startAt) return $this; } + /** + * Sets the period of validity the subscriptions shall be active (starting creation date) + * @param $periodOfValidity string + * @return \Paymill\Models\Request\Subscription + */ + public function setPeriodOfValidity($periodOfValidity) + { + $this->_periodOfValidity = $periodOfValidity; + return $this; + } + + /** + * Returns period of validity + * @return string + */ + public function getPeriodOfValidity() + { + return $this->_periodOfValidity; + } + + /** + * Returns if subscription is paused or not + * @return boolean + */ + public function getPause() + { + return $this->_pause; + } + + /** + * Sets the state of subscription to paused or unpaused + * @param $pause boolean + * @return \Paymill\Models\Request\Subscription + */ + public function setPause($pause) + { + $this->_pause = $pause; + return $this; + } + + /** + * returns timestamp of subscription start + * @return mixed + */ + public function getTrialEnd() + { + return $this->_trialEnd; + } + + /** + * set timestamp for when subscription shall start + * @param $trialEnd + * @return $this + */ + public function setTrialEnd($trialEnd) + { + $this->_trialEnd = $trialEnd; + return $this; + } + + /** + * set amount change type + * + * @param $amountChangeType + * @return $this + */ + public function setAmountChangeType($amountChangeType) + { + $this->_amountChangeType = $amountChangeType; + return $this; + } + + /** + * get amount change type + * @return int + */ + public function getAmountChangeType() + { + return $this->_amountChangeType; + } + + /** + * Set offer change type + * @param $offerChangeType + * + * @return $this + */ + public function setOfferChangeType($offerChangeType) + { + $this->_offerChangeType = $offerChangeType; + return $this; + } + + /** + * Return offer change type + * @return int + */ + public function getOfferChangeType() + { + return $this->_offerChangeType; + } + + /** + * Returns the token required for the creation of subscription + * @return string + */ + public function getToken() + { + return $this->_token; + } + + /** + * Sets the token required for the creation of subscription + * @param string $token + * @return \Paymill\Models\Request\Subscription + */ + public function setToken($token) + { + $this->_token = $token; + return $this; + } + + /** + * Returns true if subscription should also be removed + * @return mixed + */ + public function getRemove() + { + return $this->_remove; + } + + /** + * If set to true subscription will also be removed + * @param $remove + * @return \Paymill\Models\Request\Subscription + */ + public function setRemove($remove) + { + $this->_remove = $remove; + return $this; + } + /** * Returns an array of parameters customized for the argumented methodname * @param string $method @@ -155,24 +409,81 @@ public function parameterize($method) $parameterArray = array(); switch ($method) { case 'create': - $parameterArray['client'] = $this->getClient(); - $parameterArray['offer'] = $this->getOffer(); + if (!is_null($this->getClient())) { + $parameterArray['client'] = $this->getClient(); + } + if (!is_null($this->getOffer())) { + $parameterArray['offer'] = $this->getOffer(); + } $parameterArray['payment'] = $this->getPayment(); - $parameterArray['start_at'] = $this->getStartAt(); + + if (!is_null($this->getAmount())) { + $parameterArray['amount'] = $this->getAmount(); + } + if (!is_null($this->getCurrency())) { + $parameterArray['currency'] = $this->getCurrency(); + } + if (!is_null($this->getInterval())) { + $parameterArray['interval'] = $this->getInterval(); + } + if (!is_null($this->getName())) { + $parameterArray['name'] = $this->getName(); + } + if (!is_null($this->getPeriodOfValidity())) { + $parameterArray['period_of_validity'] = $this->getPeriodOfValidity(); + } + if (!is_null($this->getTrialEnd())) { + $parameterArray['trial_end'] = $this->getTrialEnd(); + } break; case 'update': - $parameterArray['cancel_at_period_end'] = $this->getCancelAtPeriodEnd(); - $parameterArray['offer'] = $this->getOffer(); - $parameterArray['payment'] = $this->getPayment(); + if (!is_null($this->getOffer())) { + $parameterArray['offer'] = $this->getOffer(); + } + if (!is_null($this->getPayment())) { + $parameterArray['payment'] = $this->getPayment(); + } else { + $parameterArray['token'] = $this->getToken(); + } + if (!is_null($this->getAmount())) { + $parameterArray['amount'] = $this->getAmount(); + } + if (!is_null($this->getCurrency())) { + $parameterArray['currency'] = $this->getCurrency(); + } + if (!is_null($this->getInterval())) { + $parameterArray['interval'] = $this->getInterval(); + } + if (!is_null($this->getName())) { + $parameterArray['name'] = $this->getName(); + } + if (!is_null($this->getPause())) { + $parameterArray['pause'] = $this->getPause(); + } + if (!is_null($this->getPeriodOfValidity())) { + $parameterArray['period_of_validity'] = $this->getPeriodOfValidity(); + } + if (!is_null($this->getTrialEnd())) { + $parameterArray['trial_end'] = $this->getTrialEnd(); + } + if (!is_null($this->getAmountChangeType())) { + $parameterArray['amount_change_type'] = $this->getAmountChangeType(); + } + if (!is_null($this->getOfferChangeType())) { + $parameterArray['offer_change_type'] = $this->getOfferChangeType(); + } break; case 'getOne': $parameterArray['count'] = 1; $parameterArray['offset'] = 0; break; case 'getAll': - $parameterArray = $this->getFilter(); + $parameterArray = $this->getFilter(); break; case 'delete': + if (!is_null($this->getRemove())){ + $parameterArray['remove'] = $this->getRemove(); + } break; } diff --git a/lib/Paymill/Models/Request/Webhook.php b/lib/Paymill/Models/Request/Webhook.php old mode 100644 new mode 100755 index 1943371..a2ee261 --- a/lib/Paymill/Models/Request/Webhook.php +++ b/lib/Paymill/Models/Request/Webhook.php @@ -25,6 +25,11 @@ class Webhook extends Base */ private $_eventTypes; + /** + * @var boolean + */ + private $_active = false; + /** * Creates an instance of the webhook request model */ @@ -100,6 +105,27 @@ public function setEmail($email) return $this; } + /** + * Sets webhook active (or inactive) + * @param boolean $active + */ + public function setActive($active) + { + $this->_active = $active; + return $this; + } + + /** + * Returns if webhook is active or inactive + * @param boolean $active + * + * @return bool + */ + public function getActive() + { + return $this->_active; + } + /** * Returns an array of parameters customized for the argumented methodname * @param string $method @@ -116,6 +142,9 @@ public function parameterize($method) $parameterArray['email'] = $this->getEmail(); } $parameterArray['event_types'] = $this->getEventTypes(); + if (!is_null($this->getActive())) { + $parameterArray['active'] = $this->getActive(); + } break; case 'update': if(!is_null($this->getUrl())){ @@ -124,6 +153,9 @@ public function parameterize($method) $parameterArray['email'] = $this->getEmail(); } $parameterArray['event_types'] = $this->getEventTypes(); + if (!is_null($this->getActive())) { + $parameterArray['active'] = $this->getActive(); + } break; case 'delete': break; diff --git a/lib/Paymill/Models/Response/Fraud.php b/lib/Paymill/Models/Response/Fraud.php new file mode 100644 index 0000000..5a9621f --- /dev/null +++ b/lib/Paymill/Models/Response/Fraud.php @@ -0,0 +1,61 @@ +_livemode; + } + + /** + * Sets the livemode flag of the fraud + * @param boolean $livemode + * @return \Paymill\Models\Response\Fraud + */ + public function setLivemode($livemode) + { + $this->_livemode = $livemode; + return $this; + } + + /** + * Returns the status for this fraud + * @return string||null + */ + public function getStatus() + { + return $this->_status; + } + + /** + * Sets the status + * @param string $status + * @return \Paymill\Models\Response\Fraud + */ + public function setStatus($status) + { + $this->_status = $status; + return $this; + } + +} diff --git a/lib/Paymill/Models/Response/Subscription.php b/lib/Paymill/Models/Response/Subscription.php index 5e09de4..03523c0 100644 --- a/lib/Paymill/Models/Response/Subscription.php +++ b/lib/Paymill/Models/Response/Subscription.php @@ -4,63 +4,88 @@ /** * Subscription Model - * Subscriptions allow you to charge recurring payments on a client’s credit card / to a client’s direct debit. - * A subscription connects a client to the offers-object. A client can have several subscriptions to different offers, + * Subscriptions allow you to charge recurring payments on a client’s credit card / to a client’s direct debit. + * A subscription connects a client to the offers-object. A client can have several subscriptions to different offers, * but only one subscription to the same offer. * @tutorial https://paymill.com/de-de/dokumentation/referenz/api-referenz/#document-subscriptions */ class Subscription extends Base { /** - * @var \Paymill\Models\Response\Offer + * @var \Paymill\Models\Response\Offer */ private $_offer; - + /** - * @var boolean + * @var boolean */ private $_livemode; - - /** - * @var boolean - */ - private $_cancelAtPeriodEnd; - + /** - * @var integer + * @var integer */ private $_trialStart; - + /** * @var integer */ private $_trialEnd; - + /** * @var integer */ private $_nextCaptureAt; - + /** * @var integer */ private $_canceledAt; - + /** - * @var \Paymill\Models\Response\Payment + * @var \Paymill\Models\Response\Payment */ private $_payment; - + /** - * @var \Paymill\Models\Response\Client + * @var \Paymill\Models\Response\Client */ private $_client; - + /** - * @var integer + * @var integer */ private $_startAt; + /** + * @var boolean + */ + private $_isCanceled; + + /** + * @var boolean + */ + private $_isDeleted; + + /** + * @var string + */ + private $_status; + + /** + * @var string + */ + private $_periodOfValidity; + + /** + * @var int + */ + private $_amountChangeType; + + /** + * @var int + */ + private $_offerChangeType; + /** * Returns the model of the offer the subscription is based on * @return \Paymill\Models\Response\Offer @@ -101,25 +126,6 @@ public function setLivemode($livemode) return $this; } - /** - * Returns the flag determining whether to cancel this subscription immediately or at the end of the current period - * @return boolean - */ - public function getCancelAtPeriodEnd() - { - return $this->_cancelAtPeriodEnd; - } - - /** - * Sets a flag determining whether to cancel this subscription immediately or at the end of the current period - * @param boolean $cancelAtPeriodEnd - * @return \Paymill\Models\Response\Subscription - */ - public function setCancelAtPeriodEnd($cancelAtPeriodEnd) - { - $this->_cancelAtPeriodEnd = $cancelAtPeriodEnd; - return $this; - } /** * Returns the Unix-Timestamp for the trial period start @@ -261,4 +267,128 @@ public function setStartAt($startAt) return $this; } + /** + * (un)cancel subscription + * @param boolean $canceled + * @return \Paymill\Models\Response\Subscription + */ + public function setIsCanceled($canceled) + { + $this->_isCanceled = $canceled; + return $this; + } + + /** + * Returns whether subscription is canceled or not + * @return boolean + */ + public function getIsCanceled() + { + return $this->_isCanceled; + + } + + /** + * (un)delete subscription + * @param boolean $deleted + * @return \Paymill\Models\Response\Subscription + */ + public function setIsDeleted($deleted) + { + $this->_isDeleted = $deleted; + return $this; + } + + /** + * Returns whether subscription is deleted or not + * @return boolean + */ + public function getIsDeleted() + { + return $this->_isDeleted; + } + + /** + * Sets the status of subscription + * @param string $status + * @return \Paymill\Models\Response\Subscription + */ + public function setStatus($status) + { + $this->_status = $status; + return $this; + } + + /** + * Returns subscription status + * @return string + */ + public function getStatus() + { + return $this->_status; + } + + /** + * Set the period of time the subscription shall be active/valid (starting creation date) + * @param $perdiodOfValidity + * @return \Paymill\Models\Response\Subscription + */ + public function setPeriodOfValidity($periodOfValidity) + { + $this->_periodOfValidity = $periodOfValidity; + return $this; + } + + /** + * Returns the period of time the subscriptions is valid (starting creation date) + * @return string + */ + public function getPeriodOfValidity() + { + return $this->_periodOfValidity; + } + + /** + * Set amount change type + * + * @param $amountChangeType + * @return $this + */ + public function setAmountChangeType($amountChangeType) + { + $this->_amountChangeType = $amountChangeType; + return $this; + } + + /** + * Return amount change type + * @return int + */ + public function getAmountChangeType() + { + return $this->_amountChangeType; + } + + /** + * Set offer change type + * @param $offerChangeType + * + * @return $this + */ + public function setOfferChangeType($offerChangeType) + { + $this->_offerChangeType; + return $this; + } + + /** + * Return offer change type + * @return int + */ + public function getOfferChangeType() + { + return $this->_offerChangeType; + } + + } \ No newline at end of file diff --git a/lib/Paymill/Models/Response/Webhook.php b/lib/Paymill/Models/Response/Webhook.php old mode 100644 new mode 100755 index bf514c1..fa1f172 --- a/lib/Paymill/Models/Response/Webhook.php +++ b/lib/Paymill/Models/Response/Webhook.php @@ -4,9 +4,9 @@ /** * Webhook Model - * With webhooks we give you the possibility to react automatically to certain events which happen within our system. - * A webhook is basically a URL where we send an HTTP POST request to, every time one of the events attached to that - * webhook is triggered. Alternatively you can define an email address where we send the event’s information to + * With webhooks we give you the possibility to react automatically to certain events which happen within our system. + * A webhook is basically a URL where we send an HTTP POST request to, every time one of the events attached to that + * webhook is triggered. Alternatively you can define an email address where we send the event’s information to * You can manage your webhooks via the API as explained below or you can use the web interface inside our cockpit. * @tutorial https://paymill.com/de-de/dokumentation/referenz/api-referenz/#document-webhooks */ @@ -16,22 +16,27 @@ class Webhook extends Base * @var string */ private $_url = null; - + /** * @var string */ private $_email = null; - + /** * @var boolean */ private $_livemode; - + /** * @var array */ private $_eventTypes; + /** + * @var boolean + */ + private $_active; + /** * Returns the webhook url * @return string @@ -83,10 +88,10 @@ public function getEventTypes() /** * Sets the event types for the webhook. - * There are a number of events you can react to. Each webhook can be configured to catch any kind of event - * individually, so you can create different webhooks for different events. Each Webhook needs to be attached - * to at least one event. For example the event subscription.succeeded is triggered every time a successful - * transaction has been made in our system that is based on a subscription. Shortly after that has been triggered, + * There are a number of events you can react to. Each webhook can be configured to catch any kind of event + * individually, so you can create different webhooks for different events. Each Webhook needs to be attached + * to at least one event. For example the event subscription.succeeded is triggered every time a successful + * transaction has been made in our system that is based on a subscription. Shortly after that has been triggered, * we will call every webhook you defined for this event and send detailed information to it. * @tutorial https://paymill.com/de-de/dokumentation/referenz/api-referenz/#document-webhooks * @param array $eventTypes @@ -119,4 +124,25 @@ public function setEmail($email) return $this; } + /** + * Sets webhook active (or inactive) + * @param boolean $active + */ + public function setActive($active) + { + $this->_active = $active; + return $this; + } + + /** + * Returns if webhook is active or inactive + * @param boolean $active + * + * @return bool + */ + public function getActive() + { + return $this->_active; + } + } \ No newline at end of file diff --git a/lib/Paymill/Request.php b/lib/Paymill/Request.php old mode 100644 new mode 100755 index ef2e5ed..36dcd8b --- a/lib/Paymill/Request.php +++ b/lib/Paymill/Request.php @@ -196,7 +196,7 @@ private function _getHTTPMethod($method) private function _request(Base $model, $method) { if(!is_a($this->_connectionClass, '\Paymill\API\CommunicationAbstract')){ - throw new PaymillException(null,'The connenction class is missing!'); + throw new PaymillException(null,'The connection class is missing!'); } $httpMethod = $this->_getHTTPMethod($method); $parameter = $model->parameterize($method); @@ -205,7 +205,6 @@ private function _request(Base $model, $method) $source = empty($this->_source) ? "PhpLib" . $this->getVersion(): "PhpLib" . $this->getVersion() . "_" . $this->getSource(); $parameter['source'] = $source; } - try { $this->_lastRequest = $parameter; $response = $this->_connectionClass->requestApi( @@ -229,7 +228,7 @@ private function _request(Base $model, $method) if (is_a($convertedResponse, '\Paymill\Models\Response\Error')) { throw new PaymillException( - $convertedResponse->getResponseCode(), $convertedResponse->getErrorMessage(), $convertedResponse->getHttpStatusCode() + $convertedResponse->getResponseCode(), $convertedResponse->getErrorMessage(), $convertedResponse->getHttpStatusCode() ); } diff --git a/lib/Paymill/Services/ResponseHandler.php b/lib/Paymill/Services/ResponseHandler.php index f96a91f..7c9a5fc 100644 --- a/lib/Paymill/Services/ResponseHandler.php +++ b/lib/Paymill/Services/ResponseHandler.php @@ -110,6 +110,9 @@ private function _convertResponseToModel($response, $resourceName) case 'webhook': $model = $this->_createWebhook($response); break; + case 'fraud': + $model = $this->_createFraud($response); + break; } return $model; @@ -277,7 +280,6 @@ private function _createSubscription($response) $model->setId($response['id']); $model->setOffer($this->_convertResponseToModel($response['offer'], 'offer')); $model->setLivemode($response['livemode']); - $model->setCancelAtPeriodEnd($response['cancel_at_period_end']); $model->setTrialStart($response['trial_start']); $model->setTrialEnd($response['trial_end']); $model->setNextCaptureAt($response['next_capture_at']); @@ -287,6 +289,9 @@ private function _createSubscription($response) $model->setPayment($this->_convertResponseToModel($response['payment'], "payment")); $model->setClient($this->_convertResponseToModel($response['client'], "client")); $model->setAppId($response['app_id']); + $model->setIsCanceled($response['is_canceled']); + $model->setIsDeleted($response['is_deleted']); + $model->setStatus($response['status']); return $model; } @@ -306,6 +311,25 @@ private function _createWebhook($response) $model->setCreatedAt($response['created_at']); $model->setUpdatedAt($response['updated_at']); $model->setAppId($response['app_id']); + $model->setActive($response['active']); + return $model; + } + + /** + * Creates and fills a fraudmodel + * + * @param array $response + * @return \Paymill\Models\Response\Fraud + */ + private function _createFraud($response) + { + $model = new Models\Fraud(); + $model->setId($response['id']); + $model->setLivemode($response['livemode']); + $model->setStatus($response['status']); + $model->setCreatedAt($response['created_at']); + $model->setUpdatedAt($response['updated_at']); + $model->setActive($response['active']); return $model; } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d3fe7a7..cd3ce2d 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -8,7 +8,7 @@ if (!defined('API_HOST') && getenv('PAYMILL_TEST_API_HOST')) { define('API_HOST', getenv('PAYMILL_TEST_API_HOST')); } -defined('API_HOST') || define('API_HOST', 'https://api.paymill.com/v2/'); +defined('API_HOST') || define('API_HOST', 'https://api.paymill.com/v2.1/'); /** * $apiKey should be set to api test key diff --git a/tests/integration/ClientTest.php b/tests/integration/ClientTest.php old mode 100755 new mode 100644 index 70edaf7..bf06ce8 --- a/tests/integration/ClientTest.php +++ b/tests/integration/ClientTest.php @@ -74,6 +74,7 @@ public function updateClient($model) } /** + * * @test * @codeCoverageIgnore * @expectedException \Paymill\Services\PaymillException @@ -117,12 +118,12 @@ public function getAllClient() public function getAllClientWithFilter() { $this->_model->setFilter(array( - 'count' => 2, + 'count' => 1, 'offset' => 0 ) ); $result = $this->_service->getAll($this->_model); - $this->assertEquals(2, count($result), var_export($result, true)); + $this->assertEquals(1, count($result), var_export($result, true)); } /** diff --git a/tests/integration/OfferTest.php b/tests/integration/OfferTest.php old mode 100755 new mode 100644 index a1fa8b1..bdcf6d3 --- a/tests/integration/OfferTest.php +++ b/tests/integration/OfferTest.php @@ -56,9 +56,10 @@ public function createOffer() ->setCurrency('EUR') ->setInterval('2 DAY') ->setName('TestOffer'); - $result = $this->_service->create($this->_model); - $this->assertInstanceOf('Paymill\Models\Response\Offer', $result, var_export($result, true)); - return $result; + $offerModelResult = $this->_service->create($this->_model); + $this->assertInstanceOf('Paymill\Models\Response\Offer', $offerModelResult, var_export($offerModelResult, true)); + + return $offerModelResult; } /** @@ -107,26 +108,95 @@ public function getAllOffer() public function getAllOfferWithFilter() { $this->_model->setFilter(array( - 'count' => 2, + 'count' => 1, 'offset' => 0 ) ); $result = $this->_service->getAll($this->_model); - $this->assertEquals(2, count($result), var_export($result, true)); + $this->assertEquals(1, count($result), var_export($result, true)); + } + + /** + * @test + * @depends createOffer + */ + public function getRequestSubscription($offer) + { + $subscriptionModel = new Models\Request\Subscription(); + $subscriptionModel->setOffer($offer->getId()); + $PaymentModel = new Models\Request\Payment(); + $PaymentModel->setToken("098f6bcd4621d373cade4e832627b4f6"); + $PaymentModelResponse = $this->_service->create($PaymentModel); + $this->assertInstanceOf('Paymill\Models\Response\Payment', $PaymentModelResponse, var_export($PaymentModelResponse, true)); + + $subscriptionModel->setClient($PaymentModelResponse->getClient()) + ->setPayment($PaymentModelResponse->getId()); + $subscription = $this->_service->create($subscriptionModel); + + $this->assertEquals($offer->getId(), $subscription->getOffer()->getId()); + + return $subscription; } + + /** * @test * @codeCoverageIgnore * @depends createOffer - * @depends getOneOffer - * @depends updateOffer + * @depends getRequestSubscription */ - public function deleteOffer($model) + public function deleteOfferWithSubscriptions($model, $subscriptionResponse) { - $this->_model->setId($model->getId()); + $subscriptionRequest = new Models\Request\Subscription(); + $subscriptionRequest->setId($subscriptionResponse->getId()); + + $this->assertInstanceOf('Paymill\Models\Response\Subscription', $subscriptionWithOffer = $this->_service->getOne($subscriptionRequest), var_export($subscriptionWithOffer, true)); + + $this->_model->setRemoveWithSubscriptions(true) + ->setId($model->getId()); + $result = $this->_service->delete($this->_model); + $this->assertInternalType('array', $result, var_export($result, true)); + + $subscriptionRequest->setId($subscriptionWithOffer->getId()); + + $subscriptionResponse = $this->_service->getOne($subscriptionRequest); + + $this->assertTrue($subscriptionResponse->getIsCanceled()); + $this->assertTrue($subscriptionResponse->getIsDeleted()); } + /** + * @test + * @codeCoverageIgnore + * + * + */ + public function deleteOfferWithoutSubscriptions() + { + $offer = $this->createOffer(); + $subscriptionResponse = $this->getRequestSubscription($offer); + $subscriptionRequest = new Models\Request\Subscription(); + $subscriptionRequest->setId($subscriptionResponse->getId()); + + $this->assertInstanceOf('Paymill\Models\Response\Subscription', $subscriptionWithOffer = $this->_service->getOne($subscriptionRequest), var_export($subscriptionWithOffer, true)); + + $this->_model->setRemoveWithSubscriptions(false) + ->setId($offer->getId()); + + $result = $this->_service->delete($this->_model); + + $this->assertInternalType('array', $result, var_export($result, true)); + + $subscriptionRequest->setId($subscriptionWithOffer->getId()); + + $subscriptionResponse = $this->_service->getOne($subscriptionRequest); + + $this->assertFalse($subscriptionResponse->getIsCanceled()); + $this->assertFalse($subscriptionResponse->getIsDeleted()); + } + + } diff --git a/tests/integration/PaymentTest.php b/tests/integration/PaymentTest.php old mode 100755 new mode 100644 index 9ada4c0..c105f33 --- a/tests/integration/PaymentTest.php +++ b/tests/integration/PaymentTest.php @@ -103,12 +103,12 @@ public function getAllPayment() public function getAllPaymentWithFilter() { $this->_model->setFilter(array( - 'count' => 2, + 'count' => 1, 'offset' => 0 ) ); $result = $this->_service->getAll($this->_model); - $this->assertEquals(2, count($result), var_export($result, true)); + $this->assertEquals(1, count($result), var_export($result, true)); } /** @@ -122,7 +122,7 @@ public function deletePayment($model) { $this->_model->setId($model->getId()); $result = $this->_service->delete($this->_model); - $this->assertInternalType('array', $result, var_export($result, true)); + $this->assertEquals(null, $result, var_export($result, true)); } } diff --git a/tests/integration/PreauthorizationTest.php b/tests/integration/PreauthorizationTest.php old mode 100755 new mode 100644 index 9989d3c..c169d7e --- a/tests/integration/PreauthorizationTest.php +++ b/tests/integration/PreauthorizationTest.php @@ -109,12 +109,12 @@ public function getAllPreauthorization() public function getAllPreauthorizationWithFilter() { $this->_model->setFilter(array( - 'count' => 2, + 'count' => 1, 'offset' => 0 ) ); $result = $this->_service->getAll($this->_model); - $this->assertEquals(2, count($result), var_export($result, true)); + $this->assertEquals(1, count($result), var_export($result, true)); } /** diff --git a/tests/integration/RefundTest.php b/tests/integration/RefundTest.php old mode 100755 new mode 100644 index 6c6cfad..b4a8986 --- a/tests/integration/RefundTest.php +++ b/tests/integration/RefundTest.php @@ -111,12 +111,12 @@ public function getAllRefund() public function getAllRefundWithFilter() { $this->_model->setFilter(array( - 'count' => 2, + 'count' => 1, 'offset' => 0 ) ); $result = $this->_service->getAll($this->_model); - $this->assertEquals(2, count($result), var_export($result, true)); + $this->assertEquals(1, count($result), var_export($result, true)); } /** diff --git a/tests/integration/SubscriptionTest.php b/tests/integration/SubscriptionTest.php old mode 100755 new mode 100644 index df71cb1..c1b4e41 --- a/tests/integration/SubscriptionTest.php +++ b/tests/integration/SubscriptionTest.php @@ -1,7 +1,7 @@ _service = new Request(); - $this->_service->setConnectionClass( - new Curl(API_TEST_KEY, API_HOST, array(CURLOPT_SSL_VERIFYPEER => SSL_VERIFY_PEER)) - ); - + $this->_service->setConnectionClass(new Curl(API_TEST_KEY)); $this->_model = new Models\Request\Subscription(); parent::setUp(); } @@ -47,22 +44,20 @@ protected function tearDown() } /** + * @group testing * @test * @codeCoverageIgnore */ - public function createSubscription() + public function createSubscriptionWithOffer() { - $this->markTestIncomplete( - 'Needs to be clarified with Paymill. Creation crashes with Message "currently there exists subscriptions, please delete them first"' - ); - $OfferModel = new Models\Request\Offer(); - $OfferModel->setAmount(100) + $offerModel = new Models\Request\Offer(); + $offerModel->setAmount(100) ->setCurrency('EUR') ->setInterval('2 DAY') ->setName('TestOffer'); - $OfferModelResponse = $this->_service->create($OfferModel); - $this->assertInstanceOf('Paymill\Models\Response\Offer', $OfferModelResponse, var_export($OfferModelResponse, true)); + $offerModelResponse = $this->_service->create($offerModel); + $this->assertInstanceOf('Paymill\Models\Response\Offer', $offerModelResponse, var_export($offerModelResponse, true)); $PaymentModel = new Models\Request\Payment(); $PaymentModel->setToken("098f6bcd4621d373cade4e832627b4f6"); @@ -70,35 +65,71 @@ public function createSubscription() $this->assertInstanceOf('Paymill\Models\Response\Payment', $PaymentModelResponse, var_export($PaymentModelResponse, true)); $this->_model->setClient($PaymentModelResponse->getClient()) - ->setOffer($OfferModelResponse->getId()) - ->setPayment($PaymentModelResponse->getId()) - ->setCancelAtPeriodEnd(false); + ->setOffer($offerModelResponse->getId()) + ->setPayment($PaymentModelResponse->getId()); $result = $this->_service->create($this->_model); $this->assertInstanceOf('Paymill\Models\Response\Subscription', $result, var_export($result, true)); - //$this->_service->delete($OfferModel->setId($OfferModelResponse->getId())); - //$this->_service->delete($PaymentModel->setId($PaymentModelResponse->getId())); + $offerModel->setRemoveWithSubscriptions(false); + $this->_service->delete($offerModel->setId($offerModelResponse->getId())); return $result; } /** * @test * @codeCoverageIgnore - * @depends createSubscription */ - public function updateSubscription($model) + public function createSubscriptionWithoutOffer() { - $this->_model->setId($model->getId()) - ->setCancelAtPeriodEnd(true); + $this->_model->setAmount(2000) + ->setCurrency('EUR') + ->setInterval('2 WeEK, tUEsDAY'); + $PaymentModel = new Models\Request\Payment(); + $PaymentModel->setToken("098f6bcd4621d373cade4e832627b4f6"); + $PaymentModelResponse = $this->_service->create($PaymentModel); + $this->assertInstanceOf('Paymill\Models\Response\Payment', $PaymentModelResponse, var_export($PaymentModelResponse, true)); + + $this->_model->setClient($PaymentModelResponse->getClient()) + ->setPayment($PaymentModelResponse->getId()); + $result = $this->_service->create($this->_model); + $this->assertInstanceOf('Paymill\Models\Response\Subscription', $result, var_export($result, true)); + + return $result; + } + + /** + * @test + * @codeCoverageIgnore + * @depends createSubscriptionWithOffer + */ + public function pauseSubscription($model) + { + $this->_model->setId($model->getId()); + $this->_model->setPause(true); $result = $this->_service->update($this->_model); $this->assertInstanceOf('Paymill\Models\Response\Subscription', $result, var_export($result, true)); - $this->assertTrue($result->getCancelAtPeriodEnd()); + $this->assertEquals('inactive', $result->getStatus()); + } + + + /** + * @test + * @codeCoverageIgnore + * @depends createSubscriptionWithOffer + */ + public function unPauseSubscription($model) + { + $this->_model->setId($model->getId()); + $this->_model->setPause(false); + $result = $this->_service->update($this->_model); + $this->assertInstanceOf('Paymill\Models\Response\Subscription', $result, var_export($result, true)); + $this->assertEquals('active', $result->getStatus()); } /** * @test * @codeCoverageIgnore - * @depends createSubscription + * @depends createSubscriptionWithOffer */ public function getOneSubscription($model) { @@ -110,7 +141,7 @@ public function getOneSubscription($model) /** * @test * @codeCoverageIgnore - * @depends createSubscription + * @depends createSubscriptionWithOffer */ public function getAllSubscription() { @@ -126,27 +157,40 @@ public function getAllSubscription() public function getAllSubscriptionWithFilter() { $this->_model->setFilter(array( - 'count' => 2, - 'offset' => 0 + 'count' => 1, + 'offset' => 0 ) ); $result = $this->_service->getAll($this->_model); - $this->assertEquals(2, count($result), var_export($result, true)); + $this->assertEquals(1, count($result), var_export($result, true)); } /** * @test * @codeCoverageIgnore - * @depends createSubscription + * @depends createSubscriptionWithOffer * @depends getOneSubscription * @depends updateSubscription */ public function deleteSubscription($model) { $this->_model->setId($model->getId()); - $this->markTestIncomplete('Subscription does not return a empty array like the other resources.'); $result = $this->_service->delete($this->_model); - $this->assertInternalType('array', $result, var_export($result, true)); + $this->assertTrue($result->getIsCanceled(), var_export($result, true)); + $this->assertFalse($result->getIsDeleted(), var_export($result, true)); + } + + /** + * @test + * @depends createSubscriptionWithoutOffer + */ + public function completelyDeleteSubscription($model) + { + $this->_model->setId($model->getId()) + ->setRemove(true); + $result = $this->_service->delete($this->_model); + $this->assertTrue($result->getIsCanceled(), var_export($result, true)); + $this->assertTrue($result->getIsDeleted(), var_export($result, true)); } } diff --git a/tests/integration/TransactionTest.php b/tests/integration/TransactionTest.php old mode 100755 new mode 100644 index 33d49c3..d8ce47c --- a/tests/integration/TransactionTest.php +++ b/tests/integration/TransactionTest.php @@ -132,12 +132,12 @@ public function getAllTransaction() public function getAllTransactionWithFilter() { $this->_model->setFilter(array( - 'count' => 2, + 'count' => 1, 'offset' => 0 ) ); $result = $this->_service->getAll($this->_model); - $this->assertEquals(2, count($result), var_export($result, true)); + $this->assertEquals(1, count($result), var_export($result, true)); } /** diff --git a/tests/integration/WebhookTest.php b/tests/integration/WebhookTest.php old mode 100755 new mode 100644 index 3bd9d55..241e41e --- a/tests/integration/WebhookTest.php +++ b/tests/integration/WebhookTest.php @@ -54,11 +54,13 @@ protected function tearDown() public function createWebhookWithUrl() { $this->_model->setUrl('http://example.com/dummyCallback') + ->setActive(true) ->setEventTypes(array( 'transaction.succeeded', 'subscription.created' )); $result = $this->_service->create($this->_model); $this->assertInstanceOf('Paymill\Models\Response\Webhook', $result, var_export($result, true)); + $this->assertTrue($result->getActive()); return $result; } @@ -69,6 +71,7 @@ public function createWebhookWithUrl() public function createWebhookWithEmail() { $this->_model->setEmail('dummy@example.com') + ->setActive(true) ->setEventTypes(array( 'transaction.succeeded', 'subscription.created' )); @@ -85,11 +88,13 @@ public function createWebhookWithEmail() public function updateWebhook($model) { $this->_model->setId($model->getId()) + ->setActive(false) ->setUrl('http://example.com/dummyCallbackUpdate'); $result = $this->_service->update($this->_model); $this->assertInstanceOf('Paymill\Models\Response\Webhook', $result, var_export($result, true)); $this->assertEquals($model->getId(), $result->getId()); + $this->assertFalse($result->getActive()); } /** @@ -118,17 +123,18 @@ public function getAllWebhook() /** * @test + * @depends createWebhookWithUrl * @codeCoverageIgnore */ public function getAllWebhookWithFilter() { $this->_model->setFilter(array( - 'count' => 2, + 'count' => 1, 'offset' => 0 ) ); $result = $this->_service->getAll($this->_model); - $this->assertEquals(2, count($result), var_export($result, true)); + $this->assertEquals(1, count($result), var_export($result, true)); } /** diff --git a/tests/unit/Paymill/Models/Request/OfferTest.php b/tests/unit/Paymill/Models/Request/OfferTest.php old mode 100644 new mode 100755 index a2cd40b..f1a4d3f --- a/tests/unit/Paymill/Models/Request/OfferTest.php +++ b/tests/unit/Paymill/Models/Request/OfferTest.php @@ -61,27 +61,35 @@ public function setGetTest() * @test * @depends setGetTest */ - public function parameterizeTest($offer) + public function parameterizeTest(Request\Offer $offer) { $testId = "offer_88a388d9dd48f86c3136"; $offer->setId($testId); - $creationArray = $offer->parameterize("create"); + $offer->setUpdateSubscriptions(true); $updateArray = $offer->parameterize("update"); $getOneArray = $offer->parameterize("getOne"); $this->assertEquals($creationArray, array( - 'amount' => '4200', // E.g. "4200" for 42.00 EUR + 'amount' => 4200, // E.g. "4200" for 42.00 EUR 'currency' => 'EUR', // ISO 4217 'interval' => '1 MONTH', 'name' => 'Test Offer', 'trial_period_days' => null )); - $this->assertEquals($updateArray, array('name' => $offer->getName())); + $expectedUpdateArray = array( + 'name' => $offer->getName(), + 'amount' => $offer->getAmount(), + 'currency' => $offer->getCurrency(), + 'interval' => $offer->getInterval(), + 'trial_period_days' => $offer->getTrialPeriodDays(), + 'update_subscriptions' => $offer->getUpdateSubscriptions() + + ); + $this->assertEquals($expectedUpdateArray, $updateArray); $this->assertEquals($getOneArray, array( 'count' => 1, 'offset' => 0 )); } - -} \ No newline at end of file +} diff --git a/tests/unit/Paymill/Models/Request/SubscriptionTest.php b/tests/unit/Paymill/Models/Request/SubscriptionTest.php index 1e5e369..d8e84b5 100644 --- a/tests/unit/Paymill/Models/Request/SubscriptionTest.php +++ b/tests/unit/Paymill/Models/Request/SubscriptionTest.php @@ -53,7 +53,6 @@ public function setGetTest() $this->assertEquals($this->_subscription->getOffer(), $sample['offer']); $this->assertEquals($this->_subscription->getPayment(), $sample['payment']); - return $this->_subscription; } @@ -65,27 +64,23 @@ public function setGetTest() public function parameterizeTest($subscription) { $testId = "subscription_88a388d9dd48f86c3136"; - $cancelAtPeriodEnd = true; $subscription->setId($testId); - $subscription->setCancelAtPeriodEnd($cancelAtPeriodEnd); $creationArray = $subscription->parameterize("create"); $updateArray = $subscription->parameterize("update"); $getOneArray = $subscription->parameterize("getOne"); - $this->assertEquals($creationArray, array( + $this->assertEquals(array( 'client' => 'client_88a388d9dd48f86c3136', 'offer' => 'offer_40237e20a7d5a231d99b', - 'payment' => 'pay_95ba26ba2c613ebb0ca8', - 'start_at' => null - )); + 'payment' => 'pay_95ba26ba2c613ebb0ca8' + ), $creationArray); $this->assertEquals($getOneArray, array( 'count' => 1, 'offset' => 0 )); $this->assertEquals($updateArray, array( - 'cancel_at_period_end' => true, 'offer' => 'offer_40237e20a7d5a231d99b', 'payment' => 'pay_95ba26ba2c613ebb0ca8' )); diff --git a/tests/unit/Paymill/Models/Request/WebhookTest.php b/tests/unit/Paymill/Models/Request/WebhookTest.php index 12cac60..898dad2 100644 --- a/tests/unit/Paymill/Models/Request/WebhookTest.php +++ b/tests/unit/Paymill/Models/Request/WebhookTest.php @@ -44,17 +44,20 @@ public function setGetTest() $sample = array( 'url' => 'your-webhook-url', 'email' => 'your-webhook-email', - 'event_types' => array('transaction.succeeded', 'subscription.created') + 'event_types' => array('transaction.succeeded', 'subscription.created'), + 'state' => true ); $this->_webhook ->setUrl($sample['url']) ->setEmail($sample['email']) - ->setEventTypes($sample['event_types']); + ->setEventTypes($sample['event_types']) + ->setActive($sample['state']); $this->assertEquals($this->_webhook->getUrl(), $sample['url']); $this->assertEquals($this->_webhook->getEmail(), $sample['email']); $this->assertEquals($this->_webhook->getEventTypes(), $sample['event_types']); + $this->assertEquals($this->_webhook->getActive(), $sample['state']); return $this->_webhook; } @@ -75,11 +78,13 @@ public function parameterizeTest($webhook) $this->assertEquals($creationArray, array( 'url' => 'your-webhook-url', - 'event_types' => array('transaction.succeeded', 'subscription.created') + 'event_types' => array('transaction.succeeded', 'subscription.created'), + 'active' => true )); $this->assertEquals($updateArray, array( 'url' => 'your-webhook-url', - 'event_types' => array('transaction.succeeded', 'subscription.created') + 'event_types' => array('transaction.succeeded', 'subscription.created'), + 'active' => true )); $this->assertEquals($getOneArray, array('count' => 1, 'offset' => 0)); } diff --git a/tests/unit/Paymill/Models/Response/SubscriptionTest.php b/tests/unit/Paymill/Models/Response/SubscriptionTest.php index d696ba2..2288076 100644 --- a/tests/unit/Paymill/Models/Response/SubscriptionTest.php +++ b/tests/unit/Paymill/Models/Response/SubscriptionTest.php @@ -54,7 +54,6 @@ public function setGetTest() $this->_subscription->setOffer($offer) ->setLivemode($liveMode) - ->setCancelAtPeriodEnd($cancelAtPeriodEnd) ->setTrialStart($trialStart) ->setTrialEnd($trialEnd) ->setNextCaptureAt($nextCaptureAt) @@ -64,7 +63,6 @@ public function setGetTest() $this->assertEquals($this->_subscription->getOffer(), $offer); $this->assertEquals($this->_subscription->getLivemode(), $liveMode); - $this->assertEquals($this->_subscription->getCancelAtPeriodEnd(), $cancelAtPeriodEnd); $this->assertEquals($this->_subscription->getTrialStart(), $trialStart); $this->assertEquals($this->_subscription->getTrialEnd(), $trialEnd); $this->assertEquals($this->_subscription->getNextCaptureAt(), $nextCaptureAt); diff --git a/tests/unit/Paymill/Services/RequestTest.php b/tests/unit/Paymill/Services/RequestTest.php old mode 100644 new mode 100755 index 2f71cec..652c155 --- a/tests/unit/Paymill/Services/RequestTest.php +++ b/tests/unit/Paymill/Services/RequestTest.php @@ -78,7 +78,7 @@ public function setConnectionClassWithinConstructorTest() * Test the setter for the connection class * @test * @expectedException \Paymill\Services\PaymillException - * @expectedExceptionMessage The connenction class is missing! + * @expectedExceptionMessage The connection class is missing! */ public function missingConnectionClassTest() { @@ -499,4 +499,4 @@ private function _getCurlMock($action, $params, $method, $response) return $this->_curlObjectMock; } -} \ No newline at end of file +} diff --git a/tests/unit/Paymill/Services/ResponseHandlerTest.php b/tests/unit/Paymill/Services/ResponseHandlerTest.php index 657bfa4..618680b 100644 --- a/tests/unit/Paymill/Services/ResponseHandlerTest.php +++ b/tests/unit/Paymill/Services/ResponseHandlerTest.php @@ -517,13 +517,15 @@ public function subscriptionTest() "app_id" => null ), "livemode" => false, - "cancel_at_period_end" => false, "trial_start" => null, "trial_end" => null, "next_capture_at" => 1369563095, "created_at" => 1341935490, "updated_at" => 1341935490, "canceled_at" => null, + "is_canceled" => false, + "is_deleted" => false, + "status" => 'active', "payment" => array( 'id' => "pay_be64260ee1b0a368efe597e8", 'type' => "creditcard", @@ -583,7 +585,9 @@ public function urlWebhookTest() ), "created_at" => 1358982000, "updated_at" => 1358982000, - "app_id" => null + "app_id" => null, + "version" => '2.0', + "active" => true ); $subject = $this->_responseHandler->convertResponse($response, "webhooks/"); $this->assertInstanceOf("\Paymill\Models\Response\Webhook", $subject, var_export($subject, true)); @@ -606,7 +610,10 @@ public function emailWebhookTest() ), "created_at" => 1358982000, "updated_at" => 1358982000, - "app_id" => null + "app_id" => null, + "version" => '2.0', + "active" => true + ); $subject = $this->_responseHandler->convertResponse($response, "webhooks/"); $this->assertInstanceOf("\Paymill\Models\Response\Webhook", $subject, var_export($subject, true));