/**
  * Process payment
  * @return boolean
  */
 private function processPayment()
 {
     $this->payment_processor = new Services_Paymill_PaymentProcessor(Configuration::get('PIGMBH_PAYMILL_PRIVATEKEY'), 'https://api.paymill.com/v2/');
     $this->payment_processor->setAmount((int) round($this->context->cart->getOrderTotal(true, Cart::BOTH) * 100));
     $this->payment_processor->setToken($this->token);
     $this->payment_processor->setCurrency(Tools::strtolower($this->iso_currency));
     $this->payment_processor->setName($this->context->customer->lastname . ', ' . $this->context->customer->firstname);
     $this->payment_processor->setEmail($this->context->customer->email);
     $this->payment_processor->setDescription('');
     $this->payment_processor->setLogger($this);
     $this->payment_processor->setSource(Configuration::get('PIGMBH_PAYMILL_VERSION') . '_prestashop_' . _PS_VERSION_);
     if ($this->payment == 'creditcard') {
         $sql = 'SELECT `clientId`,`paymentId` FROM `' . _DB_PREFIX_ . 'pigmbh_paymill_creditcard_userdata` WHERE `userId`=' . (int) $this->context->customer->id;
     } elseif ($this->payment == 'debit') {
         $sql = 'SELECT `clientId`,`paymentId` FROM `' . _DB_PREFIX_ . 'pigmbh_paymill_directdebit_userdata` WHERE `userId`=' . (int) $this->context->customer->id;
     }
     $user_data = $this->db->getRow($sql);
     $this->payment_processor->setClientId(!empty($user_data['clientId']) ? $user_data['clientId'] : null);
     if ($this->token === 'dummyToken') {
         $this->payment_processor->setPaymentId(!empty($user_data['paymentId']) ? $user_data['paymentId'] : null);
     }
     $capture_now = true;
     if ($this->payment == 'creditcard') {
         $capture_now = Configuration::get('PIGMBH_PAYMILL_CAPTURE') !== 'on';
     }
     $result = $this->payment_processor->processPayment($capture_now);
     $this->log('Payment processing resulted in', $result ? 'Success' : 'Fail');
     return $result;
 }
 function fastCheckout()
 {
     $data = $this->fastCheckout->loadFastCheckoutData($_SESSION['customer_id']);
     if ($this->fastCheckout->canCustomerFastCheckoutCc($_SESSION['customer_id']) && $this->code === 'paymillCc') {
         if (!empty($data['paymentID_CC'])) {
             $this->paymentProcessor->setPaymentId($data['paymentID_CC']);
         }
     }
     if ($this->fastCheckout->canCustomerFastCheckoutElv($_SESSION['customer_id']) && $this->code === 'paymillElv') {
         if (!empty($data['paymentID_ELV'])) {
             $this->paymentProcessor->setPaymentId($data['paymentID_ELV']);
         }
     }
 }
 private function _fastCheckout($code)
 {
     if ($this->_fastCheckout->canCustomerFastCheckoutCc($_SESSION['customer']->customers_id) && $code === 'xt_paymill_cc') {
         $data = $this->_fastCheckout->loadFastCheckoutData($_SESSION['customer']->customers_id);
         if (!empty($data->paymentID_CC)) {
             $this->_paymentProcessor->setPaymentId($data->paymentID_CC);
         }
     }
     if ($this->_fastCheckout->canCustomerFastCheckoutElv($_SESSION['customer']->customers_id) && $code === 'xt_paymill_dd') {
         $data = $this->_fastCheckout->loadFastCheckoutData($_SESSION['customer']->customers_id);
         if ($data->paymentID_ELV) {
             $this->_paymentProcessor->setPaymentId($data->paymentID_ELV);
         }
     }
 }
Beispiel #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'));
         }
     }
 }
 public function initContent($cart, $user, $shopname)
 {
     session_start();
     unset($_SESSION['log_id']);
     $_SESSION['log_id'] = time();
     $db = Db::getInstance();
     $token = Tools::getValue('paymillToken');
     $payment = Tools::getValue('payment');
     $validPayments = array();
     if (Configuration::get('PIGMBH_PAYMILL_DEBIT')) {
         $validPayments[] = 'debit';
     }
     if (Configuration::get('PIGMBH_PAYMILL_CREDITCARD')) {
         $validPayments[] = 'creditcard';
     }
     if (empty($token)) {
         $this->log('No paymill token was provided. Redirect to payments page.', null);
         Tools::redirect('order.php?step=1&paymillerror=1&paymillpayment=' . $payment);
     } elseif (!in_array($payment, $validPayments)) {
         $this->log('The selected Paymentmethod is not valid.', $payment);
         Tools::redirect('order.php?step=1&paymillerror=1&paymillpayment=' . $payment);
     }
     $this->log('Start processing payment with token', $token);
     $paymentProcessor = new Services_Paymill_PaymentProcessor(Configuration::get('PIGMBH_PAYMILL_PRIVATEKEY'), "https://api.paymill.com/v2/");
     $currency = Currency::getCurrency((int) $cart->id_currency);
     $iso_currency = $currency['iso_code'];
     $paymentProcessor->setAmount($_SESSION['pigmbhPaymill']['authorizedAmount']);
     $paymentProcessor->setPreAuthAmount($_SESSION['pigmbhPaymill']['authorizedAmount']);
     $paymentProcessor->setToken($token);
     $paymentProcessor->setCurrency(strtolower($iso_currency));
     $paymentProcessor->setName($user["lastname"] . ', ' . $user["firstname"]);
     $paymentProcessor->setEmail($user["email"]);
     $paymentProcessor->setDescription(" ");
     $paymentProcessor->setLogger($this);
     $paymentProcessor->setSource(Configuration::get('PIGMBH_PAYMILL_VERSION') . "_prestashop_" . _PS_VERSION_);
     if ($payment == 'creditcard') {
         $userData = $db->getRow('SELECT `clientId`,`paymentId` FROM `pigmbh_paymill_creditcard_userdata` WHERE `userId`=' . $user["id_customer"]);
     } elseif ($payment == 'debit') {
         $userData = $db->getRow('SELECT `clientId`,`paymentId` FROM `pigmbh_paymill_directdebit_userdata` WHERE `userId`=' . $user["id_customer"]);
     }
     $paymentProcessor->setClientId(!empty($userData['clientId']) ? $userData['clientId'] : null);
     if ($token === "dummyToken") {
         $paymentProcessor->setPaymentId(!empty($userData['paymentId']) ? $userData['paymentId'] : null);
     }
     $result = $paymentProcessor->processPayment();
     $this->log('Payment processing resulted in', $result ? 'Success' : 'Fail');
     $paymill = new PigmbhPaymill();
     // finish the order if payment was sucessfully processed
     if ($result === true) {
         $customer = new Customer((int) $cart->id_customer);
         if ($payment === 'debit') {
             $days = Configuration::get('PIGMBH_PAYMILL_DEBIT_DAYS');
             if (!is_numeric($days)) {
                 $days = '7';
             }
             $paymentText = $paymill->l('ELV /SEPA Debit Date: ') . date('Y-m-d', strtotime("+{$days} day"));
         } else {
             $paymentText = $paymill->l('Credit Card');
         }
         $_SESSION['piPaymentText'] = $paymentText;
         $this->saveUserData($paymentProcessor->getClientId(), $paymentProcessor->getPaymentId(), (int) $cart->id_customer);
         $orderID = $paymill->validateOrder((int) $cart->id, Configuration::get('PIGMBH_PAYMILL_ORDERSTATE'), $cart->getOrderTotal(true, Cart::BOTH), $paymentText, null, array(), null, false, $customer->secure_key);
         $_SESSION['piOrderId'] = $orderID;
         $this->updatePaymillTransaction($paymentProcessor->getTransactionId(), 'OrderID: ' . $orderID . ' - Name:' . $user["lastname"] . ', ' . $user["firstname"]);
         Tools::redirect('order-confirmation.php?key=' . $customer->secure_key . '&id_cart=' . (int) $cart->id . '&id_module=' . (int) $paymill->id . '&id_order=' . (int) $paymill->currentOrder);
     } else {
         $errorMessage = $paymill->errorCodeMapping($paymentProcessor->getErrorCode());
         $this->log('ErrorCode', $errorMessage);
         Tools::redirect('order.php?paymillpayment=' . $payment . '&step=3&paymillerror=1&errorCode=' . $paymentProcessor->getErrorCode());
     }
 }