/**
  * Constructor.
  *
  * @param ProviderInterface $providerObject Parent payment
  * @param array             $options        Configuration array
  *
  * @return self
  */
 public function __construct(ProviderInterface $providerObject, array $options = array())
 {
     $this->providerObject = $providerObject;
     $this->paymentObject = $this->providerObject->getPaymentObject();
     $this->pibaseObject = $this->paymentObject->getParentObject();
     $this->options = $options;
 }
 /**
  * Load configured criteria.
  *
  * @return void
  * @throws \Exception If criteria was not of correct interface
  */
 protected function loadCriteria()
 {
     // Get and instantiate registered criteria of this payment provider
     $criteraConfigurations = SettingsFactory::getInstance()->getConfiguration('SYSPRODUCTS.PAYMENT.types.' . $this->paymentObject->getType() . '.provider.' . $this->type . '.criteria');
     if (is_array($criteraConfigurations)) {
         foreach ($criteraConfigurations as $criterionConfiguration) {
             if (!is_array($criterionConfiguration['options'])) {
                 $criterionConfiguration['options'] = array();
             }
             /**
              * Criterion.
              *
              * @var ProviderCriterionInterface
              */
             $criterion = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($criterionConfiguration['class'], $this, $criterionConfiguration['options']);
             if (!$criterion instanceof ProviderCriterionInterface) {
                 throw new \Exception('Criterion ' . $criterionConfiguration['class'] . ' must implement interface \\CommerceTeam\\Commerce\\Payment\\Provider\\ProviderCriterionInterface', 1307720945);
             }
             $this->criteria[] = $criterion;
         }
     }
 }
 /**
  * Constructor.
  *
  * @param \CommerceTeam\Commerce\Payment\PaymentInterface $paymentObject Payment
  * @param array                                           $options       Configuration array
  *
  * @return self
  */
 public function __construct(\CommerceTeam\Commerce\Payment\PaymentInterface $paymentObject, array $options = array())
 {
     $this->paymentObject = $paymentObject;
     $this->pibaseObject = $this->paymentObject->getParentObject();
     $this->options = $options;
 }
 /**
  * Save an order in the given folder
  * Order-ID has to be calculated beforehand!
  *
  * @param int $orderId Uid of the order
  * @param int $pid Uid of the folder to save the order in
  * @param \CommerceTeam\Commerce\Domain\Model\Basket $basket Basket object of the user
  * @param \CommerceTeam\Commerce\Payment\PaymentInterface $paymentObj Payment
  * @param bool $doHook Flag if the hooks should be executed
  * @param bool $doStock Flag if stock reduce should be executed
  *
  * @return array $orderData Array with all the order data
  */
 public function saveOrder($orderId, $pid, \CommerceTeam\Commerce\Domain\Model\Basket $basket, \CommerceTeam\Commerce\Payment\PaymentInterface $paymentObj, $doHook = true, $doStock = true)
 {
     $database = $this->getDatabaseConnection();
     // Save addresses with reference to the pObj - which is an instance of pi3
     $uids = array();
     $types = $database->exec_SELECTgetRows('name', 'tx_commerce_address_types', '1');
     foreach ($types as $type) {
         $uids[$type['name']] = $this->handleAddress($type['name']);
     }
     // Generate an order id on the fly if none was passed
     if (empty($orderId)) {
         $orderId = uniqid('', true);
     }
     // create backend user for inserting the order data
     $orderData = array();
     if (isset($uids['delivery']) && !empty($uids['delivery'])) {
         $orderData['cust_deliveryaddress'] = $uids['delivery'];
     } else {
         $orderData['cust_deliveryaddress'] = $uids['billing'];
     }
     $orderData['cust_invoice'] = $uids['billing'];
     $orderData['paymenttype'] = $this->getPaymentType(true);
     $orderData['sum_price_net'] = $basket->getSumNet();
     $orderData['sum_price_gross'] = $basket->getSumGross();
     $orderData['order_sys_language_uid'] = $this->getFrontendController()->sys_language_uid;
     $orderData['pid'] = $pid;
     $orderData['order_id'] = $orderId;
     $orderData['crdate'] = $GLOBALS['EXEC_TIME'];
     $orderData['tstamp'] = $GLOBALS['EXEC_TIME'];
     $orderData['cu_iso_3_uid'] = $this->conf['currencyId'];
     $orderData['comment'] = GeneralUtility::removeXSS(strip_tags($this->piVars['comment']));
     if (is_array($this->getFrontendUser()->user)) {
         $orderData['cust_fe_user'] = $this->getFrontendUser()->user['uid'];
     }
     // Get hook objects
     $hooks = array();
     if ($doHook) {
         $hooks = HookFactory::getHooks('Controller/CheckoutController', 'saveOrder');
         // Insert order
         foreach ($hooks as $hookObj) {
             if (method_exists($hookObj, 'preinsert')) {
                 $hookObj->preinsert($orderData, $this);
             }
         }
     }
     $this->debug($orderData, '$orderData', __FILE__ . ' ' . __LINE__);
     $tceMain = $this->getInstanceOfTceMain($pid);
     $data = array();
     if (isset($this->conf['lockOrderIdInGenerateOrderId']) && $this->conf['lockOrderIdInGenerateOrderId'] == 1) {
         $data['tx_commerce_orders'][(int) $this->orderUid] = $orderData;
         $tceMain->start($data, array());
         $tceMain->process_datamap();
     } else {
         $newUid = uniqid('NEW');
         $data['tx_commerce_orders'][$newUid] = $orderData;
         $tceMain->start($data, array());
         $tceMain->process_datamap();
         $this->orderUid = $tceMain->substNEWwithIDs[$newUid];
     }
     // make orderUid avaible in hookObjects
     $orderUid = $this->orderUid;
     // Call update method from the payment class
     $paymentObj->updateOrder($orderUid, $this->sessionData);
     // Insert order
     foreach ($hooks as $hookObj) {
         if (method_exists($hookObj, 'modifyBasketPreSave')) {
             $hookObj->modifyBasketPreSave($basket, $this);
         }
     }
     // Save order articles
     if (is_array($basket->getBasketItems())) {
         /**
          * Basket item.
          *
          * @var \CommerceTeam\Commerce\Domain\Model\BasketItem $basketItem
          */
         foreach ($basket->getBasketItems() as $artUid => $basketItem) {
             /**
              * Article.
              *
              * @var \CommerceTeam\Commerce\Domain\Model\Article $article
              */
             $article = $basketItem->article;
             $this->debug($article, '$article', __FILE__ . ' ' . __LINE__);
             $orderArticleData = array();
             $orderArticleData['pid'] = $orderData['pid'];
             $orderArticleData['crdate'] = $GLOBALS['EXEC_TIME'];
             $orderArticleData['tstamp'] = $GLOBALS['EXEC_TIME'];
             $orderArticleData['article_uid'] = $artUid;
             $orderArticleData['article_type_uid'] = $article->getArticleTypeUid();
             $orderArticleData['article_number'] = $article->getOrdernumber();
             $orderArticleData['title'] = $basketItem->getTitle();
             $orderArticleData['subtitle'] = $article->getSubtitle();
             $orderArticleData['price_net'] = $basketItem->getPriceNet();
             $orderArticleData['price_gross'] = $basketItem->getPriceGross();
             $orderArticleData['tax'] = $basketItem->getTax();
             $orderArticleData['amount'] = $basketItem->getQuantity();
             $orderArticleData['order_uid'] = $orderUid;
             $orderArticleData['order_id'] = $orderId;
             $this->debug($orderArticleData, '$orderArticleData', __FILE__ . ' ' . __LINE__);
             $newUid = 0;
             foreach ($hooks as $hookObj) {
                 if (method_exists($hookObj, 'modifyOrderArticlePreSave')) {
                     $hookObj->modifyOrderArticlePreSave($newUid, $orderArticleData, $this, $basketItem);
                 }
             }
             if ($this->conf['useStockHandling'] == 1 && $doStock == true) {
                 $article->reduceStock($basketItem->getQuantity());
             }
             if (!$newUid) {
                 $newUid = uniqid('NEW');
             }
             $data = array();
             $data['tx_commerce_order_articles'][$newUid] = $orderArticleData;
             $tceMain->start($data, array());
             $tceMain->process_datamap();
             $newUid = $tceMain->substNEWwithIDs[$newUid];
             foreach ($hooks as $hookObj) {
                 if (method_exists($hookObj, 'modifyOrderArticlePostSave')) {
                     $hookObj->modifyOrderArticlePostSave($newUid, $orderArticleData, $this);
                 }
             }
         }
     }
     unset($backendUser);
     return $orderData;
 }