You are here

protected function WorldpayPaymentTrait::getShippingAddress in Commerce Worldpay 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Commerce/PaymentGateway/WorldpayPaymentTrait.php \Drupal\commerce_worldpay\Plugin\Commerce\PaymentGateway\WorldpayPaymentTrait::getShippingAddress()

Get the shipping address to pass to WorldPay.

Parameters

\Drupal\commerce_shipping\Entity\ShipmentInterface $shipment: The commerce shipment entity.

Return value

bool|\array Return false if no shipping profile. Otherwise return the shipping customer details.

Throws

\Drupal\Core\TypedData\Exception\MissingDataException

1 call to WorldpayPaymentTrait::getShippingAddress()
WorldpayRedirect::buildFormData in src/Plugin/Commerce/PaymentGateway/WorldpayRedirect.php

File

src/Plugin/Commerce/PaymentGateway/WorldpayPaymentTrait.php, line 51

Class

WorldpayPaymentTrait

Namespace

Drupal\commerce_worldpay\Plugin\Commerce\PaymentGateway

Code

protected function getShippingAddress(ShipmentInterface $shipment) {
  if (!($shippingProfile = $shipment
    ->getShippingProfile())) {
    return FALSE;
  }
  $country_list = \Drupal::service('address.country_repository')
    ->getList();

  /** @var \Drupal\address\Plugin\Field\FieldType\AddressItem $address */
  $shippingAddress = $shippingProfile
    ->get('address')
    ->first();
  return [
    'DeliveryFirstname' => $shippingAddress
      ->getGivenName(),
    'DeliverySurname' => $shippingAddress
      ->getFamilyName(),
    'DeliveryAddress1' => $shippingAddress
      ->getAddressLine1(),
    'DeliveryAddress2' => $shippingAddress
      ->getAddressLine2(),
    'DeliveryCity' => $shippingAddress
      ->getLocality(),
    'DeliveryPostCode' => $shippingAddress
      ->getPostalCode(),
    'DeliveryCountry' => $shippingAddress
      ->getCountryCode(),
    'DeliveryCountryString' => $country_list[$shippingAddress
      ->getCountryCode()],
  ];
}