Attempts to add the voucher to the basket. Error and success messages are sent to $sMessageHandler.

@param TdbShopVoucher $oVoucher
@param string         $sMessageHandler - send any messages to this message consumer

@return bool
427707
public function AddVoucher(TdbShopVoucher &$oVoucher, $sMessageHandler)
    {
        $bVoucherAdded = false;
        $oMessageManager = TCMSMessageManager::GetInstance();

        $oVoucherSeries = $oVoucher->GetFieldShopVoucherSeries();
        $aMessageData = $oVoucherSeries->GetObjectPropertiesAsArray();
        $aVoucherData = $oVoucher->GetObjectPropertiesAsArray();
        $aMessageData = array_merge($aMessageData, $aVoucherData);

        $cAllowUseOfVoucherResult = $oVoucher->AllowUseOfVoucher();
        if (TdbShopVoucher::ALLOW_USE != $cAllowUseOfVoucherResult) {
            if (TdbShopVoucher::USE_ERROR_NOT_VALID_FOR_CUSTOMER_GROUP_MISSING_LOGIN == $cAllowUseOfVoucherResult ||
               TdbShopVoucher::USE_ERROR_NOT_VALID_FOR_CUSTOMER_MISSING_LOGIN == $cAllowUseOfVoucherResult) {
                $oExtranet = TdbDataExtranet::GetInstance();
                if (!is_null($oExtranet)) {
                    $aMessageData['sLinkLoginStart'] = '<a href="'.$oExtranet->GetLinkLoginPage().'">';
                    $aMessageData['sLinkLoginEnd'] = '</a>';
                }
            }
            $oMessageManager->AddMessage($sMessageHandler, 'VOUCHER-ERROR-'.$cAllowUseOfVoucherResult, $aMessageData);
        } else {
            $this->GetActiveVouchers()->AddItem($oVoucher);
            $oMessageManager->AddMessage($sMessageHandler, 'VOUCHER-ADDED', $aMessageData);
            $bVoucherAdded = true;
            $this->SetBasketRecalculationFlag();
        }

        return $bVoucherAdded;
    }
857363
protected function addBcc(Mail\Message $oMessage)
    {
        if (isset($this->aRendererConfig['mail_bcc']) && is_array($this->aRendererConfig['mail_bcc'])) {
            foreach ($this->aRendererConfig['mail_bcc'] as $sBccAddress) {
                // Avoid sending email copy to "to" AND bcc
                $bFound = false;
                foreach ($oMessage->getTo() as $oTo) {
                    if ($oTo->getEmail() == $sBccAddress) {
                        $bFound = true;
                        break;
                    }
                }
                if (!$bFound) {
                    $oAddressListBcc = new Mail\AddressList();
                    $oAddressListBcc->add(
                        new Mail\Address($sBccAddress)
                    );
                    $oMessage->addBcc($oAddressListBcc);
                }
            }
        }

        return $this;
    }
1018871
public function onEventInvalid($sMessage)
    {
        if(($this->xInvalidCallback))
        {
            call_user_func_array($this->xInvalidCallback, array($this->xResponse, $sMessage));
        }
        return $this->xResponse;
    }
1039195
public function &GetListMatchingVat(TdbShopVat &$oVat)
    {
        $oArticles = new TShopBasketArticleList();
        /** @var $oArticles TShopBasketArticleList */
        $iPointer = $this->getItemPointer();
        $this->GoToStart();
        while ($oItem = &$this->Next()) {
            $oItemVat = $oItem->GetVat();
            if (!is_null($oItemVat) && $oItemVat->id == $oVat->id) {
                $oArticles->AddItem($oItem);
            }
        }

        $this->setItemPointer($iPointer);

        return $oArticles;
    }
1101498
public function ShopOrderSendConfirmOrderMail($sMail = null)
    {
        $oGlobal = TGlobal::instance();
        if (is_null($sMail)) {
            $sMail = $oGlobal->GetUserData('sTargetMail');
        }
        $oReturnData = $this->GetObjectShortInfo();
        $oReturnData->sTargetMail = $sMail;

        $bSuccess = false;
        $oOrder = TdbShopOrder::GetNewInstance();
        /** @var $oOrder TdbShopOrder */
        $oOrder->AllowEditByAll(true);
        if (!$oOrder->Load($this->sId)) {
            $oOrder = null;
        } else {
            $bSuccess = $oOrder->SendOrderNotification($sMail);
        }

        if (true === $bSuccess) {
            $oReturnData->bSuccess = true;
            $oReturnData->sMessage = TGlobal::Translate('chameleon_system_shop.orders.msg_order_confirm_sent', array('%mail%' => $sMail));
        } else {
            $oReturnData->bSuccess = false;
            $oReturnData->sMessage = TGlobal::Translate('chameleon_system_shop.orders.error_sending_confirm_mail', array('%error%' => $bSuccess));
        }

        return $oReturnData;
    }
941915
protected function _markVouchers($oBasket, $oUser)
    {
        $this->_aVoucherList = $oBasket->getVouchers();

        if (is_array($this->_aVoucherList)) {
            foreach ($this->_aVoucherList as $sVoucherId => $oSimpleVoucher) {
                $oVoucher = oxNew(\OxidEsales\Eshop\Application\Model\Voucher::class);
                $oVoucher->load($sVoucherId);
                $oVoucher->markAsUsed($this->oxorder__oxid->value, $oUser->oxuser__oxid->value, $oSimpleVoucher->dVoucherdiscount);

                $this->_aVoucherList[$sVoucherId] = $oVoucher;
            }
        }
    }
440050
protected function SendFailureSettlementMail(TdbShopOrder &$oOrder)
    {
        $bSendMail = false;
        $oMail = TdbDataMailProfile::GetProfile('payment_datatrans_error_settlement');
        if (!is_null($oMail)) {
            $sInfo = TGlobal::OutHTML(TGlobal::Translate('chameleon_system_shop.payment_data_trans.settlement_failure_mail_info',
                    array(
                        '%ordernumber%' => $oOrder->fieldOrdernumber,
                        '%ref%' => $this->GetRefNoParameter(false),
                    )
                ));
            $oMail->AddData('sInfo', $sInfo);
            $bSendMail = $oMail->SendUsingObjectView('emails', 'Customer');
        }

        return $bSendMail;
    }
1198616
public function onClientHandlerMessage(ClientHandlerJobRequest $msg)
    {
        $request = new Request($msg->getRequestId(), $msg->getActionName(), $msg->getParameters());
        $this->addRequest($request);

        $this->getStream('clientHandler')->send(
            new ClientHandlerJobResponse(
                $msg->getRequestId(),
                $this->getId()
            )
        );
    }
1066404
protected function AddToWishlist($sArticleId = null, $dAmount = null, $sMessageHandler = null, $bIsInternalCall = false)
    {
        $oGlobal = TGlobal::instance();
        $aRequestData = $oGlobal->GetUserData(self::URL_REQUEST_PARAMETER);
        if (is_null($sArticleId) && array_key_exists(self::URL_ITEM_ID_NAME, $aRequestData)) {
            $sArticleId = $aRequestData[self::URL_ITEM_ID_NAME];
            if (empty($sArticleId)) {
                $sArticleId = null;
            }
        }
        if (is_null($dAmount) && array_key_exists(self::URL_ITEM_AMOUNT_NAME, $aRequestData)) {
            $dAmount = $aRequestData[self::URL_ITEM_AMOUNT_NAME];
            if (empty($dAmount)) {
                $dAmount = 1;
            }
        }

        if (is_null($sMessageHandler) && array_key_exists(self::URL_MESSAGE_CONSUMER_NAME, $aRequestData)) {
            $sMessageHandler = $aRequestData[self::URL_MESSAGE_CONSUMER_NAME];
            if (empty($sMessageHandler)) {
                $sMessageHandler = null;
            }
        }
        if (is_null($sMessageHandler)) {
            $sMessageHandler = self::MSG_CONSUMER_NAME;
        }

        $oMsgManager = TCMSMessageManager::GetInstance();
        if (is_null($sArticleId)) {
            $oMsgManager->AddMessage($sMessageHandler, 'ERROR-SHOP-WISHLIST-ADD-ITEM-NO-ID-GIVEN');
        } else {
            $oItem = TdbShopArticle::GetNewInstance();
            /** @var $oItem TdbShopArticle */
            if ($oItem->Load($sArticleId)) {
                $oShop = TdbShop::GetInstance();
                $oExtranet = &TdbDataExtranet::GetInstance();
                $aInfoData = array('sLinkLoginStart' => '<a href="'.$oExtranet->GetLinkLoginPage().'">', 'sLinkLoginEnd' => '</a>', 'sLinkWishlistStart' => '<a href="'.$oShop->GetLinkToSystemPage('wishlist').'">', 'sLinkWishlistEnd' => '</a>', 'sLinkArticleStart' => '<a href="'.$oItem->GetDetailLink().'">', 'sLinkArticleEnd' => '</a>', 'sArticleName' => TGlobal::OutHTML($oItem->GetName()), 'dAddedAmount' => $dAmount);
                $oUser = TdbDataExtranetUser::GetInstance();
                if (!$oUser->IsLoggedIn()) {
                    $oMsgManager->AddMessage($sMessageHandler, 'WISHLIST-USER-NOT-LOGGED-IN', $aInfoData);
                } else {
                    // add item to list
                    $dNewAmountOnList = $oUser->AddArticleIdToWishlist($sArticleId, $dAmount);

                    $aInfoData['dNewAmount'] = $dNewAmountOnList;
                    if (false === $dNewAmountOnList) {
                        // article was already on notice list...
                        $oMsgManager->AddMessage($sMessageHandler, 'WISHLIST-ITEM-ALREADY-ON-LIST', $aInfoData);
                    } else {
                        $oMsgManager->AddMessage($sMessageHandler, 'WISHLIST-ADDED-ITEM', $aInfoData);
                    }
                }
            } else {
                $oMsgManager->AddMessage($sMessageHandler, 'ERROR-SHOP-WISHLIST-INVALID-ITEM-ID');
            }
        }

        // now redirect either to requested page, or to calling page
        $iRedirectNodeId = null;
        if (array_key_exists(self::URL_REDIRECT_NODE_ID_NAME, $aRequestData)) {
            $iRedirectNodeId = $aRequestData[self::URL_REDIRECT_NODE_ID_NAME];
            if (empty($iRedirectNodeId)) {
                $iRedirectNodeId = null;
            }
        }

        if (!$bIsInternalCall) {
            $this->RedirectAfterEvent($iRedirectNodeId);
        }
    }
437153
public function AllowVoucherForArticle(TShopBasketArticle $oArticle)
    {
        $bMayBeUsed = true;

        $oVoucherDef = &$this->GetFieldShopVoucherSeries();

        if ($oArticle->fieldExcludeFromVouchers && empty($oVoucherDef->fieldShopVoucherSeriesSponsorId)) {
            $bMayBeUsed = false;
        }

        // check article restrictions
        if ($bMayBeUsed) {
            $aArticleRestrictons = $oVoucherDef->GetMLTIdList('shop_article_mlt');
            if (count($aArticleRestrictons) > 0 && !in_array($oArticle->id, $aArticleRestrictons)) {
                $bMayBeUsed = false;
            }
        }

        // check manufacturer restrictions
        if ($bMayBeUsed) {
            $aManufacturerRestrictons = $oVoucherDef->GetMLTIdList('shop_manufacturer_mlt');
            if (count($aManufacturerRestrictons) > 0 && !in_array($oArticle->fieldShopManufacturerId, $aManufacturerRestrictons)) {
                $bMayBeUsed = false;
            }
        }

        // check category restrictions
        if ($bMayBeUsed) {
            $aCategoryRestrictons = $oVoucherDef->GetMLTIdList('shop_category_mlt');
            if (count($aCategoryRestrictons) > 0) {
                if (!$oArticle->IsInCategory($aCategoryRestrictons)) {
                    $bMayBeUsed = false;
                }
            }
        }

        // check product group restrictions
        if ($bMayBeUsed) {
            $aArticleGroupRestrictons = $oVoucherDef->GetMLTIdList('shop_article_group_mlt');
            if (count($aArticleGroupRestrictons) > 0) {
                $aGroups = $oArticle->GetMLTIdList('shop_article_group_mlt');
                $aMatches = array_intersect($aGroups, $aArticleGroupRestrictons);
                if (0 == count($aMatches)) {
                    $bMayBeUsed = false;
                }
            }
        }

        return $bMayBeUsed;
    }
934760
public function addVoucherWithCode($name, $code, $params = null)
    {
        return $this->client->post("/campaigns/" . rawurlencode($name) . "/vouchers/" . rawurlencode($code), $params);
    }
1013333
public function sendOrderEmailToUser($oOrder, $sSubject = null)
    {
        self::$blSendToUserWasCalled = true;
        self::$oUserOrder = $oOrder;

        return self::$blRetValue;
    }
291826
public OvhVoucherStatus voucher_checkValidity_POST(String voucher) throws IOException {
		String qPath = "/me/voucher/checkValidity";
		StringBuilder sb = path(qPath);
		HashMap<String, Object>o = new HashMap<String, Object>();
		addBody(o, "voucher", voucher);
		String resp = exec(qPath, "POST", sb.toString(), o);
		return convertTo(resp, OvhVoucherStatus.class);
	}
406731
public function removeVoucher($sVoucherId)
    {
        // removing if it exists
        if (isset($this->_aVouchers[$sVoucherId])) {
            $oVoucher = oxNew(\OxidEsales\Eshop\Application\Model\Voucher::class);
            $oVoucher->load($sVoucherId);

            $oVoucher->unMarkAsReserved();

            // unset it if exists this voucher in DB or not
            unset($this->_aVouchers[$sVoucherId]);
            $this->onUpdate();
        }
    }
511659
public function parseRequest(TdbPkgShopPaymentIpnMessage $oMessage)
    {
        if (false === $this->isIPNRequest()) {
            throw new TPkgShopPaymentIPNException_RequestError($this, "handleIPN called with an invalid URL (URL: {$this->getRequestURL(
            )})", 0);
        }

        $aParts = explode(self::URL_IPN_IDENTIFIER, $this->requestURL);
        if (2 !== count($aParts)) {
            throw new TPkgShopPaymentIPNException_RequestError($this, "handleIPN called with an invalid URL (URL: {$this->getRequestURL(
            )})", 0);
        }

        $sData = substr(
            $this->requestURL,
            stripos($this->requestURL, self::URL_IPN_IDENTIFIER) + strlen(self::URL_IPN_IDENTIFIER)
        );

        if ('' === empty($sData)) {
            throw new TPkgShopPaymentIPNException_RequestError($this, "handleIPN called with an invalid URL (URL: {$this->getRequestURL(
            )})", 0);
        }

        $sPaymentGroupIdentifier = null;
        $sOrderCmsIdent = null;
        if (false !== strpos($sData, '__')) {
            $sPaymentGroupIdentifier = substr($sData, 0, strpos($sData, '__'));
            $sOrderCmsIdent = substr($sData, strpos($sData, '__') + 2);
        } else {
            $sPaymentGroupIdentifier = $sData;
        }

        if (null !== $sPaymentGroupIdentifier) {
            $this->paymentHandlerGroup = null;
            $oPaymentHandlerGroup = TdbShopPaymentHandlerGroup::GetNewInstance();
            if (false === $oPaymentHandlerGroup->LoadFromField('ipn_group_identifier', $sPaymentGroupIdentifier)) {
                if (false === $oPaymentHandlerGroup->LoadFromField('system_name', $sPaymentGroupIdentifier)) {
                    $oPaymentHandlerGroup = null;
                }
            }

            // cast to correct object type
            if (null !== $oPaymentHandlerGroup) {
                $this->paymentHandlerGroup = TdbShopPaymentHandlerGroup::GetNewInstance($oPaymentHandlerGroup->sqlData);
            }
        }
        if (null === $this->paymentHandlerGroup) {
            throw new TPkgShopPaymentIPNException_InvalidPaymentHandlerGroupInRequest($this, "no payment handler group found for URL (URL: {$this->getRequestURL(
            )})", 0);
        }

        // we have a payment group - we may need to transform the raw data using it (because the encoding may be non utf8 for exampel)
        $oMessage->SaveFieldsFast(array('shop_payment_handler_group_id' => $this->paymentHandlerGroup->id));

        // once we have the group we may need to convert the request data
        if ('UTF-8' !== strtoupper($this->getPaymentHandlerGroup()->fieldIpnPayloadCharacterCharset)) {
            $this->requestPayload = $this->convertCharset(
                $this->requestPayload,
                $this->getPaymentHandlerGroup()->fieldIpnPayloadCharacterCharset
            );
        }

        $this->requestPayload = $this->paymentHandlerGroup->processRawRequestData($this->requestPayload);

        $oMessage->SaveFieldsFast(
            array('payload' => serialize($this->requestPayload))
        ); // note: we need to serialize the data since savefieldsfast does NO data transformation before saving

        if (null !== $sOrderCmsIdent) {
            $oOrder = TdbShopOrder::GetNewInstance();
            if (true === $oOrder->LoadFromField('cmsident', $sOrderCmsIdent)) {
                $this->order = $oOrder;
            } else {
                throw new TPkgShopPaymentIPNException_OrderNotFound($sOrderCmsIdent, $this, "order [{$sOrderCmsIdent}] passed via URL not found (URL: {$this->getRequestURL(
                )})", 0);
            }
        } else {
            $this->order = $this->getPaymentHandlerGroup()->getOrderFromRequestData($this->getRequestPayload());
            if (null === $this->order) {
                throw new TPkgShopPaymentIPNException_OrderNotFound($sOrderCmsIdent, $this, "Order not found using payment group [{$this->getPaymentHandlerGroup(
                )->id} class: ".get_class($this->getPaymentHandlerGroup()).'] for request ['.print_r(
                    $this->getRequestPayload(),
                    true
                )."] (URL: {$this->getRequestURL()})", 0);
            }
        }

        $oMessage->SaveFieldsFast(array('shop_order_id' => $this->getOrder()->id));

        $oPaymentHandler = $this->getOrder()->GetPaymentHandler();

        if (null === $oPaymentHandler || false === ($oPaymentHandler instanceof IPkgShopPaymentIPNPaymentHandler)) {
            throw new TPkgShopPaymentIPNException_SystemError_PaymentHanlderDoesNotSupportIPN($this, "Payment handler in order ({$this->getOrder(
            )->id}) must be an instance of IPkgShopPaymentIPNPaymentHandler", 0);
        }

        $this->paymentHandler = $oPaymentHandler;

        // add trigger
        $this->addTrigger($oMessage);
    }
963017
public function SendShopReviewMail($aOrder)
    {
        $bMailWasSend = false;

        $oUser = TdbDataExtranetUser::GetNewInstance();
        $oUser->Load($aOrder['data_extranet_user_id']);

        if ($this->AllowSendingMailForOrder($oUser, $aOrder)) {
            $oRatingService = $this->GetSuitableRatingService($oUser, $aOrder);
            if (null !== $oRatingService) {
                $bMailWasSend = $oRatingService->SendShopRatingEmail($oUser, $aOrder);
                if ($bMailWasSend) {
                    $query = "UPDATE `shop_order` SET `pkg_shop_rating_service_mail_sent` = '1', `pkg_shop_rating_service_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($oRatingService->id)."' WHERE `id` = '".MySqlLegacySupport::getInstance()->real_escape_string($aOrder['id'])."'";
                    MySqlLegacySupport::getInstance()->query($query);
                    if (false == $this->bDisableSentHistory) {
                        $sNewID = TTools::GetUUID();
                        $iSendDate = date('Y-m-d H:i:s');
                        $query = "INSERT INTO `pkg_shop_rating_service_history`
                               SET `id` = '".MySqlLegacySupport::getInstance()->real_escape_string($sNewID)."',
                                   `data_extranet_user_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($oUser->id)."',
                                   `shop_order_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($aOrder['id'])."',
                                   `date` = '".MySqlLegacySupport::getInstance()->real_escape_string($iSendDate)."',
                                   `pkg_shop_rating_service_id_list` = '".MySqlLegacySupport::getInstance()->real_escape_string($oRatingService->id)."'
                           ";
                        if ($this->bDebug) {
                            echo __LINE__.': '.$query."\n<br />\n";
                        }
                        MySqlLegacySupport::getInstance()->query($query);
                    }
                }
            }
        }

        return $bMailWasSend;
    }
802853
protected function GetExternalPaymentHandlerURL(TdbShopOrder $oOrder)
    {
        $oUser = TdbDataExtranetUser::GetInstance();
        $oCountry = $oUser->GetCountry();
        $sActiveFrontEndLanguageCode = self::getLanguageService()->getLanguageIsoCode();
        $aParameter = array(
            'PSPID' => $this->GetPSPID(),
            'ORDERID' => $oOrder->fieldOrdernumber,
            'AMOUNT' => $oOrder->fieldValueTotal * 100,
            'CURRENCY' => $this->GetCurrency(),
            'LANGUAGE' => strtolower($sActiveFrontEndLanguageCode).'_'.strtoupper($sActiveFrontEndLanguageCode),
            'CN' => $oUser->fieldFirstname.' '.$oUser->fieldLastname,
            'EMAIL' => $oUser->fieldName,
            'OWNERADDRESS' => $oUser->fieldStreet.' '.$oUser->fieldStreetnr,
            'OWNERCTY' => $oCountry->fieldName,
            'OWNERTOWN' => $oUser->fieldCity,
            'OWNERZIP' => $oUser->fieldPostalcode,
            'PARAMPLUS' => 'PAYCALL='.self::URL_IDENTIFIER.'&PAYHAID='.$this->sqlData['cmsident'], 'PARAMVAR' => self::URL_IDENTIFIER_NOTIFY, );
        $this->AddCustomParameter($aParameter);
        $sOgonePaymentLayoutPageURL = $this->GetOgonePaymentLayoutPage();
        if ($sOgonePaymentLayoutPageURL) {
            $aParameter['TP'] = $sOgonePaymentLayoutPageURL;
        }
        $aParameter['ACCEPTURL'] = $this->GetResponseURL('success');
        $aParameter['DECLINEURL'] = $this->GetResponseURL('decline');
        $aParameter['SHASIGN'] = $this->BuildOutgoingHash($aParameter);
        $sExternalHandlerURL = $this->GetPaymentURL().'?'.str_replace('&amp;', '&', TTools::GetArrayAsURL($aParameter));

        return $sExternalHandlerURL;
    }