-
app/Notifications/SubscribeSuccessfully.php
Open in GitHubuse Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; class SubscribeSuccessfully extends Notification { protected $plan; public function __construct($plan_id) { $stripe = new \Stripe\StripeClient(\Config::get('services.stripe.secret')); if (is_array($plan_id)) { $this->plan = $stripe->plans->retrieve($plan_id['planId']); } else { $this->plan = $stripe->plans->retrieve($plan_id); } } public function toMail($notifiable) { return (new MailMessage) ->subject('subscribed Successfully!') ->line('You have subscribed successfully!') ->line('Subscription Plan:'.$this->plan->nickname) ->line('Thank you for using Genealogia!'); } }
-
app/Http/Controllers/StripeController.php
Open in GitHubuse App\Notifications\SubscribeSuccessfully; class StripeController extends Controller { // public function subscribe() { $user = auth()->user(); $user->syncRoles('OTY'); $plan_id = request()->plan_id; if (request()->has('payment_method')) { $paymentMethod = request()->payment_method; $user->newSubscription('default', $plan_id)->create($paymentMethod, ['name' => request()->card_holder_name, 'address' => ['country' => 'GB', 'state' => 'England', 'city' => 'Abberley', 'postal_code' => 'WR6', 'line1' => 'test', 'line2' => '']]); $user->notify(new SubscribeSuccessfully($plan_id)); } elseif ($user->hasDefaultPaymentMethod()) { $paymentMethod = $user->defaultPaymentMethod(); $user->newSubscription('default', $plan_id)->create($paymentMethod->id); $user->notify(new SubscribeSuccessfully($plan_id)); } else { $user->subscription('default')->swap($plan_id); } return ['success' => true]; } // }