From 6aa85413069ac05f304100bbef8e822d7cffa648 Mon Sep 17 00:00:00 2001 From: imitrik Date: Thu, 13 Jun 2019 15:09:36 -0400 Subject: [PATCH] AVS Address Fix --- src/Message/CreatePaymentMethodRequest.php | 72 +++++++++++++++++++ .../CreatePaymentMethodRequestTest.php | 48 +++++++++++++ 2 files changed, 120 insertions(+) diff --git a/src/Message/CreatePaymentMethodRequest.php b/src/Message/CreatePaymentMethodRequest.php index 95b5f5f..4c8fcbc 100644 --- a/src/Message/CreatePaymentMethodRequest.php +++ b/src/Message/CreatePaymentMethodRequest.php @@ -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; @@ -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); + } + } diff --git a/tests/Message/CreatePaymentMethodRequestTest.php b/tests/Message/CreatePaymentMethodRequestTest.php index fc7a98d..5e0750b 100644 --- a/tests/Message/CreatePaymentMethodRequestTest.php +++ b/tests/Message/CreatePaymentMethodRequestTest.php @@ -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', @@ -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',