本文整理匯總了PHP中Laravel\Spark\Spark::swapSubscriptionsWith方法的典型用法代碼示例。如果您正苦於以下問題:PHP Spark::swapSubscriptionsWith方法的具體用法?PHP Spark::swapSubscriptionsWith怎麽用?PHP Spark::swapSubscriptionsWith使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Laravel\Spark\Spark
的用法示例。
在下文中一共展示了Spark::swapSubscriptionsWith方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: customizeRegistration
/**
* 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();
});
}
}