Skip to content

Support for Accept.js #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/Message/AIMAbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,44 @@ public function setInvoiceNumber($value)
return $this->setParameter('invoiceNumber', $value);
}

/**
* @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data
* @return string
*/
public function getOpaqueDataDescriptor()
{
return $this->getParameter('opaqueDataDescriptor');
}

/**
* @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data
* @return string
*/
public function getOpaqueDataValue()
{
return $this->getParameter('opaqueDataValue');
}

/**
* @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data
* @param string
* @return string
*/
public function setOpaqueDataDescriptor($value)
{
return $this->setParameter('opaqueDataDescriptor', $value);
}

/**
* @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data
* @param string
* @return string
*/
public function setOpaqueDataValue($value)
{
return $this->setParameter('opaqueDataValue', $value);
}

public function sendData($data)
{
$headers = array('Content-Type' => 'text/xml; charset=utf-8');
Expand Down
9 changes: 9 additions & 0 deletions src/Message/AIMAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ public function getData()

protected function addPayment(\SimpleXMLElement $data)
{
/**
* @link http://developer.authorize.net/api/reference/features/acceptjs.html Documentation on opaque data
*/
if ($this->getOpaqueDataDescriptor() && $this->getOpaqueDataValue()) {
$data->transactionRequest->payment->opaqueData->dataDescriptor = $this->getOpaqueDataDescriptor();
$data->transactionRequest->payment->opaqueData->dataValue = $this->getOpaqueDataValue();
return;
}

$this->validate('card');
/** @var CreditCard $card */
$card = $this->getCard();
Expand Down
11 changes: 11 additions & 0 deletions tests/Message/AIMAuthorizeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ public function testGetDataTestMode()
$this->assertEquals('true', $setting->settingValue);
}

public function testGetDataOpaqueData()
{
$this->request->setOpaqueDataDescriptor('COMMON.ACCEPT.INAPP.PAYMENT');
$this->request->setOpaqueDataValue('jb2RlIjoiNTB');

$data = $this->request->getData();

$this->assertEquals('COMMON.ACCEPT.INAPP.PAYMENT', $data->transactionRequest->payment->opaqueData->dataDescriptor);
$this->assertEquals('jb2RlIjoiNTB', $data->transactionRequest->payment->opaqueData->dataValue);
}

public function testShouldIncludeDuplicateWindowSetting()
{
$data = $this->request->getData();
Expand Down
10 changes: 10 additions & 0 deletions tests/Message/AIMResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public function testAuthorizeInvalid()
$this->assertSame('', $response->getAVSCode());
}

public function testAuthorizeInvalidOTSToken()
{
$httpResponse = $this->getMockHttpResponse('AIMAuthorizeInvalidOTSToken.txt');
$response = new AIMResponse($this->getMockRequest(), $httpResponse->getBody());

$this->assertFalse($response->isSuccessful());
$this->assertSame('E00114', $response->getReasonCode());
$this->assertSame('Invalid OTS Token.', $response->getMessage());
}

public function testCaptureSuccess()
{
$httpResponse = $this->getMockHttpResponse('AIMCaptureSuccess.txt');
Expand Down
13 changes: 13 additions & 0 deletions tests/Mock/AIMAuthorizeInvalidOTSToken.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
HTTP/1.1 200 OK
Date: Sat, 02 Aug 2014 05:20:38 GMT
Server: Microsoft-IIS/6.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: x-requested-with, cache-control, content-type, origin, method
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Content-Length: 844

<?xml version="1.0" encoding="utf-8"?><createTransactionResponse><messages><resultCode>Error</resultCode><message><code>E00114</code><text>Invalid OTS Token.</text></message></messages><transactionResponse/></createTransactionResponse>