/**
  * Sends an XML-Request
  *
  * @param mixed $Model
  *
  * @return \DOMDocument
  */
 public function xmlRequest($Model)
 {
     $xml = Shopware_Plugins_Frontend_RpayRatePay_Component_Service_Util::convertToXml($Model, 'request');
     $this->_zendHttpClient->setRawData(trim($xml->asXML(), ""), "text/xml; charset=UTF-8");
     $result = $this->_zendHttpClient->request('POST');
     $dom = new DOMDocument();
     $dom->loadXML($result->getBody());
     $this->_logging->logRequest($this->getLastRequest(), $this->getLastResponse());
     return $dom;
 }
Esempio n. 2
0
 /**
  * Procceds the whole Paymentprocess
  */
 private function _proceedPayment()
 {
     $paymentInitModel = $this->_modelFactory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentInit());
     $result = $this->_service->xmlRequest($paymentInitModel->toArray());
     if (Shopware_Plugins_Frontend_RpayRatePay_Component_Service_Util::validateResponse('PAYMENT_INIT', $result)) {
         Shopware()->Session()->RatePAY['transactionId'] = $result->getElementsByTagName('transaction-id')->item(0)->nodeValue;
         $this->_modelFactory->setTransactionId(Shopware()->Session()->RatePAY['transactionId']);
         $paymentRequestModel = $this->_modelFactory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentRequest());
         $result = $this->_service->xmlRequest($paymentRequestModel->toArray());
         if (Shopware_Plugins_Frontend_RpayRatePay_Component_Service_Util::validateResponse('PAYMENT_REQUEST', $result)) {
             $uniqueId = $this->createPaymentUniqueId();
             $orderNumber = $this->saveOrder(Shopware()->Session()->RatePAY['transactionId'], $uniqueId, 17);
             $paymentConfirmModel = $this->_modelFactory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentConfirm());
             $matches = array();
             preg_match("/<descriptor.*>(.*)<\\/descriptor>/", $this->_service->getLastResponse(), $matches);
             $dgNumber = $matches[1];
             $result = $this->_service->xmlRequest($paymentConfirmModel->toArray());
             if (Shopware_Plugins_Frontend_RpayRatePay_Component_Service_Util::validateResponse('PAYMENT_CONFIRM', $result)) {
                 if (Shopware()->Session()->sOrderVariables['sBasket']['sShippingcosts'] > 0) {
                     $this->initShipping($orderNumber);
                 }
                 try {
                     $orderId = Shopware()->Db()->fetchOne('SELECT `id` FROM `s_order` WHERE `ordernumber`=?', array($orderNumber));
                     Shopware()->Db()->update('s_order_attributes', array('attribute5' => $dgNumber, 'attribute6' => Shopware()->Session()->RatePAY['transactionId']), 'orderID=' . $orderId);
                 } catch (Exception $exception) {
                     Shopware()->Pluginlogger()->error($exception->getMessage());
                 }
                 //set cleared date
                 $dateTime = new DateTime();
                 $order = Shopware()->Models()->find('Shopware\\Models\\Order\\Order', $orderId);
                 $order->setClearedDate($dateTime);
                 Shopware()->Models()->flush($order);
                 //set payments status to payed
                 $this->savePaymentStatus(Shopware()->Session()->RatePAY['transactionId'], $uniqueId, 12);
                 /**
                  * unset DFI token
                  */
                 if (Shopware()->Session()->RatePAY['dfpToken']) {
                     unset(Shopware()->Session()->RatePAY['dfpToken']);
                 }
                 /*
                  * redirect to success page
                  */
                 $this->redirect(array('controller' => 'checkout', 'action' => 'finish', 'sUniqueID' => $uniqueId, 'forceSecure' => true));
             } else {
                 $this->_error();
             }
         } else {
             $this->_customerMessage = $result->getElementsByTagName('customer-message')->item(0)->textContent;
             $this->_error();
         }
     } else {
         $this->_error();
     }
 }
 /**
  * Add the given Items to the given order
  */
 public function addAction()
 {
     $orderId = $this->Request()->getParam("orderId");
     $insertedIds = json_decode($this->Request()->getParam("insertedIds"));
     $subOperation = $this->Request()->getParam("suboperation");
     $order = Shopware()->Db()->fetchRow("SELECT * FROM `s_order` WHERE `id`=?", array($orderId));
     $orderItems = Shopware()->Db()->fetchAll("SELECT *, (`quantity` - `delivered` - `cancelled`) AS `quantityDeliver` FROM `s_order_details` " . "INNER JOIN `rpay_ratepay_order_positions` ON `s_order_details`.`id` = `rpay_ratepay_order_positions`.`s_order_details_id` " . "WHERE `orderID`=?", array($orderId));
     $basketItems = array();
     foreach ($orderItems as $row) {
         if ($row['quantityDeliver'] == 0) {
             continue;
         }
         $basketItem = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_item();
         $basketItem->setArticleName($row['name']);
         $basketItem->setArticleNumber($row['articleordernumber']);
         $basketItem->setQuantity($row['quantityDeliver']);
         $basketItem->setTaxRate($row['tax_rate']);
         $basketItem->setUnitPriceGross($row['price']);
         $basketItems[] = $basketItem;
     }
     $shippingRow = $this->getShippingFromDBAsItem($orderId);
     if (!is_null($shippingRow) && $shippingRow['quantityDeliver'] != 0) {
         $basketItem = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_item();
         $basketItem->setArticleName($shippingRow['name']);
         $basketItem->setArticleNumber($shippingRow['articleordernumber']);
         $basketItem->setQuantity($shippingRow['quantityDeliver']);
         $basketItem->setTaxRate($shippingRow['tax_rate']);
         $basketItem->setUnitPriceGross($shippingRow['price']);
         $basketItems[] = $basketItem;
     }
     $basket = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_ShoppingBasket();
     $basket->setAmount($this->getRecalculatedAmount($basketItems));
     $basket->setCurrency($order['currency']);
     $basket->setItems($basketItems);
     $this->_modelFactory->setTransactionId($order['transactionID']);
     $paymentChange = $this->_modelFactory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentChange(), $orderId);
     $head = $paymentChange->getHead();
     $head->setOperationSubstring($subOperation);
     $paymentChange->setHead($head);
     $paymentChange->setShoppingBasket($basket);
     $response = $this->_service->xmlRequest($paymentChange->toArray());
     $result = Shopware_Plugins_Frontend_RpayRatePay_Component_Service_Util::validateResponse('PAYMENT_CHANGE', $response);
     if ($result) {
         $event = $subOperation === 'credit' ? 'Nachlass wurde hinzugefügt' : 'Artikel wurde hinzugefügt';
         foreach ($insertedIds as $id) {
             $newItems = Shopware()->Db()->fetchRow("SELECT * FROM `s_order_details` WHERE `id`=?", array($id));
             if ($newItems['quantity'] <= 0) {
                 continue;
             }
             $this->_history->logHistory($orderId, $event, $newItems['name'], $newItems['articleordernumber'], $newItems['quantity']);
         }
     }
     $this->setNewOrderState($orderId);
     $this->View()->assign(array("result" => $result, "success" => true));
 }
Esempio n. 4
0
 /**
  * Fills an object of the class Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentRequest
  *
  * @param Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentRequest $paymentRequestModel
  */
 private function fillPaymentRequest(Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentRequest &$paymentRequestModel)
 {
     $method = Shopware_Plugins_Frontend_RpayRatePay_Component_Service_Util::getPaymentMethod(Shopware()->Session()->sOrderVariables['sUserData']['additional']['payment']['name']);
     $shopUser = Shopware()->Models()->find('Shopware\\Models\\Customer\\Customer', Shopware()->Session()->sUserId);
     // Checkout address ids are set in RP session from shopware version >=5.2.0
     if (isset(Shopware()->Session()->RatePAY['checkoutBillingAddressId']) && Shopware()->Session()->RatePAY['checkoutBillingAddressId'] > 0) {
         $addressModel = Shopware()->Models()->getRepository('Shopware\\Models\\Customer\\Address');
         $checkoutAddressBilling = $addressModel->findOneBy(array('id' => Shopware()->Session()->RatePAY['checkoutBillingAddressId']));
         $checkoutAddressShipping = $addressModel->findOneBy(array('id' => Shopware()->Session()->RatePAY['checkoutShippingAddressId'] ? Shopware()->Session()->RatePAY['checkoutShippingAddressId'] : Shopware()->Session()->RatePAY['checkoutBillingAddressId']));
         $countryCodeBilling = $checkoutAddressBilling->getCountry()->getIso();
         $countryCodeShipping = $checkoutAddressShipping->getCountry()->getIso();
         $company = $checkoutAddressBilling->getCompany();
         if (empty($company)) {
             $dateOfBirth = $shopUser->getBirthday()->format("Y-m-d");
             // From Shopware 5.2 date of birth has moved to customer object
         }
         $merchantCustomerId = $shopUser->getNumber();
         // From Shopware 5.2 billing number has moved to customer object
     } else {
         $checkoutAddressBilling = $shopUser->getBilling();
         $checkoutAddressShipping = $shopUser->getShipping() !== null ? $shopUser->getShipping() : $shopUser->getBilling();
         $countryBilling = Shopware()->Models()->find('Shopware\\Models\\Country\\Country', $checkoutAddressBilling->getCountryId());
         $countryCodeBilling = $countryBilling->getIso();
         $countryShipping = Shopware()->Models()->find('Shopware\\Models\\Country\\Country', $checkoutAddressShipping->getCountryId());
         $countryCodeShipping = $countryShipping->getIso();
         $company = $checkoutAddressBilling->getCompany();
         if (!empty($company)) {
             $dateOfBirth = $shopUser->getBilling()->getBirthday()->format("Y-m-d");
         }
         $merchantCustomerId = $shopUser->getBilling()->getNumber();
     }
     $head = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_Head();
     $head->setTransactionId(Shopware()->Session()->RatePAY['transactionId']);
     $head->setOperation('PAYMENT_REQUEST');
     $head->setProfileId($this->getProfileId());
     $head->setSecurityCode($this->getSecurityCode());
     $head->setSystemId(Shopware()->Shop()->getHost() ?: $_SERVER['SERVER_ADDR']);
     $head->setSystemVersion($this->_getVersion());
     $head->setOrderId($this->_getOrderIdFromTransactionId());
     $head->setMerchantConsumerId($merchantCustomerId);
     //set device ident token if available
     if (Shopware()->Session()->RatePAY['dfpToken']) {
         $head->setDeviceToken(Shopware()->Session()->RatePAY['dfpToken']);
     }
     $customer = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_Customer();
     // only for elv and sepa elv
     if ($method === 'ELV') {
         $bankAccount = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_BankAccount();
         $bankAccount->setBankAccount(Shopware()->Session()->RatePAY['bankdata']['account']);
         $bankAccount->setBankCode(Shopware()->Session()->RatePAY['bankdata']['bankcode']);
         $bankAccount->setOwner(Shopware()->Session()->RatePAY['bankdata']['bankholder']);
         $customer->setBankAccount($bankAccount);
     }
     $customer->setFirstName($checkoutAddressBilling->getFirstName());
     $customer->setLastName($checkoutAddressBilling->getLastName());
     $customer->setEmail($shopUser->getEmail());
     if (!empty($company)) {
         $customer->setCompanyName($checkoutAddressBilling->getCompany());
         $customer->setVatId($checkoutAddressBilling->getVatId());
     } else {
         $customer->setDateOfBirth($dateOfBirth);
     }
     /**
      * set gender and salutation based on the given billingaddress salutation
      */
     $gender = 'U';
     if ($checkoutAddressBilling->getSalutation() === 'mr') {
         $gender = 'M';
         $customer->setSalutation('Herr');
     } elseif ($checkoutAddressBilling->getSalutation() === 'ms') {
         $gender = 'F';
         $customer->setSalutation('Frau');
     } else {
         $customer->setSalutation($checkoutAddressBilling->getSalutation());
     }
     $customer->setGender($gender);
     $customer->setPhone($checkoutAddressBilling->getPhone());
     $customer->setNationality($this->_countryCode);
     $customer->setIpAddress($this->_getCustomerIP());
     $customer->setBillingAddresses($this->_getCheckoutAddress($checkoutAddressBilling, 'BILLING', $countryCodeBilling));
     $customer->setShippingAddresses($this->_getCheckoutAddress($checkoutAddressShipping, 'DELIVERY', $countryCodeShipping));
     $payment = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_Payment();
     $payment->setAmount($this->getAmount());
     $payment->setCurrency(Shopware()->Currency()->getShortName());
     $payment->setMethod($method);
     if ($method === 'INSTALLMENT') {
         $payment->setAmount(Shopware()->Session()->RatePAY['ratenrechner']['total_amount']);
         $payment->setDirectPayType('BANK-TRANSFER');
         $payment->setInstallmentAmount(Shopware()->Session()->RatePAY['ratenrechner']['rate']);
         $payment->setInstallmentNumber(Shopware()->Session()->RatePAY['ratenrechner']['number_of_rates']);
         $payment->setInterestRate(Shopware()->Session()->RatePAY['ratenrechner']['interest_rate']);
         $payment->setLastInstallmentAmount(Shopware()->Session()->RatePAY['ratenrechner']['last_rate']);
     }
     $basket = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_ShoppingBasket();
     $basket->setAmount($this->getAmount());
     $basket->setCurrency(Shopware()->Currency()->getShortName());
     $shopItems = Shopware()->Session()->sOrderVariables['sBasket']['content'];
     $items = array();
     foreach ($shopItems as $shopItem) {
         $item = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_item();
         $item->setArticleName($shopItem['articlename']);
         $item->setArticleNumber($shopItem['ordernumber']);
         $item->setQuantity($shopItem['quantity']);
         $item->setTaxRate($shopItem['tax_rate']);
         $item->setUnitPriceGross($shopItem['priceNumeric']);
         $items[] = $item;
     }
     if (Shopware()->Session()->sOrderVariables['sBasket']['sShippingcosts'] > 0) {
         $items[] = $this->getShippingAsItem(Shopware()->Session()->sOrderVariables['sBasket']['sShippingcosts'], Shopware()->Session()->sOrderVariables['sBasket']['sShippingcostsTax']);
     }
     $basket->setItems($items);
     $paymentRequestModel->setHead($head);
     $paymentRequestModel->setCustomer($customer);
     $paymentRequestModel->setPayment($payment);
     $paymentRequestModel->setShoppingBasket($basket);
 }
Esempio n. 5
0
 /**
  * Sends a Profile_request and saves the data into the Database
  *
  * @param string $profileId
  * @param string $securityCode
  *
  * @return boolean
  */
 private function getRatepayConfig($profileId, $securityCode, $shopId, $sandbox)
 {
     $factory = new Shopware_Plugins_Frontend_RpayRatePay_Component_Mapper_ModelFactory();
     $profileRequestModel = $factory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_ProfileRequest());
     $head = $profileRequestModel->getHead();
     $head->setProfileId($profileId);
     $head->setSecurityCode($securityCode);
     $profileRequestModel->setHead($head);
     $requestService = new Shopware_Plugins_Frontend_RpayRatePay_Component_Service_RequestService($sandbox);
     $response = $requestService->xmlRequest($profileRequestModel->toArray());
     if (Shopware_Plugins_Frontend_RpayRatePay_Component_Service_Util::validateResponse('PROFILE_REQUEST', $response)) {
         $data = array($response->getElementsByTagName('profile-id')->item(0)->nodeValue, $response->getElementsByTagName('activation-status-invoice')->item(0)->nodeValue, $response->getElementsByTagName('activation-status-elv')->item(0)->nodeValue, $response->getElementsByTagName('activation-status-installment')->item(0)->nodeValue, $response->getElementsByTagName('b2b-invoice')->item(0)->nodeValue ?: 'no', $response->getElementsByTagName('b2b-elv')->item(0)->nodeValue ?: 'no', $response->getElementsByTagName('b2b-installment')->item(0)->nodeValue ?: 'no', $response->getElementsByTagName('delivery-address-invoice')->item(0)->nodeValue ?: 'no', $response->getElementsByTagName('delivery-address-elv')->item(0)->nodeValue ?: 'no', $response->getElementsByTagName('delivery-address-installment')->item(0)->nodeValue ?: 'no', $response->getElementsByTagName('tx-limit-invoice-min')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-elv-min')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-installment-min')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-invoice-max')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-elv-max')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-installment-max')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-invoice-max-b2b')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-elv-max-b2b')->item(0)->nodeValue, $response->getElementsByTagName('tx-limit-installment-max-b2b')->item(0)->nodeValue, $response->getElementsByTagName('month-allowed')->item(0)->nodeValue, $response->getElementsByTagName('rate-min-normal')->item(0)->nodeValue, $response->getElementsByTagName('interestrate-default')->item(0)->nodeValue, $response->getElementsByTagName('eligibility-device-fingerprint')->item(0)->nodeValue ?: 'no', $response->getElementsByTagName('device-fingerprint-snippet-id')->item(0)->nodeValue, strtoupper($response->getElementsByTagName('country-code-billing')->item(0)->nodeValue), strtoupper($response->getElementsByTagName('country-code-delivery')->item(0)->nodeValue), strtoupper($response->getElementsByTagName('currency')->item(0)->nodeValue), $shopId);
         $activePayments = [];
         if ($response->getElementsByTagName('activation-status-invoice')->item(0)->nodeValue == 2) {
             $activePayments[] = '"rpayratepayinvoice"';
         } else {
             $inactivePayments[] = '"rpayratepayinvoice"';
         }
         if ($response->getElementsByTagName('activation-status-elv')->item(0)->nodeValue == 2) {
             $activePayments[] = '"rpayratepaydebit"';
         } else {
             $inactivePayments[] = '"rpayratepaydebit"';
         }
         if ($response->getElementsByTagName('activation-status-installment')->item(0)->nodeValue == 2) {
             $activePayments[] = '"rpayratepayrate"';
         } else {
             $inactivePayments[] = '"rpayratepayrate"';
         }
         if (count($activePayments) > 0) {
             $updateSqlActivePaymentMethods = 'UPDATE `s_core_paymentmeans` SET `active` = 1 WHERE `name` in(' . implode(",", $activePayments) . ') AND `active` <> 0';
         }
         if (count($inactivePayments) > 0) {
             $updateSqlInactivePaymentMethods = 'UPDATE `s_core_paymentmeans` SET `active` = 0 WHERE `name` in(' . implode(",", $inactivePayments) . ')';
         }
         $configSql = 'REPLACE INTO `rpay_ratepay_config`' . '(`profileId`, `invoiceStatus`,`debitStatus`,`rateStatus`,' . '`b2b-invoice`, `b2b-debit`, `b2b-rate`,' . '`address-invoice`, `address-debit`, `address-rate`,' . '`limit-invoice-min`, `limit-debit-min`, `limit-rate-min`,' . '`limit-invoice-max`, `limit-debit-max`, `limit-rate-max`,' . '`limit-invoice-max-b2b`, `limit-debit-max-b2b`, `limit-rate-max-b2b`,' . '`month-allowed`, `rate-min-normal`, `interestrate-default`,' . '`device-fingerprint-status`, `device-fingerprint-snippet-id`,' . '`country-code-billing`, `country-code-delivery`,' . '`currency`,' . ' `shopId`)' . 'VALUES(' . substr(str_repeat('?,', 28), 0, -1) . ');';
         // In case of altering cols change 28 by amount of affected cols
         try {
             Shopware()->Db()->query($configSql, $data);
             if (count($activePayments) > 0) {
                 Shopware()->Db()->query($updateSqlActivePaymentMethods);
             }
             if (count($inactivePayments) > 0) {
                 Shopware()->Db()->query($updateSqlInactivePaymentMethods);
             }
             return true;
         } catch (Exception $exception) {
             Shopware()->Pluginlogger()->info($exception->getMessage());
             return false;
         }
     } else {
         Shopware()->Pluginlogger()->error('RatePAY: Profile_Request failed!');
         return false;
     }
 }