Skip to content

Commit

Permalink
Merge pull request #121 from academe/master
Browse files Browse the repository at this point in the history
Fix for issue #120
  • Loading branch information
judgej committed Nov 14, 2018
2 parents c36ea1e + 539b3e8 commit 4ff0114
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Message/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getTransactionReference()
// if not already in the response (it will be for Sage Pay Form).

if (! array_key_exists('VendorTxCode', $reference)) {
$reference['VendorTxCode'] = $this->getRequest()->getTransactionId();
$reference['VendorTxCode'] = $this->getTransactionId();
}

ksort($reference);
Expand Down
2 changes: 1 addition & 1 deletion src/Message/ServerCompleteAuthorizeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getTransactionReference()
{
if (isset($this->data['TxAuthNo'])) {
$reference = json_decode($this->getRequest()->getTransactionReference(), true);
$reference['VendorTxCode'] = $this->getRequest()->getTransactionId();
$reference['VendorTxCode'] = $this->getTransactionId();
$reference['TxAuthNo'] = $this->data['TxAuthNo'];

return json_encode($reference);
Expand Down
9 changes: 9 additions & 0 deletions src/Message/ServerNotifyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,13 @@ public function sendResponse($status, $nextUrl, $detail = null)
exit;
}
}

/**
* Overrides the Form/Server/Direct method since there is no
* getRequest() to inspect in a notification.
*/
public function getTransactionId()
{
return $this->getDataItem('VendorTxCode');
}
}
12 changes: 12 additions & 0 deletions src/Traits/ResponseFieldsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,16 @@ public function getExpiryYear()
return (int)$dateTime->format('Y');
}
}

/**
* The transaction ID will be returned in the data for the Form API, or
* we will have to refer to the request for the Server and Direct APIs.
*
* @return @inherit
*/
public function getTransactionId()
{
return $this->getDataItem('VendorTxCode')
?: $this->getRequest()->getTransactionId();
}
}
11 changes: 1 addition & 10 deletions src/Traits/ServerNotifyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,6 @@ public function getVPSTxId()
return $this->getDataItem('VPSTxId');
}

/**
* The VendorTxCode is POSTed - we will need this for looking up the transaction
* locally.
*/
public function getTransactionId()
{
return $this->getDataItem('VendorTxCode');
}

/**
* Gateway Reference.
*
Expand Down Expand Up @@ -188,7 +179,7 @@ public function getTransactionReference()

$reference['SecurityKey'] = $this->getSecurityKey();

$reference['VendorTxCode'] = $this->getDataItem('VendorTxCode');
$reference['VendorTxCode'] = $this->getTransactionId();

ksort($reference);

Expand Down
33 changes: 33 additions & 0 deletions tests/Message/ServerCompleteAuthorizeResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,49 @@ public function testServerCompleteAuthorizeResponseSuccess()
'DeclineCode' => '00',
'ExpiryDate' => '0722',
'BankAuthCode' => '999777',
//'VendorTxCode' => '123', <-- Not in response
)
);

// The transaction ID is set in the original request only.

$this->getMockRequest()->shouldReceive('getTransactionId')->once()->andReturn('123');
$this->getMockRequest()->shouldReceive('getTransactionReference')->once()->andReturn('{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"4255","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"438791"}');

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"b","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"123"}', $response->getTransactionReference());
$this->assertNull($response->getMessage());

//$this->assertSame('123', $response->getTransactionId());
}

public function testFormCompleteAuthorizeResponseSuccess()
{
$response = new ServerCompleteAuthorizeResponse(
$this->getMockRequest(),
array(
'Status' => 'OK',
'TxAuthNo' => 'b',
'AVSCV2' => 'c',
'AddressResult' => 'd',
'PostCodeResult' => 'e',
'CV2Result' => 'f',
'GiftAid' => 'g',
'3DSecureStatus' => 'h',
'CAVV' => 'i',
'AddressStatus' => 'j',
'PayerStatus' => 'k',
'CardType' => 'l',
'Last4Digits' => 'm',
'DeclineCode' => '00',
'ExpiryDate' => '0722',
'BankAuthCode' => '999777',
'VendorTxCode' => '123', // In response
)
);

$this->assertSame('123', $response->getTransactionId());
}

public function testServerCompleteAuthorizeResponseFailure()
Expand Down

0 comments on commit 4ff0114

Please sign in to comment.