/** * Customize Spark's new user registration logic. * * @return void */ protected function customizeRegistration() { Spark::validateRegistrationsWith(function (Request $request) { return ['name' => 'required|max:255', 'email' => 'required|email|unique:users', 'password' => 'required|confirmed|min:6', 'terms' => 'required|accepted']; }); // Spark::createUsersWith(function (Request $request) { // // Return New User Instance... // }); }
/** * Customize Spark's new user registration logic. * * @return void */ protected function customizeRegistration() { if (Spark::basedInEU()) { Spark::validateRegistrationsWith(function (Request $request, $withSubscription = false) { $userRules = ['name' => 'required|max:255', 'email' => 'required|email|unique:users', 'password' => 'required|confirmed|min:6', 'terms' => 'required|accepted']; $addressRules = ['street' => 'required', 'city' => 'required', 'zip' => 'required', 'country' => 'required', 'vat_id' => 'vat_number']; return $withSubscription ? array_merge($userRules, $addressRules) : $userRules; }); } // Spark::validateSubscriptionsWith(function (Request $request) { // return [ // 'plan' => 'required', // 'terms' => 'required|accepted', // 'stripe_token' => 'required', // ]; // }); // Spark::createUsersWith(function (Request $request) { // // Return New User Instance... // }); /** * To comply with the EU VAT regulations we need to pass * the user's address, IP and company name to stripe. * This data will also be used for the invoices. */ if (Spark::basedInEU()) { Spark::createSubscriptionsWith(function (Request $request, $user, $subscription) { /** * Apply tax rate from the given country. * If a valid VAT ID is given, the VAT * rate will be set to 0. */ $user->setTaxForCountry($request->country, $request->has('vat_id')); $subscription->create($request->stripe_token, ['email' => $user->email, 'description' => $user->name, 'metadata' => ['ip' => $request->getClientIp(), 'company' => $request->company, 'vat_id' => $request->vat_id, 'tax_percent' => $user->getTaxPercent()]]); }); } /** * Apply the tax rate of the customer to the invoice * when swapping plans. */ if (Spark::basedInEU()) { Spark::swapSubscriptionsWith(function (Request $request, $user) { $user->subscription($request->plan)->maintainTrial()->prorate()->swap(); $customer = $user->subscription()->getStripeCustomer(); \Stripe\Invoice::create(['customer' => $customer->id, 'tax_percent' => $customer->metadata->tax_percent], $user->getStripeKey())->pay(); }); } }