Exemplo n.º 1
0
 /**
  * If a Cart Payment exists for the shopping cart it is returned
  * Otherwise we create one for the shopping cart.
  *
  * @return bool|CartPayment
  */
 public static function getOrCreateCartPayment()
 {
     $objPayment = null;
     if (is_null(Yii::app()->shoppingcart->payment_id) === false) {
         $objPayment = CartPayment::model()->findByPk(Yii::app()->shoppingcart->payment_id);
     } else {
         $objPayment = new CartPayment();
         if ($objPayment->save() === false) {
             Yii::log("Error saving payment:\n" . print_r($objPayment->getErrors(), true), 'error', 'application.' . __CLASS__ . '.' . __FUNCTION__);
             return false;
         }
     }
     return $objPayment;
 }
 /**
  * Our AIM payment handling function
  *
  * @param $intPaymentId
  * @return bool
  */
 protected function runPayment($intPaymentId)
 {
     $objCart = Yii::app()->shoppingcart;
     $objPayment = CartPayment::model()->findByPk($intPaymentId);
     Yii::log("Running payment on " . $objCart->id_str, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
     $arrPaymentResult = Yii::app()->getComponent($objPayment->payment_module)->setCheckoutForm($this->checkoutForm)->run();
     Yii::log("{$objPayment->payment_module} result:\n" . print_r($arrPaymentResult, true), 'info', 'application.' . __CLASS__ . '.' . __FUNCTION__);
     return $this->finalizeOrder($arrPaymentResult);
 }
 /**
  * Mark a cart as paid manually
  */
 public function actionPay()
 {
     $id = Yii::app()->getRequest()->getQuery('id');
     $objCartPayment = CartPayment::model()->findByPk($id);
     $objCart = Cart::model()->findByAttributes(array('payment_id' => $id));
     if (isset($_POST['Cart']) && isset($_POST['CartPayment'])) {
         echo self::processManualPayment($objCart, $objCartPayment);
     } else {
         echo $this->renderPartial("_pay", array('objCart' => $objCart, 'model' => $objCartPayment), true);
     }
 }
Exemplo n.º 4
0
 /**
  * Process payments coming in from third party systems, such as Paypal IPN and other SIM integrations
  */
 public function actionPayment()
 {
     $strModule = Yii::app()->getRequest()->getQuery('id');
     Yii::log("Incoming message for " . $strModule, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
     try {
         $retVal = Yii::app()->getComponent($strModule)->gateway_response_process();
         Yii::log("Gateway response {$strModule}:\n" . print_r($retVal, true), 'info', 'application.' . __CLASS__ . '.' . __FUNCTION__);
         if (is_array($retVal)) {
             if ($retVal['success']) {
                 $objCart = Cart::model()->findByAttributes(array('id_str' => $retVal['order_id']));
                 if (is_null($objCart)) {
                     Yii::log($retVal['order_id'] . " is not our order, ignoring", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                 }
                 if ($objCart instanceof Cart && $objCart->cart_type == CartType::awaitpayment) {
                     $objPayment = CartPayment::model()->findByPk($objCart->payment_id);
                     $objPayment->payment_amount = isset($retVal['amount']) ? $retVal['amount'] : 0;
                     $objPayment->payment_data = $retVal['data'];
                     $objPayment->datetime_posted = isset($retVal['payment_date']) ? date("Y-m-d H:i:s", strtotime($retVal['payment_date'])) : new CDbExpression('NOW()');
                     $objPayment->save();
                     self::EmailReceipts($objCart);
                     Yii::log('Receipt e-mails added to the queue', 'info', __CLASS__ . '.' . __FUNCTION__);
                     self::FinalizeCheckout($objCart, Yii::app()->getComponent($strModule)->performInternalFinalizeSteps);
                     Yii::log('Checkout Finalized', 'info', __CLASS__ . '.' . __FUNCTION__);
                     if (!isset($retVal['output'])) {
                         Yii::app()->controller->redirect(Yii::app()->controller->createAbsoluteUrl('cart/receipt', array('getuid' => $objCart->linkid), 'http'));
                     }
                 }
             }
             if (isset($retVal['output'])) {
                 echo $retVal['output'];
             } else {
                 $objCart = Cart::LoadByIdStr($retVal['order_id']);
                 if ($objCart instanceof Cart) {
                     Yii::app()->controller->redirect(Yii::app()->controller->createAbsoluteUrl('cart/restore', array('getuid' => $objCart->linkid)));
                 }
                 echo Yii::t('global', 'Payment Error: Was not successful, and payment attempt did not return a proper error message');
             }
         }
     } catch (Exception $e) {
         //Can't find module. if $val=="fancyshipping" then filename must be "FancyshippingModule.php" (case sensitive)
         Yii::log("Received payment but could not process {$e}", 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
     }
 }