* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @copyright PayPal */ namespace PaypalAddons\services\Builder; use Address; use Context; use Country; use Customer; use Tools; use Validate; class ConfirmPaymentSourceBuilder implements BuilderInterface { protected $apmMethod; protected $context; public function __construct($apmMethod, $context = null) { $this->apmMethod = $apmMethod; if ($context instanceof Context) { $this->context = $context; } else { $this->context = Context::getContext(); } } public function build() { $output = [ 'payment_source' => [ $this->apmMethod => [ 'name' => $this->getName(), 'country_code' => $this->getCountryCode(), ], ], ]; return $output; } protected function getName() { if (empty($this->context->cart->id_customer)) { return ''; } $customer = new Customer($this->context->cart->id_customer); if (false == Validate::isLoadedObject($customer)) { return ''; } return $customer->firstname . ' ' . $customer->lastname; } protected function getCountryCode() { if (empty($this->context->cart->id_address_delivery)) { return ''; } $address = new Address($this->context->cart->id_address_delivery); return Tools::strtoupper(Country::getIsoById($address->id_country)); } }