public function buyerStore()
 {
     //$select = User::orderBy('created_at', 'desc')->first();
     $select = User::where('fbId', '=', $_SESSION['userFbID'])->get();
     $buyer = new Buyer();
     foreach ($select as $selects) {
         $name = $selects['name'];
         $fbId = $selects['fbId'];
         $email = $selects['email'];
         $image = $selects['image'];
     }
     $buyer->name = $name;
     $buyer->fbId = $fbId;
     $buyer->email = $email;
     $buyer->image = $image;
     $findUsers = Buyer::all();
     $count = 0;
     foreach ($findUsers as $findUser) {
         if ($findUser['fbId'] == $_SESSION['userFbID']) {
             $count = +1;
         }
     }
     if ($count == 0) {
         $buyer->save();
     }
     return Redirect::to('homeBuyer');
 }
Example #2
0
 /**
  * @dataProvider addressData
  */
 public function testSetAddress($address)
 {
     $client = new Buyer();
     $client->setAddress($address['street'], $address['city'], $address['zipcode'], $address['country']);
     $this->assertTrue(is_array($client->getAddress()));
     $this->assertEquals($address, $client->getAddress());
 }
Example #3
0
 public function testValidateMethod()
 {
     $violations = 0;
     $executionContext = $this->getMockBuilder('\\Symfony\\Component\\Validator\\Context\\ExecutionContextInterface')->getMock();
     $violationBuilder = $this->getMockBuilder('\\Symfony\\Component\\Validator\\Violation\\ConstraintViolationBuilderInterface')->getMock();
     $violationBuilder->expects($this->any())->method('addViolation')->willReturnCallback(function () use(&$violations) {
         $violations += 1;
     });
     $executionContext->expects($this->any())->method('buildViolation')->willReturn($violationBuilder);
     $buyer = new Buyer();
     $buyer->validate($executionContext);
     $this->assertEquals(0, $violations);
     $violations = 0;
     $buyer->setEmail('t');
     $buyer->validate($executionContext);
     $this->assertEquals(1, $violations);
     $violations = 0;
     $buyer->setFirstName('t');
     $buyer->validate($executionContext);
     $this->assertEquals(1, $violations);
     $violations = 0;
     $buyer->setLastName('t');
     $buyer->validate($executionContext);
     $this->assertEquals(0, $violations);
 }
Example #4
0
 static function getOrCreate($member)
 {
     $email = $member['email'];
     if ($buyer = Buyer::where('email', '=', $email)->first()) {
         return $buyer;
     } else {
         $buyer = new Buyer();
         $buyer->first_name = $member['fname'] ? $member['fname'] : 'First';
         $buyer->last_name = $member['lname'] ? $member['lname'] : 'Last';
         $buyer->email = $member['email'];
         $buyer->save();
         return $buyer;
     }
 }
Example #5
0
 /**
  * Search Licenses
  */
 static function search($q = NULL, $param = NULL, $product_code = NULL)
 {
     $_tbl_licenses = License::getTableName();
     $_tbl_licensesUses = LicensesUses::getTableName();
     $_tbl_transactions = Transaction::getTableName();
     $_tbl_purchases = Purchase::getTableName();
     $_tbl_products = Product::getTableName();
     $_tbl_plans = Plan::getTableName();
     $_tbl_buyers = Buyer::getTableName();
     $fields = array("{$_tbl_licenses}.*", DB::raw("COUNT({$_tbl_licensesUses}.id) AS totalUsed"), "{$_tbl_buyers}.first_name", "{$_tbl_buyers}.last_name", "{$_tbl_buyers}.email", "{$_tbl_products}.code", "{$_tbl_plans}.code AS plan_code", "{$_tbl_products}.api_key");
     $licenses = DB::table($_tbl_licenses)->leftJoin($_tbl_licensesUses, "{$_tbl_licensesUses}.license_id", '=', "{$_tbl_licenses}.id")->join($_tbl_transactions, "{$_tbl_transactions}.id", '=', "{$_tbl_licenses}.transaction_id")->join($_tbl_plans, "{$_tbl_transactions}.plan_id", '=', "{$_tbl_plans}.id")->join($_tbl_purchases, "{$_tbl_purchases}.id", '=', "{$_tbl_transactions}.purchase_id")->join($_tbl_products, "{$_tbl_products}.id", '=', "{$_tbl_purchases}.product_id")->join($_tbl_buyers, "{$_tbl_buyers}.id", '=', "{$_tbl_purchases}.buyer_id")->select($fields)->groupBy("{$_tbl_licenses}.id");
     $q = $q ? $q : Input::get('q');
     $param = $param ? $param : Input::get('param');
     if ($q) {
         if ($param == "key") {
             $licenses = $licenses->where("license_key", '=', $q);
         }
         if ($param == "email") {
             $licenses = $licenses->where("email", '=', $q);
         }
         if ($product_code) {
             $licenses = $licenses->where($_tbl_licenses . ".license_key", 'LIKE', strtoupper($product_code) . '-%');
         }
     }
     return $licenses->orderBy($_tbl_licenses . '.created_at', 'DESC')->paginate(25);
 }
 public function buyers()
 {
     // Eloquent
     $buyer_objs = Buyer::active();
     $buyers = array();
     foreach ($buyer_objs as $key => $buyer) {
         $buyers[] = array('id' => $buyer['id'], 'name' => ucfirst(strtolower($buyer['name'])));
     }
     return Response::json($buyers);
 }
 public function order($id)
 {
     $orderCake = Cake::find($id);
     $buyer = Buyer::orderBy('created_at', 'desc')->first();
     $fbID = $buyer->fbID;
     $select = Cake::where('id', '=', $id)->get();
     $order = new Order();
     $name = $select['name'];
     $price = $select['price'];
     $category = $select['category'];
     $description = $select['description'];
     $fbID = $fbID;
     $image = $select['image'];
     $order->name = $name;
     $order->price = $price;
     $order->category = $category;
     $order->description = $description;
     $order->buyersID = $fbID;
     $order->image = $image;
     $order->save();
     return Redirect::to('myaccountBuyer');
 }
Example #8
0
 public static function check_phone($phone, $mobile1, $mobile2)
 {
     $em = Buyer::where('phone', 'like', $phone)->orWhere('mobile1', 'like', $mobile1)->orWhere('mobile2', 'like', $mobile2)->first();
     if ($em) {
         return $em;
     } else {
         return false;
     }
 }
Example #9
0
 public function getBuyerName()
 {
     return $this->buyer->getName();
 }
Example #10
0
    /**
     *
     * @param String $post
     * @return int $state
     */
    public function transactionDecode($post)
    {
        $sh = new Sherlocks($this->Buyer);
        //attention this->buyer pas instancié - voir pour le mettre en statique
        $rtn = $sh->decode($post);
        if ($rtn[0] == 1) {
            //$this->log->log(__FILE__.' : '.__LINE__.' rtn reload sherlocks '.$rtn[1].' '.$rtn[2], Zend_Log::WARN);
            $trace = "via sherlocks " . $rtn[0];
            $this->db->query("UPDATE ts_user_usr SET usr_credit = (usr_credit + '%u') WHERE usr_id = '%u';", array($rtn[1], $rtn[2]));
            if ($this->db->affectedRows() == 1) {
                $trace .= " via BUYsherlocks";
                $this->db->query("INSERT INTO t_recharge_rec (rty_id, usr_id_buyer, usr_id_operator, poi_id, rec_date, rec_credit, rec_trace) VALUES ('%u', '%u', '%u', '%u', NOW(), '%u', '%s')", array(3, $rtn[2], $rtn[2], 1, $rtn[1], $trace));
                $Buyer = new Buyer($rtn[2], 3, '', '', 1);
                //mail
                $subject = 'Rechargement Buckutt';
                $message = 'Bonjour ' . $Buyer->getFirstname() . ' ' . $Buyer->getLastname() . ',<br>
<br>
Tu viens d&#39;effectuer un rechargement sur ton porte-monnaie électronique BuckUTT.<br>
<br>
Ton numéro de rechargement est le ' . $this->db->insertId() . '<br>

<br>

<div style="width: 640px; font-family: Arial,Helvetica,sans-serif; font-size: 11px;">--------------------------------------------------------------------------------------------<br>
<b>Montant rechargé : </b>' . $rtn[1] / 100 . ' euros<br>
--------------------------------------------------------------------------------------------<br><br>
<b>Informations complémentaires : </b><br>
Pour plus d&#39;informations : <a href="http://etu.utt.fr/buckutt">http://etu.utt.fr/buckutt</a><br>
Pour toute question : <a href="mailto:buckutt@utt.fr" target="_blank">buckutt@utt.fr</a><br>
<br>
<b>Mentions légales :</b><br>
Facture établie par : Association BDE UTT - 12, rue Marie Curie - 10000 - TROYES - FRANCE, à l&#39;attention de : ' . $Buyer->getLastname() . ' ' . $Buyer->getFirstname() . ' .<br>';
                $headers = 'From: buckutt@utt.fr' . "\r\n" . 'Reply-To: buckutt@utt.fr' . "\r\n" . 'Content-Type: text/html; charset=windows-1252' . 'X-Mailer: PHP/' . phpversion();
                $err = mail($Buyer->getMail(), $subject, $message, $headers);
                /*
                				if ($err) {
                	$this->log->log(__FILE__.' : '.__LINE__.' mail reload sherlocks bien reussi denvoie mail, contenu prevu '.$Buyer->getMail().$message, Zend_Log::WARN);
                   
                } else {
                   $this->log->log(__FILE__.' : '.__LINE__.' /!\ mail reload sherlocks echec denvoie mail, contenu prevu '.$Buyer->getMail().$message, Zend_Log::WARN);
                }
                */
                return 1;
            } else {
                return 405;
            }
            //$this->log->log(__FILE__.' : '.__LINE__.' rtn reload sherlocks '.$tmp, Zend_Log::WARN);
            return $tmp;
        } else {
            return $rtn[0];
        }
    }
 /**
  * Stripe IPN
  */
 private function _ipn_stripe()
 {
     // Set your secret key: remember to change this to your live secret key in production
     // See your keys here https://manage.stripe.com/account
     // Add Stripe library
     require_once app_path() . "/libraries/stripe-php-1.9.0/lib/Stripe.php";
     // Add Stripe library
     Stripe::setApiKey(Config::get('project.stripe_secret_key'));
     // Retrieve the request's body and parse it as JSON
     $body = @file_get_contents('php://input');
     $event_json = json_decode($body);
     // For extra security, retrieve from the Stripe API
     try {
         $event_id = $event_json->id;
         $event_json = Stripe_Event::retrieve($event_id);
     } catch (Exception $e) {
         exit($e->getMessage());
     }
     // Do something with $event_json
     if (isset($event_json->type)) {
         // Customer and Affiliate
         // Get user_id
         $customer_id = !empty($event_json->data->object->customer) ? $event_json->data->object->customer : NULL;
         if ($customer_id) {
             try {
                 $customer = Stripe_Customer::retrieve($customer_id);
                 $email = $customer->email;
                 $dkData = $customer->metadata;
                 $buyer = Buyer::where('email', '=', $email)->first();
                 $affiliate_id = !empty($dkData['affiliate_id']) ? $dkData['affiliate_id'] : NULL;
                 // $buyer->affiliate_id
                 $first_name = !empty($dkData['first_name']) ? $dkData['first_name'] : NULL;
                 $last_name = !empty($dkData['last_name']) ? $dkData['last_name'] : NULL;
                 // Get Product Info
                 $product = Product::where('id', '=', $dkData['product_id'])->first();
             } catch (Exception $e) {
                 header('HTTP/1.1 400 Bad Request', true, 400);
                 exit("Not able to fetch customer");
             }
         } else {
             // No customer ID was found, stop the process here
             exit('Customer was not found in object');
         }
         // If No buyer was found
         if (empty($buyer)) {
             exit($event_json->type . ' : Buyer was not found');
         }
         // If No product was found
         if (empty($product)) {
             exit($event_json->type . ' : Product was not found');
         }
         // Create subscription
         if ($event_json->type == "customer.subscription.created") {
             $plan_code = $event_json->data->object->plan->id;
             // Remove word "_split" from it
             $plan_code = str_replace('_split', '', $plan_code);
             // Get Plan and Product
             $plan = Plan::where('stripe_id', '=', $plan_code)->first();
             // Push IPN to product IPN URL
             $ipn_data = array("type" => "sales", "password" => isset($dkData['password']) ? $dkData['password'] : NULL, "plan" => $plan->code, "amount" => $plan->price, "email" => $email, "first_name" => $first_name, "last_name" => $last_name);
             // Add an encrypted key to the request
             $ipn_data['key'] = $this->_generateHash($ipn_data, $product->api_key);
             $this->_push_ipn($product->ipn_url, $ipn_data);
         }
         // Successful Charge
         if ($event_json->type == "charge.succeeded") {
             // Delay 10 seconds, so purchase can be added to database
             sleep(10);
             $pay_id = $event_json->data->object->id;
             $paid_amount = $event_json->data->object->amount / 100;
             // Check if Pay ID already exist
             if (Transaction::where('pay_id', '=', $pay_id)->first()) {
                 echo "Transaction was already recorded.";
                 return;
             }
             $chargeMetadata = $event_json->data->object->metadata;
             if (empty($chargeMetadata->plan_id)) {
                 $plan_id = $dkData['plan_id'];
             } else {
                 $plan_id = !empty($chargeMetadata->plan_id) ? $chargeMetadata->plan_id : NULL;
             }
             // Get Plan and Product
             $plan = Plan::where('id', '=', $plan_id)->first();
             $purchase = Purchase::where('product_id', '=', $product->id)->where('buyer_id', '=', $buyer->id)->first();
             if (!$purchase) {
                 header('HTTP/1.1 400 Bad Request', true, 400);
                 echo "Purchase was not found";
                 // Delete InfusionSoft Invoice
                 //$this->_delete_infusion_invoice($invoice_id);
                 return;
             }
             // User all transactions
             $user_transactions = Transaction::where('purchase_id', '=', $purchase->id)->where('plan_id', '=', $plan->id)->get();
             // If Split payment installment is received
             if ($plan->has_split_pay) {
                 if (count($user_transactions) + 1 >= $plan->total_installments) {
                     // Cancel the subscription
                     $params['stripe_customer_id'] = $customer_id;
                     $params['plan_id'] = $plan->stripe_id . '_split';
                     Log::info('Stripe Split Not Cancelled', array('product' => $product->code, 'plan' => $plan->code));
                     $this->_cancelSubscription('Stripe', $params);
                 }
             }
             // Add payment in InfusionSoft
             if ($invoice_id = $this->_infusion_sales($product, $plan, $email, $first_name, $last_name, $affiliate_id, $paid_amount)) {
                 if (!$buyer->last_used_ip) {
                     $buyer = Buyer::where('id', '=', $buyer->id)->first();
                 }
                 // Record Sales Transaction
                 $transaction = new Transaction();
                 $transaction->purchase_id = $purchase->id;
                 $transaction->plan_id = $plan->id;
                 $transaction->amount = $paid_amount;
                 //$plan->price;
                 $transaction->invoice_id = $invoice_id;
                 $transaction->pay_id = $pay_id;
                 $transaction->pay_data = '';
                 //json_encode($event_json);
                 $transaction->buyer_ip = $buyer->last_used_ip;
                 $transaction->save();
                 // Do not generate license key if this is recurring charge
                 $license_key = NULL;
                 if (count($user_transactions) + 1 === 1) {
                     // Generate and Save License Key
                     $license_key = $this->_generate_license($product, $plan, $transaction->id);
                 }
                 // Email Receipt
                 $this->_send_email_receipt($product->name, $plan->name, $email, $pay_id, $paid_amount, $license_key);
             }
             // Push IPN to product IPN URL
             $ipn_data = array("type" => "sales", "password" => isset($dkData['password']) ? $dkData['password'] : NULL, "plan" => $plan->code, "pay_id" => $event_json->data->object->id, "amount" => $plan->price, "email" => $email, "first_name" => $first_name, "last_name" => $last_name);
             // Add an encrypted key to the request
             $ipn_data['key'] = $this->_generateHash($ipn_data, $product->api_key);
             $this->_push_ipn($product->ipn_url, $ipn_data);
         }
         // Update subscription
         if ($event_json->type == "customer.subscription.updated") {
             // $event_json->data->object->cancel_at_period_end
             $stripe_plan_code = $event_json->data->object->plan->id;
             // Remove word "_split" from it
             $stripe_plan_code = str_replace('_split', '', $stripe_plan_code);
             $plan = Plan::where('stripe_id', '=', $stripe_plan_code)->first();
             // Update Customer Metadata in Stripe
             try {
                 $metadata = $customer->metadata;
                 $metadata['plan_id'] = $plan->id;
                 $customer->metadata = $metadata;
                 $customer->save();
             } catch (Exception $e) {
                 header('HTTP/1.1 400 Bad Request', true, 400);
                 echo "Customer was not update";
                 return;
             }
             // Push to IPN
             $ipn_data = array("type" => "sub-update", "plan" => $plan->code, "email" => $buyer->email);
             // Add an encrypted key to the request
             $ipn_data['key'] = $this->_generateHash($ipn_data, $product->api_key);
             $this->_push_ipn($product->ipn_url, $ipn_data);
         }
         // Delete Subscription
         if ($event_json->type == "customer.subscription.deleted") {
             $stripe_plan_code = $event_json->data->object->plan->id;
             // Remove word "_split" from it
             $stripe_plan_code = str_replace('_split', '', $stripe_plan_code);
             $plan = Plan::where('stripe_id', '=', $stripe_plan_code)->first();
             // If Split payment installment is received
             if ($plan->has_split_pay) {
                 $purchase = Purchase::where('product_id', '=', $product->id)->where('buyer_id', '=', $buyer->id)->first();
                 $total_paid_installments = Transaction::where('purchase_id', '=', $purchase->id)->where('plan_id', '=', $plan->id)->get();
                 if (count($total_paid_installments) >= $plan->total_installments) {
                     // Do not push IPN, its fine user has paid all installments
                     Log::info('Stripe Split Cancelled', array('product' => $product->code, 'plan' => $plan->code));
                     return;
                 }
             }
             // Push to IPN
             $ipn_data = array("type" => "sub-cancel", "plan" => $plan->code, "email" => $buyer->email);
             // Add an encrypted key to the request
             $ipn_data['key'] = $this->_generateHash($ipn_data, $product->api_key);
             $this->_push_ipn($product->ipn_url, $ipn_data);
         }
         // Charge Failed
         if ($event_json->type == "charge.failed") {
             // Charge failed, ask customer to update card via email
             // @TODO: Ask Mark to enable some tries after failure
         }
         // Charge refunded
         if ($event_json->type == "charge.refunded") {
             // Check if transaction has not been refunded from UI, then go ahead
             // Else stop process
             $pay_id = $event_json->data->object->id;
             $transaction = Transaction::where('pay_id', '=', $pay_id)->first();
             if ($transaction->is_refunded) {
                 return;
             }
             // Push to IPN
             $ipn_data = array("type" => "refund", "plan" => $transaction->plan->code, "email" => $buyer->email);
             // Add an encrypted key to the request
             $ipn_data['key'] = $this->_generateHash($ipn_data, $product->api_key);
             $this->_push_ipn($product->ipn_url, $ipn_data);
         }
         if (isset($error)) {
             header('HTTP/1.1 400 Bad Request', true, 400);
             echo "Unsuccessful event";
             return;
         }
     }
 }
Example #12
0
 /**
  * Post manual additions transacton form
  */
 static function addManually($params)
 {
     extract($params);
     $ipn_url = Config::get('project.paypal_ipn_url');
     $params = array('first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'), 'email' => Input::get('email'), 'password' => Input::get('password'), 'product_id' => Input::get('product_id'), 'plan_id' => Input::get('plan_id'), 'pay_id' => Input::get('pay_id'), 'stripe_token' => Input::get('stripe_token'), 'paypal_sub_id' => Input::get('paypal_sub_id'), 'amount' => Input::get('amount'), 'affiliate_id' => Input::get('affiliate_id'));
     $members[] = array('email' => $email, 'fname' => $first_name, 'lname' => $last_name);
     $data = array();
     if ($members) {
         foreach ($members as $member) {
             // Add or get buyer
             if ($buyer = Buyer::getOrCreate($member)) {
                 // Get Plan
                 $plan = Plan::find($plan_id);
                 if ($plan and !$plan->is_oto) {
                     // Add purchase for the buyer
                     $purchase = new Purchase();
                     $purchase->buyer_id = $buyer->id;
                     $purchase->product_id = $product_id;
                     $purchase->plan_id = $plan_id;
                     $purchase->stripe_token = $stripe_token ? $stripe_token : NULL;
                     $purchase->paypal_sub_id = $paypal_sub_id ? $paypal_sub_id : NULL;
                     $purchase->pay_method = 2;
                     $purchase->affiliate_id = $affiliate_id;
                     // If method is Stripe
                     if ($pay_id and DKHelpers::GetPayMethod($pay_id) == 'Stripe') {
                         $purchase->pay_method = 1;
                     }
                     $purchase->save();
                 }
                 // Push to PayPal IPN of DK
                 $ipn_data = array('plan_id' => $plan_id, 'product_id' => $product_id, 'email' => $buyer->email, 'first_name' => $buyer->first_name, 'last_name' => $buyer->last_name, 'password' => $password, 'transaction_id' => $pay_id ? $pay_id : 'MNL-' . time(), 'amount' => $amount, 'manual_transaction' => TRUE);
                 if ($password) {
                     $ipn_data['dk_new_user'] = TRUE;
                 } else {
                     $ipn_data['dk_new_charge'] = TRUE;
                     $ipn_data['buyer_id'] = $buyer->id;
                 }
                 // Add Curl library
                 require_once app_path() . "/libraries/Curl/Curl.php";
                 // Post data to IPN
                 $curl = new Curl();
                 $curl->simple_post($ipn_url, $ipn_data, array(CURLOPT_BUFFERSIZE => 10));
             }
         }
     }
     return TRUE;
 }
Example #13
0
 /**
  * Reset son propre mot de passe et l'envoi par mail
  * 0:Ok sa marche
  * 1:Pas d'email
  * 2:pas d'user
  * 3:Modif du pass impossible
  * 4:mail pas partie
  * @return int $state
  * @param String $usr_id
  * @param String $email
  */
 public function resetKey($usr_id, $email)
 {
     $rand = rand(0, 9999);
     if ($rand < 100) {
         $rand = "00" . $rand;
     } else {
         if ($rand < 1000) {
             $rand = "0" . $rand;
         }
     }
     if (empty($email)) {
         return 1;
     } elseif (empty($usr_id)) {
         return 2;
     }
     $Buyer = new Buyer($usr_id, 1, '', '', 1);
     $this->db->query("UPDATE ts_user_usr SET usr_pwd='%s' WHERE usr_id='%u'", array(md5($rand), $Buyer->getId()));
     $nb = $this->db->affectedRows();
     if ($nb != 1) {
         return 3;
     }
     $subject = 'Changement code PIN BuckUTT';
     $message = "<p>Bonjour,</p>\n        <p>Tu as demandé un nouveau code PIN et bah le voila</p>\n\t\t<p>CODE PIN = {$rand}</p>";
     $headers = 'From: buckutt@utt.fr' . "\r\n" . 'Content-Type: text/html; charset="UTF-8"' . "\r\n" . 'Reply-To: buckutt@utt.fr' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
     $err = mail($email, $subject, $message, $headers);
     if (!$err) {
         return 4;
     } else {
         $this->db->query("UPDATE ts_user_usr SET usr_blocked=0 WHERE usr_id='" . $Buyer->getId() . "'");
         $nb = $this->db->affectedRows();
         //  if($nb != 1){
         //	return 5;
         //  }
         return 0;
     }
 }
Example #14
0
 public function registerAction()
 {
     $form = new App_Form_Register();
     if (!empty($_POST) && $form->isValid($_POST)) {
         if ($form->getValue('sellerAccount')) {
             $account = new Seller();
         } else {
             $account = new Buyer();
         }
         $account->username = $form->getValue('emailAddress');
         $account->emailAddress = $form->getValue('emailAddress');
         $account->password = $form->getValue('password');
         $account->confirmed = false;
         $account->save();
         // send the confirmation, and redirect to the confirm page
         $this->_sendConfirmEmail($account->emailAddress);
         $msg = "A confirmation code has been set to " . "<cite>{$account->emailAddress}</cite>.  Please check " . "your enter the confirmation into the field below.";
         $this->_flash->addMessage($msg);
         $this->_redirector->gotoSimple('confirm', null, null, array('email' => $account->emailAddress));
     }
     $form->setMethod('post');
     $this->view->form = $form;
 }
Example #15
0
 /**
  * Функция отправки письма для сброса пароля
  * @return
  */
 public function actionForgotPassword()
 {
     $model = $this->loadModel($this->model);
     $model->scenario = 'resetPassword';
     $this->performAjaxValidation($model);
     if (isset($_POST[$this->model])) {
         $model->attributes = $_POST;
         if (!empty($model->email)) {
             //посылка письма для сброса
             if ($model->validate(array('email'))) {
                 $buyer = Ar::model($this->model)->find('email = :email', array(':email' => $model->email));
                 $username = $buyer->username;
                 $key = String::getUniqueString($this->model, 'reset_key', 12);
                 // отправить сообщение для сброса пароля
                 $status = app()->mail->send($buyer->email, t('front', 'Сброс пароля на сайте {site}!', array('{site}' => app()->name)), app()->mail->getView('auth.reset-password', array('username' => $username, 'key' => $key)));
                 //save reset key in db
                 Buyer::model()->updateByPk($buyer->id, array('reset_key' => $key));
                 //set user flash message
                 setFlash('email-sent', 'forgot-password-success');
             }
         }
     }
     $this->pageTitle = t('buyer', 'Смена пароля');
     $this->render('forgotpassword', compact('model'));
 }
 /**
  * Check if user has already purchase the plan
  */
 private function _check_already_purchase($buyer_email, $product, $plan)
 {
     // Get Buyer
     $buyer = Buyer::where('email', '=', $buyer_email)->first();
     if ($buyer) {
         $purchase = Purchase::where('buyer_id', '=', $buyer->id)->first();
         if ($purchase) {
             if ($transaction = Transaction::where('purchase_id', '=', $purchase->id)->where('plan_id', '=', $plan->id)->where('is_refunded', '=', 0)->first()) {
                 // Redirect to next page
                 header("location: " . $plan->next_page_url);
                 exit;
             }
         }
     }
 }
Example #17
0
<?php

set_include_path(dirname(_FILE_) . '/../');
require_once 'class/Buyer.class.php';
require_once 'class/Seller.class.php';
//$newPoint = new Point(0, 'Foyer');
//echo $newPoint->getName();
echo '<h2>Ok id etu</h2>';
$User = new Buyer('6362', 2, '', 1);
echo $User->getState();
echo $User->getCredit();
echo $User->hasDroit('Droit A', 1, 1);
echo $User->hasDroit('Droit A');
echo $User->hasDroit('Droit A', 3, 1);
echo $User->hasDroit('point_admin', 3);
echo $User->hasDroit('point_admin', 0, 2);
echo $User->hasDroit('point_admin', 1, 1);
echo $User->hasDroit('Droit B', 1, 1);
echo '<h2>groupes</h2>';
echo '<pre>';
print_r($User->getGroups());
echo '</pre>';
echo '<h2>identity</h2>';
echo '<pre>';
print_r($User->getIdentity());
echo '</pre>';
/*
echo '<h2>test Seller</h2>';
$User = new Seller('6362', 2, 'toto', 0, 'hioh', 3);
echo $User->getState();
echo $User->isAllowedOnPoint();
 /**
  * Get Stripe purchase
  */
 private function _get_stripe_customer_id($email = NULL, $product_code = NULL)
 {
     $email = $email ? $email : Input::get('email');
     $product_code = $product_code ? $product_code : Input::get('code');
     // Get product
     $product = Product::where('code', '=', $product_code)->first();
     // Get buyer
     if (!($buyer = Buyer::where('email', '=', $email)->first())) {
         $this->_invalidRequest("Buyer account was not found");
     }
     // Get purchase
     if (!($purchase = Purchase::where('buyer_id', '=', $buyer->id)->where('product_id', '=', $product->id)->where('pay_method', '=', '1')->first())) {
         $this->_invalidRequest("No purchase was found, contact support.");
     }
     // Get Stripe Customer ID
     if (!$purchase->stripe_token) {
         $this->_invalidRequest("Payment processor's customer ID is missing, contact support.");
     }
     return $purchase->stripe_token;
 }