Example #1
0
 private static function useCoupon($code, $amount, $amountTotal = null, $orderId = null, $comment = null)
 {
     $params = self::get_params();
     $userId = $params['user_id'];
     $apiKey = $params['api_key'];
     $partner_token_prefix = $params['partner_token_prefix'];
     if (empty($partner_token_prefix) || strpos($code, $partner_token_prefix) !== 0) {
         return true;
     }
     $client = new Giftd_Client($userId, $apiKey);
     try {
         $data = $client->charge($code, $amount, $amountTotal, $orderId, $comment);
     } catch (Exception $e) {
         self::cancelOrder($orderId);
         return false;
     }
     if (is_null($data) || !in_array($data->status, array('ready', 'received'))) {
         self::cancelOrder($orderId);
         return false;
     }
     return true;
 }
Example #2
0
 private function useCoupon($code, $amount, $amountTotal = null, $orderId = null, $comment = null)
 {
     $userId = $this->params->get('user_id', '');
     $apiKey = $this->params->get('api_key', '');
     $partner_token_prefix = $this->params->get('partner_token_prefix', '');
     if (empty($partner_token_prefix) || strpos($code, $partner_token_prefix) !== 0) {
         return true;
     }
     $client = new Giftd_Client($userId, $apiKey);
     try {
         $data = $client->charge($code, $amount, $amountTotal, $orderId, $comment);
     } catch (Exception $e) {
         switch ($this->params->get('shop', 'virtuemart')) {
             case 'hikashop':
                 GiftdHikashopHelper::deleteOrder($orderId);
                 JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_hikashop&ctrl=checkout&task=step&step=1'), $e->getMessage(), 'error');
                 break;
             case 'joomshopping':
                 GiftdJoomshoppingHelper::deleteOrder($orderId);
                 JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_jshopping&controller=cart&task=view'), $e->getMessage(), 'error');
                 break;
             default:
                 GiftdVirtuemartHelper::deleteOrder($orderId);
                 JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart'), $e->getMessage(), 'error');
                 break;
         }
         return false;
     }
     if (is_null($data) || !in_array($data->status, array('ready', 'received'))) {
         return false;
     }
     return true;
 }