Skip to content

Commit

Permalink
Add support for billing address in CreatePaymentMethodRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
dennislindsey committed Apr 12, 2021
1 parent 612bf06 commit 94393c2
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/Message/CreateCustomerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,27 @@ class CreateCustomerRequest extends AbstractRequest
{
public function getData()
{
return $this->getCustomerData();
$data = $this->getCustomerData();

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

$creditCard = $this->getCardData();

if (array_key_exists('billing', $creditCard) && !empty($billingAddress = $creditCard['billing'])) {
$data['billingAddress'] = [
'company' => $billingAddress['company'],
'countryCodeAlpha3' => $billingAddress['countryName'],
'extendedAddress' => $billingAddress['extendedAddress'],
'firstName' => $billingAddress['firstName'],
'lastName' => $billingAddress['lastName'],
'locality' => $billingAddress['locality'],
'postalCode' => $billingAddress['postalCode'],
'region' => $billingAddress['region'],
'streetAddress' => $billingAddress['streetAddress'],
];
}

return $data;
}

/**
Expand Down
53 changes: 53 additions & 0 deletions tests/Message/CreateCustomerRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,57 @@ public function testRequestData()
$this->request->getCustomerData()
);
}

public function testGetDataWithAVS()
{
$this->request->initialize([
'customerData' => [
'firstName' => 'Mike',
'lastName' => 'Jones',
'email' => '[email protected]',
'paymentMethodNonce' => 'testnonce',
],
'addBillingAddressToPaymentMethod' => true,
'failOnDuplicatePaymentMethod' => false,
'makeDefault' => true,
'verifyCard' => true,
'card' => [
'billingFirstName' => 'John',
'billingLastName' => 'Doe',
'billingAddress1' => '123 Main Street',
'billingAddress2' => 'Suite 101',
'billingCity' => 'Los Angeles',
'billingState' => 'CA',
'billingPostcode' => '90210',
'billingCountry' => 'USA',
'billingCompany' => 'Apple Inc',
],
]);

$expectedData = [
'firstName' => 'Mike',
'lastName' => 'Jones',
'email' => '[email protected]',
'paymentMethodNonce' => 'testnonce',
'options' => [
'addBillingAddressToPaymentMethod' => true,
'failOnDuplicatePaymentMethod' => false,
'makeDefault' => true,
'verifyCard' => true,
],
'billingAddress' => [
'company' => 'Apple Inc',
'countryCodeAlpha3' => 'USA',
'extendedAddress' => 'Suite 101',
'firstName' => 'John',
'lastName' => 'Doe',
'locality' => 'Los Angeles',
'postalCode' => '90210',
'region' => 'CA',
'streetAddress' => '123 Main Street',
],
];
$this->assertSame($expectedData, $this->request->getData());
}

}

0 comments on commit 94393c2

Please sign in to comment.