Skip to content
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

Using the XML API for AIM gateway #6

Closed
wants to merge 72 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
d584200
Completely separated AIM and SIM classes. Updated AIM to use the new …
anush Aug 2, 2014
7c7578b
AIM request classes construct XML requests
anush Aug 2, 2014
f055372
PSR-2 formatting
anush Aug 2, 2014
69fe39d
Removed missed dependencies between AIM and SIM
anush Aug 2, 2014
69eb1c4
Added functional tests
anush Aug 2, 2014
426bc3f
Update AuthorizeNet_AIM to support refunds
rushi Aug 13, 2014
47f47be
Add tests for success and failure responses in AIMGatewayTest
rushi Aug 13, 2014
9f078db
Remove support for description attribute. This is because description…
rushi Aug 13, 2014
e17f7a7
Decouple SIMGateway from AIMGateway
rushi Aug 13, 2014
00d0f8e
Code formatting
anush Aug 14, 2014
881d9d4
Code formatting
anush Aug 14, 2014
c121250
Do not validate credit card for Refund transactions because it is not…
rushi Aug 18, 2014
2e39772
Merge pull request #2 from rushi/master
rushi Aug 18, 2014
4426ff1
CC last 4 to string
rushi Aug 18, 2014
7c2b2c0
CC last 4 to string
rushi Aug 18, 2014
0f5f96d
Create card implemented with integration test for Authorize.net CIM
kotrakrishna Sep 16, 2014
d1b6501
Abstract out common method for CIM requests
kotrakrishna Sep 17, 2014
f7abefc
Implement all transactions in CIM Gateway
kotrakrishna Sep 17, 2014
9d43913
Add unit tests using mocks. CIM response also checks and parses Error…
kotrakrishna Sep 18, 2014
6ad83f6
Clean up logging used during development
kotrakrishna Sep 18, 2014
58e4de3
Use Developer mode rather than test mode for setting the dev context …
kotrakrishna Sep 18, 2014
de9ef97
Use customer shipping address id only if present while making a tran…
kotrakrishna Sep 18, 2014
87e594d
If create card fails due to duplicate profile error, then create a pa…
kotrakrishna Sep 19, 2014
b076d75
Unit test using mocks for get profile, update payment profile
kotrakrishna Sep 22, 2014
9967d32
Add forceCardUpdate parameter to createCard.
kotrakrishna Sep 23, 2014
d697e2f
Create card will always return customer profile as response. Card ref…
kotrakrishna Sep 23, 2014
c7022a5
Create card always returns response of a perticular payment profile
kotrakrishna Sep 23, 2014
d398f93
Response is always an array. Create card response is augmented with f…
kotrakrishna Sep 26, 2014
808e673
Add expiry month and expiry year to the CIM create card response.
kotrakrishna Sep 26, 2014
5084452
Merge pull request #1 from kotrakrishna/master
rushi Nov 13, 2014
5efb7c2
Cleanup code, fix failing unit tests
rushi Nov 13, 2014
c6b1e3f
Move dependencies into require-dev
rushi Nov 13, 2014
a95b5ca
Fix xml2array and issues that arise because of it.
rushi Nov 14, 2014
169edbd
Do not format the amount as it voids the XML schema.
rushi Nov 14, 2014
e9e0c44
Fix duplicate payment profile handling
rushi Nov 17, 2014
81343c3
Update unit tests
rushi Nov 17, 2014
36d7c3a
Remove dev dependencies that are no longer required
rushi Nov 19, 2014
a57d213
Merge pull request #4 from rushi/master
juzerali Nov 25, 2014
e1e590c
Fix PSR-2 issues
rushi Nov 27, 2014
e8e986e
Update README.md to include mention of AuthorizeNet_CIM
rushi Nov 27, 2014
6ca8e75
Add ability to specify custom 'billTo' information
rushi Jan 28, 2015
9a227cc
Change populateBillTo to defaultBillTo. Set flags at a gateway level
rushi Jan 28, 2015
d4ff08b
Merge pull request #5 from rushi/master
anush Jan 28, 2015
1287a3f
Merge remote-tracking branch 'origin/master'
anush Mar 22, 2015
8fb8087
PHP 5.3 compatible array style
anush Mar 22, 2015
cf540fa
PHP 5.3 compatible array style
anush Mar 22, 2015
16140f8
Merge branch 'master' of github.com:thephpleague/omnipay-authorizenet
anush Aug 20, 2015
70e6c9c
XOL-2533 Adding extraOptions payload to request XML
sachinsudheendra Aug 27, 2015
87a39f0
XOL-2533 Parameterizing x_duplicate_window value and using it across …
sachinsudheendra Aug 28, 2015
6bfdef7
XOL-2533 Using the value of the parameter passed in for x_duplicate_w…
sachinsudheendra Sep 10, 2015
9344b3e
Merge pull request #7 from sachinsudheendra/XOL-2533
rushi Sep 10, 2015
9af958e
Fix CodeSniffer issue. Line should be <= 120 chars
rushi Feb 23, 2016
131d7cf
Fix test that failed due to change in SIMGateway's parent
rushi Feb 23, 2016
44e7a06
SIMGateway should inherit AIMGateway
rushi Feb 23, 2016
84b2c3f
Make CVV optional
anush Feb 29, 2016
90329a3
Merge pull request #9 from rushi/fix_codesniffer
anush Feb 29, 2016
6f24297
Merge branch 'master' of github.com:xola/authorizenet into optional-cvv
anush Feb 29, 2016
a0de700
Fix codesniffer and namespace issues
rushi Mar 1, 2016
35fc3a7
Do not validate card if no cvv provided
anush Mar 1, 2016
68d4382
CS-137 Look for duplicate payment profiles even if you reach maximum …
rushi Mar 2, 2016
4d5c93a
CS-137 Use PHP 5.3 array() syntax so tests pass
rushi Mar 2, 2016
d1e7f10
CS-137 Add tests for verification of duplicate payment profile logic
rushi Mar 2, 2016
10442c6
CS-137 Set constants for the profile response codes
rushi Mar 2, 2016
d9d1156
Merge pull request #11 from rushi/CS-137
anush Mar 2, 2016
0d5b940
XOL-2788 Ability to void a transaction and auto-void if refund fails
rushi Mar 3, 2016
b6edd12
XOL-2788 Fix transactionReference bug
rushi Mar 3, 2016
599386e
XOL-2788 Fix array syntax for PHP 5.3 compatibility
rushi Mar 3, 2016
2b5ad5e
Merge branch 'master' of github.com:xola/authorizenet into optional-cvv
rushi Mar 3, 2016
adfd19b
Merge pull request #10 from anushr/optional-cvv
rushi Mar 3, 2016
f9f1397
XOL-2788 Update test name
rushi Mar 3, 2016
c7d9a71
XOL-2788 Address code review comment
rushi Mar 3, 2016
f4fc378
Merge pull request #12 from rushi/XOL-2788
anush Mar 4, 2016
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
composer.lock
composer.phar
phpunit.xml
.idea
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ And run composer to update your dependencies:
The following gateways are provided by this package:

* AuthorizeNet_AIM
* AuthorizeNet_CIM
* AuthorizeNet_SIM
* AuthorizeNet_DPM

Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@
"homepage": "https://github.com/thephpleague/omnipay-authorizenet/contributors"
}
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/xola/omnipay-common"
}
],
"autoload": {
"psr-4": { "Omnipay\\AuthorizeNet\\" : "src/" }
},
"require": {
"omnipay/common": "~2.0"
"omnipay/common": "~2.4.2"
},
"require-dev": {
"omnipay/tests": "~2.0"
Expand Down
31 changes: 28 additions & 3 deletions src/AIMGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace Omnipay\AuthorizeNet;

use Omnipay\AuthorizeNet\Message\AIMAuthorizeRequest;
use Omnipay\AuthorizeNet\Message\AIMCaptureRequest;
use Omnipay\AuthorizeNet\Message\AIMPurchaseRequest;
use Omnipay\AuthorizeNet\Message\AIMRefundRequest;
use Omnipay\AuthorizeNet\Message\AIMVoidRequest;
use Omnipay\Common\AbstractGateway;

/**
Expand All @@ -21,8 +26,8 @@ public function getDefaultParameters()
'transactionKey' => '',
'testMode' => false,
'developerMode' => false,
'liveEndpoint' => 'https://secure2.authorize.net/gateway/transact.dll',
'developerEndpoint' => 'https://test.authorize.net/gateway/transact.dll',
'liveEndpoint' => 'https://api.authorize.net/xml/v1/request.api',
'developerEndpoint' => 'https://apitest.authorize.net/xml/v1/request.api',
);
}

Expand Down Expand Up @@ -82,26 +87,46 @@ public function setDeveloperEndpoint($value)
return $this->setParameter('developerEndpoint', $value);
}

/**
* @param array $parameters
* @return AIMAuthorizeRequest
*/
public function authorize(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMAuthorizeRequest', $parameters);
}

/**
* @param array $parameters
* @return AIMCaptureRequest
*/
public function capture(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CaptureRequest', $parameters);
return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMCaptureRequest', $parameters);
}

/**
* @param array $parameters
* @return AIMPurchaseRequest
*/
public function purchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMPurchaseRequest', $parameters);
}

/**
* @param array $parameters
* @return AIMVoidRequest
*/
public function void(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMVoidRequest', $parameters);
}

/**
* @param array $parameters
* @return AIMRefundRequest
*/
public function refund(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\AIMRefundRequest', $parameters);
Expand Down
81 changes: 81 additions & 0 deletions src/CIMGateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Omnipay\AuthorizeNet;

use Omnipay\AuthorizeNet\Message\CIMCreateCardRequest;

/**
* Authorize.Net CIM Class
*/
class CIMGateway extends AIMGateway
{
public function getDefaultParameters()
{
$params = parent::getDefaultParameters();
$params['forceCardUpdate'] = false;
$params['defaultBillTo'] = array(array());
return $params;
}

public function getName()
{
return 'Authorize.Net CIM';
}

public function setForceCardUpdate($forceCardUpdate)
{
return $this->setParameter('forceCardUpdate', $forceCardUpdate);
}

public function getForceCardUpdate()
{
return $this->getParameter('forceCardUpdate');
}

public function setDefaultBillTo($defaultBillTo)
{
return $this->setParameter('defaultBillTo', $defaultBillTo);
}

public function getDefaultBillTo()
{
return $this->getParameter('defaultBillTo');
}

/**
* Create a new debit or credit card
*
* @param array $parameters
*
* @return CIMCreateCardRequest
*/
public function createCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMCreateCardRequest', $parameters);
}

public function authorize(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMAuthorizeRequest', $parameters);
}

public function capture(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMCaptureRequest', $parameters);
}

public function purchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMPurchaseRequest', $parameters);
}

public function refund(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMRefundRequest', $parameters);
}

public function void(array $parameters = array())
{
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMVoidRequest', $parameters);
}
}
201 changes: 201 additions & 0 deletions src/Message/AIMAbstractRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
<?php

namespace Omnipay\AuthorizeNet\Message;

use Omnipay\Common\CreditCard;
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Message\AbstractRequest;

/**
* Authorize.Net AIM Abstract Request
*/
abstract class AIMAbstractRequest extends AbstractRequest
{
protected $action = null;

public function getApiLoginId()
{
return $this->getParameter('apiLoginId');
}

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

public function getTransactionKey()
{
return $this->getParameter('transactionKey');
}

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

public function getDeveloperMode()
{
return $this->getParameter('developerMode');
}

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

public function getCustomerId()
{
return $this->getParameter('customerId');
}

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

public function getHashSecret()
{
return $this->getParameter('hashSecret');
}
public function setHashSecret($value)
{
return $this->setParameter('hashSecret', $value);
}

public function setDuplicateWindow($value)
{
$this->setParameter('duplicateWindow', $value);
}

private function getDuplicateWindow()
{
return $this->getParameter('duplicateWindow'); // Maps x_duplicate_window
}

protected function addExtraOptions(\SimpleXMLElement $data)
{
if (!is_null($this->getDuplicateWindow())) {
$extraOptions = $data->addChild('extraOptions');
$node = dom_import_simplexml($extraOptions);
$nodeOwner = $node->ownerDocument;
$duplicateWindowStr = sprintf("x_duplicate_window=%s", $this->getDuplicateWindow());
$node->appendChild($nodeOwner->createCDATASection($duplicateWindowStr));
}
return $data;
}

/**
* @return mixed|\SimpleXMLElement
* @throws \Omnipay\Common\Exception\InvalidRequestException
*/
public function getBaseData()
{
$data = new \SimpleXMLElement('<createTransactionRequest/>');
$data->addAttribute('xmlns', 'AnetApi/xml/v1/schema/AnetApiSchema.xsd');

// Credentials
$data->merchantAuthentication->name = $this->getApiLoginId();
$data->merchantAuthentication->transactionKey = $this->getTransactionKey();

// User-assigned transaction ID
$txnId = $this->getTransactionId();
if (!empty($txnId)) {
$data->refId = $this->getTransactionId();
}

// Transaction type
if (!$this->action) {
// The extending class probably hasn't specified an "action"
throw new InvalidRequestException();
}
$data->transactionRequest->transactionType = $this->action;

return $data;
}

/**
* Adds billing data to a partially filled request data object.
*
* @param \SimpleXMLElement $data
*
* @return \SimpleXMLElement
*/
protected function addBillingData(\SimpleXMLElement $data)
{
/** @var mixed $req */
$req = $data->transactionRequest;

// Merchant assigned customer ID
$customer = $this->getCustomerId();
if (!empty($customer)) {
$req->customer->id = $customer;
}

/** @var CreditCard $card */
if ($card = $this->getCard()) {
// A card is present, so include billing and shipping details
$req->billTo->firstName = $card->getBillingFirstName();
$req->billTo->lastName = $card->getBillingLastName();
$req->billTo->company = $card->getBillingCompany();
$req->billTo->address = trim($card->getBillingAddress1() . " \n" . $card->getBillingAddress2());
$req->billTo->city = $card->getBillingCity();
$req->billTo->state = $card->getBillingState();
$req->billTo->zip = $card->getBillingPostcode();
$req->billTo->country = $card->getBillingCountry();

$req->shipTo->firstName = $card->getShippingLastName();
$req->shipTo->lastName = $card->getShippingLastName();
$req->shipTo->company = $card->getShippingCompany();
$req->shipTo->address = trim($card->getShippingAddress1() . " \n" . $card->getShippingAddress2());
$req->shipTo->city = $card->getShippingCity();
$req->shipTo->state = $card->getShippingState();
$req->shipTo->zip = $card->getShippingPostcode();
$req->shipTo->country = $card->getShippingCountry();
}

return $data;
}

protected function addTestModeSetting(\SimpleXMLElement $data)
{
// Test mode setting
$data->transactionRequest->transactionSettings->setting->settingName = 'testRequest';
$data->transactionRequest->transactionSettings->setting->settingValue = $this->getTestMode() ? 'true' : 'false';

return $data;
}

public function sendData($data)
{
$headers = array('Content-Type' => 'text/xml; charset=utf-8');
$data = $data->saveXml();
$httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send();

return $this->response = new AIMResponse($this, $httpResponse->getBody());
}

public function getLiveEndpoint()
{
return $this->getParameter('liveEndpoint');
}

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

public function getDeveloperEndpoint()
{
return $this->getParameter('developerEndpoint');
}

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

public function getEndpoint()
{
return $this->getDeveloperMode() ? $this->getDeveloperEndpoint() : $this->getLiveEndpoint();
}
}
Loading