Skip to content
This repository has been archived by the owner on Aug 26, 2020. It is now read-only.

Commit

Permalink
Added the ability to created a tokenized card on FAC during an author…
Browse files Browse the repository at this point in the history
…ize request.
  • Loading branch information
Derek Caswell committed Feb 17, 2017
1 parent 98bbf7f commit 60216d1
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,14 @@ protected function getEndpoint()
*/
protected function getTransactionCode()
{
return $this->getRequireAvsCheck() ? $this->transactionCode + 1 : $this->transactionCode;
$transactionCode = $this->transactionCode;
if($this->getRequireAvsCheck()) {
$transactionCode += 1;
}
if($this->getCreateCard()) {
$transactionCode += 128;
}
return $transactionCode;
}

/**
Expand All @@ -155,4 +162,22 @@ protected function newResponse($xml)
{
return new AuthorizeResponse($this, $xml);
}

/**
* @param boolean $value Create a tokenized card on FAC during an authorize request
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setCreateCard($value)
{
return $this->setParameter('createCard', $value);
}

/**
* @return boolean Create a tokenized card on FAC during an authorize request
*/
public function getCreateCard()
{
return $this->getParameter('createCard');
}
}
10 changes: 10 additions & 0 deletions src/Message/AuthorizeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,14 @@ public function getTransactionReference()
{
return isset($this->data['CreditCardTransactionResults']['ReferenceNumber']) ? $this->data['CreditCardTransactionResults']['ReferenceNumber'] : null;
}

/**
* If the createCard parameter is set to true on the authorize request this will return the token
*
* @return string|null
*/
public function getCardReference()
{
return isset($this->data['CreditCardTransactionResults']['TokenizedPAN']) ? $this->data['CreditCardTransactionResults']['TokenizedPAN'] : null;
}
}
12 changes: 12 additions & 0 deletions tests/AuthorizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


use Omnipay\FirstAtlanticCommerce\Gateway;
use Omnipay\FirstAtlanticCommerce\Message\AuthorizeResponse;
use Omnipay\Tests\GatewayTestCase;

/**
Expand Down Expand Up @@ -184,4 +185,15 @@ public function testPurchaseFailure()
$this->assertEquals('Transaction is declined.', $response->getMessage());
$this->assertEquals(307916543749, $response->getTransactionReference());
}

public function testAuthorizeWithTokenization()
{
$this->setMockHttpResponse('AuthorizeToken.txt');

/** @var AuthorizeResponse $response */
$response = $this->gateway->authorize($this->purchaseOptions)->send();

$this->assertTrue($response->isSuccessful());
$this->assertNotEmpty($response->getCardReference());
}
}
18 changes: 18 additions & 0 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


use Omnipay\FirstAtlanticCommerce\Gateway;
use Omnipay\FirstAtlanticCommerce\Message\AuthorizeResponse;
use Omnipay\FirstAtlanticCommerce\Message\CreateCardResponse;
use Omnipay\FirstAtlanticCommerce\Message\UpdateCardResponse;
use Omnipay\Tests\GatewayTestCase;
Expand Down Expand Up @@ -171,4 +172,21 @@ public function testStatus()
$this->assertTrue($statusResponse->isSuccessful());
$this->assertEquals('Transaction is approved.', $statusResponse->getMessage());
}

public function testAuthorizeWithCreateCard()
{
$transactionId = uniqid();
/** @var AuthorizeResponse $authorizeResponse */
$authorizeResponse = $this->gateway->authorize([
'amount' => '30.00',
'currency' => 'USD',
'transactionId' => $transactionId,
'card' => $this->getValidCard(),
'createCard' => true
])->send();

$this->assertTrue($authorizeResponse->isSuccessful());
$this->assertNotEmpty($authorizeResponse->getCardReference());
echo $authorizeResponse->getCardReference();
}
}
24 changes: 24 additions & 0 deletions tests/Mock/AuthorizeToken.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
HTTP/1.1 201 OK
Date: Tue, 11 Feb 2014 02:34:58 GMT
Content-type: text/html; charset=utf-8

<AuthorizeResponse xmlns="http://schemas.firstatlanticcommerce.com/gateway/data">
<ExtensionData/>
<AcquirerId>464748</AcquirerId>
<CreditCardTransactionResults>
<ExtensionData/>
<AVSResult/>
<AuthCode>123456</AuthCode>
<CVV2Result>M</CVV2Result>
<OriginalResponseCode>00</OriginalResponseCode>
<PaddedCardNumber>XXXXXXXXXXXX1111</PaddedCardNumber>
<ReasonCode>1</ReasonCode>
<ReasonCodeDescription>Transaction is approved.</ReasonCodeDescription>
<ReferenceNumber>307916543749</ReferenceNumber>
<ResponseCode>1</ResponseCode>
<TokenizedPAN>411111_000011111</TokenizedPAN>
</CreditCardTransactionResults>
<MerchangtId>123</MerchangtId>
<Signature>qx6W+o50NL4XlqH0+Z/eSx3qrCU=</Signature>
<SignatureMethod>SHA1</SignatureMethod>
</AuthorizeResponse>

0 comments on commit 60216d1

Please sign in to comment.