Skip to content

Commit 16140f8

Browse files
committed
Merge branch 'master' of github.com:thephpleague/omnipay-authorizenet
Conflicts: src/AIMGateway.php src/Message/SIMAbstractRequest.php
2 parents cf540fa + ccf3229 commit 16140f8

24 files changed

+1053
-36
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The following gateways are provided by this package:
3434
* AuthorizeNet_AIM
3535
* AuthorizeNet_CIM
3636
* AuthorizeNet_SIM
37+
* AuthorizeNet_DPM
3738

3839
For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay)
3940
repository.

src/AIMGateway.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ public function getName()
2222
public function getDefaultParameters()
2323
{
2424
return array(
25-
'apiLoginId' => '',
26-
'transactionKey' => '',
27-
'testMode' => false,
28-
'developerMode' => false,
25+
'apiLoginId' => '',
26+
'transactionKey' => '',
27+
'testMode' => false,
28+
'developerMode' => false,
29+
'liveEndpoint' => 'https://api.authorize.net/xml/v1/request.api',
30+
'developerEndpoint' => 'https://apitest.authorize.net/xml/v1/request.api',
2931
);
3032
}
3133

@@ -59,6 +61,32 @@ public function setDeveloperMode($value)
5961
return $this->setParameter('developerMode', $value);
6062
}
6163

64+
public function setEndpoints($endpoints)
65+
{
66+
$this->setParameter('liveEndpoint', $endpoints['live']);
67+
return $this->setParameter('developerEndpoint', $endpoints['developer']);
68+
}
69+
70+
public function getLiveEndpoint()
71+
{
72+
return $this->getParameter('liveEndpoint');
73+
}
74+
75+
public function setLiveEndpoint($value)
76+
{
77+
return $this->setParameter('liveEndpoint', $value);
78+
}
79+
80+
public function getDeveloperEndpoint()
81+
{
82+
return $this->getParameter('developerEndpoint');
83+
}
84+
85+
public function setDeveloperEndpoint($value)
86+
{
87+
return $this->setParameter('developerEndpoint', $value);
88+
}
89+
6290
/**
6391
* @param array $parameters
6492
* @return AIMAuthorizeRequest

src/CIMGateway.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@ class CIMGateway extends AIMGateway
1111
{
1212
public function getDefaultParameters()
1313
{
14-
return array(
15-
'apiLoginId' => '',
16-
'transactionKey' => '',
17-
'testMode' => false,
18-
'developerMode' => false,
19-
'forceCardUpdate' => false,
20-
'defaultBillTo' => array(array())
21-
);
14+
$params = parent::getDefaultParameters();
15+
$params['forceCardUpdate'] = false;
16+
$params['defaultBillTo'] = array(array());
17+
return $params;
2218
}
2319

2420
public function getName()

src/DPMGateway.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet;
4+
5+
/**
6+
* Authorize.Net DPM (Direct Post Method) Class
7+
*/
8+
class DPMGateway extends SIMGateway
9+
{
10+
public function getName()
11+
{
12+
return 'Authorize.Net DPM';
13+
}
14+
15+
/**
16+
* Helper to generate the authorize direct-post form.
17+
*/
18+
public function authorize(array $parameters = array())
19+
{
20+
return $this->createRequest('\Omnipay\AuthorizeNet\Message\DPMAuthorizeRequest', $parameters);
21+
}
22+
23+
/**
24+
* Get, validate, interpret and respond to the Authorize.Net callback.
25+
*/
26+
public function completeAuthorize(array $parameters = array())
27+
{
28+
return $this->createRequest('\Omnipay\AuthorizeNet\Message\DPMCompleteRequest', $parameters);
29+
}
30+
31+
/**
32+
* Helper to generate the purchase direct-post form.
33+
*/
34+
public function purchase(array $parameters = array())
35+
{
36+
return $this->createRequest('\Omnipay\AuthorizeNet\Message\DPMPurchaseRequest', $parameters);
37+
}
38+
39+
/**
40+
* Get, validate, interpret and respond to the Authorize.Net callback.
41+
*/
42+
public function completePurchase(array $parameters = array())
43+
{
44+
return $this->createRequest('\Omnipay\AuthorizeNet\Message\DPMCompleteRequest', $parameters);
45+
}
46+
}

src/Message/AIMAbstractRequest.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
*/
1212
abstract class AIMAbstractRequest extends AbstractRequest
1313
{
14-
protected $liveEndpoint = 'https://api.authorize.net/xml/v1/request.api';
15-
protected $developerEndpoint = 'https://apitest.authorize.net/xml/v1/request.api';
16-
1714
protected $action = null;
1815

1916
public function getApiLoginId()
@@ -146,8 +143,28 @@ public function sendData($data)
146143
return $this->response = new AIMResponse($this, $httpResponse->getBody());
147144
}
148145

146+
public function getLiveEndpoint()
147+
{
148+
return $this->getParameter('liveEndpoint');
149+
}
150+
151+
public function setLiveEndpoint($value)
152+
{
153+
return $this->setParameter('liveEndpoint', $value);
154+
}
155+
156+
public function getDeveloperEndpoint()
157+
{
158+
return $this->getParameter('developerEndpoint');
159+
}
160+
161+
public function setDeveloperEndpoint($value)
162+
{
163+
return $this->setParameter('developerEndpoint', $value);
164+
}
165+
149166
public function getEndpoint()
150167
{
151-
return $this->getDeveloperMode() ? $this->developerEndpoint : $this->liveEndpoint;
168+
return $this->getDeveloperMode() ? $this->getDeveloperEndpoint() : $this->getLiveEndpoint();
152169
}
153170
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet\Message;
4+
5+
/**
6+
* Authorize.Net DPM Authorize Request.
7+
* Takes the data that will be used to create the direct-post form.
8+
*/
9+
class DPMAuthorizeRequest extends SIMAuthorizeRequest
10+
{
11+
protected $action = 'AUTH_ONLY';
12+
13+
public function getData()
14+
{
15+
$data = parent::getData();
16+
17+
// If x_show_form is set, then the form will be displayed on the Authorize.Net
18+
// gateway, in a similar way to the SIM gateway. The DPM documentation does NOT
19+
// make this clear at all.
20+
// Since x_show_form is set in the SIM gateway, make sure we unset it here.
21+
22+
unset($data['x_show_form']);
23+
24+
// Must be set for DPM.
25+
// This directs all errors to the relay response.
26+
27+
$data['x_relay_always'] = 'TRUE';
28+
29+
// The card details are optional.
30+
// They will most likely only be used for development and testing.
31+
// The card fields are still needed in the direct-post form regardless.
32+
33+
if ($this->getCard()) {
34+
$data['x_card_num'] = $this->getCard()->getNumber();
35+
36+
// Workaround for https://github.com/thephpleague/omnipay-common/issues/29
37+
$expiry_date = $this->getCard()->getExpiryDate('my');
38+
$data['x_exp_date'] = ($expiry_date === '1299' ? '' : $expiry_date);
39+
40+
$data['x_card_code'] = $this->getCard()->getCvv();
41+
} else {
42+
$data['x_card_num'] = '';
43+
$data['x_exp_date'] = '';
44+
$data['x_card_code'] = '';
45+
}
46+
47+
return $data;
48+
}
49+
50+
51+
/**
52+
* Given the DPM data, we want to turn it into a form for the user to submit to Authorize.net
53+
* The form may have most of the fields hidden, or may allow the user to change some details -
54+
* that depends on the use-case.
55+
* So this method will provide us with an object used to build the form.
56+
*/
57+
public function sendData($data)
58+
{
59+
return $this->response = new DPMResponse($this, $data, $this->getEndpoint());
60+
}
61+
}

src/Message/DPMCompleteRequest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet\Message;
4+
5+
use Omnipay\Common\Exception\InvalidRequestException;
6+
7+
/**
8+
* Authorize.Net DPM Complete Authorize Request
9+
*/
10+
class DPMCompleteRequest extends SIMCompleteAuthorizeRequest
11+
{
12+
public function sendData($data)
13+
{
14+
return $this->response = new DPMCompleteResponse($this, $data);
15+
}
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet\Message;
4+
5+
/**
6+
* SIM and DPM both have identical needs when handling the notify request.
7+
*/
8+
class DPMCompleteResponse extends SIMCompleteAuthorizeResponse
9+
{
10+
}

src/Message/DPMPurchaseRequest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet\Message;
4+
5+
/**
6+
* Authorize.Net DPM Purchase Request (aka "Authorize and Capture")
7+
*/
8+
class DPMPurchaseRequest extends DPMAuthorizeRequest
9+
{
10+
protected $action = 'AUTH_CAPTURE';
11+
}

0 commit comments

Comments
 (0)