Add PayPal support for add-on and gift voucher checkout

This commit is contained in:
Codex Agent
2026-02-04 14:54:40 +01:00
parent 7025418d9e
commit 17025df47b
24 changed files with 1599 additions and 34 deletions

View File

@@ -36,7 +36,7 @@ class GiftVoucherCheckoutController extends Controller
if (! $checkout['checkout_url']) {
throw ValidationException::withMessages([
'tier_key' => __('Unable to create Lemon Squeezy checkout.'),
'tier_key' => __('Unable to create checkout.'),
]);
}
@@ -51,19 +51,38 @@ class GiftVoucherCheckoutController extends Controller
'code' => ['nullable', 'string', 'required_without_all:checkout_id,order_id'],
]);
$voucherQuery = GiftVoucher::query();
$voucherQuery = GiftVoucher::query()
->where('status', '!=', GiftVoucher::STATUS_PENDING)
->where(function ($query) use ($data) {
$hasCondition = false;
if (! empty($data['checkout_id'])) {
$voucherQuery->where('lemonsqueezy_checkout_id', $data['checkout_id']);
}
if (! empty($data['checkout_id'])) {
$query->where(function ($inner) use ($data) {
$inner->where('lemonsqueezy_checkout_id', $data['checkout_id'])
->orWhere('paypal_order_id', $data['checkout_id']);
});
if (! empty($data['order_id'])) {
$voucherQuery->orWhere('lemonsqueezy_order_id', $data['order_id']);
}
$hasCondition = true;
}
if (! empty($data['code'])) {
$voucherQuery->orWhere('code', strtoupper($data['code']));
}
if (! empty($data['order_id'])) {
$method = $hasCondition ? 'orWhere' : 'where';
$query->{$method}(function ($inner) use ($data) {
$inner->where('lemonsqueezy_order_id', $data['order_id'])
->orWhere('paypal_capture_id', $data['order_id'])
->orWhere('paypal_order_id', $data['order_id']);
});
$hasCondition = true;
}
if (! empty($data['code'])) {
$method = $hasCondition ? 'orWhere' : 'where';
$query->{$method}('code', strtoupper($data['code']));
}
});
$voucher = $voucherQuery->latest()->firstOrFail();