-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add endpoint to request a checkout with the given quote hash and cust…
…omer token
- Loading branch information
1 parent
fc7429f
commit b79481e
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Rapidez\Core\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\URL; | ||
use Illuminate\Support\Str; | ||
|
||
class GetSignedCheckoutController | ||
{ | ||
/** | ||
* Time for the signed route to be valid for, 2 minutes will result in a timeout anyways. | ||
* So it's better to remove the mask and token after that time. | ||
*/ | ||
public const URL_TIMEOUT = 120; | ||
|
||
public function __invoke(Request $request) | ||
{ | ||
$data = $request->validate([ | ||
'mask' => 'required', | ||
'token' => 'nullable', | ||
]); | ||
$cachekey = (string)Str::uuid(); | ||
Cache::put('checkout-'.$cachekey, $data, static::URL_TIMEOUT); | ||
|
||
return ['url' => URL::signedRoute('signed-checkout', ['key' => $cachekey], static::URL_TIMEOUT)]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Rapidez\Core\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Cache; | ||
use Rapidez\Core\Models\Quote; | ||
|
||
class SignedCheckoutController | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
if (! $request->hasValidSignature() || !Cache::has('checkout-' . $request->get('key'))) { | ||
return redirect(config('rapidez.magento_url'), 301); | ||
} | ||
|
||
$data = Cache::get('checkout-' . $request->get('key')); | ||
Cache::forget('checkout-' . $request->get('key')); | ||
|
||
$response = redirect()->to('checkout'); | ||
|
||
if (!Quote::whereQuoteIdOrCustomerToken($data['mask'] ?? $data['token'])->exists()) { | ||
return redirect(config('rapidez.magento_url'), 301); | ||
} | ||
|
||
if ($data['mask'] ?? false) { | ||
$response->withCookie('mask', $data['mask'], 525949, null, null, null, false); | ||
} | ||
|
||
if ($data['token'] ?? false) { | ||
$response->withCookie('token', $data['token'], 525949, null, null, null, false); | ||
} | ||
|
||
return $response; | ||
} | ||
} |