public static function CheckoutSdk::formatAddress in Commerce PayPal 8
Formats the given address into a format expected by PayPal.
Parameters
\Drupal\address\AddressInterface $address: The address to format.
string $type: The address type ("billing"|"shipping").
Return value
array The formatted address.
1 call to CheckoutSdk::formatAddress()
- CheckoutSdk::prepareOrderRequest in src/
CheckoutSdk.php - Prepare the order request parameters.
File
- src/
CheckoutSdk.php, line 432
Class
- CheckoutSdk
- Provides a replacement of the PayPal SDK.
Namespace
Drupal\commerce_paypalCode
public static function formatAddress(AddressInterface $address, $type = 'billing') {
$return = [
'address' => [
'address_line_1' => $address
->getAddressLine1(),
'address_line_2' => $address
->getAddressLine2(),
'admin_area_2' => mb_substr($address
->getLocality(), 0, 120),
'admin_area_1' => $address
->getAdministrativeArea(),
'postal_code' => mb_substr($address
->getPostalCode(), 0, 60),
'country_code' => $address
->getCountryCode(),
],
];
if ($type == 'billing') {
$return['name'] = [
'given_name' => $address
->getGivenName(),
'surname' => $address
->getFamilyName(),
];
}
elseif ($type == 'shipping') {
$return['name'] = [
'full_name' => mb_substr($address
->getGivenName() . ' ' . $address
->getFamilyName(), 0, 300),
];
}
return $return;
}