/**
  * Return payment data if available
  * 
  * @param string $code
  * @return array
  */
 public function getPaymentData($code)
 {
     $payment = array();
     if ($this->hasData($code)) {
         $payments = new Services_Paymill_Payments(Mage::helper('paymill/optionHelper')->getPrivateKey(), Mage::helper('paymill')->getApiUrl());
         $payment = $payments->getOne($this->getPaymentId($code));
         if (!array_key_exists('last4', $payment) && !array_key_exists('code', $payment)) {
             $payment = array();
         }
     }
     return $payment;
 }
Exemplo n.º 2
0
 /**
  * Update paymill payment data if necessary
  *
  * @param array $db_data
  * @return boolean|array
  */
 private function updatePaymillPayment($db_data)
 {
     $payment = false;
     if ($db_data && $this->validatePayment($db_data['paymentId'])) {
         $payment_object = new Services_Paymill_Payments(Configuration::get('PIGMBH_PAYMILL_PRIVATEKEY'), 'https://api.paymill.com/v2/');
         $payment_response = $payment_object->getOne($db_data['paymentId']);
         if ($payment_response['id'] === $db_data['paymentId']) {
             $payment = $db_data['paymentId'] !== '' ? $payment_response : false;
         }
         $payment['expire_date'] = null;
         if (isset($payment['expire_month'])) {
             $payment['expire_month'] = $payment['expire_month'] <= 9 ? '0' . $payment['expire_month'] : $payment['expire_month'];
             $payment['expire_date'] = $payment['expire_month'] . '/' . $payment['expire_year'];
         }
     }
     return $payment;
 }
 public function testCreateDebit()
 {
     $payment = $this->_payments->create(array("type" => "debit", "code" => "12345678", "account" => "37465234", "holder" => "Max Kunde"));
     $this->assertInternalType('array', $payment);
     $this->assertArrayHasKey("id", $payment);
     $this->assertEquals("debit", $payment["type"]);
     $this->assertEquals($payment['code'], '12345678');
     $this->assertEquals($payment['holder'], 'Max Kunde');
     $this->assertEquals($payment['account'], '****5234');
     $paymentId = $payment['id'];
     $params = array('amount' => 999, 'currency' => 'eur', 'description' => 'Deuterium Cartridge', 'payment' => $paymentId);
     $transaction = $this->_transaction->create($params);
     $this->assertInternalType('array', $transaction);
     $this->assertArrayHasKey('id', $transaction);
     $this->assertNotEmpty($transaction['id']);
     $this->assertEquals($transaction['amount'], 999);
     $this->assertEquals($transaction['description'], 'Deuterium Cartridge');
     $transactionId = $transaction['id'];
     return $transactionId;
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 public function index()
 {
     global $config;
     $this->baseUrl = preg_replace("/\\/index\\.php/", "", $this->request->server['SCRIPT_NAME']);
     $this->load->model('checkout/order');
     $this->order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     $amount = $this->currency->format($this->order_info['total'], $this->order_info['currency_code'], false, false);
     $this->data['paymill_amount'] = $amount;
     $this->data['paymill_currency'] = $this->order_info['currency_code'];
     $this->data['paymill_fullname'] = $this->order_info['firstname'] . ' ' . $this->order_info['lastname'];
     $this->data['paymill_css'] = $this->baseUrl . '/catalog/view/theme/default/stylesheet/paymill_styles.css';
     $this->data['paymill_iframe_css'] = $this->baseUrl . '/catalog/view/theme/default/stylesheet/paymill_iframe_styles.css';
     $this->data['paymill_image_folder'] = $this->baseUrl . '/catalog/view/theme/default/image/payment';
     $this->data['paymill_js'] = $this->baseUrl . '/catalog/view/javascript/paymill/';
     $this->data['paymill_publickey'] = trim($this->config->get($this->getPaymentName() . '_publickey'));
     $this->data['paymill_debugging'] = $this->config->get($this->getPaymentName() . '_debugging');
     $this->data['paymill_buttonSolution'] = $this->config->get($this->getPaymentName() . '_buttonSolution');
     $this->data['button_confirm'] = $this->language->get('button_confirm');
     $this->language->load('payment/' . $this->getPaymentName());
     $this->data['paymill_accountholder'] = $this->language->get('paymill_accountholder');
     $this->data['paymill_accountnumber'] = $this->language->get('paymill_accountnumber');
     $this->data['paymill_banknumber'] = $this->language->get('paymill_banknumber');
     $this->data['paymill_iban'] = $this->language->get('paymill_iban');
     $this->data['paymill_bic'] = $this->language->get('paymill_bic');
     $this->data['paymill_cardholder'] = $this->language->get('paymill_cardholder');
     $this->data['paymill_cardnumber'] = $this->language->get('paymill_cardnumber');
     $this->data['paymill_cvc'] = $this->language->get('paymill_cvc');
     $this->data['paymill_expirydate'] = $this->language->get('paymill_expirydate');
     $this->data['paymill_description'] = $this->language->get('paymill_description');
     $this->data['paymill_paymilllabel_cc'] = $this->language->get('paymill_paymilllabel_cc');
     $this->data['paymill_paymilllabel_elv'] = $this->language->get('paymill_paymilllabel_elv');
     $this->data['paymill_icon_text'] = $this->language->get('paymill_icon_text');
     $this->data['paymill_error'] = isset($this->session->data['error_message']) ? $this->session->data['error_message'] : null;
     $this->data['paymill_javascript_error'] = $this->language->get('error_javascript');
     $this->data['paymill_translation_fields'] = array('cardholder' => $this->language->get('paymill_cardholder'), 'cardnumber' => $this->language->get('paymill_cardnumber'), 'expire_date' => $this->language->get('paymill_expirydate'), 'cvc' => $this->language->get('paymill_cvc'), 'changebutton' => $this->language->get('paymill_change_button'), 'lang' => $this->language->get('paymill_lang'));
     $this->data['paymill_icon_visa'] = $this->config->get($this->getPaymentName() . '_icon_visa');
     $this->data['paymill_icon_master'] = $this->config->get($this->getPaymentName() . '_icon_master');
     $this->data['paymill_icon_amex'] = $this->config->get($this->getPaymentName() . '_icon_amex');
     $this->data['paymill_icon_jcb'] = $this->config->get($this->getPaymentName() . '_icon_jcb');
     $this->data['paymill_icon_maestro'] = $this->config->get($this->getPaymentName() . '_icon_maestro');
     $this->data['paymill_icon_diners_club'] = $this->config->get($this->getPaymentName() . '_icon_diners_club');
     $this->data['paymill_icon_discover'] = $this->config->get($this->getPaymentName() . '_icon_discover');
     $this->data['paymill_icon_china_unionpay'] = $this->config->get($this->getPaymentName() . '_icon_china_unionpay');
     $this->data['paymill_icon_dankort'] = $this->config->get($this->getPaymentName() . '_icon_dankort');
     $this->data['paymill_icon_carta_si'] = $this->config->get($this->getPaymentName() . '_icon_carta_si');
     $this->data['paymill_icon_carte_bleue'] = $this->config->get($this->getPaymentName() . '_icon_carte_bleue');
     $this->data['paymill_icon'] = $this->showCreditcardIcons();
     $table = $this->getDatabaseName();
     $payment = null;
     if ($this->customer->getId() != null) {
         $row = $this->db->query("SELECT `paymentID` FROM {$table} WHERE `userId`=" . $this->customer->getId());
         if (!empty($row->row['paymentID'])) {
             $privateKey = trim($this->config->get($this->getPaymentName() . '_privatekey'));
             $paymentObject = new Services_Paymill_Payments($privateKey, 'https://api.paymill.com/v2/');
             $payment = $paymentObject->getOne($row->row['paymentID']);
         }
     }
     if (isset($payment['expire_month'])) {
         $payment['expire_month'] = $payment['expire_month'] <= 9 ? '0' . $payment['expire_month'] : $payment['expire_month'];
         $payment['expire_date'] = $payment['expire_month'] . "/" . $payment['expire_year'];
     } else {
         $payment['expire_date'] = null;
     }
     $this->data['paymill_prefilled'] = $payment;
     if ($this->getPaymentName() == 'paymillcreditcard') {
         $this->data['paymill_form_action'] = "index.php?route=payment/paymillcreditcard/confirm";
     } elseif ($this->getPaymentName() == 'paymilldirectdebit') {
         $this->data['paymill_form_action'] = "index.php?route=payment/paymilldirectdebit/confirm";
     }
     $this->data['paymill_activepayment'] = $this->getPaymentName();
     if ($this->getPaymentName() == "paymillcreditcard" && !$this->config->get($this->getPaymentName() . '_pci')) {
         $this->data['paymill_load_frame_fastcheckout'] = false;
         if (isset($payment['last4']) && isset($payment['expire_date'])) {
             $this->data['paymill_load_frame_fastcheckout'] = true;
         }
         $this->template = 'default/template/payment/paymill_pci_frame.tpl';
         if (file_exists($this->config->get('config_template') . '/template/payment/paymill_frame.tpl')) {
             $this->template = $this->config->get('config_template') . '/template/payment/paymill_frame.tpl';
         }
     } else {
         $this->template = 'default/template/payment/paymill.tpl';
         if (file_exists($this->config->get('config_template') . '/template/payment/paymill.tpl')) {
             $this->template = $this->config->get('config_template') . '/template/payment/paymill.tpl';
         }
     }
     $this->render();
 }
 /**
  * Tests Services_Paymill_Payments->delete()
  * @depends testCreateDebit
  */
 public function testDeleteDebit($paymentId)
 {
     $payment = $this->_payments->delete($paymentId);
     $this->assertInternalType('array', $payment);
     $this->assertCount(0, $payment);
 }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
0
    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'];
        $payment['expire_date'] = $payment['expire_month'] . "/" . $payment['expire_year'];
    }
}
$currency = Currency::getCurrency((int) $cart->id_currency);
$_SESSION['pigmbhPaymill']['authorizedAmount'] = (int) round($cart->getOrderTotal(true, Cart::BOTH) * 100);
$brands = array();
foreach (json_decode(Configuration::get('PIGMBH_PAYMILL_ACCEPTED_BRANDS'), true) as $brandKey => $brandValue) {
    $brands[str_replace('-', '', $brandKey)] = $brandValue;
Exemplo n.º 9
0
 /**
  * Returns the payment id of the chosen payment for the given user
  *
  * @param string $paymentShortTag Either "cc" or "elv" depending of the desired payment method
  * @param string $userId
  *
  * @return mixed
  */
 public function getPaymillPaymentId($paymentShortTag, $userId)
 {
     $sql = null;
     switch ($paymentShortTag) {
         case "cc":
         case "paymillcc":
             $sql = "SELECT paymill_payment_id_cc\n                    FROM s_user_attributes a, s_user u\n                    WHERE u.id = a.userID\n                    AND u.id = ?\n                    AND a.paymill_payment_id_cc IS NOT NULL";
             break;
         case "elv":
         case "paymilldebit":
             $sql = "SELECT paymill_payment_id_elv\n                    FROM s_user_attributes a, s_user u\n                    WHERE u.id = a.userID\n                    AND u.id = ?\n                    AND a.paymill_payment_id_elv IS NOT NULL";
             break;
     }
     try {
         require_once dirname(__FILE__) . '/../lib/Services/Paymill/Payments.php';
         $swConfig = Shopware()->Plugins()->Frontend()->PaymPaymentCreditcard()->Config();
         $paymentId = Shopware()->Db()->fetchOne($sql, array($userId));
         $payment = new Services_Paymill_Payments(trim($swConfig->get("privateKey")), 'https://api.paymill.com/v2/');
         $paymentData = $payment->getOne($paymentId);
         if (!isset($paymentData['id'])) {
             $paymentId = "";
         }
         if (isset($paymentData['client'])) {
             if ($paymentData['client'] !== $this->getPaymillClientId($userId)) {
                 $paymentId = "";
             }
         }
     } catch (Exception $exception) {
         $paymentId = "";
     }
     return $paymentId ? $paymentId : "";
 }