Example #1
0
 public function returnPage($systemCode = null)
 {
     //get Attempt
     $attemptModel = $this->_payment->getReturnAttempt($systemCode);
     if (!$attemptModel) {
         return false;
     }
     $returnUrl = null;
     //check order status
     switch ($attemptModel->order->status) {
         case Order::STATUS_ERROR:
         case Order::STATUS_VOID:
         case Order::STATUS_RETURNED:
             $error = urlencode('Order revoked');
             $returnUrl = 'https://' . $attemptModel->order->campaign->return_url . '?error=' . $error;
             break;
         case Order::STATUS_NEW:
         case Order::STATUS_OK:
         case Order::STATUS_SENT:
         case Order::STATUS_SHIPPED:
             if (!$attemptModel->order->isFlag('paid')) {
                 $this->_payment->updateStatusAttempt($attemptModel);
                 Pixel::firePixelPb($attemptModel->order);
             }
             $returnUrl = self::getReturnUrlByOrder($attemptModel->order);
             break;
     }
     echo '<a target="_bank" href="' . $returnUrl . '">' . $returnUrl . '</a>';
     die;
     header('Location: ' . $returnUrl);
     exit;
 }
Example #2
0
 function cloneAction()
 {
     if (isset($_POST['clone'])) {
         $model = AFActiveDataProvider::models('Campaign');
         $campaigns = $model->getCampaigns();
         $campaigns = AF::userAccess()->array2RestrictionArray('campaign_id', $campaigns);
         AF::setJsonHeaders('json');
         echo json_encode(array('campaigns' => $campaigns));
         die;
     }
     if (isset($_POST['ajax'])) {
         AF::setJsonHeaders('json');
         $campaign_id = AF::get($_POST, 'campaign_id', 0);
         $pixel_ids = AF::get($_POST, 'pixel_id', 0);
         if (AF::userAccess()->hasRestrictions('campaign_id')) {
             $rf = AF::userAccess()->getRestrictionSearchFields('campaign_id', array());
             if (!in_array($campaign_id, $rf)) {
                 Message::echoJsonError(__('pixel_not_cloned'));
             }
         }
         if (!$pixel_ids && !$campaign_id) {
             Message::echoJsonError(__('campaign_id_not_found'));
         }
         $pixels = explode(',', $pixel_ids);
         $message = array();
         $newIDs = array();
         $isMany = count($pixels) > 1 ? true : false;
         $isThisCampaign = true;
         foreach ($pixels as $pixel_id) {
             $model = new Pixel();
             if (!$model->fillFromDbPk($pixel_id)) {
                 if ($isMany) {
                     continue;
                 }
                 Message::echoJsonError(__('pixel_not_found'));
             }
             if ($model->campaign_id != $campaign_id) {
                 $model->campaign_id = $campaign_id;
                 $isThisCampaign = false;
             }
             if (!$model->cloneModel()) {
                 if ($isMany) {
                     continue;
                 }
                 Message::echoJsonError(__('pixel_not_found'));
             }
             $newID = $newIDs[] = $model->getPkValue();
             $message[] = __('pixel_cloned') . ' <a href="' . $this->controller . '/update/id=' . $newID . '">' . __('edit') . ' (ID: ' . $newID . ')</a><br>';
             unset($model);
         }
         if (!$message) {
             Message::echoJsonError(__('pixel_not_cloned'));
         }
         $message = implode($message);
         $newIDs = implode(',', $newIDs);
         $v = array('message' => $message);
         if ($isThisCampaign) {
             $v['newid'] = $newIDs;
         }
         Message::echoJsonSuccess($v);
     }
 }
Example #3
0
 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);
     }
 }
Example #4
0
 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');
         }
     }
 }