Add PayPal support for add-on and gift voucher checkout
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user