/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionView($id) { $model = PurchasedPlan::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } $modelPayments = PurchasedPlanPayment::model()->findByAttributes(array('pplan_id' => $id)); if ($modelPayments === null) { throw new CHttpException(404, 'The requested page does not exist.'); } $modelLimits = PlanLimit::model()->findByAttributes(array('plan_id' => $model->plan_id)); $this->render('view', array('model' => $model, 'modelPayments' => $modelPayments, 'modelLimits' => $modelLimits)); }
function afterSave() { if ($this->isNewRecord) { $purchasedPlan = PurchasedPlan::model()->findByPk($this->pplan_id); if ($purchasedPlan == null) { throw new CHttpException(1234, "No plan found!"); } if ($purchasedPlan->type == PlanType::ADVERTISER_PLAN && $purchasedPlan->advertiser_id != '') { $advertiser = Advertiser::model()->findByPk($purchasedPlan->advertiser_id); if ($advertiser == null) { throw new CHttpException(1234, "No advertiser found!"); } if ($advertiser->mbroker_id != '') { // insert commission for this media broker $wlAccount = WhiteLabel::model()->findByPk($purchasedPlan->wlabel_id); if ($wlAccount == null) { throw new CHttpException(1234, "No account found!"); } if ($wlAccount->mb_commission != '' && $wlAccount->mb_commission != 0 && $wlAccount->mb_commission_type != '' && $wlAccount->mb_commission_type != 0) { if ($wlAccount->mb_commission_type == CommissionType::TYPE_FIXED) { $commissionAmount = $wlAccount->mb_commission; } else { // percentage $commissionAmount = $purchasedPlan->price / 100 * $wlAccount->mb_commission; } $mbCommissions = new MediabrokerCommission(); $mbCommissions->mbroker_id = $advertiser->mbroker_id; $mbCommissions->pppayment_id = $this->pppayment_id; $mbCommissions->date_created = date("Y-m-d h:i:s"); $mbCommissions->amount = $commissionAmount; $mbCommissions->save(); } } } } return parent::afterSave(); }
public function verifyDelete() { if (PlanLimit::model()->findByAttributes(array('plan_id' => $this->plan_id))) { throw new CHttpException(400, 'You cannot delete plan that has some limits, delete limits first!'); } if (PurchasedPlan::model()->findByAttributes(array('plan_id' => $this->plan_id))) { throw new CHttpException(400, 'You cannot delete a plan that was already purchased!'); } return true; }
public function verifyDelete() { $advertiserId = $this->advertiser_id; if (Employee::model()->findByAttributes(array('advertiser_id' => $this->advertiser_id))) { throw new CHttpException(400, 'You cannot delete advertiser that contains some employees!'); } if (PurchasedPlan::model()->findByAttributes(array('advertiser_id' => $this->advertiser_id))) { throw new CHttpException(400, 'You cannot delete advertiser that has some purchased plans!'); } return true; }
public static function checkAuthorizeNetPlans($planType, $advertiserId) { $sql = "SELECT plan_id, pplan_id, subscription_id, type, duration, expired FROM p_purchased_plans" . " WHERE wlabel_id=" . Yii::app()->user->getWhiteLabelId() . " AND expired=0" . " AND method=" . PaymentType::TYPE_AUTHORIZENET; if ($planType == PlanType::ADVERTISER_PLAN && $advertiserId != '') { $sql .= " AND advertiser_id=" . $advertiserId; } $dbCommand = Yii::app()->db->createCommand($sql); $results = $dbCommand->queryAll(); if ($results == null) { return null; } foreach ($results as $row) { // now check the plan subscription status through Authorize.net $status = PlanRestriction::checkSubscriptionStatus($row['subscription_id']); if ($status == 'active') { // insert new purchased plan payment PlanRestriction::insertNewPurchasedPlanPayment($row['pplan_id'], $row['duration']); return array('plan_id' => $row['plan_id']); } else { // set plan to expired $purchasedPlan = PurchasedPlan::model()->findByPk($row['pplan_id']); $purchasedPlan->expired = 1; $purchasedPlan->save(); } } return null; }
private function processPayment() { if (!isset($_REQUEST['txn_type'])) { throw new Exception("Txn type doesn't exist"); } if (isset($_REQUEST['txn_type']) && $_REQUEST['txn_type'] != 'subscr_payment') { throw new Exception("Txn type is not payment: " . $_REQUEST['txn_type']); } if (!isset($_REQUEST['payment_status'])) { throw new Exception("Payment status doesn't exist"); } if (isset($_REQUEST['payment_status']) && $_REQUEST['payment_status'] != 'Completed') { throw new Exception("Payment not completed"); } $ids = explode('_', $_REQUEST['item_number']); $planId = $ids[0]; if (isset($ids[1])) { $advertiserId = $ids[1]; } else { $advertiserId = ''; } $plan = Plan::model()->findByPk($planId); if ($plan == null) { throw new Exception("Plan not found, ID: {$planId}"); } if ($plan->type == PlanType::ADVERTISER_PLAN) { if ($advertiserId == '') { throw new Exception("Advertiser not found in item_number"); } $advertiser = Advertiser::model()->findByPk($advertiserId); if ($advertiser == null) { throw new Exception("Advertiser not found, ID: {$advertiserId}"); } if ($advertiser->wlabel_id != $plan->wlabel_id) { throw new Exception("Advertiser and Plan belong to a different accounts: " . $advertiser->wlabel_id . " <> " . $plan->wlabel_id); } } $purchasedPlan = PurchasedPlan::model()->findByAttributes(array('subscription_id' => $_REQUEST['subscr_id'], 'wlabel_id' => $plan->wlabel_id)); if ($purchasedPlan == null) { if (intval($plan->price) != intval($_REQUEST['mc_gross'])) { throw new Exception("Advertiser and Plan have different prices, possible fraud? " . intval($plan->price) . " <> " . intval($_REQUEST['amount3'])); } // insert new purchased plan $purchasedPlan = new PurchasedPlan(); $purchasedPlan->plan_id = $plan->plan_id; $purchasedPlan->wlabel_id = $plan->wlabel_id; $purchasedPlan->type = $plan->type; if ($advertiserId != '') { $purchasedPlan->advertiser_id = $advertiserId; } $purchasedPlan->method = PaymentType::TYPE_PAYPAL; $purchasedPlan->price = $plan->price; $purchasedPlan->subscription_id = $_REQUEST['subscr_id']; $purchasedPlan->date_created = date("Y-m-d h:i:s"); if (!$purchasedPlan->validate()) { throw new Exception("Plan purchase cannot be saved: " . $this->putErrorsToString($purchasedPlan->getErrors())); } $purchasedPlan->save(); } // create new purchased_plans payments record $purchasedPlanPayment = PurchasedPlanPayment::model()->findByAttributes(array('transaction_id' => $_REQUEST['txn_id'])); if ($purchasedPlanPayment != null) { throw new Exception("There already exists payment with this transaction ID: " . $_REQUEST['txn_id']); } $purchasedPlanPayment = new PurchasedPlanPayment(); $purchasedPlanPayment->pplan_id = $purchasedPlan->pplan_id; $purchasedPlanPayment->date_paid = $purchasedPlan->date_created; $purchasedPlanPayment->date_expire = Date('y-m-d', strtotime("+{$plan->duration} day")); $purchasedPlanPayment->transaction_id = $_REQUEST['txn_id']; if (!$purchasedPlanPayment->validate()) { throw new Exception("Plan payment cannot be saved: " . $this->putErrorsToString($purchasedPlanPayment->getErrors())); } $purchasedPlanPayment->save(); }