Allowing local lemonsqueezy payment skip and emulate success response
This commit is contained in:
@@ -65,6 +65,14 @@ class LemonSqueezyCheckoutController extends Controller
|
||||
$this->sessions->applyCoupon($session, $preview['coupon'], $preview['pricing']);
|
||||
}
|
||||
|
||||
if (app()->environment('local')) {
|
||||
$checkout = $this->simulateLocalCheckout($session, $package, $couponCode);
|
||||
|
||||
return response()->json(array_merge($checkout, [
|
||||
'checkout_session_id' => $session->id,
|
||||
]));
|
||||
}
|
||||
|
||||
$checkout = $this->checkout->createCheckout($tenant, $package, [
|
||||
'success_url' => $data['success_url'] ?? null,
|
||||
'return_url' => $data['return_url'] ?? null,
|
||||
@@ -93,6 +101,36 @@ class LemonSqueezyCheckoutController extends Controller
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{checkout_url: string|null, id: string, order_id: string, simulated: bool}
|
||||
*/
|
||||
protected function simulateLocalCheckout(CheckoutSession $session, Package $package, string $couponCode): array
|
||||
{
|
||||
$checkoutId = 'chk_'.Str::uuid();
|
||||
$orderId = 'order_'.Str::uuid();
|
||||
|
||||
$session->forceFill([
|
||||
'lemonsqueezy_checkout_id' => $checkoutId,
|
||||
'provider_metadata' => array_merge($session->provider_metadata ?? [], array_filter([
|
||||
'lemonsqueezy_checkout_id' => $checkoutId,
|
||||
'lemonsqueezy_order_id' => $orderId,
|
||||
'lemonsqueezy_status' => 'paid',
|
||||
'lemonsqueezy_local_simulated_at' => now()->toIso8601String(),
|
||||
'coupon_code' => $couponCode ?: null,
|
||||
])),
|
||||
])->save();
|
||||
|
||||
return [
|
||||
'checkout_url' => route('marketing.success', [
|
||||
'locale' => app()->getLocale(),
|
||||
'packageId' => $package->id,
|
||||
], absolute: true),
|
||||
'id' => $checkoutId,
|
||||
'order_id' => $orderId,
|
||||
'simulated' => true,
|
||||
];
|
||||
}
|
||||
|
||||
protected function resolveLegalVersion(): string
|
||||
{
|
||||
return config('app.legal_version', now()->toDateString());
|
||||
|
||||
Reference in New Issue
Block a user