Skip to content

Commit d4ff08b

Browse files
committed
Merge pull request thephpleague#5 from rushi/master
Add ability to specify custom 'billTo' information
2 parents e8e986e + 9a227cc commit d4ff08b

File tree

6 files changed

+106
-6
lines changed

6 files changed

+106
-6
lines changed

src/CIMGateway.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,43 @@
99
*/
1010
class CIMGateway extends AIMGateway
1111
{
12+
public function getDefaultParameters()
13+
{
14+
return array(
15+
'apiLoginId' => '',
16+
'transactionKey' => '',
17+
'testMode' => false,
18+
'developerMode' => false,
19+
'forceCardUpdate' => false,
20+
'defaultBillTo' => [[]]
21+
);
22+
}
23+
1224
public function getName()
1325
{
1426
return 'Authorize.Net CIM';
1527
}
1628

29+
public function setForceCardUpdate($forceCardUpdate)
30+
{
31+
return $this->setParameter('forceCardUpdate', $forceCardUpdate);
32+
}
33+
34+
public function getForceCardUpdate()
35+
{
36+
return $this->getParameter('forceCardUpdate');
37+
}
38+
39+
public function setDefaultBillTo($defaultBillTo)
40+
{
41+
return $this->setParameter('defaultBillTo', $defaultBillTo);
42+
}
43+
44+
public function getDefaultBillTo()
45+
{
46+
return $this->getParameter('defaultBillTo');
47+
}
48+
1749
/**
1850
* Create a new debit or credit card
1951
*
@@ -45,4 +77,9 @@ public function refund(array $parameters = array())
4577
{
4678
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMRefundRequest', $parameters);
4779
}
80+
81+
public function void(array $parameters = array())
82+
{
83+
return $this->createRequest('\Omnipay\AuthorizeNet\Message\CIMVoidRequest', $parameters);
84+
}
4885
}

src/Message/CIMAbstractRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ public function getForceCardUpdate()
6767
return $this->getParameter('forceCardUpdate');
6868
}
6969

70+
public function setDefaultBillTo($defaultBillTo)
71+
{
72+
return $this->setParameter('defaultBillTo', $defaultBillTo);
73+
}
74+
75+
public function getDefaultBillTo()
76+
{
77+
return $this->getParameter('defaultBillTo');
78+
}
79+
7080
/**
7181
* Create and return the base XML data required to create a new request
7282
*

src/Message/CIMCreateCardRequest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ protected function addBillingData(\SimpleXMLElement $data)
8888
$req->zip = $card->getBillingPostcode();
8989
$req->country = $card->getBillingCountry();
9090

91+
$defaultBillTo = $this->getParameter('defaultBillTo');
92+
if (is_array($defaultBillTo)) {
93+
// A configuration parameter to populate billTo has been specified
94+
foreach ($defaultBillTo as $field => $value) {
95+
if (empty($req->{$field}) && !empty($value)) {
96+
// This particular field is empty and default value in populateBillTo has been specified
97+
// so use it
98+
$req->{$field} = $value;
99+
}
100+
}
101+
}
102+
91103
$req = $data->addChild('payment');
92104
$req->creditCard->cardNumber = $card->getNumber();
93105
$req->creditCard->expirationDate = $card->getExpiryDate('Y-m');

src/Message/CIMVoidRequest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet\Message;
4+
5+
/**
6+
* Authorize.Net CIM Void Request
7+
*/
8+
class CIMVoidRequest extends CIMAbstractRequest
9+
{
10+
protected $action = 'voidTransaction';
11+
12+
public function getData()
13+
{
14+
$this->validate('transactionReference');
15+
16+
$data = $this->getBaseData();
17+
$data->transactionRequest->refTransId = $this->getTransactionReference();
18+
$this->addTestModeSetting($data);
19+
20+
return $data;
21+
}
22+
}

tests/CIMGatewayTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ public function setUp()
3838
'transactionReference' => '{"approvalCode":"DMK100","transId":"2220001902","cardReference":"{\"customerProfileId\":\"28972084\",\"customerPaymentProfileId\":\"26317840\",\"customerShippingAddressId\":\"27057149\"}"}',
3939
);
4040

41-
$this->authorizeOptions = array(
42-
'cardReference' => '{"customerProfileId":"28972084","customerPaymentProfileId":"26317840","customerShippingAddressId":"27057149"}',
43-
'amount' => 10.00,
44-
'description' => 'purchase'
45-
);
46-
4741
$this->refundOptions = array(
4842
'amount' => '10.00',
4943
'transactionReference' => '{"approvalCode":"DMK100","transId":"2220001902","cardReference":"{\"customerProfileId\":\"28972084\",\"customerPaymentProfileId\":\"26317840\",\"customerShippingAddressId\":\"27057149\"}"}',

tests/Message/CIMCreateCardRequestTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,29 @@ public function testGetData()
2929
$this->assertEquals($card['number'], $data->profile->paymentProfiles->payment->creditCard->cardNumber);
3030
$this->assertEquals('testMode', $data->validationMode);
3131
}
32+
33+
public function testGetDataShouldHaveCustomBillTo()
34+
{
35+
$card = $this->getValidCard();
36+
unset($card['billingAddress1']);
37+
unset($card['billingAddress2']);
38+
unset($card['billingCity']);
39+
$this->request->initialize(
40+
array(
41+
'email' => "kaylee@serenity.com",
42+
'card' => $card,
43+
'developerMode' => true,
44+
'forceCardUpdate' => true,
45+
'defaultBillTo' => [
46+
'address' => '1234 Test Street',
47+
'city' => 'Blacksburg'
48+
]
49+
)
50+
);
51+
52+
$data = $this->request->getData();
53+
$this->assertEquals('12345', $data->profile->paymentProfiles->billTo->zip);
54+
$this->assertEquals('1234 Test Street', $data->profile->paymentProfiles->billTo->address);
55+
$this->assertEquals('Blacksburg', $data->profile->paymentProfiles->billTo->city);
56+
}
3257
}

0 commit comments

Comments
 (0)