Skip to content

Commit

Permalink
Merge pull request #12 from AngeloG/master
Browse files Browse the repository at this point in the history
Signed status response code from @jvandesande and fixed bug with invalid locales, updated example to use iDEAL v2
  • Loading branch information
joostfaassen committed Jul 11, 2015
2 parents 6905c66 + 88ffc28 commit 893ab03
Show file tree
Hide file tree
Showing 19 changed files with 722 additions and 33 deletions.
4 changes: 2 additions & 2 deletions examples/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ static function demoRequest() {
// Specify which service / action we are calling
$TransactionRequest->Services = new SOAP\Services();
$TransactionRequest->Services->Service
= new SOAP\Service('ideal', 'Pay', 1);
= new SOAP\Service('ideal', 'Pay', 2);

// Add parameters for this service
$TransactionRequest->Services->Service->RequestParameter
= new SOAP\RequestParameter('issuer', '0031');
= new SOAP\RequestParameter('issuer', 'RABONL2U');

// Optionally pass the client ip-address for logging
$TransactionRequest->ClientIP = new SOAP\IPAddress('123.123.123.123');
Expand Down
77 changes: 47 additions & 30 deletions src/LinkORB/Buckaroo/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,32 @@ class Request
private $culture = 'nl-NL';
private $testMode = false;
private $channel = 'Web';

public function __construct($websiteKey = null, $testMode = false)
protected static $defaultSoapOptions = array(
'trace' => 1,
'classmap' => array(
'Body' => 'LinkORB\\Buckaroo\\SOAP\\Type\\Body',
'Status' => 'LinkORB\\Buckaroo\\SOAP\\Type\\Status',
'RequiredAction' => 'LinkORB\\Buckaroo\\SOAP\\Type\\RequiredAction',
'ParameterError' => 'LinkORB\\Buckaroo\\SOAP\\Type\\ParameterError',
'CustomParameterError' => 'LinkORB\\Buckaroo\\SOAP\\Type\\CustomParameterError',
'ServiceError' => 'LinkORB\\Buckaroo\\SOAP\\Type\\ServiceError',
'ActionError' => 'LinkORB\\Buckaroo\\SOAP\\Type\\ActionError',
'ChannelError' => 'LinkORB\\Buckaroo\\SOAP\\Type\\ChannelError',
'RequestErrors' => 'LinkORB\\Buckaroo\\SOAP\\Type\\RequestErrors',
'StatusCode' => 'LinkORB\\Buckaroo\\SOAP\\Type\\StatusCode',
'StatusSubCode' => 'LinkORB\\Buckaroo\\SOAP\\Type\\StatusCode',
)
);

public function __construct($websiteKey = null, $testMode = false, array $soapOptions = array())
{

$this->websiteKey = $websiteKey;
$this->testMode = $testMode;

$wsdl_url = "https://checkout.buckaroo.nl/soap/soap.svc?wsdl";
$this->soapClient = new SoapClientWSSEC($wsdl_url, array('trace'=>1));
}
$wsdl_url = "https://checkout.buckaroo.nl/soap/soap.svc?wsdl";
$this->soapClient = new SoapClientWSSEC($wsdl_url, array_merge(static::$defaultSoapOptions, $soapOptions));
}

public function loadPem($filename)
{
Expand Down Expand Up @@ -79,47 +95,47 @@ public function sendRequest($TransactionRequest, $type)
$soapHeaders[] = new \SOAPHeader('https://checkout.buckaroo.nl/PaymentEngine/', 'MessageControlBlock', $Header->MessageControlBlock);
$soapHeaders[] = new \SOAPHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', $Header->Security);
$this->soapClient->__setSoapHeaders($soapHeaders);

if ($this->testMode) {
$this->soapClient->__SetLocation('https://testcheckout.buckaroo.nl/soap/');
} else {
$this->soapClient->__SetLocation('https://checkout.buckaroo.nl/soap/');
}

switch($type) {
case 'invoiceinfo':
$this->soapClient->InvoiceInfo($TransactionRequest);
break;
case 'transaction':
$this->soapClient->TransactionRequest($TransactionRequest);
break;

if ($this->testMode) {
$this->soapClient->__SetLocation('https://testcheckout.buckaroo.nl/soap/');
} else {
$this->soapClient->__SetLocation('https://checkout.buckaroo.nl/soap/');
}
switch($type) {
case 'invoiceinfo':
$this->soapClient->InvoiceInfo($TransactionRequest);
break;
case 'transaction':
$this->soapClient->TransactionRequest($TransactionRequest);
break;
case 'transactionstatus':
$this->soapClient->TransactionStatus($TransactionRequest);
break;
case 'refundinfo':
$this->soapClient->RefundInfo($TransactionRequest);
break;
}
case 'refundinfo':
$this->soapClient->RefundInfo($TransactionRequest);
break;
}

$return['response'] = $this->soapClient->__getLastResponse();
$return['request'] = $this->soapClient->__getLastRequest();
return $return;
}
$return['response'] = $this->soapClient->__getLastResponse();
$return['request'] = $this->soapClient->__getLastRequest();
return $return;
}

/**
* @param boolean $testMode
* @return Request
*/
public function setTestMode($testMode)
public function setTestMode($testMode)
{
$this->testMode = $testMode;

return $this;
}

/**
* @return boolean
*/
public function getTestMode()
public function getTestMode()
{
return $this->testMode;
}
Expand All @@ -131,13 +147,14 @@ public function getTestMode()
public function setCulture($culture)
{
$this->culture = $culture;

return $this;
}

/**
* @return string
*/
public function getCulture()
public function getCulture()
{
return $this->culture;
}
Expand Down
130 changes: 130 additions & 0 deletions src/LinkORB/Buckaroo/Response/PostResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace LinkORB\Buckaroo\Response;

use LinkORB\Buckaroo\Response;
use LinkORB\Buckaroo\SignatureComposer\SignatureComposer;

/**
* PostResponse can be used to verify and read post and push responses from Buckaroo.
*
* <code>
* use LinkORB\Buckaroo\Response\PostResponse;
* use LinkORB\Buckaroo\SignatureComposer\Sha1Composer;
*
* $response = new PostResponse($_POST);
* if ($response->isValid(new Sha1Composer('YourSecretKey')) {
* var_dump($response->getParameter('BRQ_STATUSCODE'));
* }
* </code>
*
* @author Joris van de Sande <[email protected]>
*/
class PostResponse implements \ArrayAccess
{
const SIGNATURE_FIELD = 'BRQ_SIGNATURE';

/**
* @var array
*/
protected $parameters;

/**
* @var string
*/
protected $signature;

/**
* @var array
*/
protected $upperParameters;

/**
* @param array $parameters
*/
public function __construct(array $parameters)
{
$upperParameters = array_change_key_case($parameters, CASE_UPPER);
$this->signature = $this->getSignature($upperParameters);
unset($parameters[static::SIGNATURE_FIELD], $parameters[strtolower(static::SIGNATURE_FIELD)]);

$this->parameters = $parameters;
$this->upperParameters = array_change_key_case($parameters, CASE_UPPER);
}

/**
* Returns whether this response is valid.
*
* @param SignatureComposer $composer
* @return bool
*/
public function isValid(SignatureComposer $composer)
{
return $this->signature === $composer->compose($this->parameters);
}

/**
* Returns the value for the given key.
*
* @param string $key
* @return string
* @throws \InvalidArgumentException
*/
public function getParameter($key)
{
$key = strtoupper($key);

if (! isset($this->upperParameters[$key])) {
throw new \InvalidArgumentException('Parameter ' . $key . ' does not exist.');
}

return $this->upperParameters[$key];
}

/**
* Returns whether the parameter exists.
* @param string $key
* @return bool
*/
public function hasParameter($key)
{
return isset($this->upperParameters[strtoupper($key)]);
}

public function offsetExists($offset)
{
return isset($this->upperParameters[strtoupper($offset)]);
}

public function offsetGet($offset)
{
return $this->getParameter($offset);
}

public function offsetSet($offset, $value)
{
throw new \RuntimeException('It is not possible to change the parameters.');
}

public function offsetUnset($offset)
{
throw new \RuntimeException('It is not possible to change the parameters.');
}

/**
* Extract the sign field.
*
* @param array $parameters
* @throws \InvalidArgumentException
* @return string
*/
protected function getSignature(array $parameters)
{
if (! array_key_exists(static::SIGNATURE_FIELD, $parameters) || $parameters[static::SIGNATURE_FIELD] == '') {
throw new \InvalidArgumentException(
sprintf('Sign key (%s) not present in parameters.', static::SIGNATURE_FIELD)
);
}
return $parameters[static::SIGNATURE_FIELD];
}
}
120 changes: 120 additions & 0 deletions src/LinkORB/Buckaroo/Response/StatusResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

namespace LinkORB\Buckaroo\Response;

/**
* StatusResponse.
*
* @see PostResponse
* @author Joris van de Sande <[email protected]>
*/
class StatusResponse extends PostResponse
{
const PENDING_INPUT = 790;
const PENDING_PROCESSING = 791;
const AWAITING_CUSTOMER = 792;
const SUCCESS = 190;
const FAILED = 490;
const VALIDATION_FAILURE = 491;
const TECHNICAL_FAILURE = 492;
const CANCELLED_BY_USER = 890;
const CANCELLED_BY_MERCHANT = 891;
const REJECTED = 690;

/**
* @return string
*/
public function getTransactionKey()
{
return $this->getParameter('brq_transactions');
}

/**
* @return string
*/
public function getPayment()
{
return $this->getParameter('brq_payment');
}

/**
* @return int
*/
public function getStatusCode()
{
return (int) $this->getParameter('brq_statuscode');
}

/**
* @return bool
*/
public function isTest()
{
return $this->hasParameter('brq_test') && $this->getParameter('brq_test') === 'true';
}

/**
* @return \DateTime
*/
public function getTimestamp()
{
return new \DateTime($this->getParameter('brq_timestamp'));
}

/**
* @return string
*/
public function getInvoiceNumber()
{
return $this->getPayment('brq_invoicenumber');
}

/**
* @return bool
*/
public function isSuccess()
{
return $this->getStatusCode() == static::SUCCESS;
}

/**
* @return bool
*/
public function isFinal()
{
return ! $this->isPending();
}

/**
* @return bool
*/
public function isPending()
{
return in_array(
$this->getStatusCode(),
array(static::PENDING_INPUT, static::PENDING_PROCESSING, static::AWAITING_CUSTOMER)
);
}

/**
* @return bool
*/
public function isCancelled()
{
return in_array(
$this->getStatusCode(),
array(static::CANCELLED_BY_MERCHANT, static::CANCELLED_BY_USER)
);
}

/**
* @return bool
*/
public function isFailed()
{
return in_array(
$this->getStatusCode(),
array(static::FAILED, static::TECHNICAL_FAILURE, static::VALIDATION_FAILURE)
);
}
}
Loading

0 comments on commit 893ab03

Please sign in to comment.