Ejemplo n.º 1
0
 /**
  * Returns the prefilldata for directdebit
  *
  * @param integer $userId
  * @return array
  */
 private function prefillDirectdebit($userId, $userFullName)
 {
     $prefillData = array('paymillAccountholder' => $userFullName, 'paymillAccountNumber' => '', 'paymillBankCode' => '');
     $paymentId = $this->modelHelper->getPaymillPaymentId('elv', $userId);
     if ($paymentId != "") {
         $paymentObject = $this->servicePayments->getOne($paymentId);
         $prefillData['paymillAccountHolder'] = $paymentObject['holder'] != null ? $paymentObject['holder'] : $userFullName;
         $prefillData['paymillAccountNumber'] = $paymentObject['iban'] != null ? $paymentObject['iban'] : $paymentObject['account'];
         $prefillData['paymillBankCode'] = $paymentObject['bic'] != null ? $paymentObject['bic'] : $paymentObject['code'];
     }
     return $prefillData;
 }
 /**
  * Performs the necessary installation steps
  *
  * @throws Exception
  * @return boolean
  */
 public function install()
 {
     try {
         Shopware_Plugins_Frontend_PaymPaymentCreditcard_Components_WebhookService::install();
         Shopware_Plugins_Frontend_PaymPaymentCreditcard_Components_LoggingManager::install();
         Shopware_Plugins_Frontend_PaymPaymentCreditcard_Components_ModelHelper::install($this);
         $this->createPaymentMeans();
         $this->_createForm();
         $this->_registerController();
         $this->_createEvents();
         $this->_updateOrderMail();
         $this->_applyBackendViewModifications();
         $this->_translatePaymentNames();
         $translationHelper = new Shopware_Plugins_Frontend_PaymPaymentCreditcard_Components_TranslationHelper($this->Form());
         $translationHelper->createPluginConfigTranslation();
         $this->solveKnownIssue();
         $this->Plugin()->setActive(true);
     } catch (Exception $exception) {
         $this->uninstall();
         throw new Exception($exception->getMessage());
     }
     $installSuccess = parent::install();
     return $installSuccess;
 }
 /**
  * Action Listener to execute the capture for applicable transactions
  *
  */
 public function refundAction()
 {
     $result = false;
     $code = null;
     require_once dirname(__FILE__) . '/../../lib/Services/Paymill/Transactions.php';
     require_once dirname(__FILE__) . '/../../lib/Services/Paymill/Refunds.php';
     $swConfig = Shopware()->Plugins()->Frontend()->PaymPaymentCreditcard()->Config();
     $refund = new Services_Paymill_Refunds(trim($swConfig->get("privateKey")), 'https://api.paymill.com/v2/');
     $transactionObject = new Services_Paymill_Transactions(trim($swConfig->get("privateKey")), 'https://api.paymill.com/v2/');
     $modelHelper = new Shopware_Plugins_Frontend_PaymPaymentCreditcard_Components_ModelHelper();
     $orderNumber = $modelHelper->getOrderNumberById($this->Request()->getParam("orderId"));
     $transactionId = $modelHelper->getPaymillTransactionId($orderNumber);
     $transactionResult = $transactionObject->getOne($transactionId);
     //Create Transaction
     $parameter = array('transactionId' => $transactionId, 'params' => array('amount' => $transactionResult['amount'], 'description' => $transactionResult['client']['email'] . " " . Shopware()->Config()->get('shopname')));
     $response = $refund->create($parameter);
     if (isset($response['response_code'])) {
         $code = $response['response_code'];
     }
     //Validate result and prepare feedback
     if ($this->_validateRefundResponse($response)) {
         $result = true;
         $modelHelper->setPaymillRefund($orderNumber, $response['id']);
         $this->_updatePaymentStatus(20, $this->Request()->getParam("orderId"));
     }
     $this->View()->assign(array('success' => $result, 'code' => $code));
 }
Ejemplo n.º 4
0
 /**
  * Frontend index action controller
  */
 public function indexAction()
 {
     //Initialise variables
     $privateKey = trim($this->config->get("privateKey"));
     $user = Shopware()->Session()->sOrderVariables['sUserData'];
     $sState = array('reserviert' => 18, 'bezahlt' => 12);
     $processId = md5(time() . " " . $user['billingaddress']['lastname'] . ', ' . $user['billingaddress']['firstname']);
     Shopware()->Session()->paymillProcessId = $processId;
     $this->logging->setProcessId($processId);
     // read transaction token from session
     $paymillToken = Shopware()->Session()->paymillTransactionToken;
     // check if token present
     if (empty($paymillToken)) {
         $this->logging->log("No paymill token was provided. Redirect to payments page.", null);
         $url = $this->Front()->Router()->assemble(array('action' => 'payment', 'sTarget' => 'checkout', 'sViewport' => 'account', 'appendSession' => true, 'forceSecure' => true));
         $this->redirect($url . '&paymill_error=1');
     }
     $this->logging->log("Start processing payment " . $paymillToken === "NoTokenRequired" ? "without" : "with" . " token.", $paymillToken);
     // process the payment
     $userId = $user['billingaddress']['userID'];
     $paymentShortcut = $this->getPaymentShortName();
     $params = array('token' => $paymillToken, 'authorizedAmount' => (int) Shopware()->Session()->paymillTotalAmount, 'amount' => (int) round($this->getAmount() * 100, 0), 'currency' => $this->getCurrencyShortName(), 'name' => Shopware()->Session()->paymillTransactionName ? Shopware()->Session()->paymillTransactionName : $user['billingaddress']['lastname'] . ', ' . $user['billingaddress']['firstname'], 'email' => $user['additional']['user']['email'], 'description' => substr($user['additional']['user']['email'] . " " . Shopware()->Config()->get('shopname'), 0, 128), 'payment' => $paymentShortcut);
     $paymentProcessor = new Shopware_Plugins_Frontend_PaymPaymentCreditcard_Components_PaymentProcessor($params, $processId);
     $modelHelper = new Shopware_Plugins_Frontend_PaymPaymentCreditcard_Components_ModelHelper();
     $clientId = $modelHelper->getPaymillClientId($userId);
     $paymentId = $modelHelper->getPaymillPaymentId($this->getPaymentShortName(), $userId);
     if ($clientId != "") {
         $apiUrl = "https://api.paymill.com/v2/";
         require_once dirname(dirname(dirname(__FILE__))) . '/lib/Services/Paymill/Clients.php';
         $client = new Services_Paymill_Clients($privateKey, $apiUrl);
         $client->update(array('id' => $clientId, 'email' => $user['additional']['user']['email']));
         $paymentProcessor->setClientId($clientId);
     }
     if ($paymentId != "") {
         if ($paymillToken === "NoTokenRequired") {
             $paymentProcessor->setPaymentId($paymentId);
         }
     }
     $preAuthOption = $this->config->get("paymillPreAuth");
     $isCCPayment = $paymentShortcut === 'paymillcc';
     $captureNow = !($preAuthOption && $isCCPayment);
     $result = $paymentProcessor->processPayment($captureNow);
     $this->logging->log("Payment processing resulted in: " . ($result ? "Success" : "Failure"), print_r($result, true));
     // finish the order if payment was successfully processed
     if ($result !== true) {
         Shopware()->Session()->paymillTransactionToken = null;
         Shopware()->Session()->pigmbhErrorMessage = $this->_getSnippet('PAYMILL_' . $paymentProcessor->getErrorCode());
         return $this->forward('error');
     }
     //Save Client Id
     $modelHelper->setPaymillClientId($userId, $paymentProcessor->getClientId());
     //Save Fast Checkout Data
     $isFastCheckoutEnabled = $this->config->get("paymillFastCheckout");
     if ($isFastCheckoutEnabled) {
         $paymentId = $paymentProcessor->getPaymentId();
         $modelHelper->setPaymillPaymentId($this->getPaymentShortName(), $userId, $paymentId);
     }
     //Create the order
     $statusId = $captureNow ? $sState['bezahlt'] : $sState['reserviert'];
     $transactionId = $captureNow ? $paymentProcessor->getTransactionId() : $paymentProcessor->getPreauthId();
     $orderNumber = $this->saveOrder($this->createPaymentUniqueId(), md5($this->createPaymentUniqueId()), $statusId);
     $this->logging->log("Finish order.", "Ordernumber: " . $orderNumber, "using TransactionId: " . $transactionId);
     if ($captureNow) {
         $modelHelper->setPaymillTransactionId($orderNumber, $paymentProcessor->getTransactionId());
     } else {
         $modelHelper->setPaymillPreAuthorization($orderNumber, $paymentProcessor->getPreauthId());
     }
     $this->_updateTransaction($orderNumber, $paymentProcessor);
     // reset the session field
     Shopware()->Session()->paymillTransactionToken = null;
     return $this->redirect(array('controller' => 'checkout', 'action' => 'finish', 'forceSecure' => 1, 'sUniqueID' => md5($transactionId)));
 }