|
|
@@ -233,5 +233,43 @@ class OnepageController extends APIController
|
|
|
if (! $cart->payment) {
|
|
|
throw new \Exception(trans('shop::app.checkout.cart.specify-payment-method'));
|
|
|
}
|
|
|
+
|
|
|
+ if ($cart->giftcard_number) {
|
|
|
+ $this->validateGiftCard($cart);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Validate gift card before order creation.
|
|
|
+ *
|
|
|
+ * @param \Webkul\Checkout\Models\Cart $cart
|
|
|
+ * @return void
|
|
|
+ * @throws \Exception
|
|
|
+ */
|
|
|
+ protected function validateGiftCard($cart)
|
|
|
+ {
|
|
|
+ $giftCard = \Longyi\Gift\Models\GiftCards::where('giftcard_number', $cart->giftcard_number)->first();
|
|
|
+
|
|
|
+ if (!$giftCard) {
|
|
|
+ throw new \Exception('The gift card does not exist or has been deleted. Please select a new gift card');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($giftCard->giftcard_status != 1) {
|
|
|
+ throw new \Exception('The gift card has been used or has expired. Please choose another payment method');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($giftCard->remaining_giftcard_amount < $cart->giftcard_amount) {
|
|
|
+ throw new \Exception(
|
|
|
+ sprintf(
|
|
|
+ 'The gift card balance is insufficient (current balance: %s, required payment: %s). Please reselect a payment method',
|
|
|
+ core()->formatPrice($giftCard->remaining_giftcard_amount, $cart->cart_currency_code),
|
|
|
+ core()->formatPrice($cart->giftcard_amount, $cart->cart_currency_code)
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($giftCard->expirationdate && $giftCard->expirationdate->isPast()) {
|
|
|
+ throw new \Exception('The gift card has expired. Please choose another payment method');
|
|
|
+ }
|
|
|
}
|
|
|
}
|