/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionMakePayment()
 {
     $model = new UserPayment();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['UserPayment'])) {
         $model->attributes = $_POST['UserPayment'];
         $model->user_id = Yii::app()->user->user_id;
         $model->payment_date = new CDbExpression('NOW()');
         if ($model->save()) {
             $Customer = $model;
             $validator = new CEmailValidator();
             if ($validator->validateValue($Customer->email)) {
                 //email payment receipt
                 $adminEmail = SnapUtil::config('boxomatic/adminEmail');
                 $adminEmailFromName = SnapUtil::config('boxomatic/adminEmailFromName');
                 $message = new YiiMailMessage('Payment receipt');
                 $message->view = 'customer_payment_receipt';
                 $message->setBody(array('Customer' => $Customer, 'UserPayment' => $model), 'text/html');
                 $message->addTo($Customer->email);
                 $message->addTo($adminEmail);
                 $message->setFrom(array($adminEmail => $adminEmailFromName));
                 if (!@Yii::app()->mail->send($message)) {
                     $mailError = true;
                 }
             }
             $this->redirect(array('view', 'id' => $model->payment_id));
         }
     }
     $User = BoxomaticUser::model()->findByPk(Yii::app()->user->id);
     $this->render('make_payment', array('model' => $model, 'User' => $User, 'Customer' => $User));
 }
 /**
  * 
  */
 public function actionRefund($custBox)
 {
     $CustBox = UserBox::model()->findByPk($custBox);
     if ($CustBox) {
         $Payment = new UserPayment();
         $Payment->payment_value = 1 * ($CustBox->Box->box_price + $CustBox->delivery_cost);
         //make price a negative value for payment table
         $Payment->payment_type = 'CREDIT';
         $Payment->payment_date = new CDbExpression('NOW()');
         $Payment->user_id = $CustBox->user_id;
         $Payment->staff_id = Yii::app()->user->id;
         $note = 'REFUND FOR: 1 x ' . $CustBox->Box->BoxSize->box_size_name . ' Box @ ' . SnapFormat::currency($CustBox->Box->box_price);
         $tmpDel = (double) $CustBox->delivery_cost;
         if (!empty($tmpDel)) {
             $note .= ' + ' . SnapFormat::currency($tmpDel) . ' delivery';
         }
         $Payment->payment_note = $note;
         $Payment->save();
         $CustBox->delete();
         Yii::app()->user->setFlash('success', "Customer box has been excluded for delivery and refunded.");
     } else {
         Yii::app()->user->setFlash('success', "Could not find the given Customer Box");
     }
     $this->redirect(array('userBoxes', 'date' => $CustBox->Box->delivery_date_id));
 }
 /**
  * @author Chienlv levanchien.it@gmail.com
  * @todo action process payment, support Paypal and Pin
  */
 public function actionProcess()
 {
     $data = isset($_POST) ? $_POST : false;
     if ($data) {
         #{
         switch ($data['payment-method']) {
             /**
              * @todo Default is Paypal
              * @link http://stackoverflow.com/questions/14843212/submit-form-via-curl-and-redirect-browser-to-paypal tutoria
              */
             default:
             case 0:
                 #Delete $ data ['payment-method'] because it is not for paypal
                 unset($data['payment-method']);
                 #The variable $data obtained from the form sent to
                 header('Location: https://www.paypal.com/cgi-bin/webscr?' . http_build_query($data));
                 break;
                 /**
                  * @todo use Pin paymant
                  * Cac tham so gui tu from
                  * validate email? @toantv
                  */
             /**
              * @todo use Pin paymant
              * Cac tham so gui tu from
              * validate email? @toantv
              */
             case 1:
                 $model = new PinPaymentForm();
                 if (isset($_POST['PinPaymentForm'])) {
                     $model->attributes = $_POST['PinPaymentForm'];
                     if ($model->validate()) {
                         $reponse = $model->pinPayMent();
                         if (isset($reponse['error'])) {
                             Yii::app()->user->setFlash('errors', $reponse);
                         } elseif (isset($reponse['response'])) {
                             $model_pay = new UserPayment();
                             $model_pay->payment_date = new CDbExpression('NOW()');
                             $model_pay->payment_type = 'CREDIT-PIN';
                             $model_pay->payment_value = number_format($reponse['response']['amount'] / 100, 2);
                             $model_pay->user_id = Yii::app()->user->id;
                             $model_pay->staff_id = null;
                             $model_pay->payment_note = $reponse['response']['token'];
                             $model_pay->save();
                             $BoxoCart = new BoxoCart();
                             $BoxoCart->confirmOrder();
                             $this->redirect(array('user/payments'));
                         }
                     }
                 }
                 $this->render('_pin', array('model' => $model, 'paymentMethod' => $data['payment-method'], 'amount' => $data['amount']));
                 break;
                 /**
                  * @todo Bank Transfer
                  */
             /**
              * @todo Bank Transfer
              */
             case 2:
                 //Send email
                 $adminEmail = SnapUtil::config('boxomatic/adminEmail');
                 $adminEmailFromName = SnapUtil::config('boxomatic/adminEmailFromName');
                 $message = new YiiMailMessage('Transfer information of ' . Yii::app()->name);
                 $message->view = 'bank_transfer';
                 $message->setBody($data, 'text/html');
                 $message->addTo($adminEmail);
                 $message->addTo($data['email']);
                 $message->setFrom(array($adminEmail => $adminEmailFromName));
                 if (Yii::app()->mail->send($message)) {
                     $BoxoCart = new BoxoCart();
                     $BoxoCart->confirmOrder();
                 }
                 $this->render('_bank_transfer', array('data' => $data));
                 break;
         }
     }
 }
 /**
  * Displays upload polygon page header.
  *
  * @Route("/ftransaction", name="useraccount_ftransaction", options={"expose"=true})
  * @Method("GET|POST")
  * @Template()
  */
 public function ftransactionAction(Request $request)
 {
     $user = $this->getUser();
     $em = $this->getDoctrine()->getManager();
     $newpayment = new UserPayment();
     $newpayment->setUser($user);
     $newpayment->setBankApprovalCode($request->get("bank_approval_code"));
     $newpayment->setCardholder($request->get("cardholder"));
     $newpayment->setIsVisaDebit($request->get("is_visa_debit"));
     $newpayment->setIsoCode($request->get("iso_code"));
     $newpayment->setBankTransactionId($request->get("bank_transaction_id"));
     $newpayment->setResponseOrderId($request->get("response_order_id"));
     $newpayment->setChargeTotal($request->get("charge_total"));
     $newpayment->setTransName($request->get("trans_name"));
     $newpayment->setRvarTransid($request->get("rvar_transid"));
     $newpayment->setRvarBilltype($request->get("rvar_billtype"));
     $newpayment->setF4l4($request->get("f4l4"));
     $newpayment->setCard($request->get("card"));
     $newpayment->setMessage($request->get("message"));
     $newpayment->setExpiryDate($request->get("expiry_date"));
     $newpayment->setResult($request->get("result"));
     $newpayment->setTxnNum($request->get("txn_num"));
     $newpayment->setTimeStamp($request->get("time_stamp"));
     $newpayment->setDateStamp($request->get("date_stamp"));
     $newpayment->setResponseCode($request->get("response_code"));
     $em->persist($newpayment);
     $em->flush();
     return array('user' => $user, 'payment' => $newpayment);
 }
Beispiel #5
0
<?php

$Payment = new UserPayment();
//Needed for attribute labels
?>
<div class="page-header">
    <h1>Payments</h1>
</div>
<div class="row">
    <div class="col-sm-2">
        <strong><?php 
echo CHtml::encode($Payment->getAttributeLabel('payment_date'));
?>
</strong>
    </div>
    <div class="col-sm-6">
        <strong><?php 
echo CHtml::encode($Payment->getAttributeLabel('payment_note'));
?>
</strong>
    </div>
    <div class="col-sm-1">
        <strong><?php 
echo CHtml::encode($Payment->getAttributeLabel('payment_type'));
?>
</strong>
    </div>
    <div class="col-sm-1 text-right">
        <strong><?php 
echo CHtml::encode($Payment->getAttributeLabel('credit'));
?>
 /**
  * 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 = UserPayment::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 /**
  * Process payment and notify user if IPN is received.
  */
 public function actionIpn()
 {
     $ipn = new PPIpnAction($this, "ipn");
     /*
      * Process payment
      *
      * See PPPhpTransaction for validation details, important values:
      * - PPPhpTransaction::currency = Valid currency (default: USD)
      * - PPPhpTransaction::amount = Minumum payment amount (default: 5.00)
      *
      * I recommend using an active record for storage / validation.
      */
     $ipn->onRequest = function ($event) {
         // Check if this is a transaction
         if (!isset($event->details["txn_id"])) {
             $event->msg = "Missing txn_id";
             Yii::log($event->msg, "warning", "payPal.controllers.DefaultController");
             $event->sender->onFailure($event);
             return;
         }
         Yii::log("Begin Paypal Transaction", "error", "payPal.controllers.DefaultController");
         // Put payment details into a transaction model
         //			$transaction = new PPPhpTransaction;
         //			$transaction->paymentStatus = $event->details["payment_status"];
         //			$transaction->mcCurrency = $event->details["mc_currency"];
         //			$transaction->mcGross = $event->details["mc_gross"];
         //			$transaction->receiverEmail = $event->details["receiver_email"];
         //			$transaction->txnId = $event->details["txn_id"];
         // Put payment details into a transaction model
         $transaction = new UserPayment();
         $transaction->scenario = 'PaypalIPN';
         $transaction->paypal_payment_status = $event->details["payment_status"];
         $transaction->paypal_mc_currency = $event->details["mc_currency"];
         $transaction->paypal_mc_gross = $event->details["mc_gross"];
         $transaction->paypal_receiver_email = $event->details["receiver_email"];
         $transaction->paypal_txn_id = $event->details["txn_id"];
         $transaction->payment_value = $event->details["mc_gross"];
         $transaction->payment_type = 'PAYPAL';
         $transaction->payment_date = new CDbExpression('NOW()');
         $transaction->user_id = (int) $event->details["custom"];
         $transaction->payment_note = 'PayPal Payment of: ' . $event->details["mc_gross"];
         // Successfully processed payment: Log and invoke success event
         if ($transaction->save()) {
             $event->msg = "Successfully processed payment";
             Yii::log("{$event->msg}\nTransaction ID: {$event->details["txn_id"]}", "error", "payPal.controllers.DefaultController");
             $event->sender->onSuccess($event);
         } else {
             $event->msg = "Could not process payment";
             Yii::log("{$event->msg}\nTransaction ID: {$event->details["txn_id"]}", "error", "payPal.controllers.DefaultController");
             $errorStr = print_r($transaction->getErrors(), true);
             Yii::log($errorStr, "error", "payPal.controllers.DefaultController");
             $event->sender->onFailure($event);
         }
     };
     // Ignoring failures
     $ipn->onFailure = function ($event) {
         // Could e.g. send a notification mail on certain events
         $respstr = print_r($event->details, true);
         Yii::log("IPN Failure" . $respstr, "error", "payPal.controllers.ipn.PPIpnAction");
     };
     // Send confirmation mail to customer
     $ipn->onSuccess = function ($event) {
         Yii::log("IPN Success", "error", "payPal.controllers.ipn.PPIpnAction");
         //			$to = $event->details["payer_email"];
         //			$from = $event->details["receiver_email"];
         //			$subject = "Payment received";
         //			$body = "Your payment has been processed.\n" .
         //				"Receiver: $from\n" .
         //				"Amount: {$event->details["mc_gross"]} {$event->details["mc_amount"]}\n";
         //			$headers="From: $from\r\nReply-To: $from";
         $respstr = print_r($event->details, true);
         Yii::log("Success:" . $respstr, "error", "payPal.controllers.ipn.PPIpnAction");
         //mail($to,$subject,$body,$headers);
     };
     $ipn->run();
 }