public function submitGiftCard() { //get the giftcards from the database $giftCard = \CI::GiftCards()->getGiftCard(\CI::input()->post('gift_card')); if (!$giftCard) { echo json_encode(['error' => lang('gift_card_not_exist')]); } else { //does the giftcard have any value left? if (\CI::GiftCards()->isValid($giftCard)) { $message = \GC::addGiftCard($giftCard); if ($message['success']) { \GC::saveCart(); echo json_encode(['message' => lang('gift_card_balance_applied')]); } else { echo json_encode($message); } } else { echo json_encode(['error' => lang('gift_card_zero_balance')]); } } }