/**
  * Return paymill client data
  * @return array
  */
 public function getClientData()
 {
     $clients = new Services_Paymill_Clients(Mage::helper('paymill/optionHelper')->getPrivateKey(), Mage::helper('paymill')->getApiUrl());
     $clientId = Mage::helper("paymill/fastCheckoutHelper")->getClientId();
     $client = null;
     if (!empty($clientId)) {
         $client = $clients->getOne($clientId);
         if (!array_key_exists('email', $client)) {
             $client = null;
         }
     }
     return $client;
 }
示例#2
0
 /**
  * Tests Services_Paymill_Clients->delete()
  * @depends testUpdate
  */
 public function testDelete($clientId)
 {
     $client = $this->_clients->delete($clientId);
     $this->assertInternalType('array', $client);
     $this->assertEquals($clientId, $client["id"]);
     $client = $this->_clients->getOne($clientId);
     $this->assertEquals("Client not found", $client["error"]);
 }
 private function _existingClient($data)
 {
     $client = $this->_clients->getOne($data->clientID);
     if ($client['email'] !== $_SESSION['customer']->customer_info['customers_email_address']) {
         $this->_clients->update(array('id' => $data->clientID, 'email' => $_SESSION['customer']->customer_info['customers_email_address']));
     }
     if (array_key_exists('email', $client)) {
         $this->_paymentProcessor->setClientId($client['id']);
     }
 }
示例#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'));
         }
     }
 }
 /**
  * Eventhandler for the update of the client with new data on email change
  * @param $arguments
  */
 public function onUpdateCustomerEmail($arguments)
 {
     $user = Shopware()->System()->sMODULES['sAdmin']->sGetUserData();
     $userId = $user['billingaddress']['userID'];
     $modelHelper = new Shopware_Plugins_Frontend_PaymPaymentCreditcard_Components_ModelHelper();
     $clientId = $modelHelper->getPaymillClientId($userId);
     //If there is a client for the customer
     if ($clientId !== "") {
         $email = $arguments['email'];
         $description = $user['billingaddress']['customernumber'] . " " . Shopware()->Config()->get('shopname');
         $description = substr($description, 0, 128);
         //Update the client
         $swConfig = Shopware()->Plugins()->Frontend()->PaymPaymentCreditcard()->Config();
         $privateKey = trim($swConfig->get("privateKey"));
         $apiUrl = "https://api.paymill.com/v2/";
         require_once dirname(__FILE__) . '/lib/Services/Paymill/Clients.php';
         $client = new Services_Paymill_Clients($privateKey, $apiUrl);
         $client->update(array('id' => $clientId, 'email' => $email, 'description' => $description));
     }
 }
示例#6
0
 public function onAKPaymentCallback($paymentmethod, $data)
 {
     JLoader::import('joomla.utilities.date');
     // Check if we're supposed to handle this
     if ($paymentmethod != $this->ppName) {
         return false;
     }
     $isValid = true;
     // Load the relevant subscription row
     $id = $data['sid'];
     $subscription = null;
     // CHECK: Is this a valid subscription record?
     if ($id > 0) {
         $subscription = F0FModel::getTmpInstance('Subscriptions', 'AkeebasubsModel')->setId($id)->getItem();
         if ($subscription->akeebasubs_subscription_id <= 0 || $subscription->akeebasubs_subscription_id != $id) {
             $subscription = null;
             $isValid = false;
         }
     } else {
         $isValid = false;
     }
     if (!$isValid) {
         $data['akeebasubs_failure_reason'] = 'The subscription ID is invalid';
     }
     // CHECK: Is the amount correct?
     $isPartialRefund = false;
     if ($isValid) {
         $mc_gross = $data['amount'];
         // Remember: the amount is in cents, e.g. 400 means 4.00 Euros
         $gross = (int) ($subscription->gross_amount * 100);
         $isValid = $gross - $mc_gross < 0.01;
         if (!$isValid) {
             $data['akeebasubs_failure_reason'] = 'Paid amount does not match the subscription amount';
         }
     }
     // CHECK: Is this transaction valid?
     // Log the IPN data
     $this->logIPN($data, $isValid, 'CALLBACK');
     // Fraud attempt? Do nothing more!
     if (!$isValid) {
         $level = F0FModel::getTmpInstance('Levels', 'AkeebasubsModel')->setId($subscription->akeebasubs_level_id)->getItem();
         $error_url = 'index.php?option=' . JRequest::getCmd('option') . '&view=level&slug=' . $level->slug . '&layout=' . JRequest::getCmd('layout', 'default');
         $error_url = JRoute::_($error_url, false);
         JFactory::getApplication()->redirect($error_url, $data['akeebasubs_failure_reason'], 'error');
         return false;
     }
     // ACTION: Initialise common variables
     if ($isValid) {
         $apiKey = $this->getPrivateKey();
         $apiEndpoint = 'https://api.paymill.de/v2/';
         $db = JFactory::getDbo();
     }
     // CHECK: Do we have a user already defined in PayMill?
     $user = JFactory::getUser($subscription->user_id);
     $clientsObject = new Services_Paymill_Clients($apiKey, $apiEndpoint);
     $filters = array('email' => $user->email);
     $clients = $clientsObject->get($filters);
     // ACTION: Get the client ID or create and save a new user in PayMill if necessary
     if (count($clients)) {
         $clientRecord = array_pop($clients);
     } else {
         $params = array('email' => $user->email, 'description' => $user->name . ' [' . $user->username . ']');
         try {
             $clientRecord = $clientsObject->create($params);
         } catch (Exception $exc) {
             $isValid = false;
             $params['akeebasubs_failure_reason'] = $exc->getMessage();
         }
         if (!array_key_exists('id', $clientRecord) || empty($clientRecord['id'])) {
             // Apparently the client creation failed
             $isValid = false;
             $params['akeebasubs_failure_reason'] = JText::_('PLG_AKPAYMENT_PAYMILL_ERROR_CLIENT');
         }
         // Log the user creation data
         $this->logIPN($data, $isValid, 'USER');
         // Fraud attempt? Do nothing more!
         if (!$isValid) {
             $level = F0FModel::getTmpInstance('Levels', 'AkeebasubsModel')->setId($subscription->akeebasubs_level_id)->getItem();
             $error_url = 'index.php?option=' . JRequest::getCmd('option') . '&view=level&slug=' . $level->slug . '&layout=' . JRequest::getCmd('layout', 'default');
             $error_url = JRoute::_($error_url, false);
             JFactory::getApplication()->redirect($error_url, $params['akeebasubs_failure_reason'], 'error');
             return false;
         }
     }
     $client = $clientRecord['id'];
     // CHECK: Do we already have a payment for this subscription?
     // -- Load the processor key from database. This prevents race conditions.
     $query = $db->getQuery(true)->select($db->qn('processor_key'))->from('#__akeebasubs_subscriptions')->where($db->qn('akeebasubs_subscription_id') . ' = ' . $db->q($subscription->akeebasubs_subscription_id));
     $db->setQuery($query);
     $payment_id = $db->loadResult();
     // ACTION: Create and save a new payment for this subscription if there is no payment or transaction yet
     if (substr($payment_id, 0, 4) != 'pay_' && substr($payment_id, 0, 5) != 'tran_') {
         $params = array('client' => $client, 'token' => $data['token']);
         $paymentsObject = new Services_Paymill_Payments($apiKey, $apiEndpoint);
         try {
             $creditcard = $paymentsObject->create($params);
         } catch (Exception $exc) {
             $isValid = false;
             $params['akeebasubs_failure_reason'] = $exc->getMessage();
         }
         if (!array_key_exists('id', $creditcard) || empty($creditcard['id'])) {
             // Apparently the credit card capture creation failed
             $isValid = false;
             $params['akeebasubs_failure_reason'] = JText::_('PLG_AKPAYMENT_PAYMILL_ERROR_CC') . '<br/>Tech info: <tt>' . htmlentities($creditcard['error']) . '</tt>';
         }
         // Log the payment creation data
         $this->logIPN($data, $isValid, 'PAYMENT');
         // Fraud attempt? Do nothing more!
         if (!$isValid) {
             $level = F0FModel::getTmpInstance('Levels', 'AkeebasubsModel')->setId($subscription->akeebasubs_level_id)->getItem();
             $error_url = 'index.php?option=' . JRequest::getCmd('option') . '&view=level&slug=' . $level->slug . '&layout=' . JRequest::getCmd('layout', 'default');
             $error_url = JRoute::_($error_url, false);
             JFactory::getApplication()->redirect($error_url, $params['akeebasubs_failure_reason'], 'error');
             return false;
         }
         $subscription->processor_key = $creditcard['id'];
         $payment_id = $creditcard['id'];
         // Save the payment information WITHOUT using the table (skips the plugins)
         // This prevents double payments from being recorded
         $oUpdate = (object) array('akeebasubs_subscription_id' => $subscription->akeebasubs_subscription_id, 'processor_key' => $subscription->processor_key, 'state' => 'P');
         JFactory::getDbo()->updateObject('#__akeebasubs_subscriptions', $oUpdate, 'akeebasubs_subscription_id');
     }
     // CHECK: Do we already have a transaction for this subscription?
     // -- Load the processor key from database. This prevents race conditions.
     $query = $db->getQuery(true)->select($db->qn('processor_key'))->from('#__akeebasubs_subscriptions')->where($db->qn('akeebasubs_subscription_id') . ' = ' . $db->q($subscription->akeebasubs_subscription_id));
     $db->setQuery($query);
     $payment_id = $db->loadResult();
     // ACTION: Create a transaction if necessary
     if (substr($payment_id, 0, 5) != 'tran_') {
         // First update the object with a fake transaction
         $subscription->processor_key = 'tran_in_progress';
         // Save the payment information WITHOUT using the table (skips the plugins)
         // This prevents double payments from being recorded
         $oUpdate = (object) array('akeebasubs_subscription_id' => $subscription->akeebasubs_subscription_id, 'processor_key' => $subscription->processor_key, 'state' => 'P');
         JFactory::getDbo()->updateObject('#__akeebasubs_subscriptions', $oUpdate, 'akeebasubs_subscription_id');
         // Create the transaction
         $params = array('amount' => $data['amount'], 'currency' => $data['currency'], 'client' => $client, 'payment' => $payment_id, 'description' => $data['description']);
         try {
             $transactionsObject = new Services_Paymill_Transactions($apiKey, $apiEndpoint);
             $transaction = $transactionsObject->create($params);
         } catch (Exception $exc) {
             $isValid = false;
             $params['akeebasubs_failure_reason'] = $exc->getMessage();
         }
         if (!array_key_exists('id', $transaction) || empty($transaction['id'])) {
             // Apparently the transaction creation failed
             $isValid = false;
             $params['akeebasubs_failure_reason'] = JText::_('PLG_AKPAYMENT_PAYMILL_ERROR_TRANS');
         }
         // Log the payment creation data
         $this->logIPN($data, $isValid, 'TRANSACTION');
         if (!$isValid) {
             $transaction_id = $payment_id;
         } else {
             $transaction_id = $transaction['id'];
         }
         // First update the object
         $subscription->processor_key = $transaction_id;
         // Save the payment information WITHOUT using the table (skips the plugins)
         // This prevents double payments from being recorded
         $oUpdate = (object) array('akeebasubs_subscription_id' => $subscription->akeebasubs_subscription_id, 'processor_key' => $subscription->processor_key);
         JFactory::getDbo()->updateObject('#__akeebasubs_subscriptions', $oUpdate, 'akeebasubs_subscription_id');
         // Fraud attempt? Do nothing more!
         if (!$isValid) {
             $level = F0FModel::getTmpInstance('Levels', 'AkeebasubsModel')->setId($subscription->akeebasubs_level_id)->getItem();
             $error_url = 'index.php?option=' . JRequest::getCmd('option') . '&view=level&slug=' . $level->slug . '&layout=' . JRequest::getCmd('layout', 'default');
             $error_url = JRoute::_($error_url, false);
             JFactory::getApplication()->redirect($error_url, $params['akeebasubs_failure_reason'], 'error');
             return false;
         }
     } else {
         // ACTION: If no transaction is necessary, show an error
         $level = F0FModel::getTmpInstance('Levels', 'AkeebasubsModel')->setId($subscription->akeebasubs_level_id)->getItem();
         $error_url = 'index.php?option=' . JRequest::getCmd('option') . '&view=level&slug=' . $level->slug . '&layout=' . JRequest::getCmd('layout', 'default');
         $error_url = JRoute::_($error_url, false);
         JFactory::getApplication()->redirect($error_url, 'Cannot process the transaction twice. Wait to receive your subscription confirmation email and do not retry submitting the payment form again.', 'error');
         return false;
     }
     if ($isValid) {
         if ($this->params->get('sandbox') == $transaction['livemode']) {
             $isValid = false;
             $data['akeebasubs_failure_reason'] = "Transaction done in wrong mode.";
         }
     }
     // Payment status
     // Check the payment_status
     switch ($transaction['status']) {
         case 'closed':
         case 'partial_refunded':
             $newStatus = 'C';
             break;
         case 'open':
         case 'pending':
         case 'preauthorize':
             $newStatus = 'P';
             break;
         case 'failed':
         case 'refunded':
             $newStatus = 'X';
             break;
     }
     // Update subscription status (this also automatically calls the plugins)
     $updates = array('akeebasubs_subscription_id' => $id, 'processor_key' => $transaction_id, 'state' => $newStatus, 'enabled' => 0);
     JLoader::import('joomla.utilities.date');
     if ($newStatus == 'C') {
         $this->fixDates($subscription, $updates);
     }
     $subscription->save($updates);
     // Run the onAKAfterPaymentCallback events
     JLoader::import('joomla.plugin.helper');
     JPluginHelper::importPlugin('akeebasubs');
     $app = JFactory::getApplication();
     $jResponse = $app->triggerEvent('onAKAfterPaymentCallback', array($subscription));
     // Redirect the user to the "thank you" page
     $level = F0FModel::getTmpInstance('Levels', 'AkeebasubsModel')->setId($subscription->akeebasubs_level_id)->getItem();
     $thankyouUrl = JRoute::_('index.php?option=com_akeebasubs&view=message&slug=' . $level->slug . '&layout=order&subid=' . $subscription->akeebasubs_subscription_id, false);
     JFactory::getApplication()->redirect($thankyouUrl);
     return true;
 }
示例#7
0
 /**
  * Update paymill client data if necessary
  *
  * @param array $db_data
  */
 private function updatePaymillClient($db_data)
 {
     if ($db_data && $this->validateClient($db_data['clientId'])) {
         $client_object = new Services_Paymill_Clients(Configuration::get('PIGMBH_PAYMILL_PRIVATEKEY'), 'https://api.paymill.com/v2/');
         $old_client = $client_object->getOne($db_data['clientId']);
         if ($this->context->customer->email !== $old_client['email']) {
             $client_object->update(array('id' => $db_data['clientId'], 'email' => $this->context->customer->email));
         }
     }
 }
    }
}
if (Configuration::get('PIGMBH_PAYMILL_FASTCHECKOUT')) {
    if (Tools::getValue('payment') == 'creditcard') {
        $sql = 'SELECT `clientId`,`paymentId` FROM `pigmbh_paymill_creditcard_userdata` WHERE `userId`=' . $cart->id_customer;
    } elseif (Tools::getValue('payment') == 'debit') {
        $sql = 'SELECT `clientId`,`paymentId` FROM `pigmbh_paymill_directdebit_userdata` WHERE `userId`=' . $cart->id_customer;
    }
    try {
        $dbData = $db->getRow($sql);
    } catch (Exception $exception) {
        $dbData = false;
    }
}
if ($dbData && validateClient($dbData['clientId'])) {
    $clientObject = new Services_Paymill_Clients(Configuration::get('PIGMBH_PAYMILL_PRIVATEKEY'), "https://api.paymill.com/v2/");
    $oldClient = $clientObject->getOne($dbData['clientId']);
    if ($customer["email"] !== $oldClient['email']) {
        $clientObject->update(array('id' => $dbData['clientId'], 'email' => $customer["email"]));
    }
}
$payment = false;
if ($dbData && validatePayment($dbData['paymentId'])) {
    $paymentObject = new Services_Paymill_Payments(Configuration::get('PIGMBH_PAYMILL_PRIVATEKEY'), "https://api.paymill.com/v2/");
    $paymentResponse = $paymentObject->getOne($dbData['paymentId']);
    if ($paymentResponse['id'] === $dbData['paymentId']) {
        $payment = $dbData['paymentId'] !== '' ? $paymentResponse : false;
    }
    $payment['expire_date'] = null;
    if (isset($payment['expire_month'])) {
        $payment['expire_month'] = $payment['expire_month'] <= 9 ? '0' . $payment['expire_month'] : $payment['expire_month'];
 /**
  * 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)));
 }
 /**
  * Handle paymill client update if exist
  * 
  * @param string $clientId
  */
 private function _existingClientHandling($clientId)
 {
     if (!empty($clientId)) {
         $clients = new Services_Paymill_Clients(trim(Mage::helper('paymill/optionHelper')->getPrivateKey()), Mage::helper('paymill')->getApiUrl());
         $quote = Mage::getSingleton('checkout/session')->getQuote();
         $client = $clients->getOne($clientId);
         if (Mage::helper("paymill/customerHelper")->getCustomerEmail($quote) !== $client['email']) {
             $clients->update(array('id' => $clientId, 'email' => Mage::helper("paymill/customerHelper")->getCustomerEmail($quote)));
         }
     }
 }
示例#11
0
 /**
  * Returns the client id of the chosen user
  *
  * @param string $userId
  *
  * @return String
  */
 public function getPaymillClientId($userId)
 {
     $sql = "SELECT paymill_client_id\n                FROM s_user_attributes a, s_user u\n                WHERE u.id = a.userID\n                AND u.id = ?\n                AND a.paymill_client_id IS NOT NULL";
     try {
         require_once dirname(__FILE__) . '/../lib/Services/Paymill/Clients.php';
         $swConfig = Shopware()->Plugins()->Frontend()->PaymPaymentCreditcard()->Config();
         $clientId = Shopware()->Db()->fetchOne($sql, array($userId));
         $client = new Services_Paymill_Clients(trim($swConfig->get("privateKey")), 'https://api.paymill.com/v2/');
         $clientData = $client->getOne($clientId);
         if (!isset($clientData['id'])) {
             $clientId = "";
             $this->setPaymillClientId($userId, "");
         }
     } catch (Exception $exception) {
         $clientId = "";
     }
     return $clientId ? $clientId : "";
 }