public function __construct()
 {
     global $page;
     $this->_apiUrl = Util::$apiUrl;
     $this->_fastCheckout = new FastCheckout();
     $this->_transactions = new Services_Paymill_Transactions(trim($this->_getPaymentConfig('PRIVATE_API_KEY')), $this->_apiUrl);
     $this->_payments = new Services_Paymill_Payments(trim($this->_getPaymentConfig('PRIVATE_API_KEY')), $this->_apiUrl);
     $this->_clients = new Services_Paymill_Clients(trim($this->_getPaymentConfig('PRIVATE_API_KEY')), $this->_apiUrl);
     if ($page->page_name == 'checkout' && $page->page_action == 'confirmation') {
         $this->_setCheckoutData();
     }
     $this->_paymentProcessor = new Services_Paymill_PaymentProcessor();
     $this->_paymentProcessor->setApiUrl($this->_apiUrl);
     $this->_paymentProcessor->setLogger($this);
     $this->_paymentProcessor->setPrivateKey(trim($this->_getPaymentConfig('PRIVATE_API_KEY')));
     $this->_paymentProcessor->setSource($this->version . '_xt:Commerce_' . _SYSTEM_VERSION);
     $this->allowed_subpayments = array('cc', 'dd');
     if ($page->page_name == 'checkout' && $page->page_action == 'success') {
         $this->_success();
     }
     if ($page->page_name == 'checkout' && $page->page_action == 'payment') {
         if (array_key_exists('xt_paymill_cc_error', $_SESSION)) {
             $this->data['xt_paymill']['error_cc'] = $_SESSION['xt_paymill_cc_error'];
             unset($_SESSION['xt_paymill_cc_error']);
         }
         if (array_key_exists('xt_paymill_dd_error', $_SESSION)) {
             $this->data['xt_paymill']['error_elv'] = $_SESSION['xt_paymill_dd_error'];
             unset($_SESSION['xt_paymill_dd_error']);
         }
     }
 }
 function before_process()
 {
     global $order;
     $_SESSION['paymill_identifier'] = time();
     $this->paymentProcessor->setToken((string) $_POST['paymill_token']);
     $this->paymentProcessor->setAmount((int) $this->format_raw($order->info['total']));
     $this->paymentProcessor->setApiUrl((string) $this->apiUrl);
     $this->paymentProcessor->setCurrency((string) strtoupper($order->info['currency']));
     $this->paymentProcessor->setDescription(utf8_encode(substr((string) STORE_NAME, 0, 128)));
     $this->paymentProcessor->setEmail((string) $order->customer['email_address']);
     $this->paymentProcessor->setName((string) $order->customer['lastname'] . ', ' . $order->customer['firstname']);
     $this->paymentProcessor->setPrivateKey((string) $this->privateKey);
     $this->paymentProcessor->setLogger($this);
     $this->paymentProcessor->setSource($this->version . '_OSCOM_' . tep_get_version());
     $this->fastCheckout->setFastCheckoutFlag($this->fastCheckoutFlag);
     if ($_POST['paymill_token'] == 'dummyToken') {
         $this->fastCheckout();
     }
     $data = $this->fastCheckout->loadFastCheckoutData($_SESSION['customer_id']);
     if (array_key_exists('clientID', $data) && $data['clientID'] != '' && $data['clientID'] != null) {
         $this->existingClient($data);
     }
     if (!$this->preauth) {
         $result = $this->paymentProcessor->processPayment();
         $_SESSION['paymill']['transaction_id'] = $this->paymentProcessor->getTransactionId();
     } else {
         $result = $this->paymentProcessor->processPayment(!$this->preauth);
         $_SESSION['paymill']['preauth_id'] = $this->paymentProcessor->getPreauthId();
     }
     if (!$result) {
         unset($_SESSION['paymill_identifier']);
         $errorCode = $this->paymentProcessor->getErrorCode();
         tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false) . '?step=step2&payment_error=' . $this->code . '&error=' . $errorCode);
     }
     if ($this->fastCheckoutFlag) {
         $this->savePayment();
     } else {
         $this->saveClient();
     }
     unset($_SESSION['paymill_identifier']);
 }
 function before_process()
 {
     global $order;
     $_SESSION['paymill_identifier'] = time();
     $this->paymentProcessor->setAmount((int) $_SESSION['paymill']['amount']);
     $this->paymentProcessor->setApiUrl((string) $this->apiUrl);
     $this->paymentProcessor->setCurrency((string) strtoupper($order->info['currency']));
     $this->paymentProcessor->setDescription(utf8_encode(substr((string) STORE_NAME . ' ' . $order->customer['lastname'] . ', ' . $order->customer['firstname'], 0, 128)));
     $this->paymentProcessor->setEmail((string) $order->customer['email_address']);
     $this->paymentProcessor->setName($order->customer['lastname'] . ', ' . $order->customer['firstname']);
     $this->paymentProcessor->setPrivateKey((string) $this->privateKey);
     $this->paymentProcessor->setToken((string) $_POST['paymill_token']);
     $this->paymentProcessor->setLogger($this);
     $this->paymentProcessor->setSource($this->version . '_' . str_replace(' ', '_', PROJECT_VERSION));
     $this->fastCheckout->setFastCheckoutFlag($this->fastCheckoutFlag);
     if ($_POST['paymill_token'] === 'dummyToken') {
         $this->fastCheckout();
     }
     $data = $this->fastCheckout->loadFastCheckoutData($_SESSION['customer_id']);
     if (!empty($data['clientID'])) {
         $this->existingClient($data);
     }
     $result = $this->paymentProcessor->processPayment();
     $_SESSION['paymill']['transaction_id'] = $this->paymentProcessor->getTransactionId();
     if (!$result) {
         unset($_SESSION['paymill_identifier']);
         $errorCode = $this->paymentProcessor->getErrorCode();
         xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'step=step2&payment_error=' . $this->code . '&error=' . $errorCode, 'SSL', true, false));
     }
     if ($this->fastCheckoutFlag) {
         $this->savePayment();
     } else {
         $this->saveClient();
     }
     unset($_SESSION['paymill_identifier']);
 }
示例#4
0
 public function confirm()
 {
     $preauth = (bool) $this->config->get($this->getPaymentName() . '_preauth');
     // read transaction token from session
     if (isset($this->request->post['paymillToken'])) {
         $paymillToken = $this->request->post['paymillToken'];
     }
     if (isset($this->request->post['paymillFastcheckout'])) {
         $fastcheckout = $this->request->post['paymillFastcheckout'];
     }
     $this->_logId = time();
     $this->language->load('payment/' . $this->getPaymentName());
     // check if token present
     if (empty($paymillToken)) {
         $this->log("No paymill token was provided. Redirect to payments page.", '');
         $this->redirect($this->url->link('checkout/checkout'));
     } else {
         $this->log("Start processing payment with token.", $paymillToken);
         $this->load->model('checkout/order');
         $this->order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
         $amountRaw = $this->currency->format($this->order_info['total'], $this->order_info['currency_code'], false, false);
         $amount = number_format($amountRaw, 2, '.', '') * 100;
         $source = $this->getVersion() . "_opencart_" . VERSION;
         $privateKey = trim($this->config->get($this->getPaymentName() . '_privatekey'));
         $paymentProcessor = new Services_Paymill_PaymentProcessor();
         $paymentProcessor->setToken($paymillToken);
         $paymentProcessor->setAmount((int) $amount);
         $paymentProcessor->setPrivateKey($privateKey);
         $paymentProcessor->setApiUrl('https://api.paymill.com/v2/');
         $paymentProcessor->setCurrency($this->order_info['currency_code']);
         $paymentProcessor->setDescription(substr("OrderID:" . $this->session->data['order_id'] . " " . $this->order_info['email'], 0, 128));
         $paymentProcessor->setEmail($this->order_info['email']);
         $paymentProcessor->setLogger($this);
         $paymentProcessor->setName($this->order_info['firstname'] . ' ' . $this->order_info['lastname']);
         $paymentProcessor->setSource($source);
         if ($this->customer->getId() != null) {
             $table = $this->getDatabaseName();
             $row = $this->db->query("SELECT `clientId`, `paymentId` FROM {$table} WHERE `userId`=" . $this->customer->getId());
             if ($row->num_rows === 1) {
                 if ($fastcheckout === "true") {
                     $paymentID = empty($row->row['paymentId']) ? null : $row->row['paymentId'];
                     $paymentProcessor->setPaymentId($paymentID);
                 }
                 $clientObject = new Services_Paymill_Clients($privateKey, 'https://api.paymill.com/v2/');
                 $client = $clientObject->getOne($row->row['clientId']);
                 $paymentProcessor->setClientId($row->row['clientId']);
                 if (array_key_exists('email', $client)) {
                     if ($client['email'] !== $this->order_info['email']) {
                         $clientObject->update(array('id' => $row->row['clientId'], 'email' => $this->order_info['email']));
                         $this->log("Client-mail has been changed. Client updated", $this->order_info['email']);
                     }
                 }
             }
         }
         $captureNow = !$preauth;
         // process the payment
         $result = $paymentProcessor->processPayment($captureNow);
         $this->log("Payment processing resulted in: ", $result ? "Success" : "Fail");
         if (!$captureNow) {
             $preauthId = $paymentProcessor->getPreauthId();
             $transId = '';
         } else {
             $preauthId = '';
             $transId = $paymentProcessor->getTransactionId();
         }
         $comment = '';
         if ($this->getPaymentName() == 'paymilldirectdebit') {
             $daysUntil = (int) $this->config->get($this->getPaymentName() . '_sepa_date');
             $comment = $this->language->get('paymill_infotext_sepa') . ": ";
             $comment .= date("d.m.Y", strtotime("+ {$daysUntil} DAYS"));
         }
         // finish the order if payment was sucessfully processed
         if ($result === true) {
             $this->log("Finish order.", '');
             $this->_saveUserData($this->customer->getId(), $paymentProcessor->getClientId(), $paymentProcessor->getPaymentId());
             $this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('config_order_status_id'), $comment, true);
             $this->_updateOrderComment($this->session->data['order_id'], $comment);
             $this->_saveOrderDetails($this->session->data['order_id'], $transId, $preauthId);
             $this->redirect($this->url->link('checkout/success'));
         } else {
             $responseCode = array_key_exists($paymentProcessor->getErrorCode(), $this->_response_codes) ? $this->_response_codes[$paymentProcessor->getErrorCode()] : 'unknown error';
             $this->session->data['error_message'] = 'An error occured while processing your payment: ' . $responseCode;
             $this->redirect($this->url->link('payment/' . $this->getPaymentName() . '/error'));
         }
     }
 }