-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from AngeloG/master
Signed status response code from @jvandesande and fixed bug with invalid locales, updated example to use iDEAL v2
- Loading branch information
Showing
19 changed files
with
722 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} | ||
} |
Oops, something went wrong.