/**
  * Tests WirecardCEE_QPay_FrontendClient->getResponse()
  */
 public function testSetPluginVersion()
 {
     $sPluginVersion = $this->object->generatePluginVersion('phpunit', '1.0.0', 'phpunit', '1.0.0', array('phpunit' => '3.5.15'));
     $this->object->setPluginVersion($sPluginVersion);
     $expected = array_merge($this->aExpectedRequestData, array(WirecardCEE_QPay_FrontendClient::PLUGIN_VERSION => $sPluginVersion));
     $this->assertAttributeEquals($expected, '_requestData', $this->object);
 }
Esempio n. 2
0
 public function config($urls)
 {
     //$returnUrl = $this->getUrl('wirecard_checkoutpage/processing/return', array('_secure' => true, '_nosid' => true));
     $returnUrl = $urls['return'];
     $init = new \WirecardCEE_QPay_FrontendClient($this->_dataHelper->getConfigArray());
     $init->setPluginVersion($this->_dataHelper->getPluginVersion());
     $init->setOrderReference('Configtest #' . uniqid());
     if ($this->_dataHelper->getConfigData('options/sendconfirmemail')) {
         $init->setConfirmMail($this->_dataHelper->getStoreConfigData('trans_email/ident_general/email'));
     }
     $consumerData = new \WirecardCEE_Stdlib_ConsumerData();
     $consumerData->setIpAddress($this->_dataHelper->getClientIp());
     $consumerData->setUserAgent($this->_dataHelper->getUserAgent());
     $init->setAmount(10)->setCurrency('EUR')->setPaymentType(\WirecardCEE_QPay_PaymentType::SELECT)->setOrderDescription('Configtest #' . uniqid())->setSuccessUrl($returnUrl)->setPendingUrl($returnUrl)->setCancelUrl($returnUrl)->setFailureUrl($returnUrl)->setConfirmUrl($urls['confirm'])->setServiceUrl($this->_dataHelper->getConfigData('options/service_url'))->setConsumerData($consumerData);
     if (strlen($this->_dataHelper->getConfigData('options/bgcolor'))) {
         $init->setBackgroundColor($this->_dataHelper->getConfigData('options/bgcolor'));
     }
     if (strlen($this->_dataHelper->getConfigData('options/displaytext'))) {
         $init->setDisplayText($this->_dataHelper->getConfigData('options/displaytext'));
     }
     if (strlen($this->_dataHelper->getConfigData('options/imageurl'))) {
         $init->setImageUrl($this->_dataHelper->getConfigData('options/imageurl'));
     }
     $initResponse = $init->initiate();
     if ($initResponse->getStatus() == \WirecardCEE_QPay_Response_Initiation::STATE_FAILURE) {
         $msg = $initResponse->getError()->getConsumerMessage();
         if (!strlen($msg)) {
             $msg = $initResponse->getError()->getMessage();
         }
         throw new \Exception($msg);
     }
     return true;
 }
Esempio n. 3
0
 /**
  * Init payment, server2server
  *
  * @param CheckoutCart $cart
  * @param $urls
  * @param \Magento\Framework\DataObject $data
  *
  * @return \WirecardCEE_QPay_Response_Initiation
  * @throws \Exception
  */
 public function initPaymentByCart(CheckoutCart $cart, $urls, \Magento\Framework\DataObject $data)
 {
     $quote = $cart->getQuote();
     $init = new \WirecardCEE_QPay_FrontendClient($this->_dataHelper->getConfigArray());
     $init->setPluginVersion($this->_dataHelper->getPluginVersion());
     $init->setConfirmUrl($urls['confirm']);
     $quote->reserveOrderId();
     $quote->save();
     $orderId = $quote->getReservedOrderId();
     $init->setOrderReference(sprintf('%010d', $orderId));
     $init->uniqueId = $this->_getUniqueId($cart);
     $init->setAmount(round($cart->getQuote()->getBaseGrandTotal(), $this->_dataHelper->getPrecision()))->setCurrency($quote->getCurrency()->getBaseCurrencyCode())->setPaymentType($this->_paymentMethod)->setOrderDescription($this->getUserDescription($quote))->setSuccessUrl($urls['return'])->setPendingUrl($urls['return'])->setCancelUrl($urls['return'])->setFailureUrl($urls['return'])->createConsumerMerchantCrmId($quote->getCustomerEmail())->setServiceUrl($this->_dataHelper->getConfigData('options/service_url'))->setConsumerData($this->_getConsumerData($quote))->setMaxRetries($this->_dataHelper->getConfigData('options/maxretries'));
     $init->mage_orderId = $orderId;
     $init->mage_quoteId = $quote->getId();
     $init->mage_orderCreation = $this->_dataHelper->getConfigData('options/order_creation');
     $init->generateCustomerStatement($this->_dataHelper->getConfigData('options/shopname'), sprintf('%010d', $orderId));
     if ($this->_dataHelper->getConfigData('options/sendbasketinformation') || $this->forceSendingBasket()) {
         $basket = new \WirecardCEE_Stdlib_Basket();
         $basket->setCurrency($quote->getBaseCurrencyCode());
         foreach ($quote->getAllVisibleItems() as $item) {
             /** @var \Magento\Quote\Model\Quote\Item $item */
             $bitem = new \WirecardCEE_Stdlib_Basket_Item();
             $bitem->setDescription($item->getProduct()->getName());
             $bitem->setArticleNumber($item->getSku());
             $bitem->setUnitPrice(number_format($item->getPrice(), $this->_dataHelper->getPrecision(), '.', ''));
             $bitem->setTax(number_format($item->getTaxAmount(), $this->_dataHelper->getPrecision(), '.', ''));
             $basket->addItem($bitem, (int) $item->getQty());
         }
         $bitem = new \WirecardCEE_Stdlib_Basket_Item();
         $bitem->setArticleNumber('shipping');
         $bitem->setUnitPrice(number_format($quote->getShippingAddress()->getShippingAmount(), $this->_dataHelper->getPrecision(), '.', ''));
         $bitem->setTax(number_format($quote->getShippingAddress()->getShippingTaxAmount(), $this->_dataHelper->getPrecision(), '.', ''));
         $bitem->setDescription($quote->getShippingAddress()->getShippingDescription());
         $basket->addItem($bitem);
         foreach ($basket->__toArray() as $k => $v) {
             $init->{$k} = $v;
         }
     }
     if ($this->_dataHelper->getConfigData('options/sendconfirmationemail')) {
         $init->setConfirmMail($this->_dataHelper->getStoreConfigData('trans_email/ident_general/email'));
     }
     if (strlen($this->_dataHelper->getConfigData('options/bgcolor'))) {
         $init->setBackgroundColor($this->_dataHelper->getConfigData('options/bgcolor'));
     }
     if (strlen($this->_dataHelper->getConfigData('options/displaytext'))) {
         $init->setDisplayText($this->_dataHelper->getConfigData('options/displaytext'));
     }
     if (strlen($this->_dataHelper->getConfigData('options/imageurl'))) {
         $init->setImageUrl($this->_dataHelper->getConfigData('options/imageurl'));
     }
     if (strlen($this->_dataHelper->getConfigData('options/layout'))) {
         $init->setLayout($this->_dataHelper->getConfigData('options/layout'));
     }
     if ($this->_dataHelper->getConfigData('options/autodeposit') && $this->_autoDepositAllowed) {
         $init->setAutoDeposit(true);
     }
     if ($this->_dataHelper->getConfigData('options/duplicaterequestcheck')) {
         $init->setDuplicateRequestCheck($this->_dataHelper->getConfigData('options/duplicaterequestcheck'));
     }
     if ($this->_dataHelper->getConfigData('options/mobiledetect')) {
         $detect = new \WirecardCEE_QPay_MobileDetect();
         if ($detect->isTablet()) {
             $layout = 'TABLET';
         } elseif ($detect->isMobile()) {
             $layout = 'SMARTPHONE';
         } else {
             $layout = 'DESKTOP';
         }
         $init->setLayout($layout);
     }
     if (strlen($data->getData('financialInstitution'))) {
         $init->setFinancialInstitution($data->getData('financialInstitution'));
     }
     $init->iframeUsed = $this->getDisplayMode() != 'redirect';
     $init->quoteHash = $this->_dataHelper->calculateQuoteChecksum($quote);
     $this->setAdditionalRequestData($init, $cart);
     $this->_logger->debug(__METHOD__ . ':' . print_r($init->getRequestData(), true));
     try {
         $initResponse = $init->initiate();
     } catch (\Exception $e) {
         $this->_logger->debug(__METHOD__ . ':' . $e->getMessage());
         throw new $e();
     }
     if ($initResponse->getStatus() == \WirecardCEE_QPay_Response_Initiation::STATE_FAILURE) {
         $error = $initResponse->getError();
         $message = $this->_dataHelper->__('An error occurred during the payment process');
         if ($error !== false) {
             if (strlen($error->getConsumerMessage())) {
                 $message = $error->getConsumerMessage();
             }
             $this->_logger->debug(__METHOD__ . ':' . $error->getMessage());
         }
         throw new \Exception($message);
     }
     return $initResponse;
 }