-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.php
More file actions
72 lines (54 loc) · 1.88 KB
/
web.php
File metadata and controls
72 lines (54 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
use App\Services\BoathouseApi;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Http;
use Illuminate\Http\Request;
Route::get('/', function () {
return view('welcome');
});
Route::get('/login', function () {
return view('login');
})->name('login');
Route::post('/login', function () {
// Generate a random email address
$randomEmail = 'playground-' . Str::uuid()->toString() . '@mailexample.com';
// Call Boathouse API
$boathouseApi = new BoathouseApi();
$response = $boathouseApi->getBoathouseResponse(
$randomEmail,
null,
url()->full()
);
// Set cookie in the response
$cookie = cookie('PaddleCustomerID', $response["paddleCustomerId"], 60); // 60 minutes for cookie expiration
return redirect('/account')->withCookie($cookie);
});
Route::get('/account', function (Request $request) {
$paddleCustomerId = $request->cookie('PaddleCustomerID');
// Call Boathouse API
$boathouseApi = new BoathouseApi();
$boathouse = $boathouseApi->getBoathouseResponse(
null,
$paddleCustomerId,
url()->full()
);
return view('account', [
'paddleCustomerId' => $paddleCustomerId,
'boathouse' => $boathouse
]);
})->name('account');
Route::get('/processing', function (Request $request) {
$priceIds = explode(',', $request->input('pids', ''));
$paddleCustomerID = $request->cookie('PaddleCustomerID');
$boathouseApi = new BoathouseApi();
$boathouse = $boathouseApi->getBoathouseResponse(null, $paddleCustomerID);
$checkoutCompleted = collect($priceIds)->every(function ($pid) use ($boathouse) {
return collect($boathouse['activeSubscriptions'])->contains(strtolower($pid));
});
if ($checkoutCompleted) {
return redirect()->route('account');
} else {
return view('processing');
}
});