Exemplo n.º 1
0
 function createCustomer()
 {
     global $osC_ShoppingCart, $osC_Customer;
     $address = $osC_ShoppingCart->getBillingAddress();
     $data = array('firstname' => $address['firstname'], 'lastname' => $address['lastname'], 'password' => $address['password'], 'gender' => $address['gender'], 'email_address' => $address['email_address']);
     if (osC_Account::createEntry($data, false)) {
         //insert billing address
         osC_Account::createNewAddress($osC_Customer->getID(), $address);
         //insert shipping address
         if (isset($address['ship_to_this_address']) && $address['ship_to_this_address'] == '0') {
             $shipping_address = $osC_ShoppingCart->getShippingAddress();
             osC_Account::createNewAddress($osC_Customer->getID(), $shipping_address);
         }
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 2
0
 function _process()
 {
     global $messageStack, $osC_Database, $osC_Language, $osC_Customer;
     $data = array();
     if (DISPLAY_PRIVACY_CONDITIONS == '1') {
         if (isset($_POST['privacy_conditions']) === false || isset($_POST['privacy_conditions']) && $_POST['privacy_conditions'] != '1') {
             $messageStack->add($this->_module, $osC_Language->get('error_privacy_statement_not_accepted'));
         }
     }
     if (ACCOUNT_GENDER == '1') {
         if (isset($_POST['gender']) && ($_POST['gender'] == 'm' || $_POST['gender'] == 'f')) {
             $data['gender'] = $_POST['gender'];
         } else {
             $messageStack->add($this->_module, $osC_Language->get('field_customer_gender_error'));
         }
     } else {
         $data['gender'] = isset($_POST['gender']) ? $_POST['gender'] : '';
     }
     if (isset($_POST['firstname']) && strlen(trim($_POST['firstname'])) >= ACCOUNT_FIRST_NAME) {
         $data['firstname'] = $_POST['firstname'];
     } else {
         $messageStack->add($this->_module, sprintf($osC_Language->get('field_customer_first_name_error'), ACCOUNT_FIRST_NAME));
     }
     if (isset($_POST['lastname']) && strlen(trim($_POST['lastname'])) >= ACCOUNT_LAST_NAME) {
         $data['lastname'] = $_POST['lastname'];
     } else {
         $messageStack->add($this->_module, sprintf($osC_Language->get('field_customer_last_name_error'), ACCOUNT_LAST_NAME));
     }
     $data['newsletter'] = isset($_POST['newsletter']) && $_POST['newsletter'] == '1' ? 1 : 0;
     if (ACCOUNT_DATE_OF_BIRTH == '1') {
         if (isset($_POST['dob_days']) && isset($_POST['dob_months']) && isset($_POST['dob_years']) && checkdate($_POST['dob_months'], $_POST['dob_days'], $_POST['dob_years'])) {
             $data['dob'] = mktime(0, 0, 0, $_POST['dob_months'], $_POST['dob_days'], $_POST['dob_years']);
         } else {
             $messageStack->add($this->_module, $osC_Language->get('field_customer_date_of_birth_error'));
         }
     }
     if (isset($_POST['email_address']) && strlen(trim($_POST['email_address'])) >= ACCOUNT_EMAIL_ADDRESS) {
         if (osc_validate_email_address($_POST['email_address'])) {
             if (osC_Account::checkDuplicateEntry($_POST['email_address']) === false) {
                 $data['email_address'] = $_POST['email_address'];
             } else {
                 $messageStack->add($this->_module, $osC_Language->get('field_customer_email_address_exists_error'));
             }
         } else {
             $messageStack->add($this->_module, $osC_Language->get('field_customer_email_address_check_error'));
         }
     } else {
         $messageStack->add($this->_module, sprintf($osC_Language->get('field_customer_email_address_error'), ACCOUNT_EMAIL_ADDRESS));
     }
     if (isset($_POST['password']) === false || isset($_POST['password']) && strlen(trim($_POST['password'])) < ACCOUNT_PASSWORD) {
         $messageStack->add($this->_module, sprintf($osC_Language->get('field_customer_password_error'), ACCOUNT_PASSWORD));
     } elseif (isset($_POST['confirmation']) === false || isset($_POST['confirmation']) && trim($_POST['password']) != trim($_POST['confirmation'])) {
         $messageStack->add($this->_module, $osC_Language->get('field_customer_password_mismatch_with_confirmation'));
     } else {
         $data['password'] = $_POST['password'];
     }
     if ($messageStack->size($this->_module) === 0) {
         if (osC_Account::createEntry($data)) {
             $messageStack->add_session('create', $osC_Language->get('success_account_updated'), 'success');
         }
         osc_redirect(osc_href_link(FILENAME_ACCOUNT, 'create=success', 'SSL'));
     }
 }
 function _get_express_checkout_details($params)
 {
     global $osC_ShoppingCart, $osC_Currencies, $osC_Language, $osC_Database, $osC_Tax, $messageStack, $osC_Customer, $osC_Session;
     // if there is nothing in the customers cart, redirect them to the shopping cart page
     if (!$osC_ShoppingCart->hasContents()) {
         osc_redirect(osc_href_link(FILENAME_CHECKOUT, '', 'SSL', true, true, true));
     }
     $params['VERSION'] = $this->api_version;
     $params['METHOD'] = 'GetExpressCheckoutDetails';
     $params['TOKEN'] = $_GET['token'];
     $post_string = '';
     foreach ($params as $key => $value) {
         $post_string .= $key . '=' . urlencode(utf8_encode(trim($value))) . '&';
     }
     $post_string = substr($post_string, 0, -1);
     $response = $this->sendTransactionToGateway($this->api_url, $post_string);
     $response_array = array();
     parse_str($response, $response_array);
     if ($response_array['ACK'] == 'Success' || $response_array['ACK'] == 'SuccessWithWarning') {
         $force_login = false;
         // Begin: check if e-mail address exists in database and login or create customer account
         if ($osC_Customer->isLoggedOn() == false) {
             $force_login = true;
             if (class_exists('osC_Account') == false) {
                 require_once 'includes/classes/account.php';
             }
             $email_address = $response_array['EMAIL'];
             $Qcheck = $osC_Database->query('select * from :table_customers where customers_email_address = :email_address limit 1');
             $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
             $Qcheck->bindValue(':email_address', $email_address);
             $Qcheck->execute();
             if ($Qcheck->numberOfRows() > 0) {
                 $check = $Qcheck->toArray();
                 $customer_id = $check['customers_id'];
                 $osC_Customer->setCustomerData($customer_id);
             } else {
                 $data = array('firstname' => $response_array['FIRSTNAME'], 'lastname' => $response_array['LASTNAME'], 'email_address' => $email_address, 'password' => osc_rand(ACCOUNT_PASSWORD, max(ACCOUNT_PASSWORD, 8)));
                 osC_Account::createEntry($data);
             }
             $Qcheck->freeResult();
             if (SERVICE_SESSION_REGENERATE_ID == '1') {
                 $osC_Session->recreate();
             }
         }
         // End: check if e-mail address exists in database and login or create customer account
         // Begin: Add shipping and billing address from paypal to the shopping cart
         if ($force_login == true) {
             $country_query = $osC_Database->query('select countries_id, countries_name, countries_iso_code_2, countries_iso_code_3, address_format from :table_countries where countries_iso_code_2 = :country_iso_code_2');
             $country_query->bindTable(':table_countries', TABLE_COUNTRIES);
             $country_query->bindValue(':country_iso_code_2', $response_array['SHIPTOCOUNTRYCODE']);
             $country_query->execute();
             $country = $country_query->toArray();
             $zone_name = $response_array['SHIPTOSTATE'];
             $zone_id = 0;
             $zone_query = $osC_Database->query('select zone_id, zone_name from :table_zones where zone_country_id = :zone_country_id and zone_code = :zone_code');
             $zone_query->bindTable(':table_zones', TABLE_ZONES);
             $zone_query->bindInt(':zone_country_id', $country['countries_id']);
             $zone_query->bindValue(':zone_code', $response_array['SHIPTOSTATE']);
             $zone_query->execute();
             if ($zone_query->numberOfRows()) {
                 $zone = $zone_query->toArray();
                 $zone_name = $zone['zone_name'];
                 $zone_id = $zone['zone_id'];
             }
             $sendto = array('firstname' => substr($response_array['SHIPTONAME'], 0, strpos($response_array['SHIPTONAME'], ' ')), 'lastname' => substr($response_array['SHIPTONAME'], strpos($response_array['SHIPTONAME'], ' ') + 1), 'company' => '', 'street_address' => $response_array['SHIPTOSTREET'], 'suburb' => '', 'email_address' => $response_array['EMAIL'], 'postcode' => $response_array['SHIPTOZIP'], 'city' => $response_array['SHIPTOCITY'], 'zone_id' => $zone_id, 'zone_name' => $zone_name, 'country_id' => $country['countries_id'], 'country_name' => $country['countries_name'], 'country_iso_code_2' => $country['countries_iso_code_2'], 'country_iso_code_3' => $country['countries_iso_code_3'], 'address_format_id' => $country['address_format_id'] > 0 ? $country['address_format_id'] : '1');
             $osC_ShoppingCart->setRawShippingAddress($sendto);
             $osC_ShoppingCart->setRawBillingAddress($sendto);
             $osC_ShoppingCart->setBillingMethod(array('id' => $this->getCode(), 'title' => $this->getMethodTitle()));
         }
         // End: Add shipping and billing address from paypal to the shopping cart
         //Begin: Add the shipping
         if ($osC_ShoppingCart->getContentType() != 'virtual') {
             if ($osC_ShoppingCart->hasShippingMethod() === false) {
                 if (class_exists('osC_Shipping') === false) {
                     include_once 'includes/classes/shipping.php';
                 }
                 $osC_Shipping = new osC_Shipping();
                 if ($osC_Shipping->hasQuotes()) {
                     $shipping_set = false;
                     // get all available shipping quotes
                     $quotes = $osC_Shipping->getQuotes();
                     if (isset($response_array['SHIPPINGOPTIONNAME']) && isset($response_array['SHIPPINGOPTIONAMOUNT'])) {
                         foreach ($quotes as $quote) {
                             if (!isset($quote['error'])) {
                                 foreach ($quote['methods'] as $rate) {
                                     if ($response_array['SHIPPINGOPTIONNAME'] == $quote['module'] . ' (' . $rate['title'] . ')') {
                                         if ($response_array['SHIPPINGOPTIONAMOUNT'] == $osC_Currencies->formatRaw($rate['cost'] + $quote['cost'] * $quote['tax'] / 100)) {
                                             $shipping = $quote['id'] . '_' . $rate['id'];
                                             $module = 'osC_Shipping_' . $quote['module'];
                                             if (is_object($GLOBALS[$module]) && $GLOBALS[$module]->isEnabled()) {
                                                 $quote = $osC_Shipping->getQuote($shipping);
                                                 if (isset($quote['error'])) {
                                                     $osC_ShoppingCart->resetShippingMethod();
                                                     $errors[] = $quote['error'];
                                                 } else {
                                                     $osC_ShoppingCart->setShippingMethod($quote);
                                                     $shipping_set = true;
                                                 }
                                             } else {
                                                 $osC_ShoppingCart->resetShippingMethod();
                                             }
                                             break 2;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if ($shipping_set == false) {
                         // select cheapest shipping method
                         $osC_ShoppingCart->setShippingMethod($osC_Shipping->getCheapestQuote());
                     }
                 }
             }
         }
         if (!isset($_SESSION['ppe_token'])) {
             $_SESSION['ppe_token'] = $response_array['TOKEN'];
         }
         if (!isset($_SESSION['ppe_payerid'])) {
             $_SESSION['ppe_payerid'] = $response_array['PAYERID'];
         }
         if (!isset($_SESSION['ppe_payerstatus'])) {
             $_SESSION['ppe_payerstatus'] = $response_array['PAYERSTATUS'];
         }
         if (!isset($_SESSION['ppe_addressstatus'])) {
             $_SESSION['ppe_addressstatus'] = $response_array['ADDRESSSTATUS'];
         }
         osc_redirect(osc_href_link(FILENAME_CHECKOUT, 'process', 'SSL'));
     } else {
         $messageStack->add_session('shopping_cart', $osC_Language->get('payment_paypal_express_error_title') . ' <strong>' . stripslashes($response_array['L_LONGMESSAGE0']) . '</strong>');
         osc_redirect(osc_href_link(FILENAME_CHECKOUT, '', 'SSL'));
     }
 }