WorldpayPaymentTrait.php in Commerce Worldpay 8.2
File
src/Plugin/Commerce/PaymentGateway/WorldpayPaymentTrait.php
View source
<?php
namespace Drupal\commerce_worldpay\Plugin\Commerce\PaymentGateway;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_shipping\Entity\ShipmentInterface;
trait WorldpayPaymentTrait {
private function getBillingAddress(OrderInterface $order) {
$billingAddress = $order
->getBillingProfile()
->get('address')
->first();
$country_list = \Drupal::service('address.country_repository')
->getList();
return [
'email' => $order
->get('mail')
->first()->value,
'first_name' => $billingAddress
->getGivenName(),
'surname' => $billingAddress
->getFamilyName(),
'address1' => $billingAddress
->getAddressLine1(),
'address2' => $billingAddress
->getAddressLine2(),
'city' => $billingAddress
->getLocality(),
'postCode' => $billingAddress
->getPostalCode(),
'countryCode' => $billingAddress
->getCountryCode(),
'country' => $country_list[$billingAddress
->getCountryCode()],
];
}
protected function getShippingAddress(ShipmentInterface $shipment) {
if (!($shippingProfile = $shipment
->getShippingProfile())) {
return FALSE;
}
$country_list = \Drupal::service('address.country_repository')
->getList();
$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()],
];
}
}