public function actionIndex()
 {
     $criteria = new CDbCriteria();
     $criteria->condition = "Price != 0";
     $model = Memberships::model()->findAll($criteria);
     $dp_model = new DirectPayment();
     if (isset($_POST['DirectPayment'])) {
         $dp_model->attributes = $_POST['DirectPayment'];
         $package = Memberships::model()->findByPk($dp_model->package);
         if (isset($_POST['paypalpay'])) {
             if ($dp_model->validate(array('package'))) {
                 $paymentInfo['Order']['theTotal'] = $package->Price;
                 $paymentInfo['Order']['description'] = $package->Description;
                 $paymentInfo['Order']['quantity'] = '1';
                 Yii::app()->session['theTotal'] = $package->Price;
                 Yii::app()->session['memberShippId'] = $package->Objid;
                 // call paypal
                 $result = Yii::app()->Paypal->SetExpressCheckout($paymentInfo);
                 //Detect Errors
                 if (!Yii::app()->Paypal->isCallSucceeded($result)) {
                     if (Yii::app()->Paypal->apiLive === true) {
                         //Live mode basic error message
                         $error = 'We were unable to process your request. Please try again later';
                     } else {
                         //Sandbox output the actual error message to dive in.
                         $error = $result['L_LONGMESSAGE0'];
                     }
                     $this->render('message', array('message' => $error));
                     Yii::app()->end();
                 } else {
                     // send user to paypal
                     $token = urldecode($result["TOKEN"]);
                     $payPalURL = Yii::app()->Paypal->paypalUrl . $token;
                     $this->redirect($payPalURL);
                 }
             }
         }
         if (isset($_POST['paypaldirectpay'])) {
             if ($dp_model->validate()) {
                 /*Paypla Direct payment Start*/
                 $paymentInfo = array('Member' => array('first_name' => $dp_model->name, 'last_name' => '', 'last_name' => '', 'billing_address' => '', 'billing_address2' => '', 'billing_country' => '', 'billing_city' => '', 'billing_state' => '', 'billing_zip' => ''), 'CreditCard' => array('card_number' => $dp_model->cardNumber, 'credit_type' => $dp_model->cardType, 'expiration_month' => $dp_model->expirationMonth, 'expiration_year' => $dp_model->expirationYear, 'cv_code' => $dp_model->cvCode), 'Order' => array('theTotal' => $package->Price));
                 /* 
                  * On Success, $result contains [AMT] [CURRENCYCODE] [AVSCODE] [CVV2MATCH]  
                  * [TRANSACTIONID] [TIMESTAMP] [CORRELATIONID] [ACK] [VERSION] [BUILD] 
                  *  
                  * On Fail, $ result contains [AMT] [CURRENCYCODE] [TIMESTAMP] [CORRELATIONID]  
                  * [ACK] [VERSION] [BUILD] [L_ERRORCODE0] [L_SHORTMESSAGE0] [L_LONGMESSAGE0]  
                  * [L_SEVERITYCODE0]  
                  */
                 $result = Yii::app()->Paypal->DoDirectPayment($paymentInfo);
                 //Detect Errors
                 if (!Yii::app()->Paypal->isCallSucceeded($result)) {
                     if (Yii::app()->Paypal->apiLive === true) {
                         //Live mode basic error message
                         $error = 'We were unable to process your request. Please try again later';
                     } else {
                         //Sandbox output the actual error message to dive in.
                         $error = $result['L_LONGMESSAGE0'];
                     }
                     //echo $error;
                     $this->render('message', array('message' => $error));
                 } else {
                     //Payment was completed successfully, do the rest of your stuff
                     $this->saveSubscription($result['TRANSACTIONID'], $package->Objid);
                 }
                 Yii::app()->end();
                 /*Paypla Direct payment End*/
             }
         }
     }
     $this->render('index', array('models' => $model, 'dp_model' => $dp_model));
 }
예제 #2
0
 public function payNow(DirectPayment $payment)
 {
     $payment->send();
 }