} elseif ($id_customer = Customer::customerExists($ppec->result['EMAIL'], true)) {
     $customer = new Customer($id_customer);
 } else {
     $customer = new Customer();
     $customer->email = $ppec->result['EMAIL'];
     $customer->lastname = $ppec->result['LASTNAME'];
     $customer->firstname = $ppec->result['FIRSTNAME'];
     $customer->passwd = Tools::encrypt(Tools::passwdGen());
     $customer->add();
     PayPal::addPayPalCustomer($customer->id, $ppec->result['EMAIL']);
 }
 if (!$customer->id) {
     $ppec->logs[] = $ppec->l('Cannot create customer');
 }
 if (!isset($ppec->result['PAYMENTREQUEST_0_SHIPTOSTREET']) || !isset($ppec->result['PAYMENTREQUEST_0_SHIPTOCITY']) || !isset($ppec->result['SHIPTOZIP']) || !isset($ppec->result['COUNTRYCODE'])) {
     $ppec->redirectToCheckout($customer, $ppec->type != 'payment_cart');
 }
 foreach ($customer->getAddresses($ppec->getContext()->language->id) as $address) {
     if ($address['alias'] == 'Paypal_Address') {
         $address = new Address($address['id_address']);
         break;
     }
 }
 // Create address
 if (is_array($address) && isset($address['id_address'])) {
     $address = new Address($address['id_address']);
 }
 if ((!$address || !$address->id) && $customer->id) {
     $address = new Address();
     $address->id_country = Country::getByIso($ppec->result['COUNTRYCODE']);
     $address->alias = 'Paypal_Address';