Skip to content
Open
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
72 changes: 72 additions & 0 deletions src/Message/CreatePaymentMethodRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ public function getData()
if ($cardholderName = $this->getCardholderName()) {
$data['cardholderName'] = $cardholderName;
}

if ($this->getStreetAddress() !== '') {
$data['billingAddress'] = [];
$data['billingAddress']['streetAddress'] = $this->getStreetAddress();
}
if ($this->getLocality() !== '') {
$data['billingAddress']['locality'] = $this->getLocality();
}
if ($this->getPostalCode() !== '') {
$data['billingAddress']['postalCode'] = $this->getPostalCode();
}
if ($this->getRegion() !== '') {
$data['billingAddress']['region'] = $this->getRegion();
}
if ($this->getCountryCodeAlpha2() !== '') {
$data['billingAddress']['countryCodeAlpha2'] = $this->getCountryCodeAlpha2();
}

$data += $this->getOptionData();

return $data;
Expand Down Expand Up @@ -57,4 +75,58 @@ public function getCardholderName()
{
return $this->getParameter('cardholderName');
}

/*
* All following functions are required for AVS Rules enabled on Braintree
*/
public function getStreetAddress()
{
return $this->getParameter('streetAddress');
}

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

public function getLocality()
{
return $this->getParameter('locality');
}

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

public function getPostalCode()
{
return $this->getParameter('postalCode');
}

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

public function getRegion()
{
return $this->getParameter('region');
}

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

public function getCountryCodeAlpha2()
{
return $this->getParameter('countryCodeAlpha2');
}

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

}
48 changes: 48 additions & 0 deletions tests/Message/CreatePaymentMethodRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ public function testGetData()
$expectedData = array(
'customerId' => '4815162342',
'paymentMethodNonce' => 'abc123',
'billingAddress' => array(
'streetAddress' => null,
'locality' => null,
'postalCode' => null,
'region' => null,
'countryCodeAlpha2' => null
),
'options' => array(
'verifyCard' => true,
'verificationMerchantAccountId' => '123581321',
Expand All @@ -46,6 +53,47 @@ public function testGetDataWithCardholderName()
'customerId' => '4815162342',
'paymentMethodNonce' => 'abc123',
'cardholderName' => 'John Yolo',
'billingAddress' => array(
'streetAddress' => null,
'locality' => null,
'postalCode' => null,
'region' => null,
'countryCodeAlpha2' => null
),
'options' => array(
'verifyCard' => true,
'verificationMerchantAccountId' => '123581321',
)
);
$this->assertSame($expectedData, $request->getData());
}

public function testGetDataWithAddress()
{
$request = $this->createPaymentMethodRequest();
$request->initialize(
array(
'customerId' => '4815162342',
'token' => 'abc123',
'streetAddress' => '1 Main St',
'locality' => 'New York City',
'postalCode' => '10044',
'region' => 'NY',
'countryCodeAlpha2' => 'US',
'verifyCard' => true,
'verificationMerchantAccountId' => '123581321',
)
);
$expectedData = array(
'customerId' => '4815162342',
'paymentMethodNonce' => 'abc123',
'billingAddress' => array(
'streetAddress' => '1 Main St',
'locality' => 'New York City',
'postalCode' => '10044',
'region' => 'NY',
'countryCodeAlpha2' => 'US'
),
'options' => array(
'verifyCard' => true,
'verificationMerchantAccountId' => '123581321',
Expand Down