Skip to content

Commit

Permalink
Payout function added for CCARD
Browse files Browse the repository at this point in the history
  • Loading branch information
dercoder committed Sep 8, 2017
1 parent 247dca4 commit 6e899d1
Show file tree
Hide file tree
Showing 14 changed files with 507 additions and 62 deletions.
1 change: 0 additions & 1 deletion .travis.yml
@@ -1,7 +1,6 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
Expand Down
33 changes: 33 additions & 0 deletions src/Gateway.php
Expand Up @@ -4,6 +4,7 @@

use Omnipay\Common\AbstractGateway;
use Omnipay\Common\Message\AbstractRequest;
use Omnipay\Wirecard\Message\PayoutRequest;
use Omnipay\Wirecard\Message\PurchaseRequest;
use Omnipay\Wirecard\Message\CompletePurchaseRequest;

Expand Down Expand Up @@ -100,6 +101,28 @@ public function setSecret($value)
return $this->setParameter('secret', $value);
}

/**
* Get Wirecard toolkit password.
*
* @return string toolkitPassword
*/
public function getToolkitPassword()
{
return $this->getParameter('toolkitPassword');
}

/**
* Set Wirecard toolkit password.
*
* @param string $value toolkitPassword
*
* @return $this
*/
public function setToolkitPassword($value)
{
return $this->setParameter('toolkitPassword', $value);
}

/**
* @param array $parameters
*
Expand All @@ -119,4 +142,14 @@ public function completePurchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\Wirecard\Message\CompletePurchaseRequest', $parameters);
}

/**
* @param array $parameters
*
* @return AbstractRequest|PayoutRequest
*/
public function payout(array $parameters = array())
{
return $this->createRequest('\Omnipay\Wirecard\Message\PayoutRequest', $parameters);
}
}
61 changes: 61 additions & 0 deletions src/Message/AbstractRequest.php
Expand Up @@ -8,6 +8,20 @@
*/
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
{
/**
* https://guides.wirecard.at/request_parameters#language
* @var array
*/
public $languages = array(
'AR', 'BS', 'BG', 'ZH', 'HR',
'CS', 'DA', 'NL', 'EN', 'ET',
'FI', 'FR', 'DE', 'EL', 'HE',
'HI', 'HU', 'IT', 'JA', 'KO',
'LV', 'LT', 'MK', 'NO', 'PL',
'PT', 'RO', 'RU', 'SR', 'SK',
'SL', 'ES', 'SV', 'TR', 'UK'
);

/**
* Get Wirecard customer ID.
*
Expand Down Expand Up @@ -73,4 +87,51 @@ public function setSecret($value)
{
return $this->setParameter('secret', $value);
}

/**
* Get Wirecard toolkit password.
*
* @return string toolkitPassword
*/
public function getToolkitPassword()
{
return $this->getParameter('toolkitPassword');
}

/**
* Set Wirecard toolkit password.
*
* @param string $value toolkitPassword
*
* @return $this
*/
public function setToolkitPassword($value)
{
return $this->setParameter('toolkitPassword', $value);
}

/**
* @return string language
*/
public function getLanguage()
{
if ($language = $this->getParameter('language')) {
$language = strtoupper($language);
if (in_array($language, $this->languages)) {
return $language;
}
}

return 'EN';
}

/**
* @param string $value $language
*
* @return $this
*/
public function setLanguage($value)
{
return $this->setParameter('language', $value);
}
}
56 changes: 56 additions & 0 deletions src/Message/PayoutRequest.php
@@ -0,0 +1,56 @@
<?php

namespace Omnipay\Wirecard\Message;

use Omnipay\Wirecard\Support\Helper;

/**
* Class PayoutRequest
* @package Omnipay\Wirecard\Message
*/
class PayoutRequest extends AbstractRequest
{
/**
* @var string
*/
protected $endpoint = 'https://checkout.wirecard.com/page/toolkit.php';

/**
* @return array
*/
public function getData()
{
$this->validate(
'customerId',
'secret',
'toolkitPassword',
'transactionReference',
'currency',
'amount',
'language'
);

$data = array(
'customerId' => $this->getCustomerId(),
'shopId' => $this->getShopId(),
'toolkitPassword' => $this->getToolkitPassword(),
'secret' => $this->getSecret(),
'command' => 'refund',
'language' => $this->getLanguage(),
'orderNumber' => $this->getTransactionReference(),
'amount' => $this->getAmount(),
'currency' => $this->getCurrency()
);

$data['requestFingerprint'] = Helper::getPayoutRequestFingerprint($data, $this->getSecret());
unset($data['secret']);

return $data;
}

public function sendData($data)
{
$httpResponse = $this->httpClient->post($this->endpoint, null, $data)->send();
return new PayoutResponse($this, $httpResponse->getBody(true));
}
}
80 changes: 80 additions & 0 deletions src/Message/PayoutResponse.php
@@ -0,0 +1,80 @@
<?php

namespace Omnipay\Wirecard\Message;

use Omnipay\Common\Message\AbstractResponse;
use Omnipay\Common\Message\RequestInterface;

/**
* Class PayoutResponse
* @package Omnipay\Wirecard\Message
*/
class PayoutResponse extends AbstractResponse
{
/**
* PayoutResponse constructor.
*
* @param RequestInterface $request
* @param string $data
*/
public function __construct(RequestInterface $request, $data)
{
parent::__construct($request, []);
foreach (explode('&', $data) as $keyValue) {
$param = explode('=', $keyValue);
if (sizeof($param) == 2) {
$key = urldecode($param[0]);
$value = urldecode($param[1]);
$this->data[$key] = $value;
}
}
}

/**
* @return bool
*/
public function isSuccessful()
{
return $this->getStatus() === '0';
}

/**
* @return int|null
*/
public function getTransactionReference()
{
return $this->getCreditNumber();
}

/**
* @return string|null
*/
public function getStatus()
{
return isset($this->data['status']) ? $this->data['status'] : null;
}

/**
* @return int|null
*/
public function getCode()
{
return isset($this->data['errorCode']) ? (int) $this->data['errorCode'] : null;
}

/**
* @return string|null
*/
public function getMessage()
{
return isset($this->data['message']) ? $this->data['message'] : null;
}

/**
* @return int|null
*/
public function getCreditNumber()
{
return isset($this->data['creditNumber']) ? (int) $this->data['creditNumber'] : null;
}
}

0 comments on commit 6e899d1

Please sign in to comment.