function request_payment() { global $prefs, $user; $tikilib = TikiLib::lib('tiki'); $paymentlib = TikiLib::lib('payment'); $total = $this->get_total(); if ($total > 0 || $this->total_no_discount) { // if anonymous shopping to set pref as to which shopperinfo to show in description if (empty($user) && $prefs['payment_cart_anonymous'] === 'y') { $shopperinfo_descvar = 'email'; // TODO: make this a pref if (!empty($_SESSION['shopperinfo'][$shopperinfo_descvar])) { $shopperinfo_desc = $_SESSION['shopperinfo'][$shopperinfo_descvar]; $description = tra($prefs['payment_cart_heading']) . " ({$shopperinfo_desc})"; } else { $description = tra($prefs['payment_cart_heading']); } } else { $description = tra($prefs['payment_cart_heading']) . " ({$user})"; } $invoice = $paymentlib->request_payment($description, $total, $prefs['payment_default_delay'], $this->get_description()); foreach ($this->get_behaviors() as $behavior) { $paymentlib->register_behavior($invoice, $behavior['event'], $behavior['behavior'], $behavior['arguments']); } } else { $invoice = 0; foreach ($this->get_behaviors() as $behavior) { if ($behavior['event'] == 'complete') { $name = $behavior['behavior']; $file = dirname(__FILE__) . "/behavior/{$name}.php"; $function = 'payment_behavior_' . $name; require_once $file; call_user_func_array($function, $behavior['arguments']); } } } // Handle anonymous user (not logged in) shopping that require only email if (!$user || isset($_SESSION['forceanon']) && $_SESSION['forceanon'] == 'y') { if (!empty($_SESSION['shopperinfo'])) { // should also check for pref that this anonymous shopping feature is on // First create shopper info in shopper tracker global $record_profile_items_created; $record_profile_items_created = array(); if (!empty($_SESSION['shopperinfoprofile'])) { $shopper_profile_name = $_SESSION['shopperinfoprofile']; } else { $shopper_profile_name = $prefs['payment_cart_anonshopper_profile']; } $shopperprofile = Tiki_Profile::fromDb($shopper_profile_name); $profileinstaller = new Tiki_Profile_Installer(); $profileinstaller->forget($shopperprofile); // profile can be installed multiple times $profileinstaller->setUserData($_SESSION['shopperinfo']); $profileinstaller->install($shopperprofile); // Then set user to shopper ID $cartuser = $record_profile_items_created[0]; $record_profile_items_created = array(); } else { $this->empty_cart(); return $invoice; } } else { $cartuser = $user; } $userInput = array('user' => $cartuser, 'time' => $tikilib->now, 'total' => $total, 'invoice' => $invoice, 'weight' => $this->get_total_weight()); if (!$user || isset($_SESSION['forceanon']) && $_SESSION['forceanon'] == 'y') { $orderprofile = Tiki_Profile::fromDb($prefs['payment_cart_anonorders_profile']); $orderitemprofile = Tiki_Profile::fromDb($prefs['payment_cart_anonorderitems_profile']); } else { $orderprofile = Tiki_Profile::fromDb($prefs['payment_cart_orders_profile']); $orderitemprofile = Tiki_Profile::fromDb($prefs['payment_cart_orderitems_profile']); } if ($user && $prefs['payment_cart_orders'] == 'y' || !$user && $prefs['payment_cart_anonymous'] == 'y') { if (!$orderprofile) { TikiLib::lib('errorreport')->report(tra('Advanced Shopping Cart setup error: Orders profile missing.')); return false; } $profileinstaller = new Tiki_Profile_Installer(); $profileinstaller->forget($orderprofile); // profile can be installed multiple times $profileinstaller->setUserData($userInput); } else { $profileinstaller = ''; } global $record_profile_items_created; $record_profile_items_created = array(); if ($user && $prefs['payment_cart_orders'] == 'y' || !$user && $prefs['payment_cart_anonymous'] == 'y') { $profileinstaller->install($orderprofile, 'none'); } $content = $this->get_content(); foreach ($content as $info) { if (!isset($info['is_gift_certificate']) || !$info['is_gift_certificate']) { $process_info = $this->process_item($invoice, $total, $info, $userInput, $cartuser, $profileinstaller, $orderitemprofile); } } $email_template_ids = array(); if (isset($process_info['product_classes']) && is_array($process_info['product_classes'])) { $product_classes = array_unique($process_info['product_classes']); } else { $product_classes = array(); } foreach ($product_classes as $pc) { if ($email_template_id = $this->get_tracker_value_custom($prefs['payment_cart_productclasses_tracker_name'], 'Email Template ID', $pc)) { $email_template_ids[] = $email_template_id; } } if (!empty($record_profile_items_created)) { if ($total > 0) { $paymentlib->register_behavior($invoice, 'complete', 'record_cart_order', array($record_profile_items_created)); $paymentlib->register_behavior($invoice, 'cancel', 'cancel_cart_order', array($record_profile_items_created)); if ($user) { $paymentlib->register_behavior($invoice, 'complete', 'cart_send_confirm_email', array($user, $email_template_ids)); } } else { require_once 'lib/payment/behavior/record_cart_order.php'; payment_behavior_record_cart_order($record_profile_items_created); if ($user) { require_once 'lib/payment/behavior/cart_send_confirm_email.php'; payment_behavior_cart_send_confirm_email($user, $email_template_ids); } } } if (!$user || isset($_SESSION['forceanon']) && $_SESSION['forceanon'] == 'y') { $shopperurl = 'tiki-index.php?page=' . $prefs['payment_cart_anon_reviewpage'] . '&shopper=' . intval($cartuser); global $tikiroot, $prefs; $shopperurl = $tikilib->httpPrefix(true) . $tikiroot . $shopperurl; require_once 'lib/auth/tokens.php'; $tokenlib = AuthTokens::build($prefs); $shopperurl = $tokenlib->includeToken($shopperurl, array($prefs['payment_cart_anon_group'], 'Anonymous')); if (!empty($_SESSION['shopperinfo']['email'])) { require_once 'lib/webmail/tikimaillib.php'; $smarty = TikiLib::lib('smarty'); $smarty->assign('shopperurl', $shopperurl); $smarty->assign('email_template_ids', $email_template_ids); $mail_subject = $smarty->fetch('mail/cart_order_received_anon_subject.tpl'); $mail_data = $smarty->fetch('mail/cart_order_received_anon.tpl'); $mail = new TikiMail(); $mail->setSubject($mail_subject); if ($mail_data == strip_tags($mail_data)) { $mail->setText($mail_data); } else { $mail->setHtml($mail_data); } $mail->send($_SESSION['shopperinfo']['email']); // the field to use probably needs to be configurable as well } } $this->update_gift_certificate($invoice); $this->update_group_discount($invoice); $this->empty_cart(); return $invoice; }