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'); }
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; } }
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; }
/** * Register a user * * Register a new buyer into the system */ public function postRegisterBuyer() { if ($this->_isValidRequest()) { $buyer = new Buyer(); $buyer->email = Input::get('email'); $buyer->first_name = Input::get('first_name'); $buyer->last_name = Input::get('last_name'); $buyer->affiliate_id = Input::get('affiliate_id'); $buyer->save(); die(json_encode(array('data' => array('success' => TRUE, 'id' => $buyer->id)))); } }
/** * Process payment using Stripe * * @return Void */ public function postStripe() { // Add third party libraries require_once app_path() . "/libraries/Curl/Curl.php"; // Add Curl library require_once app_path() . "/libraries/stripe-php-1.9.0/lib/Stripe.php"; // Add Stripe library require_once app_path() . "/libraries/infusionsoft/isdk.php"; // Add InfusionSoft Library // Get Affiliate ID from Cookie $affiliate_id = Cookie::get('_dks_isa'); // Get Product and Plan Data $product = Input::get("product"); $plan = Input::get("plan"); $email = Input::get("email"); $first_name = Input::get("first_name"); $last_name = Input::get("last_name"); $password = Input::get("password"); $ccNum = Input::get('ccNum'); $ccExpire = Input::get('ccExpire'); $ccCSV = Input::get('ccCSV'); $is_split_pay = Input::get("pay_option") == "split" ? TRUE : FALSE; $existing_customer = Input::get('existing_customer'); // Put every detail in Flash session to show again, // if an error occurs Session::flash('email', $email); Session::flash('first_name', $first_name); Session::flash('last_name', $last_name); Session::flash('password', $password); Session::flash('ccNum', $ccNum); Session::flash('ccExpire', $ccExpire); Session::flash('ccCSV', $ccCSV); // Get product data if (!($product = Product::where('code', '=', $product)->first())) { // Invalid product, Redirect to website Session::flash('error', "Product was not found"); return json_encode(array("error" => true, "message" => "Product was not found")); } // Get plan data if (!($plan = Plan::where('code', '=', $plan)->where('product_id', '=', $product->id)->first())) { // Invalid plan, Redirect to website Session::flash('error', "Plan was not found"); return json_encode(array("error" => true, "message" => "Plan was not found")); } // 0. Check if user entered valid email address and password $rules = array('first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email', 'password' => 'required|min:6', 'retype_password' => 'required|same:password', 'ccNum' => 'required', 'ccExpire' => 'required', 'ccCSV' => 'required'); if ($existing_customer) { unset($rules['password']); unset($rules['retype_password']); } $custom_messages = array('ccNum.required' => 'Credit Card number is required', 'ccExpire.required' => 'Credit Card expiry date is required', 'ccCSV.required' => 'Credit Card CSV number is required'); $validator = Validator::make(Input::all(), $rules, $custom_messages); if ($validator->fails()) { $messages = $validator->messages(); $messages_txt = ''; foreach ($messages->all() as $message) { $messages_txt .= "<p>{$message}</p>"; } // Error Session::flash('error', $messages_txt); return json_encode(array("error" => true, "message" => $messages_txt)); } // 1. Check if email already exists in app (Nm etc) DB // Yes, Error - Stop further process if (!$existing_customer) { $curl = new Curl(); $api_url = $product->api_url . "?email={$email}"; $reponse = json_decode($curl->simple_get($api_url)); if (!empty($reponse->user_exists) and $reponse->user_exists == true) { // Error Session::flash('error', "User with this email already exists"); return json_encode(array("error" => true, "message" => "User with this email already exists")); } } // 2. Charge Stripe Card // Error - Stop Stripe::setApiKey(Config::get('project.stripe_secret_key')); $ccExpire = explode("/", $ccExpire); $card = array("number" => $ccNum, "exp_month" => !empty($ccExpire[0]) ? trim($ccExpire[0]) : NULL, "exp_year" => !empty($ccExpire[1]) ? trim($ccExpire[1]) : NULL, "cvc" => $ccCSV); $affiliate_id = Cookie::get('_dks_isa'); $data = array("description" => "{$product->name} - {$plan->name}", "card" => $card, "email" => $email, "metadata" => array("email" => $email, "first_name" => $first_name, "last_name" => $last_name, "password" => $password, "affiliate_id" => $affiliate_id, "product_id" => $product->id, "plan_id" => $plan->id)); // If plan is recurring if ($plan->is_recurring) { $data['plan'] = $plan->stripe_id; $data['account_balance'] = $plan->setup_fee * 100; } // If plan is split payment if ($is_split_pay) { $data['plan'] = $plan->stripe_id . "_split"; $data['account_balance'] = $plan->setup_fee * 100; } try { $customer = Stripe_Customer::create($data); // If plan is not recurring if (!$plan->is_recurring and !$is_split_pay) { Stripe_Charge::create(array("amount" => $plan->price * 100, "currency" => "usd", "customer" => $customer->id, "description" => "Charge for {$plan->name} ({$email})", "metadata" => array("plan_id" => $plan->id))); } } catch (Stripe_Error $e) { // Error Session::flash('error', $e->getMessage()); return json_encode(array("error" => true, "message" => $e->getMessage())); } catch (Exception $e) { // Something else happened, completely unrelated to Stripe Session::flash('error', $e->getMessage()); return json_encode(array("error" => true, "message" => $e->getMessage())); } // No error happened, and we charged user card // Create Buyer Account $buyer = Buyer::where('email', '=', $email)->first(); // Add new buyer in DK System if (!$buyer) { $buyer = new Buyer(); $buyer->email = $email; $buyer->first_name = $first_name; $buyer->last_name = $last_name; $buyer->affiliate_id = $affiliate_id; $buyer->save(); // Add user into Aweber account $this->_add_to_aweber($buyer, $product->aweber_list_id); } else { if ($affiliate_id and $affiliate_id != $buyer->affiliate_id) { // Update new Affiliate ID $buyer->affiliate_id = $affiliate_id; $buyer->save(); } elseif (!$affiliate_id) { $affiliate_id = $buyer->affiliate_id; } } // Update Buyer IP Buyer::updateLastIP($buyer); // Create Purchase in DB $purchase = new Purchase(); $purchase->buyer_id = $buyer->id; $purchase->product_id = $product->id; $purchase->plan_id = $plan->id; $purchase->stripe_token = $customer->id; $purchase->pay_method = 1; $purchase->affiliate_id = $affiliate_id; // If plan is recurring // if($plan->is_recurring) // { // $purchase->stripe_sub_token = $customer->id; // } $purchase->save(); // Everything is ok, now remove session data // for security purpose Session::flash('ccNum', NULL); Session::flash('ccExpire', NULL); Session::flash('ccCSV', NULL); // Create a cookie with email // Cookie Name should have product code $cookieName = "_" . $product->code . "_email"; $cookie = Cookie::forever($cookieName, $email); // ->withCookie($cookie) return Response::make(json_encode(array("success" => true)))->withCookie($cookie); //return json_encode(array("success"=>true)); // 3. Check if email exists in InfusionSoft // Yes - Get contactId // No - Create new contact and get contactId // 4. Create Blank Invoice in InfusionSoft // 5. Add selected productId (InfusionSoft), order item // 6. Get affiliate ID from cookies // If Cookie not exists - Get old affiliate ID from DB // 7. Add manual amount with affiliate id (if exists) // 8. Check if buyer email exists in DK DB // Yes - update affiliate ID // No - Add user in DB with Affiliate ID // 9. Record purchase and transaction with Stripe token ($customer->id) // and Infusion Invoice ID ($newOrder) // 10. Ping product IPN URL with this new purchase }
public static function save_buyer($ds) { $bd = array(); if (isset($ds['buyer_id']) && $ds['buyer_id'] != '' && $ds['buyer_id'] > 1) { if ($pid = self::get_parent_buyer($ds['buyer_id'])) { $bd['is_child_of'] = $pid; self::update_group_count($pid); } } $bd['buyer_name'] = $ds['buyer_name']; $bd['buyerdeliveryzone'] = $ds['buyerdeliveryzone']; $bd['buyerdeliverycity'] = $ds['buyerdeliverycity']; $bd['shipping_address'] = $ds['shipping_address']; $bd['phone'] = $ds['phone']; $bd['mobile1'] = $ds['mobile1']; $bd['mobile2'] = $ds['mobile2']; $bd['recipient_name'] = $ds['recipient_name']; $bd['shipping_zip'] = $ds['shipping_zip']; $bd['email'] = $ds['email']; $bd['delivery_id'] = $ds['delivery_id']; $bd['delivery_cost'] = $ds['delivery_cost']; $bd['cod_cost'] = $ds['cod_cost']; $bd['delivery_type'] = $ds['delivery_type']; $bd['currency'] = $ds['currency']; $bd['total_price'] = $ds['total_price']; $bd['chargeable_amount'] = $ds['chargeable_amount']; $bd['delivery_bearer'] = $ds['delivery_bearer']; $bd['cod_bearer'] = $ds['cod_bearer']; $bd['cod_method'] = $ds['cod_method']; $bd['ccod_method'] = $ds['ccod_method']; $bd['application_id'] = $ds['application_id']; //$bd['buyer_id'] = $ds['buyer_id']; $bd['merchant_id'] = $ds['merchant_id']; $bd['merchant_trans_id'] = $ds['merchant_trans_id']; //$bd['courier_id'] = $ds['courier_id']; //$bd['device_id'] = $ds['device_id']; $bd['directions'] = $ds['directions']; //$bd['dir_lat'] = $ds['dir_lat']; //$bd['dir_lon'] = $ds['dir_lon']; //$bd['delivery_note'] = $ds['delivery_note']; //$bd['latitude'] = $ds['latitude']; //$bd['longitude'] = $ds['longitude']; $bd['created'] = $ds['created']; $bd['cluster_id'] = substr(md5(uniqid(rand(), true)), 0, 20); $buyer = new Buyer(); foreach ($bd as $b => $v) { $buyer->{$b} = $v; } $buyer->save(); if ($buyer) { return $buyer->id; } else { return 0; } }