當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Spark::createSubscriptionsWith方法代碼示例

本文整理匯總了PHP中Laravel\Spark\Spark::createSubscriptionsWith方法的典型用法代碼示例。如果您正苦於以下問題:PHP Spark::createSubscriptionsWith方法的具體用法?PHP Spark::createSubscriptionsWith怎麽用?PHP Spark::createSubscriptionsWith使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Laravel\Spark\Spark的用法示例。


在下文中一共展示了Spark::createSubscriptionsWith方法的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();
         });
     }
 }
開發者ID:airlst,項目名稱:spark,代碼行數:52,代碼來源:SparkServiceProvider.php


注:本文中的Laravel\Spark\Spark::createSubscriptionsWith方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。