Exemplo n.º 1
0
 private function proceedCapture($preauth_id)
 {
     $result = false;
     $this->init();
     $this->load->model('sale/order');
     $orderId = $this->getPost('orderId', 0);
     $preauth = $this->paymillPreauth->getOne($preauth_id);
     if (is_array($preauth)) {
         $this->paymillProcessor->setAmount($preauth['amount']);
         $this->paymillProcessor->setCurrency($preauth['currency']);
         $this->paymillProcessor->setPreauthId($preauth_id);
         $this->paymillProcessor->setDescription('Capture ' . $preauth_id);
         try {
             $result = $this->paymillProcessor->capture();
             $this->log('Capture resulted in', var_export($result, true));
             $this->log('Capture successfully', $this->paymillProcessor->getTransactionId());
             $this->saveTransactionId($orderId, $this->paymillProcessor->getTransactionId());
             $orderStatusId = $this->db->query('SELECT `order_status_id` FROM `' . DB_PREFIX . 'order_status` WHERE `name`= "Complete"')->row['order_status_id'];
             $this->model_sale_order->addOrderHistory($orderId, array('order_status_id' => $orderStatusId, 'notify' => false, 'comment' => ''));
         } catch (Exception $ex) {
             $result = false;
         }
     }
     return $result;
 }
 public function capturePreauth()
 {
     $transaction = oxNew('paymill_transaction');
     $transaction->load($this->getEditObjectId());
     $params = array();
     $params['amount'] = (int) (int) ($this->_getRefundAmount() * 100);
     $params['currency'] = strtoupper($this->getEditObject()->oxorder__oxcurrency->rawValue);
     $paymentProcessor = new Services_Paymill_PaymentProcessor(trim(oxRegistry::getConfig()->getShopConfVar('PAYMILL_PRIVATEKEY')), paymill_util::API_ENDPOINT, null, $params, $this);
     oxRegistry::getSession()->setVariable('preauth', true);
     $paymentProcessor->setPreauthId($transaction->paymill_transaction__preauth_id->rawValue);
     if (!$paymentProcessor->capture()) {
         oxRegistry::getSession()->setVariable('error', true);
     } else {
         $transaction->assign(array('transaction_id' => $paymentProcessor->getTransactionId()));
         $transaction->save();
         oxRegistry::getSession()->setVariable('success', true);
     }
 }
 public function processInvoice($invoice, $payment)
 {
     $data = $payment->getAdditionalInformation();
     if (array_key_exists('paymillPreauthId', $data) && !empty($data['paymillPreauthId'])) {
         $params = array();
         $params['amount'] = (int) Mage::helper("paymill/paymentHelper")->getAmount($invoice);
         $params['currency'] = Mage::helper("paymill/paymentHelper")->getCurrency($invoice);
         $params['description'] = Mage::helper('paymill/paymentHelper')->getDescription($payment->getOrder());
         $params['source'] = Mage::helper('paymill')->getSourceString();
         $paymentProcessor = new Services_Paymill_PaymentProcessor(Mage::helper('paymill/optionHelper')->getPrivateKey(), Mage::helper('paymill')->getApiUrl(), null, $params, Mage::helper('paymill/loggingHelper'));
         $paymentProcessor->setPreauthId($data['paymillPreauthId']);
         if (!$paymentProcessor->capture()) {
             Mage::throwException(Mage::helper("paymill/paymentHelper")->getErrorMessage($paymentProcessor->getErrorCode()));
         }
         Mage::helper('paymill/loggingHelper')->log("Capture created", var_export($paymentProcessor->getLastResponse(), true));
         $payment->setAdditionalInformation('paymillTransactionId', $paymentProcessor->getTransactionId());
     }
     parent::processInvoice($invoice, $payment);
 }
Exemplo n.º 4
0
 /**
  * Payment controller action
  */
 public function initContent()
 {
     $this->paymillInit();
     $result = $this->processPayment();
     if ($result === true) {
         $customer = new Customer((int) $this->context->cart->id_customer);
         $this->saveUserData($this->payment_processor->getClientId(), $this->payment_processor->getPaymentId(), (int) $this->context->cart->id_customer);
         $payment_text = $this->getPaymentText();
         $this->context->cookie->__set('paymill_payment_text', $payment_text);
         $this->module->validateOrder((int) $this->context->cart->id, Configuration::get('PIGMBH_PAYMILL_ORDERSTATE'), $this->context->cart->getOrderTotal(true, Cart::BOTH), $payment_text, null, array(), null, false, $customer->secure_key, $this->context->shop);
         $this->saveTransactionData((int) $this->module->currentOrder, $this->payment_processor->getPreauthId(), $this->payment_processor->getTransactionId());
         $this->updatePaymillTransaction($this->payment_processor->getTransactionId(), Tools::substr('OrderID: ' . (int) $this->module->currentOrder . ' - Name:' . $this->context->customer->lastname . ', ' . $this->context->customer->firstname, 0, 128));
         $url = $this->context->link->getPageLink('order-confirmation', true, null, array('key' => $customer->secure_key, 'id_cart' => (int) $this->context->cart->id, 'id_module' => (int) $this->module->id, 'id_order' => (int) $this->module->currentOrder));
         Tools::redirect($url);
     } else {
         $error_message = $this->module->errorCodeMapping($this->payment_processor->getErrorCode());
         $this->log('ErrorCode', $error_message);
         Tools::redirect($this->context->link->getPageLink('order', true, null, array('step' => '3', 'paymillerror' => '1', 'errorCode' => $this->payment_processor->getErrorCode())));
     }
 }
 public function checkoutProcessData()
 {
     global $xtLink;
     $code = 'xt_paymill_' . $_SESSION['selected_payment_sub'];
     $_SESSION['paymill_sepa'] = $code;
     $token = $_POST['paymillToken'];
     if (!$this->_isTokenAvailable($token)) {
         $_SESSION[$code . '_error'] = TEXT_PAYMILL_ERR_TOKEN;
         $xtLink->_redirect($xtLink->_link(array('page' => 'checkout', 'paction' => 'payment', 'conn' => 'SSL')));
     } else {
         $this->_setTransaction();
         $data = $this->_fastCheckout->loadFastCheckoutData($_SESSION['customer']->customers_id);
         if (!empty($data->clientID)) {
             $this->_existingClient($data);
         }
         if ($token === 'dummyToken') {
             $this->_fastCheckout($code);
         }
         $this->_paymentProcessor->setToken($token);
         unset($_SESSION['token']);
         if ($this->_getPaymentConfig('ACTIVATE_CC_PREAUTH') === 'true' && $code !== 'xt_paymill_dd') {
             $preauth = true;
             $result = $this->_paymentProcessor->processPayment(false);
         } else {
             $preauth = false;
             $result = $this->_paymentProcessor->processPayment();
         }
         if (!$result) {
             $_SESSION[$code . '_error'] = $this->_getErrorMessage($this->_paymentProcessor->getErrorCode());
             $xtLink->_redirect($xtLink->_link(array('page' => 'checkout', 'paction' => 'payment', 'conn' => 'SSL')));
         }
         if ($this->_getPaymentConfig('FAST_CHECKOUT') === 'true') {
             $this->_savePayment($code);
         }
         if ($preauth) {
             $_SESSION['paymillPreauthId'] = $this->_paymentProcessor->getPreauthId();
         } else {
             $_SESSION['paymillTransactionId'] = $this->_paymentProcessor->getTransactionId();
         }
     }
 }
 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']);
 }
<?php

require_once 'includes/application_top.php';
require_once DIR_WS_CLASSES . 'order.php';
require_once dirname(__FILE__) . '/../ext/modules/payment/paymill/lib/Services/Paymill/PaymentProcessor.php';
if (isset($_GET['oID']) && !empty($_GET['oID'])) {
    $order = new order($_GET['oID']);
    $transaction = tep_db_fetch_array(tep_db_query("SELECT * FROM pi_paymill_transaction WHERE order_id = '" . $_GET['oID'] . "'"));
    require_once dirname(__FILE__) . '/../includes/modules/payment/' . $transaction['payment_code'] . '.php';
    include dirname(__FILE__) . '/../includes/languages/' . $_SESSION['language'] . '/modules/payment/' . $transaction['payment_code'] . '.php';
    $payment = new $transaction['payment_code']();
    $params = array();
    $params['amount'] = $transaction['amount'];
    $params['currency'] = $order->info['currency'];
    $paymentProcessor = new Services_Paymill_PaymentProcessor($payment->privateKey, $payment->apiUrl, null, $params, $payment);
    $paymentProcessor->setPreauthId($transaction['preauth_id']);
    try {
        $result = $paymentProcessor->capture();
    } catch (Exception $ex) {
    }
    if ($result) {
        $statusArray = tep_db_fetch_array(tep_db_query("select orders_status_id from " . TABLE_ORDERS_STATUS . " where orders_status_name = 'Paymill [Captured]' limit 1"));
        tep_db_query("UPDATE " . TABLE_ORDERS . " SET orders_status='" . $statusArray['orders_status_id'] . "' WHERE orders_id='" . $_GET['oID'] . "'");
        tep_db_query("UPDATE pi_paymill_transaction SET transaction_id = '" . tep_db_prepare_input($paymentProcessor->getTransactionId()) . "' WHERE order_id = " . (int) $_GET['oID']);
        $messageStack->add_session(PAYMILL_CAPTURE_SUCCESS, 'success');
    } else {
        $messageStack->add_session(PAYMILL_CAPTURE_ERROR, 'error');
    }
}
tep_redirect(tep_href_link(FILENAME_ORDERS, 'oID=' . $_GET['oID'] . '&action=edit', true, false));
Exemplo n.º 9
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'));
         }
     }
 }
Exemplo n.º 10
0
 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());
     }
 }