/** * 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; } } }
/** * Allow admins to enter payments on behalf of customers. */ public function actionEnterPayments() { $model = new UserPayment(); $model->payment_date = date('Y-m-d H:i:s'); if (isset($_POST['UserPayment'])) { $model->attributes = $_POST['UserPayment']; $model->staff_id = Yii::app()->user->id; if ($model->save()) { $Customer = $model->User; $validator = new CEmailValidator(); if ($validator->validateValue($Customer->email)) { //email payment receipt $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(SnapUtil::config('boxomatic/adminEmail')); $message->setFrom(array(SnapUtil::config('boxomatic/adminEmail') => SnapUtil::config('boxomatic/adminEmailFromName'))); if (!@Yii::app()->mail->send($message)) { $mailError = true; } } $this->refresh(); } } $search_model = new UserPayment('search'); $search_model->unsetAttributes(); // clear any default values if (isset($_GET['UserPayment'])) { $search_model->attributes = $_GET['UserPayment']; } $this->render('enterPayments', array('model' => $model, 'search_model' => $search_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(); }