public static function finalizeOrder($orderID) { $modelOrder = Order::model()->findByPk((int) $orderID); if (!$modelOrder) { return false; } //Check status $modelAttempt = new Attempt(); $modelAttempt->getLastOrderAttempt($modelOrder->order_id, Attempt::DEBIT_TYPE); if (in_array($modelAttempt->status, array(Attempt::SUCCESS_STATUS, Attempt::DECLINED_STATUS))) { return true; } $payment = new PaymentAPI(); $response = $payment->updateStatusAttempt($modelAttempt); if ($response->attemptStatus == 'success') { $modelOrder->status = Order::STATUS_OK; $modelOrder->removeFlags(Order::FlAG_PAY); $modelOrder->addFlags(Order::FlAG_PAID); $modelOrder->payment_total = $modelAttempt->amount; $modelOrder->save(); Event::setEvents($modelOrder->order_id, 8, false); //update recurring_next $sql = "UPDATE `orders_products`\n JOIN `products` USING(`product_id`)\n SET `orders_products`.`recurring_next` = DATE_ADD(NOW(), INTERVAL `products`.`subscription_days` DAY)\n WHERE FIND_IN_SET('recurring', `orders_products`.`flags`)>0\n AND `orders_products`.`order_id`=?i"; self::$_msql->query($sql, $modelOrder->order_id); if ($modelOrder->billing_cycle == 0) { // Delete order prospect Prospects::deleteProspectOkOrder($modelOrder->order_id); Orders::createAttachedOrders($modelOrder); // Fire Pixel $cloneOrder = clone $modelOrder; Pixel::firePixelPb($cloneOrder); unset($cloneOrder); } } elseif ($response->attemptStatus == 'declined') { $modelOrder->status = Order::STATUS_ERROR; $modelOrder->removeFlags(Order::FlAG_PAY); $modelOrder->save(); // Delete order prospect Prospects::deleteProspectOkOrder($modelOrder->order_id); } }
private function finalizeOrder() { if ($this->order->billing_cycle == 0) { try { // delete prospect AND SEND IS_CUSTOMER INFO TO SILVERPOP Prospects::deleteProspectOkOrder($this->order->order_id); // send order details to the Silverpop relational table $this->order->addSilverpopOrderData(); } catch (Exception $e) { $msg = 'PROSPECT DELETE OR SILVERPOP ERROR'; $ord = json_encode($this->order->getDataArray()); $pst = isset($this->post) ? json_encode($this->post) : json_encode($_POST); $dump = $msg . PHP_EOL . $ord . PHP_EOL . $pst . PHP_EOL; error_log($dump, 3, getcwd() . "/api_error_log.log"); } // Fire Pixel $o = clone $this->order; Pixel::firePixelPb($o); unset($o); Event::setEvents($this->order->order_id, 8, false); // using try/catch here in case something happens the user will still be taken back to the thankyou page try { // is there an attach campaign associated with this order? // need to clone the object to be passed otherwise the createAttachedOrdersFunction will switch $this->order causing problems downstream $o = clone $this->order; Orders::createAttachedOrders($o); unset($o); } catch (Exception $e) { $msg = 'ATTACHED ORDER ERROR'; $ord = json_encode($this->order->getDataArray()); $pst = isset($this->post) ? json_encode($this->post) : json_encode($_POST); $dump = $msg . PHP_EOL . $ord . PHP_EOL . $pst . PHP_EOL; error_log($dump, 3, getcwd() . "/api_error_log.log"); } if ($this->wsType == 'salvage') { // write log OrderLog::createLog(0, $this->order->order_id, 15, 'salvage order'); } } }