/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { \Stripe\Stripe::setApiKey(env('STRIPE_SECRET')); $account = \Stripe\Account::create(array("managed" => true, "country" => "US", "email" => $data['email'], "legal_entity" => ["dob" => ["day" => $data['dob_day'], "month" => $data['dob_month'], "year" => $data['dob_year']], "first_name" => $data['first_name'], "last_name" => $data['last_name'], "type" => "individual", "ssn_last_4" => $data['last_4'], "address" => ["city" => $data['address_city'], "country" => "US", "line1" => $data['address_line1'], "line2" => $data['address_line2'], "postal_code" => $data['address_zip'], "state" => $data['address_state']]], "tos_acceptance" => ["date" => time(), "ip" => $_SERVER['REMOTE_ADDR']], "external_account" => $data['stripe_token'])); $user = User::create(['name' => $data['first_name'] . ' ' . $data['last_name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'api_token' => str_random(60), 'slug' => str_random(10)]); $stripeAccount = \App\StripeAccount::Create(['user_id' => $user->id, 'stripe_id' => $account->id]); return $user; }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { Stripe::setApiKey(\Config::get('stripe.key')); $email = $request->input('email'); $country = $request->input('country'); $managed = $request->input('managed'); try { $account = StripeAccount::create(["managed" => $managed, "country" => $country, "email" => $email]); return redirect('/accounts'); } catch (StripeError\Base $e) { return $e->getMessage(); } }
private function createAccount(UserInterface $user) { $entityClass = Account::getEntityClassByUser($user); /* @var $account AccountInterface */ $account = new $entityClass(); $account->setUser($user); $response = \Stripe\Account::create(['managed' => true, 'metadata' => ['id' => $user->getId(), 'type' => $user->getType()], 'email' => $user->getEmail()]); $account->setStripeId($response->id)->setSecretKey($response->keys->secret)->setPublishableKey($response->keys->publishable); $this->em->persist($account); $this->em->flush($account); return $account; }
function providerSignupAction() { if ($this->request->isPost()) { $name = $this->request->getPost('name'); $email = $this->request->getPost('email'); $password = $this->request->getPost('password'); $cpassword = $this->request->getPost('cpassword'); $timezone = $this->request->getPost('timezone'); $phone = $this->request->getPost('phone'); $address = $this->request->getPost('address'); $categories = $this->request->getPost('categories'); $membership = $this->request->getPost('membership'); $card_token = $this->request->getPost('card_token'); $errors = array(); $fields = array('name', 'email', 'password', 'cpassword', 'phone', 'address', 'membership', 'card_token'); $fieldsEntered = 0; foreach ($fields as $field) { if (trim(${$field}) != '') { $fieldsEntered++; } } if ($fieldsEntered < count($fields)) { array_push($errors, "Some fields were not entered."); } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { array_push($errors, "Email is invalid."); } if (strlen($password) < 6) { array_push($errors, "Password must be at least 6 characters long."); } if ($password != $cpassword) { array_push($errors, "Passwords don't match."); } if (!preg_match('/^\\(?[0-9]{3}\\)?|[0-9]{3}[-. ]? [0-9]{3}[-. ]?[0-9]{4}$/', $phone)) { array_push($errors, "Invalid phone number format."); } $apiLink = $this->config->maps->api_link; $geoData = file_get_contents($apiLink . urlencode($address)); if ($geoData === FALSE) { array_push($errors, "Invalid address."); } $provider = Providers::findFirst("email = '{$email}'"); if ($provider) { array_push($errors, "Email is already taken."); } if (!count($errors)) { $salt = bin2hex(openssl_random_pseudo_bytes(16, $cstrong)); $provider = new Providers(); $provider->name = $name; $provider->email = $email; $provider->salt = $salt; $provider->password = md5($salt . $password); $provider->timezone = $timezone; $provider->membership = $membership; require_once "../vendor/stripe-php-master/init.php"; \Stripe\Stripe::setApiKey($this->config->stripe->secret_key); $plan = Memberships::findFirst("id = '{$membership}'"); $amount = (int) $plan->total * 100; $duration = $plan->duration; $date = new DateTime(date()); $date->add(new DateInterval('P' . $duration . 'M')); $provider->expiry_date = $date->format('Y-m-d H:i:s'); $account = \Stripe\Account::create(array("managed" => true, "country" => "US")); $provider->stripe_account_token = $account->id; $customer = \Stripe\Customer::create(array("description" => $name, "email" => $email, "source" => $card_token)); $provider->stripe_customer_token = $customer->id; $provider->stripe_card_token = $customer->default_source; $providerPhone = new ProviderPhones(); $providerPhone->telephone = $phone; $provider->providerPhones = $providerPhone; $providerAddress = new ProviderAddresses(); $geoJSON = json_decode($geoData); if ($geoJSON->status == "OK") { $geometry = $geoJSON->results[0]->geometry->location; $lat = $geometry->lat; $lng = $geometry->lng; } else { $lat = 0; $lng = 0; } $providerAddress->latitude = $lat; $providerAddress->longitude = $lng; $providerAddress->address = $address; $provider->providerAddresses = $providerAddress; $providerCategories = array(); foreach ($categories as $category) { $providerCategory = new ProviderCategories(); $providerCategory->cid = $category; array_push($providerCategories, $providerCategory); } $provider->providerCategories = $providerCategories; if ($provider->create()) { \Stripe\Charge::create(array("amount" => $amount, "currency" => "usd", "customer" => $provider->stripe_customer_token, "source" => $provider->stripe_card_token, "description" => "{$plan->name} plan subscription")); $this->response->redirect('/login?success'); $this->view->disable(); } else { array_push($errors, "An error occurred during the signup process."); } } $this->view->errors = $errors; } $timezones = (require "../app/config/timezones.php"); $this->view->timezones = $timezones; $memberships = Memberships::find("id > 1"); $this->view->memberships = $memberships; $categories = Categories::find(); $this->view->categories = $categories; echo $this->view->render('auth', 'providerSignup'); }