public function showReceipt($attrs) { $account = null; if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['ouid'])) { if (CART66_PRO && isset($_POST['account'])) { $acctData = Cart66Common::postVal('account'); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] New Account Data: " . print_r($acctData, true)); $account = new Cart66Account(); $account->firstName = $acctData['first_name']; $account->lastName = $acctData['last_name']; $account->email = $acctData['email']; $account->username = $acctData['username']; $account->password = md5($acctData['password']); $errors = $account->validate(); $jqErrors = $account->getJqErrors(); if ($acctData['password'] != $acctData['password2']) { $errors[] = __("Passwords do not match", "cart66"); $jqErrors[] = 'account-password'; $jqErrors[] = 'account-password2'; } if (count($errors) == 0) { // Attach account to order $order = new Cart66Order(); $ouid = Cart66Common::postVal('ouid'); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Trying to load order with OUID: {$ouid}"); if ($order->loadByOuid($ouid)) { // Make sure the order can be loaded, then save the account $account->save(); // Attach membership to account and account to the order if ($mp = $order->getMembershipProduct()) { $account->attachMembershipProduct($mp, $account->firstName, $account->lastName); $order->account_id = $account->id; $order->save(); $account->clear(); } } } else { $attrs['errors'] = $errors; $attrs['jqErrors'] = $jqErrors; } } } $attrs['account'] = $account; $view = Cart66Common::getView('views/receipt.php', $attrs, true, true); return $view; }
$planIndex = Cart66Session::get('Cart66Cart')->getPayPalSubscriptionIndex(); $plan = new Cart66PayPalSubscription($cartItem->getPayPalSubscriptionId()); $profileResponse = $pp->CreateRecurringPaymentsProfile($token, $cartItem, $planIndex); if ('FAILURE' != strtoupper($profileResponse['ACK'])) { $paypalPaymentProfileId = $profileResponse['PROFILEID']; if (Cart66Common::isLoggedIn() && $account->isPayPalAccount()) { // Expire the current subscription and attach a new subscription $account->cancelSubscription('Your subscription has been canceled because you changed to a new subscription.', true); } $activeUntil = $plan->getStartTimeFormula(); $account->attachPayPalSubscription($details, $paypalPaymentProfileId, $plan, $activeUntil); } } elseif ($cartItem = Cart66Session::get('Cart66Cart')->getMembershipProductItem()) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Got membership product from the cart after a PayPal transaction."); $product = new Cart66Product($cartItem->getProductId()); $account->attachMembershipProduct($product, $details['FIRSTNAME'], $details['LASTNAME']); } // Save the order if ('FAILURE' != strtoupper($profileResponse['ACK'])) { $token = Cart66Common::postVal('token'); $payerId = Cart66Common::postVal('PayerID'); $opts = Cart66Setting::getValue('status_options'); $status = ''; if (!empty($opts)) { $opts = explode(',', $opts); $status = trim($opts[0]); } $transId = isset($response['TRANSACTIONID']) ? $response['TRANSACTIONID'] : ''; $promo = Cart66Session::get('Cart66PromotionCode'); $promoMsg = "none"; if ($promo) {
$transactionId = $transId = 'MT-' . Cart66Common::getRandString(); } if ($transactionId) { // Set order status based on Cart66 settings $statusOptions = Cart66Common::getOrderStatusOptions(); $status = $statusOptions[0]; // Check for account creation $accountId = 0; Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Should an account be created? " . print_r($createAccount)); if ($createAccount) { $account->save(); $accountId = $account->id; Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Just created account with id: accountId"); } if ($mp = Cart66Session::get('Cart66Cart')->getMembershipProduct()) { $account->attachMembershipProduct($mp, $account->firstName, $account->lastName); $accountId = $account->id; Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Attached membership to account id: {$accountId}"); } // Save the order locally $orderId = $gateway->saveOrder($total, $tax, $transactionId, $status, $accountId); Cart66Session::drop('Cart66SubscriberToken'); Cart66Session::set('order_id', $orderId); Cart66Session::drop('Cart66ProRateAmount'); $receiptLink = Cart66Common::getPageLink('store/receipt'); $newOrder = new Cart66Order($orderId); // Send email receipts if (CART66_PRO && CART66_EMAILS && Cart66Setting::getValue('enable_advanced_notifications') == 1) { $notify = new Cart66AdvancedNotifications($orderId); $notify->sendAdvancedEmailReceipts(); } elseif (CART66_EMAILS) {
public function saveMijirehOrder($order_number) { global $wpdb; // Make sure the order is not already in the database $orders_table = Cart66Common::getTableName('orders'); $sql = "select id from {$orders_table} where trans_id = %s"; $sql = $wpdb->prepare($sql, $order_number); $order_id = $wpdb->get_var($sql); if (!$order_id) { // Save the order $order = new Cart66Order(); $cloud_order = $this->pullOrder($order_number); $order_data = $this->buildOrderDataArray($cloud_order); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Order data: " . print_r($order_data, true)); $order_data = Cart66Common::deNullArrayValues($order_data); $order_id = $order->rawSave($order_data); // Save the order items $order_items_table = Cart66Common::getTableName('order_items'); foreach ($cloud_order['items'] as $key => $item) { $product = new Cart66Product(); $product->loadByItemNumber($item['sku']); $data = array('order_id' => $order_id, 'product_id' => $product->id, 'product_price' => $item['price'], 'item_number' => $item['sku'], 'description' => $item['name'], 'quantity' => $item['quantity'], 'duid' => md5($order_id . $item['sku'])); // Look for gravity forms data if (isset($cloud_order['meta_data'][$key]['gforms_' . $item['sku']])) { $data['form_entry_ids'] = $cloud_order['meta_data'][$key]['gforms_' . $item['sku']]; } $fIds = array(); if (isset($data['form_entry_ids'])) { $fIds = explode(',', $data['form_entry_ids']); if (is_array($fIds) && count($fIds)) { foreach ($fIds as $entryId) { if (class_exists('RGFormsModel')) { if ($lead = RGFormsModel::get_lead($entryId)) { $lead['status'] = 'active'; RGFormsModel::update_lead($lead); } } } } } $data = Cart66Common::deNullArrayValues($data); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Trying to save this order item:" . print_r($data, true)); $wpdb->insert($order_items_table, $data); $order_item_id = $wpdb->insert_id; // Decrement inventory after sale if (Cart66Setting::getValue('track_inventory') == 1) { $option_info = ''; if (isset($cloud_order['meta_data']['options_' . $item['sku']])) { $option_info = $cloud_order['meta_data']['options_' . $item['sku']]; } Cart66Product::decrementInventory($data['product_id'], $option_info, $data['quantity']); } // Look for membership product upgrades/extensions if (isset($cloud_order['meta_data']['account_id']) && is_numeric($cloud_order['meta_data']['account_id'])) { $order->load($order_id); $account_id = $cloud_order['meta_data']['account_id']; if ($mp = $order->getMembershipProduct()) { $account = new Cart66Account(); $account->load($account_id); $account->attachMembershipProduct($mp, $account->firstName, $account->lastName); $order->account_id = $account->id; $order->save(); } } } //update the number of redemptions for the promotion code. if (Cart66Session::get('Cart66Promotion')) { Cart66Session::get('Cart66Promotion')->updateRedemptions(); } // Send email receipts if (CART66_PRO && CART66_EMAILS && Cart66Setting::getValue('enable_advanced_notifications') == 1) { $notify = new Cart66AdvancedNotifications($order_id); $notify->sendAdvancedEmailReceipts(); } elseif (CART66_EMAILS) { $notify = new Cart66Notifications($order_id); $notify->sendEmailReceipts(); } //Cart66Common::sendEmailReceipts($order_id); } // Redirect to receipt page $this->goToReceipt($order_id); }