/** * Detects if current payment was already successfully processed by PayPal * * @param oxBasket $oBasket basket object * * @return bool */ public function isConfirmedByPayPal($oBasket) { $dOldBasketAmount = $this->getSession()->getVariable("oepaypal-basketAmount"); if (!$dOldBasketAmount) { return false; } $oPayPalCheckValidator = oxNew("oePayPalCheckValidator"); $oPayPalCheckValidator->setNewBasketAmount($oBasket->getPrice()->getBruttoPrice()); $oPayPalCheckValidator->setOldBasketAmount($dOldBasketAmount); return $oPayPalCheckValidator->isPayPalCheckValid(); }
/** * Sets basket information to Emos. * Uses username (email address) instead of customer number. * * @param Emos $oEmos * @param oxUser $oUser * @param oxOrder $oOrder * @param oxBasket $oBasket */ private function _setBasketInformation($oEmos, $oUser, $oOrder, $oBasket) { $oConfig = $this->getConfig(); $oCur = $oConfig->getActShopCurrencyObject(); $oEmos->addEmosBillingPageArray($this->_convertToUtf($oOrder->oxorder__oxordernr->value), $this->_convertToUtf($oUser->oxuser__oxusername->value), $oBasket->getPrice()->getBruttoPrice() * (1 / $oCur->rate), $this->_convertToUtf($oOrder->oxorder__oxbillcountry->value), $this->_convertToUtf($oOrder->oxorder__oxbillzip->value), $this->_convertToUtf($oOrder->oxorder__oxbillcity->value)); // get Basket Page Array $aBasket = array(); $aBasketProducts = $oBasket->getContents(); foreach ($aBasketProducts as $oContent) { /** @var oxBasketItem $oContent */ $sId = $oContent->getProductId(); /** @var oxArticle $oProduct */ $oProduct = oxNew('oxArticle'); $oProduct->load($sId); $sPath = $this->_getBasketProductCatPath($oProduct); $aBasket[] = $this->_convProd2EmosItem($oProduct, $sPath, $oContent->getAmount()); } $oEmos->addEmosBasketPageArray($aBasket); }
/** * Finalizes PayPal order. * * @param oePayPalResponseDoExpressCheckoutPayment $oResult PayPal results array. * @param oxBasket $oBasket Basket object. * @param string $sTransactionMode Transaction mode Sale|Authorization. */ public function finalizePayPalOrder($oResult, $oBasket, $sTransactionMode) { $sDate = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime()); // set order status, transaction ID and payment date to order $this->_setPaymentInfoPayPalOrder($oResult->getTransactionId()); $sCurrency = $oResult->getCurrencyCode(); if (!$sCurrency) { $sCurrency = $this->getOrderCurrency()->name; } //PayPal order info $oPayPalOrder = $this->getPayPalOrder(); $oPayPalOrder->setOrderId($this->getId()); $oPayPalOrder->setPaymentStatus('pending'); $oPayPalOrder->setTransactionMode($sTransactionMode); $oPayPalOrder->setCurrency($sCurrency); $oPayPalOrder->setTotalOrderSum($oBasket->getPrice()->getBruttoPrice()); if ($sTransactionMode == 'Sale') { $oPayPalOrder->setCapturedAmount($oBasket->getPrice()->getBruttoPrice()); } $oPayPalOrder->save(); $oOrderPayment = oxNew('oePayPalOrderPayment'); $oOrderPayment->setTransactionId($oResult->getTransactionId()); $oOrderPayment->setCorrelationId($oResult->getCorrelationId()); $oOrderPayment->setDate($sDate); $oOrderPayment->setAction($sTransactionMode == 'Sale' ? 'capture' : 'authorization'); $oOrderPayment->setStatus($oResult->getPaymentStatus()); $oOrderPayment->setAmount($oResult->getAmount()); $oOrderPayment->setCurrency($oResult->getCurrencyCode()); //Adding payment information $oPaymentList = $this->getPayPalOrder()->getPaymentList(); $oPaymentList->addPayment($oOrderPayment); //setting order payment status after $oPaymentStatusCalculator = oxNew('oePayPalOrderPaymentStatusCalculator'); $oPaymentStatusCalculator->setOrder($this->getPayPalOrder()); $this->getPayPalOrder()->setPaymentStatus($oPaymentStatusCalculator->getStatus()); $this->getPayPalOrder()->save(); //clear PayPal identification $this->getSession()->deleteVariable('oepaypal'); $this->getSession()->deleteVariable("oepaypal-payerId"); $this->getSession()->deleteVariable("oepaypal-userId"); $this->getSession()->deleteVariable('oepaypal-basketAmount'); }
/** * Executes payment. Additionally loads oxPaymentGateway object, initiates * it by adding payment parameters (oxPaymentGateway::setPaymentParams()) * and finally executes it (oxPaymentGateway::executePayment()). On failure - * deletes order and returns * error code 2. * * @param oxBasket $oBasket basket object * @param object $oUserpayment user payment object * * @return integer 2 or an error code */ protected function _executePayment(oxBasket $oBasket, $oUserpayment) { $oPayTransaction = $this->_getGateway(); $oPayTransaction->setPaymentParams($oUserpayment); if (!$oPayTransaction->executePayment($oBasket->getPrice()->getBruttoPrice(), $this)) { $this->delete(); // checking for error messages if (method_exists($oPayTransaction, 'getLastError')) { if ($sLastError = $oPayTransaction->getLastError()) { return $sLastError; } } // checking for error codes if (method_exists($oPayTransaction, 'getLastErrorNo')) { if ($iLastErrorNo = $oPayTransaction->getLastErrorNo()) { return $iLastErrorNo; } } return self::ORDER_STATE_PAYMENTERROR; // means no authentication } return true; // everything fine }
/** * Executes Trusted shops protection order. On failure - * deletes order and returns error code or 6. * * @param oxBasket $oBasket basket object * * @return mixed */ protected function _executeTsProtection(oxBasket $oBasket) { $aValues['tsProductId'] = $this->oxorder__oxtsprotectid->value; $aValues['amount'] = $oBasket->getPrice()->getBruttoPrice(); $oCur = $this->getConfig()->getActShopCurrencyObject(); $aValues['currency'] = $oCur->name; $aValues['buyerEmail'] = $this->oxorder__oxbillemail->value; $aValues['shopCustomerID'] = $this->oxorder__oxuserid->value; $aValues['shopOrderID'] = $this->oxorder__oxordernr->value; $aValues['orderDate'] = $this->oxorder__oxorderdate->value; $sPaymentId = $oBasket->getPaymentId(); $oTsProtection = oxNew('oxtsprotection'); $blRes = $oTsProtection->requestForTsProtection($aValues, $sPaymentId); /*if ( !$blRes ) { $this->delete(); return self::ORDER_STATE_INVALIDTSPROTECTION; }*/ return true; // everything fine }