When your user creates a subscription Mollie will notify you through the web hook saying it has completed. That's when you create the subscription in your database so your user is subscribed.
Laravel Cashier Mollie does this all for you.
I am looking to implement Mollie via Cashier on Laravel 7. However, I can't understand how Mollie works.
I use the controller given in the documentation and I use the service https://webhook.site/ to receive callback from Mollie when making a payment. I get an answer from Mollie on the webhook URL with the transaction id.
SubscriptionController.php
<?php
namespace App\Http\Controllers;
use Laravel\Cashier\SubscriptionBuilder\RedirectToCheckoutResponse;
use Illuminate\Support\Facades\Auth;
class SubscriptionController extends Controller
{
/**
* @param string $plan
* @return \Illuminate\Http\RedirectResponse
*/
public function __invoke(string $plan)
{
$user = Auth::user();
$name = 'premium';
if(!$user->subscribed($name, $plan)) {
$result = $user->newSubscription($name, $plan)->create();
if(is_a($result, RedirectToCheckoutResponse::class)) {
return $result; // Redirect to Mollie checkout
}
//create subscription
return back()->with('status', 'Welcome to the ' . $plan . ' plan');
}
return back()->with('status', 'You are already on the ' . $plan . ' plan');
}
public function index()
{
return view('dashboard.upgrade', ['user' => Auth::user()]);
}
}
My routes look like this:
http://localhost:8000/dashboard/subscribe/monthly
http://localhost:8000/dashboard/subscribe/annualy
Route::get('/dashboard/subscribe/{plan}', 'SubscriptionController')->name('userDashboardSuscribe');
What I can't understand is how Mollie works. What should I do when Mollie responds to the webhook URL?
This is more a question of integrating the solution rather than a technical question, however if you could accompany your answers with examples it would be nice.
Please or to participate in this conversation.