public function actionAffiliatePayment() { //print_r($_REQUEST); //Yii::app()->end(); $hashSecretWord = Campaign::getPayment2ChekoutHash(); //2Checkout Secret Word $hashSid = Campaign::getPayment2Chekout(); //2Checkout account number $hashTotal = $_REQUEST['total']; //Sale total to validate against $hashOrder = $_REQUEST['order_number']; //2Checkout Order Number ---- =1 for test!! $StringToHash = strtoupper(md5($hashSecretWord . $hashSid . $hashOrder . $hashTotal)); if ($StringToHash != $_REQUEST['key']) { $result = 'Fail - Hash Mismatch'; } else { $result = 'Success - Hash Matched'; $orderId = $_REQUEST['li_0_product_id']; $payment = ProjectPayments::model()->find('order_id = :ORDER_ID', array('ORDER_ID' => $orderId)); $payment->received = $payment->received + $hashTotal; $payment->to_receive -= $hashTotal; if ($payment->save() && $hashTotal != 0) { $order = Zakaz::model()->resetScope()->findByPk($orderId); if ($order->status < 3) { $order->status = 3; } $order->save(); if ($payment->received == $payment->project_price) { $this->saveFullPaymentWebmasterLog($order); } $buh = new Payment(); $buh->order_id = $orderId; $buh->receive_date = date('Y-m-d H:i:s'); $buh->theme = $order->title; $user = User::model()->findByPk($order->user_id); $buh->user = $user->email; $buh->summ = (double) $hashTotal; $buh->payment_type = Payment::INCOMING_CUSTOMER; $buh->manager = '*****@*****.**'; $buh->approve = 1; $buh->method = 'Bank'; if ($buh->save()) { echo 'ok'; //Yii::app()->user->setFlash('tipDay','Данные сохранены'); EventHelper::payForOrder($orderId); $this->redirect(array('/project/chat', 'orderId' => $orderId)); } else { echo 'Error! Can\'t save buh-payment'; } } else { echo 'Error! Can\'t save order-payment'; } } //echo $result; }
//$img = UploadPaymentImage::$folder . $chek_image; $i = 1; echo '<div class="chek-image-link">'; foreach ($images as $item) { echo CHtml::link('Чек ' . $i++, UploadPaymentImage::$folder . $item->image, array('target' => '_blank')) . ' '; } echo '</div>'; } echo '</div>'; } if (Campaign::getPayment2Chekout() != 0) { // 2Checkout form ?> <form action='https://sandbox.2checkout.com/checkout/purchase' method='post'> <input type='hidden' name='sid' value='<?php echo Campaign::getPayment2Chekout(); ?> ' /> <input type='hidden' name='mode' value='2CO' /> <input type='hidden' name='li_0_type' value='product' /> <input type='hidden' name='li_0_name' value='order<?php echo $order->id; ?> ' /> <input type='hidden' name='li_0_price' value='<?php echo $to_recive; ?> ' /> <input type='hidden' name='li_0_product_id' value='<?php echo $order->id; ?>
public function processOrderPage() { $message = false; $login_ok = false; if (!Yii::app()->user->isGuest && User::model()->isCustomer()) { $login_ok = true; } if (!$login_ok && isset($_POST['Login'])) { if (Yii::app()->user->isGuest) { $model = new UserLogin(); //$this->performAjaxValidation($model); // collect user input data $model->attributes = $_POST['Login']; // validate user input and redirect to previous page if valid if ($model->validate()) { //$this->lastViset(); $login_ok = true; } else { $message = 'Incorrect login or password'; //Yii::app()->end(); } } } if (!$login_ok && isset($_POST['User'])) { $model = new User(); $attributes = $_POST['User']; //$attributes['full_name'] = $_POST['User']['first_name'].' '.$_POST['User']['last_name']; $pos = strpos($attributes['email'], '@'); $attributes['username'] = str_replace(array('@', '.'), '_', $attributes['email']); // substr( $attributes['email'], 0, $pos); $attributes['full_name'] = $_POST['User']['first_name'] . ' ' . $_POST['User']['last_name']; unset($attributes['first_name']); unset($attributes['last_name']); $p = $_POST['Profile']; $country = $p['country']; $countryCodes = $this->getCountryCodes(); $code = $countryCodes[$country]; $attributes['phone_number'] = '+' . $code . $attributes['phone_number']; Yii::import('user.controllers.RegistrationController'); if (RegistrationController::register($model, $attributes)) { $login_ok = true; $profile = new Profile(); $profile->user_id = $model->id; $profile->country = $country; $profile->save(); } else { if ($attributes['email'] != '') { $message = 'Sorry, registration faild...<br>'; foreach ($model->errors as $err => $descr) { $message .= $descr[0] . '<br>'; } } } } $model = new Zakaz(); $model->attributes = $_POST['Zakaz']; // (unixtime) if ($login_ok) { Yii::import('project.controllers.ZakazController'); if (ZakazController::createProject($model, $_POST['Project'])) { $cost = $this->calculateCost($model); $payment = new ProjectPayments(); $payment->order_id = $model->id; $payment->project_price = $cost; $payment->received = 0; $payment->to_receive = $cost; $payment->work_price = 0; $payment->payed = 0; $payment->to_pay = 0; $payment->save(); if (Campaign::getPayment2Chekout() != 0) { $user = User::model()->with('profile')->findByPk($model->user_id); $data = array('sid' => Campaign::getPayment2Chekout(), 'mode' => '2CO', 'li_0_type' => 'product', 'li_0_name' => 'order' . $model->id, 'li_0_price' => $cost, 'li_0_product_id' => $model->id, 'x_receipt_link_url' => 'http://' . $_SERVER["HTTP_HOST"] . '/project/payment/affiliatePayment', 'card_holder_name' => $user->full_name, 'country' => $user->profile->country, 'email' => $user->email, 'phone' => $user->phone_number); $this->redirectWithPost('https://2checkout.com/checkout/purchase', $data); } echo 'Ok! Cost = ' . $cost; Yii::app()->end(); } else { //echo 'Project is not valid!!<br>'; //print_r($_POST['Project']); //Yii::app()->end(); $message = 'Please complete all required fields.'; } } if (!isset($model->unixtime) or $model->unixtime == '') { $model->unixtime = time(); } Yii::app()->theme = explode('.', $_SERVER['SERVER_NAME'])[0]; $this->render('page/order', array('logged' => $login_ok, 'message' => $message, 'project' => $model, 'countryCodes' => $this->getCountryCodes())); Yii::app()->end(); }