Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

familytree365/backend

90 stars
2 code files
View familytree365/backend on GitHub

app/Notifications/SubscribeSuccessfully.php

Open in GitHub
use 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 GitHub
use 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];
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.