public function actionRegister() { $advertiser = new Advertiser(); $user = new User(); if (isset($_POST['User'])) { // populate input data to $a and $b $user->attributes = $_POST['User']; $advertiser->wlabel_id = Yii::app()->user->getWhiteLabelId(); $user->wlabel_id = Yii::app()->user->getWhiteLabelId(); $user->type = UserType::TYPE_ADVERTISER; $user->date_created = date("Y-m-d h:i:s"); $user->status = $this->getStatusAccordingToWLModeration(); $valid = true; // validate BOTH $a and $b $valid = $advertiser->validate() && $valid; $valid = $user->validate() && $valid; if ($user->password != '' && $user->password != $user->confirm_password) { $user->addError('password', 'You have to use the same password!'); $valid = false; } if ($valid) { $user->save(false); $advertiser->user_id = $user->user_id; $advertiser->mbroker_id = Utils::getReferingMediabroker(); $advertiser->save(false); $this->redirect(array('advertiser/regsuccessful')); } } $this->render('register', array('user' => $user)); }
private function getAdvertiserIdForUser($userId) { $a = Advertiser::model()->findByAttributes(array('user_id' => $userId)); if ($a != null) { return $a->advertiser_id; } return null; }
public function actionIndex() { $this->layout = 'login'; $wlabelId = isset($_REQUEST['wid']) ? $_REQUEST['wid'] : ''; if ($wlabelId == '') { throw new CHttpException(404, 'Bad parameter wid'); } $planId = isset($_REQUEST['pid']) ? $_REQUEST['pid'] : ''; if ($planId == '') { throw new CHttpException(404, 'Bad parameter pid'); } $advertiserId = isset($_REQUEST['aid']) ? $_REQUEST['aid'] : ''; if ($advertiserId == '') { throw new CHttpException(404, 'Bad parameter aid'); } $returnUrl = isset($_REQUEST['return']) ? $_REQUEST['return'] : ''; if ($returnUrl == '') { throw new CHttpException(404, 'Bad parameter return'); } $wl = WhiteLabel::model()->findByPk(Yii::app()->user->getWhiteLabelId()); if ($wl == null) { throw new Exception("Account doesn't exist"); } $plan = Plan::model()->findByAttributes(array('plan_id' => $planId, 'wlabel_id' => $wlabelId)); if ($plan == null) { throw new CHttpException(404, 'Cannot find plan!'); } $advertiser = Advertiser::model()->findByAttributes(array('advertiser_id' => $planId, 'wlabel_id' => $advertiserId)); if ($plan == null) { throw new CHttpException(404, 'Cannot find advertiser!'); } $form = new AuthorizenetPaymentForm(); if (isset($_POST['AuthorizenetPaymentForm'])) { $form->attributes = $_POST['AuthorizenetPaymentForm']; $form->advertiser_id = $advertiserId; $form->wlabel_id = $wlabelId; $form->plan_id = $plan->plan_id; $form->refId = $plan->plan_id; $form->name = "Plan Subscription"; $form->unit = "days"; $form->totalOccurrences = 999; $form->trialOccurrences = 0; $form->trialAmount = 0; $form->startDate = date('Y-m-d'); $form->length = $plan->duration; $form->amount = $plan->price; if ($form->validate()) { if ($form->sendCreateSubscription($wl, $plan)) { $this->redirect($returnUrl); } } } if (isset($_GET['AuthorizenetPaymentForm'])) { $form->attributes = $_GET['AuthorizenetPaymentForm']; } $this->render('form_authnet_payment', array('model' => $form)); }
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(); }
<?php $advertisers = Advertiser::model()->getAdvertisers(); if (count($advertisers) > 0) { ?> <div class="form"> <?php $form = $this->beginWidget('CActiveForm', array('id' => 'purchased-plan-form', 'enableAjaxValidation' => false)); ?> <?php echo $form->errorSummary($model); ?> <div class="row"> <?php echo $form->labelEx($model, 'advertiser_id'); ?> <?php echo $form->dropDownList($model, 'advertiser_id', $advertisers, array('' => '')); ?> <?php echo $form->error($model, 'advertiser_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'plan_id');
?> <?php echo $form->errorSummary($model); ?> <?php if (!Yii::app()->user->isAdvertiser()) { ?> <div class="row"> <?php echo $form->labelEx($model, 'advertiser_id'); ?> <?php echo $form->dropDownList($model, 'advertiser_id', Advertiser::model()->getAdvertisers(), array('' => '')); ?> <?php echo $form->error($model, 'advertiser_id'); ?> </div> <?php } ?> <div class="row"> <?php echo $form->labelEx($model, 'headline'); ?> <?php
/** * @return array validation rules for model attributes. */ public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array(array('advertiser_id, url, name, street_address, city, state, zip, phone, date_created', 'required'), array('wlabel_id, advertiser_id, type', 'numerical', 'integerOnly' => true), array('wlabel_id', 'in', 'range' => array_keys(CHtml::listData(WhiteLabel::model()->findAll(), 'wlabel_id', 'name')), 'allowEmpty' => false), array('advertiser_id', 'in', 'range' => array_keys(CHtml::listData(Advertiser::model()->findAll(), 'advertiser_id', 'user_id')), 'allowEmpty' => false), array('url, name, street_address', 'length', 'max' => 100), array('city, state, zip, phone, logo, mon_open, mon_close, tue_open, tue_close, wed_open, wed_close, thu_open, thu_close, fri_open, fri_close, sat_open, sat_close, sun_open, sun_close', 'length', 'max' => 40), array('description', 'safe'), array('url', 'url'), array('logo', 'file', 'types' => 'jpg, gif, png', 'allowEmpty' => true), array('p_categories', 'verifyNumberOfCategories'), array('p_locations', 'verifyNumberOfLocations'), array('p_coupons', 'verifyNumberOfCoupons'), array('type', 'verifyNumberOfFeaturedListings'), array('listing_id, wlabel_id, advertiser_id, url, name, street_address, city, state, zip, phone, description, logo, type, date_created, mon_open, mon_close, tue_open, tue_close, wed_open, wed_close, thu_open, thu_close, fri_open, fri_close, sat_open, sat_close, sun_open, sun_close', 'safe', 'on' => 'search')); }
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(); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Advertiser::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }