/** * 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)); }
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(); }