-
Notifications
You must be signed in to change notification settings - Fork 0
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 #13 from academe/issue12
See Issue #12 Changes to `completeAuthorize()` and `completePurchase()` to ensure the results of the transaction the user returns with is the transaction the application was expecting. The authorization will not show as successful unless the `transactionId` matches.
- Loading branch information
Showing
10 changed files
with
695 additions
and
361 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
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,73 @@ | ||
<?php | ||
|
||
namespace Omnipay\Wirecard\Message\Checkout\Page; | ||
|
||
/** | ||
* Complete a Wirecard Checkout Page purchase transaction on the | ||
* user returning to the merchant shop. | ||
* Experimentally, this one class covers both the request and the response, | ||
* since not further requests back to the gateway are needed. | ||
* The advantage of doing this is that all the results needed are in the | ||
* initial request object. A merchant site can still send() that message | ||
* and get the same message back. | ||
* It should be possible to extend this as the notification handler too. If | ||
* so, then the HasFingerprintTrait becomes redundant. | ||
*/ | ||
|
||
use Omnipay\Common\Message\ResponseInterface as OmnipayResponseInterface; | ||
use Omnipay\Wirecard\Message\Checkout\AbstractRequest; | ||
use Omnipay\Wirecard\Message\AbstractResponse; | ||
use Omnipay\Wirecard\Message\HasDataTrait; | ||
|
||
class CompleteRequest extends AbstractRequest | ||
{ | ||
use HasDataTrait; | ||
|
||
/** | ||
* @inheric | ||
*/ | ||
public function getData() | ||
{ | ||
return $this->httpRequest->request->all(); | ||
} | ||
|
||
/** | ||
* Create a new Response message given the raw data in the response. | ||
*/ | ||
protected function createResponse($data) | ||
{ | ||
$this->validate('secret', 'transactionId'); | ||
|
||
$this->response = new CompleteResponse($this, $this->getData()); | ||
|
||
// Set the original transactionId and the secret, both for | ||
// validating the response. | ||
|
||
//$this->response->setOriginalTransactionId($this->getTransactionId()); | ||
//$this->response->setSecret($this->getSecret()); | ||
|
||
return $this->response; | ||
} | ||
|
||
/** | ||
* The secret for hashing. | ||
*/ | ||
public function setSecret($value) | ||
{ | ||
return $this->setParameter('secret', $value); | ||
} | ||
|
||
public function getSecret() | ||
{ | ||
return $this->getParameter('secret'); | ||
} | ||
|
||
/** | ||
* The transaction ID supplied by the gateway, in case the | ||
* application needs to look it up before calling send(). | ||
*/ | ||
public function getOriginalTransactionId() | ||
{ | ||
return $this->getDataValue(AbstractRequest::CUSTOM_FIELD_NAME_TRANSACTION_ID); | ||
} | ||
} |
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,90 @@ | ||
<?php | ||
|
||
namespace Omnipay\Wirecard\Message\Checkout\Page; | ||
|
||
/** | ||
* Complete a Wirecard Checkout Page purchase transaction on the | ||
* user returning to the merchant shop. | ||
* Experimentally, this one class covers both the request and the response, | ||
* since not further requests back to the gateway are needed. | ||
* The advantage of doing this is that all the results needed are in the | ||
* initial request object. A merchant site can still send() that message | ||
* and get the same message back. | ||
* It should be possible to extend this as the notification handler too. If | ||
* so, then the HasFingerprintTrait becomes redundant. | ||
*/ | ||
|
||
use Omnipay\Common\Message\AbstractResponse as OmnipayAbstractResponse; | ||
use Omnipay\Wirecard\Message\Checkout\AbstractRequest; | ||
use Omnipay\Wirecard\Message\AbstractResponse; | ||
use Omnipay\Wirecard\Message\HasDataTrait; | ||
use Omnipay\Wirecard\Message\HandlesNotificationTrait; | ||
|
||
class CompleteResponse extends OmnipayAbstractResponse | ||
{ | ||
use HasDataTrait; | ||
use HandlesNotificationTrait; | ||
|
||
protected $transactionIdCheckEnabled = true; | ||
|
||
protected $originalTransactionId; | ||
protected $secret; | ||
|
||
public function isRedirect() | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* The secret for hashing to check the signature. | ||
* Overrides the secret in the request. | ||
* | ||
* @return $this | ||
*/ | ||
public function setSecret($value) | ||
{ | ||
$this->secret = $value; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Use the override secret if set, otherwise attempt to get the | ||
* secret from the request, if the request supports the secret. | ||
* | ||
* @return string|null | ||
*/ | ||
public function getSecret() | ||
{ | ||
if ($this->secret) { | ||
return $this->secret; | ||
} | ||
|
||
if (method_exists($this->getRequest(), 'getSecret')) { | ||
return $this->getRequest()->getSecret(); | ||
} | ||
} | ||
|
||
/** | ||
* The original transactionId that we are expecting to get back. | ||
*/ | ||
public function setOriginalTransactionId($value) | ||
{ | ||
$this->originalTransactionId = $value; | ||
return $this; | ||
} | ||
|
||
public function getOriginalTransactionId() | ||
{ | ||
return $this->originalTransactionId | ||
?? $this->getRequest()->getTransactionId(); | ||
} | ||
|
||
/** | ||
* @inherit | ||
*/ | ||
public function isExpectedTransactionId() | ||
{ | ||
return $this->getTransactionId() | ||
&& $this->getTransactionId() === $this->getOriginalTransactionId(); | ||
} | ||
} |
Oops, something went wrong.