Skip to content

Commit

Permalink
Implemented proposed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Niels Tholenaar committed Feb 17, 2016
1 parent d39f65b commit b878cd3
Show file tree
Hide file tree
Showing 55 changed files with 3,330 additions and 756 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -31,7 +31,8 @@ And run composer to update your dependencies:

The following gateways are provided by this package:

* MultiSafepay
* MultiSafepay_Rest
* MultiSafepay_Xml (Deprecated)

For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay)
repository.
Expand Down
160 changes: 11 additions & 149 deletions src/Gateway.php
@@ -1,157 +1,19 @@
<?php namespace Omnipay\MultiSafepay;
<?php
/**
* MultiSafepay XML Api Gateway.
*/

use Omnipay\Common\AbstractGateway;
namespace Omnipay\MultiSafepay;

/**
* MultiSafepay gateway.
* MultiSafepay XML Api gateway.
*
* @link https://www.multisafepay.com/documentation/doc/API-Reference/
* @deprecated This API is deprecated and will be removed in
* an upcoming version of this package. Please switch to the Rest API.
*
* @link https://www.multisafepay.com/downloads/handleidingen/Handleiding_connect(ENG).pdf
*/
class Gateway extends AbstractGateway
class Gateway extends XmlGateway
{
public function getName()
{
return 'MultiSafepay';
}

/**
* Get the gateway parameters
*
* @return array
*/
public function getDefaultParameters()
{
return array(
'apiKey' => '',
'locale' => 'en',
'testMode' => false,
);
}

/**
* Get the locale.
*
* Optional ISO 639-1 language code which is used to specify a
* a language used to display gateway information and other
* messages in the responses.
*
* The default language is English.
*
* @return string
*/
public function getLocale()
{
return $this->getParameter('locale');
}

/**
* Set the locale.
*
* Optional ISO 639-1 language code which is used to specify a
* a language used to display gateway information and other
* messages in the responses.
*
* The default language is English.
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setLocale($value)
{
return $this->setParameter('locale', $value);
}

/**
* Get the gateway API Key
*
* Authentication is by means of a single secret API key set as
* the apiKey parameter when creating the gateway object.
*
* @return string
*/
public function getApiKey()
{
return $this->getParameter('apiKey');
}

/**
* Set the gateway API Key
*
* Authentication is by means of a single secret API key set as
* the apiKey parameter when creating the gateway object.
*
* @param string $value
* @return Gateway provides a fluent interface.
*/
public function setApiKey($value)
{
return $this->setParameter('apiKey', $value);
}

/**
* Retrieve payment methods active on the given MultiSafepay
* account.
*
* @param array $parameters
*
* @return \Omnipay\MultiSafepay\Message\FetchPaymentMethodsRequest
*/
public function fetchPaymentMethods(array $parameters = array())
{
return $this->createRequest('Omnipay\MultiSafepay\Message\FetchPaymentMethodsRequest', $parameters);
}

/**
* Retrieve issuers for gateway.
*
* @param array $parameters
*
* @return \Omnipay\MultiSafepay\Message\FetchIssuersRequest
*/
public function fetchIssuers(array $parameters = array())
{
return $this->createRequest('Omnipay\MultiSafepay\Message\FetchIssuersRequest', $parameters);
}

/**
* Retrieve transaction by the given identifier.
*
* @param array $parameters
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function fetchTransaction(array $parameters = array())
{
return $this->createRequest('Omnipay\MultiSafepay\Message\FetchTransactionRequest', $parameters);
}

/**
* Create a refund.
*
* @param array $parameters
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function refund(array $parameters = array())
{
return $this->createRequest('Omnipay\MultiSafepay\Message\RefundRequest', $parameters);
}

/**
* @param array $parameters
*
* @return \Omnipay\MultiSafepay\Message\PurchaseRequest
*/
public function purchase(array $parameters = array())
{
return $this->createRequest('Omnipay\MultiSafepay\Message\PurchaseRequest', $parameters);
}

/**
* @param array $parameters
*
* @return \Omnipay\MultiSafepay\Message\CompletePurchaseRequest
*/
public function completePurchase(array $parameters = array())
{
return $this->createRequest('Omnipay\MultiSafepay\Message\CompletePurchaseRequest', $parameters);
}
}
145 changes: 67 additions & 78 deletions src/Message/AbstractRequest.php
@@ -1,17 +1,37 @@
<?php namespace Omnipay\MultiSafepay\Message;
<?php
/**
* MultiSafepay Abstract XML Api Request.
*/

use Guzzle\Common\Event;
namespace Omnipay\MultiSafepay\Message;

abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest;

/**
* Multisafepay Abstract XML Api Request.
*
* @deprecated This API is deprecated and will be removed in
* an upcoming version of this package. Please switch to the Rest API.
*/
abstract class AbstractRequest extends BaseAbstractRequest
{
/**
* User Agent.
*
* This user agent will be sent with each API request.
*
* @var string
*/
protected $userAgent = 'Omnipay';

/**
* Live API endpoint.
*
* This endpoint will be used when the test mode is disabled.
*
* @var string
*/
protected $liveEndpoint = 'https://api.multisafepay.com/v1/json';
protected $liveEndpoint = 'https://api.multisafepay.com/ewx/';

/**
* Test API endpoint.
Expand All @@ -20,70 +40,73 @@ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
*
* @var string
*/
protected $testEndpoint = 'https://testapi.multisafepay.com/v1/json';
protected $testEndpoint = 'https://testapi.multisafepay.com/ewx/';

/**
* Get the locale.
*
* Optional ISO 639-1 language code which is used to specify a
* a language used to display gateway information and other
* messages in the responses.
*
* The default language is English.
* Get the account identifier.
*
* @return string
* @return mixed
*/
public function getLocale()
public function getAccountId()
{
return $this->getParameter('locale');
return $this->getParameter('accountId');
}

/**
* Set the locale.
*
* Optional ISO 639-1 language code which is used to specify a
* a language used to display gateway information and other
* messages in the responses.
*
* The default language is English.
* Set the account identifier.
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest
* @return BaseAbstractRequest
*/
public function setLocale($value)
public function setAccountId($value)
{
return $this->setParameter('locale', $value);
return $this->setParameter('accountId', $value);
}

/**
* Get the gateway API Key
* Get the site identifier.
*
* Authentication is by means of a single secret API key set as
* the apiKey parameter when creating the gateway object.
* @return mixed
*/
public function getSiteId()
{
return $this->getParameter('siteId');
}

/**
* Set the site identifier.
*
* @return string
* @param $value
* @return BaseAbstractRequest
*/
public function getApiKey()
public function setSiteId($value)
{
return $this->getParameter('apiKey');
return $this->setParameter('siteId', $value);
}

/**
* Set the gateway API Key
* Get the site code.
*
* Authentication is by means of a single secret API key set as
* the apiKey parameter when creating the gateway object.
* @return mixed
*/
public function getSiteCode()
{
return $this->getParameter('siteCode');
}

/**
* Set the site code.
*
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest
* @return BaseAbstractRequest
*/
public function setApiKey($value)
public function setSiteCode($value)
{
return $this->setParameter('apiKey', $value);
return $this->setParameter('siteCode', $value);
}

/**
* Get endpoint.
* Get the API endpoint.
*
* @return string
*/
Expand All @@ -97,48 +120,14 @@ public function getEndpoint()
}

/**
* {@inheritdoc}
*/
public function getData()
{
$this->validate('apiKey');
}

/**
* @param $method
* @param $endpoint
* @param null $query
* @param null $data
* @return \Guzzle\Http\Message\Response
* Get headers.
*
* @return array
*/
protected function sendRequest($method, $endpoint, $query = null, $data = null)
protected function getHeaders()
{
$this->httpClient->getEventDispatcher()->addListener('request.error', function (Event $event) {
/**
* @var \Guzzle\Http\Message\Response $response
*/
$response = $event['response'];
if ($response->isError()) {
$event->stopPropagation();
}
});

$httpRequest = $this->httpClient->createRequest(
$method,
$this->getEndpoint() . $endpoint,
array(
'api_key' => $this->getApiKey(),
),
$data
return array(
'User-Agent' => $this->userAgent,
);

// Add query parameters
if (is_array($query) && ! empty($query)) {
foreach ($query as $itemKey => $itemValue) {
$httpRequest->getQuery()->add($itemKey, $itemValue);
}
}

return $httpRequest->send();
}
}

0 comments on commit b878cd3

Please sign in to comment.