// Create Customer if not exist with address etc if ($ppec->getContext()->cookie->logged) { if (!($id_customer = Paypal::getPayPalCustomerIdByEmail($ppec->result['EMAIL']))) { PayPal::addPayPalCustomer($ppec->getContext()->customer->id, $ppec->result['EMAIL']); } $customer = $ppec->getContext()->customer; } 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'])) {
if ($ppec->hasSucceedRequest() && !empty($ppec->token)) { $address = $customer = null; $email = $ppec->result['EMAIL']; /* Create Customer if not exist with address etc */ if ($ppec->context->cookie->logged) { $id_customer = Paypal::getPayPalCustomerIdByEmail($email); if (!$id_customer) { PayPal::addPayPalCustomer($ppec->context->customer->id, $email); } $customer = $ppec->context->customer; } elseif ($id_customer = Customer::customerExists($email, true)) { $customer = new Customer($id_customer); } else { $customer = setCustomerInformation($ppec, $email); $customer->add(); PayPal::addPayPalCustomer($customer->id, $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'); } $addresses = $customer->getAddresses($ppec->context->language->id); foreach ($addresses as $address) { if ($address['alias'] == 'Paypal_Address') { //If address has already been created $address = new Address($address['id_address']); break; } }