Skip to content

Commit

Permalink
Don't use HTTP data directly to get the data
Browse files Browse the repository at this point in the history
  • Loading branch information
MujibAzizi committed Mar 25, 2015
1 parent e1ed344 commit 6c8cf52
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
54 changes: 46 additions & 8 deletions src/Omnipay/Adyen/Message/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,65 @@ class CompletePurchaseRequest extends PurchaseRequest
{
public function getData()
{
return $this->httpRequest->request->all();
$data = array();

$data['authResult'] = $this->getAuthResult();
$data['pspReference'] = $this->getPspReference();
$data['merchantReference'] = $this->getMerchantReference();
$data['skinCode'] = $this->getSkinCode();
$data['merchantSig'] = $this->generateResponseSignature();

return $data;
}

public function getAuthResult()
{
return $this->httpRequest->query->get('authResult');
return $this->getParameter('authResult');
}

public function setAuthResult($value)
{
return $this->setParameter('authResult', $value);
}

public function getPspReference()
{
return $this->httpRequest->query->get('pspReference');
return $this->getParameter('pspReference');
}

public function setPspReference($value)
{
return $this->setParameter('pspReference', $value);
}

public function getMerchantReference()
{
return $this->httpRequest->query->get('merchantReference');
return $this->getParameter('merchantReference');
}

public function setMerchantReference($value)
{
return $this->setParameter('merchantReference', $value);
}

public function getSkinCode()
{
return $this->httpRequest->query->get('skinCode');
return $this->getParameter('skinCode');
}

public function setSkinCode($value)
{
return $this->setParameter('skinCode', $value);
}

public function getMerchantReturnData()
{
return $this->httpRequest->query->get('merchantReturnData');
return $this->getParameter('merchantReturnData');
}

public function setMerchantReturnData($value)
{
return $this->setParameter('merchantReturnData', $value);
}

public function generateResponseSignature()
Expand All @@ -56,10 +89,15 @@ public function generateResponseSignature()
public function send()
{
$data = $this->getData();
$data['success'] = ('AUTHORISED' == $this->httpRequest->query->get('authResult')) ? true : false;
$data['allParams'] = $this->httpRequest->query->all();
$data['success'] = $this->isSuccessful();
$data['allParams'] = $this->getData();
$data['responseSignature'] = $this->generateResponseSignature();

return new CompletePurchaseResponse($this, $data);
}

public function isSuccessful()
{
return (bool) (strpos($this->getAuthResult(), 'AUTHROIS') + 1);
}
}
18 changes: 11 additions & 7 deletions tests/Omnipay/Adyen/Message/CompletePurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,29 @@ class CompletePurchaseRequestTest extends TestCase
{
public function setUp()
{
$this->getHttpRequest()->initialize(array(
$this->request = new CompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(array(
'secret' => 'Kah942*$7sdp0)',
'authResult' => 'AUTHORISED',
'pspReference' => '1211992213193029',
'merchantReference' => 'Internet Order 12345',
'skinCode' => '4aD37dJA',
'merchantReturnData' => '',
));

$this->request = new CompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(array(
'secret' => 'Kah942*$7sdp0)'
));
}

public function testGetData()
{

$data = $this->request->getData();
$this->assertSame($this->getHttpRequest()->request->all(), $data);

$this->assertSame(array (
'authResult' => 'AUTHORISED',
'pspReference' => '1211992213193029',
'merchantReference' => 'Internet Order 12345',
'skinCode' => '4aD37dJA',
'merchantSig' => 'ytt3QxWoEhAskUzUne0P5VA9lPw=',
), $data);

}

Expand Down

0 comments on commit 6c8cf52

Please sign in to comment.