Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Conflicts:
	tests/integration/SubscriptionTest.php
  • Loading branch information
Stefan Harenkamp committed Jul 23, 2014
2 parents 3181e8c + 2352e85 commit 4849e74
Show file tree
Hide file tree
Showing 29 changed files with 1,034 additions and 168 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{

"name": "paymill/paymill",
"type": "library",
"description": "Paymill PHPLib",
Expand All @@ -16,4 +17,6 @@
"Paymill": "lib/"
}
}

}

Binary file added composer.phar
Binary file not shown.
9 changes: 6 additions & 3 deletions lib/Paymill/API/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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);
Expand All @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions lib/Paymill/Models/Request/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public function setId($id)
*/
public function getFilter()
{
if (is_null($this->_filter)) {
return array();
}
return $this->_filter;
}

Expand Down
72 changes: 72 additions & 0 deletions lib/Paymill/Models/Request/Fraud.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Paymill\Models\Request;

/**
* Fraud Model
* This is an experimental feature! API for frauds may change before being marked as stable for production use.
*/
class Fraud extends Base
{
/**
* @var string
*/
private $identifier = null;

/**
* Creates an instance of the fraud request model
*/
function __construct()
{
$this->_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;
}
}
68 changes: 65 additions & 3 deletions lib/Paymill/Models/Request/Offer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
Loading

0 comments on commit 4849e74

Please sign in to comment.